You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by mb...@apache.org on 2007/05/22 19:06:45 UTC

svn commit: r540648 - in /incubator/uima/uimaj/trunk/uimaj-core/src: main/java/org/apache/uima/pear/tools/ main/resources/org/apache/uima/pear/ test/java/org/apache/uima/pear/util/

Author: mbaessler
Date: Tue May 22 10:06:43 2007
New Revision: 540648

URL: http://svn.apache.org/viewvc?view=rev&rev=540648
Log:
UIMA-411

change the PEAR verification implementation to use the UIMA extension classpath. Now it
is never necessary to create a new process to do the PEAR verification, so no classpath and
datapath must be constructed.

To do the modification it was necessary to change some of the signitures of public methods in
InstallationController, InstallationTester and LocalInstallationAgent. But I think these methods
were not called from an application. I think most of the users use the common public method on the
InstallationController that are described in the documentation and these methods are unchanged.

JIRA ticket https://issues.apache.org/jira/browse/UIMA-411

Added:
    incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/pear/util/TestPearInstallationVerification.java
Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/InstallationController.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/InstallationTester.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/LocalInstallationAgent.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/pear/pear_messages.properties

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/InstallationController.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/InstallationController.java?view=diff&rev=540648&r1=540647&r2=540648
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/InstallationController.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/InstallationController.java Tue May 22 10:06:43 2007
@@ -19,7 +19,6 @@
 
 package org.apache.uima.pear.tools;
 
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -27,7 +26,6 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -44,12 +42,9 @@
 import java.util.jar.JarFile;
 
 import org.apache.uima.UIMAFramework;
-import org.apache.uima.analysis_engine.impl.PearAnalysisEngineWrapper;
-import org.apache.uima.internal.util.SystemEnvReader;
 import org.apache.uima.pear.util.FileUtil;
 import org.apache.uima.pear.util.MessageRouter;
 import org.apache.uima.pear.util.StringUtil;
-import org.apache.uima.resource.Parameter;
 import org.apache.uima.resource.PearSpecifier;
 import org.xml.sax.SAXException;
 
@@ -188,10 +183,44 @@
    * 'serviceability' verification test.
    */
   public static class TestStatus {
-    // public attributes
-    public int retCode;
 
-    public String message;
+    final public static int TEST_SUCCESSFUL = 0;
+
+    final public static int TEST_NOT_SUCCESSFUL = -1;
+
+    private int retCode = TEST_NOT_SUCCESSFUL;
+
+    private String message = null;
+
+    /**
+     * @return the message
+     */
+    public String getMessage() {
+      return this.message;
+    }
+
+    /**
+     * @param message
+     *          the message to set
+     */
+    public void setMessage(String message) {
+      this.message = message;
+    }
+
+    /**
+     * @return the retCode
+     */
+    public int getRetCode() {
+      return this.retCode;
+    }
+
+    /**
+     * @param retCode
+     *          the retCode to set
+     */
+    public void setRetCode(int retCode) {
+      this.retCode = retCode;
+    }
   }
 
   // Component installation status values
@@ -212,6 +241,8 @@
   // Verification application class
   protected static final String INSTALLATION_TESTER_APP = "org.apache.uima.pear.tools.InstallationTester";
 
+  private static final String PEAR_MESSAGE_RESOURCE_BUNDLE = "org.apache.uima.pear.pear_messages";
+
   // Package configuration file
   public static final String PACKAGE_CONFIG_FILE = "metadata/PEAR.properties";
 
@@ -236,7 +267,7 @@
 
   // file generated at the end of local installation
   public static final String SET_ENV_FILE = "metadata/setenv.txt";
-  
+
   public static final String PEAR_DESC_FILE_POSTFIX = "_pear.xml";
 
   // UIMA constants
@@ -259,7 +290,7 @@
   protected static final String LOCAL_OPT = "-local";
 
   protected static final String INSTALL_IN_ROOT_OPT = "-root";
-  
+
   // static attributes
   private static boolean __inLocalMode = false;
 
@@ -635,153 +666,10 @@
   }
 
   /**
-   * Creates command for running the installation test for a given installed component, including
-   * possible separately installed delegate components, runs the test, and returns the
-   * <code>TestStatus</code> object with the test results.
-   * 
-   * @param mainRootDirPath
-   *          The given main component root directory path.
-   * @param mainInsD
-   *          The given main component <code>InstallationDescriptor</code> object.
-   * @param mainDescPath
-   *          The given main component XML descriptor file path.
-   * @param compClassPath
-   *          The given CLASSPATH for the installed component, including CLASSPATH for possible
-   *          delegate components.
-   * @param javaLibPath
-   *          The given PATH for the installed component, including PATH for possible delegate
-   *          components.
-   * @param tableOfEnvVars
-   *          The given table of required environment variables for the installed component,
-   *          including possible delegate components.
-   * @param uimaClassPath
-   *          The required UIMA CLASSPATH.
-   * @return The instance of the <code>TestStatus</code> class that contains the return code and
-   *         possible error message of the given command.
-   * @throws IOException
-   *           if any I/O error occurred.
-   */
-  protected static TestStatus deployInstallationVerificationTest(String mainRootDirPath,
-          InstallationDescriptor mainInsD, String mainDescPath, String compClassPath,
-          String javaLibPath, Properties tableOfEnvVars, String uimaClassPath) throws IOException {
-    // build command array to run installation tester app.
-    ArrayList cmdArrayList = new ArrayList();
-    StringBuffer cmdBuffer = new StringBuffer();
-    // set Java executable path - OS dependent
-    String osName = System.getProperty("os.name");
-    String javaHome = System.getProperty("java.home");
-    String javaExeName = (osName.indexOf("Windows") >= 0) ? "java.exe" : "java";
-    String javaExePath = null;
-    File javaExeFile = null;
-    // 1st - try in 'java.home'/bin folder
-    javaExePath = javaHome + java.io.File.separator + "bin" + java.io.File.separator + javaExeName;
-    javaExeFile = new File(javaExePath);
-    if (!javaExeFile.isFile()) {
-      // 2nd - try in 'java.home'/jre/bin folder
-      javaExePath = javaHome + java.io.File.separator + "jre" + java.io.File.separator + "bin"
-              + java.io.File.separator + javaExeName;
-      javaExeFile = new java.io.File(javaExePath);
-    }
-    cmdArrayList.add(javaExeFile.getAbsolutePath());
-    // specify heap size
-    cmdArrayList.add("-Xmx512M");
-    // specify classpath
-    cmdArrayList.add("-cp");
-    cmdBuffer.setLength(0);
-    cmdBuffer.append(compClassPath);
-    cmdBuffer.append(File.pathSeparatorChar);
-    cmdBuffer.append(uimaClassPath);
-    cmdArrayList.add(cmdBuffer.toString());
-    // specify java.library.path
-    if (javaLibPath.length() > 0) {
-      cmdBuffer.setLength(0);
-      cmdBuffer.append("-Djava.library.path=");
-      cmdBuffer.append(javaLibPath);
-      cmdArrayList.add(cmdBuffer.toString());
-    }
-    // for 'network' AEs: add network parameters
-    if (mainInsD.getMainComponentDeployment().equals(InstallationDescriptorHandler.NETWORK_TAG)) {
-      String[] networkParams = buildArrayOfNetworkParams(mainInsD);
-      for (int i = 0; i < networkParams.length; i++)
-        cmdArrayList.add(networkParams[i]);
-    }
-    // specify env vars and create array
-    ArrayList envArrayList = new ArrayList();
-    // get global system env vars
-    Properties tableOfSysEnvVars = new Properties();
-    try {
-      tableOfSysEnvVars = SystemEnvReader.getEnvVars();
-    } catch (Throwable err) {
-      throw new IOException("system environment error: " + err.toString());
-    }
-    // add local CLASSPATH, PATH and LD_LIBRARY_PATH to system env
-    String localClasspath = tableOfEnvVars.getProperty("CLASSPATH");
-    if (localClasspath != null && localClasspath.length() > 0) {
-      if (addToSystemEnvTable(tableOfSysEnvVars, "CLASSPATH", localClasspath))
-        tableOfEnvVars.remove("CLASSPATH");
-    }
-    String localPath = tableOfEnvVars.getProperty("PATH");
-    if (localPath != null && localPath.length() > 0) {
-      if (addToSystemEnvTable(tableOfSysEnvVars, "PATH", localPath))
-        tableOfEnvVars.remove("PATH");
-    }
-    String localLdlPath = tableOfEnvVars.getProperty("LD_LIBRARY_PATH");
-    if (localLdlPath != null && localLdlPath.length() > 0) {
-      if (addToSystemEnvTable(tableOfSysEnvVars, "LD_LIBRARY_PATH", localLdlPath))
-        tableOfEnvVars.remove("LD_LIBRARY_PATH");
-    }
-    // add system env vars to the list
-    StringBuffer envBuffer = new StringBuffer();
-    Enumeration sysKeys = tableOfSysEnvVars.keys();
-    while (sysKeys.hasMoreElements()) {
-      String key = (String) sysKeys.nextElement();
-      String value = tableOfSysEnvVars.getProperty(key);
-      if (value.length() > 0) {
-        envBuffer.setLength(0);
-        envBuffer.append(key);
-        envBuffer.append('=');
-        envBuffer.append(value);
-        envArrayList.add(envBuffer.toString());
-      }
-    }
-    // add the rest of local env vars
-    Enumeration envKeys = tableOfEnvVars.keys();
-    while (envKeys.hasMoreElements()) {
-      String key = (String) envKeys.nextElement();
-      String value = tableOfEnvVars.getProperty(key);
-      if (value.length() > 0) {
-        envBuffer.setLength(0);
-        envBuffer.append(key);
-        envBuffer.append('=');
-        envBuffer.append(value);
-        envArrayList.add(envBuffer.toString());
-        cmdBuffer.setLength(0);
-        cmdBuffer.append("-D");
-        cmdBuffer.append(envBuffer.toString());
-        cmdArrayList.add(cmdBuffer.toString());
-      }
-    }
-    // specify application class and its args
-    cmdArrayList.add(INSTALLATION_TESTER_APP);
-    cmdBuffer.setLength(0);
-    cmdBuffer.append(mainDescPath);
-    cmdArrayList.add(cmdBuffer.toString());
-    // run installation verification app.
-    String[] cmdArray = new String[cmdArrayList.size()];
-    cmdArrayList.toArray(cmdArray);
-    String[] envArray = new String[envArrayList.size()];
-    envArrayList.toArray(envArray);
-    File workDir = new File(mainRootDirPath);
-    return runInstallationVerificationTest(cmdArray, envArray, workDir);
-  }
-
-  /**
    * Extracts files with a given extension from a given PEAR file into a given target directory. If
    * the given filename extension is <code>null</code>, extracts all the files from a given PEAR
    * file. Returns the path to the new component root directory.
    * 
-   * @param componentId
-   *          The given component ID.
    * @param pearFileLocation
    *          The given PEAR file location.
    * @param fileExt
@@ -792,9 +680,9 @@
    * @throws IOException
    *           if any I/O exception occurred.
    */
-  public static String extractFilesFromPEARFile(String componentId, String pearFileLocation,
-          String fileExt, File targetDir) throws IOException {
-    return extractFilesFromPEARFile(componentId, pearFileLocation, fileExt, targetDir, null);
+  public static String extractFilesFromPEARFile(String pearFileLocation, String fileExt,
+          File targetDir) throws IOException {
+    return extractFilesFromPEARFile(pearFileLocation, fileExt, targetDir, null);
   }
 
   /**
@@ -815,8 +703,8 @@
    * @return The path to the new component root directory.
    * @throws IOException if any I/O exception occurred.
    */
-  protected static String extractFilesFromPEARFile(String componentId, String pearFileLocation,
-          String fileExt, File targetDir, InstallationController controller) throws IOException {
+  protected static String extractFilesFromPEARFile(String pearFileLocation, String fileExt,
+          File targetDir, InstallationController controller) throws IOException {
     // get PEAR file size
     long fileSize = FileUtil.getFileSize(pearFileLocation);
     // create root directory
@@ -884,8 +772,6 @@
    * Extracts all files of a given component from a given PEAR file into a given target directory.
    * Returns the path to the new component root directory.
    * 
-   * @param componentId
-   *          The given component ID.
    * @param pearFileLocation
    *          The given PEAR file location.
    * @param installationDir
@@ -894,9 +780,9 @@
    * @throws IOException
    *           if any I/O exception occurred.
    */
-  public static String extractPEARFile(String componentId, String pearFileLocation,
-          File installationDir) throws IOException {
-    return extractFilesFromPEARFile(componentId, pearFileLocation, null, installationDir);
+  public static String extractPEARFile(String pearFileLocation, File installationDir)
+          throws IOException {
+    return extractFilesFromPEARFile(pearFileLocation, null, installationDir);
   }
 
   /**
@@ -915,10 +801,9 @@
    * @return The path to the new component root directory.
    * @throws IOException if any I/O exception occurred.
    */
-  protected static String extractPEARFile(String componentId, String pearFileLocation,
-          File installationDir, InstallationController controller) throws IOException {
-    return extractFilesFromPEARFile(componentId, pearFileLocation, null, installationDir,
-            controller);
+  protected static String extractPEARFile(String pearFileLocation, File installationDir,
+          InstallationController controller) throws IOException {
+    return extractFilesFromPEARFile(pearFileLocation, null, installationDir, controller);
   }
 
   /**
@@ -959,6 +844,7 @@
     try {
       hostAddress = InetAddress.getLocalHost().getHostAddress();
     } catch (Exception e) {
+      // in case of errors use localhost IP address
     }
     return hostAddress;
   } // end of getHostIpAddress() method
@@ -1131,63 +1017,6 @@
   }
 
   /**
-   * Runs the installation test executing a given command. Sets the attributes of the returned
-   * <code>TestStatus</code> object.
-   * 
-   * @param cmdArray
-   *          The array of strings that represents the given command to be executed.
-   * @param envArray
-   *          The array of environment variables settings - (key=value) pairs.
-   * @param workDir
-   *          The working directory where the installation test needs to be run.
-   * @return The instance of the <code>TestStatus</code> class that contains the return code and
-   *         possible error message of the given command.
-   * @throws IOException
-   *           if any I/O error occurred.
-   */
-  protected static TestStatus runInstallationVerificationTest(String[] cmdArray, String[] envArray,
-          File workDir) throws IOException {
-
-    if (System.getProperty("DEBUG") != null) {
-      System.out.println(">>> DBG: command array => ");
-      for (int i = 0; i < cmdArray.length; i++)
-        System.out.println("\t[" + i + "]=" + cmdArray[i]);
-      System.out.println(">>> DBG: env array => ");
-      for (int i = 0; i < envArray.length; i++)
-        System.out.println("\t" + envArray[i]);
-      System.out.println(">>> DBG: working dir => ");
-      System.out.println("\t" + workDir.getAbsolutePath());
-    }
-    BufferedReader errReader = null;
-    TestStatus status = new TestStatus();
-    try {
-      // run specified command with specified env.vars as a separate process
-      Process process = Runtime.getRuntime().exec(cmdArray, envArray, workDir);
-      // get error message (if exists)
-      errReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
-      StringWriter msgBuffer = new StringWriter();
-      PrintWriter msgWriter = new PrintWriter(msgBuffer);
-      String line;
-      while ((line = errReader.readLine()) != null)
-        msgWriter.println(line);
-      try {
-        status.retCode = process.waitFor();
-      } catch (InterruptedException e) {
-        
-      }
-      status.message = msgBuffer.toString();
-    } finally {
-      if (errReader != null) {
-        try {
-          errReader.close();
-        } catch (Exception e) {
-        }
-      }
-    }
-    return status;
-  }
-
-  /**
    * Switches between the 'local' and 'DB' modes, depending on a given <code>boolean</code> flag.
    * 
    * @param inLocalMode
@@ -1199,69 +1028,48 @@
   }
 
   /**
-   * Creates command for running the installation test for a given installed component, including
-   * possible separately installed delegate components, runs the test, and returns the
-   * <code>TestStatus</code> object with the test results. If a given table of separately
-   * installed delegate components is not empty, adds environment variables for the specified
-   * delegate components to the test process environment.
+   * Runs the installation test for a given installed pear component, and returns the
+   * <code>TestStatus</code> object with the test results.
    * 
-   * @param controller
-   *          The given active <code>InstallationController</code> object.
-   * @param uimaHomePath
-   *          The UIMA_HOME directory path.
+   * @param pkgBrowser
+   *          The given package borwser object of the installed pear package.
    * @return The <code>TestStatus</code> object that contains the return code and possible error
    *         message of the test.
    */
-  public static synchronized TestStatus verifyComponentInstallation(
-          InstallationController controller, String uimaHomePath) {
+  public static synchronized TestStatus verifyComponentInstallation(PackageBrowser pkgBrowser) {
     try {
-      // check input parameters
-      if (controller._insdObject == null)
-        throw new RuntimeException("null installation descriptor");
-      InstallationDescriptor mainInsD = controller._insdObject;
-      String mainRootDirPath = mainInsD.getMainComponentRoot();
-      if (mainRootDirPath == null)
-        throw new RuntimeException("main root directory not specified");
-      String mainDescPath = mainInsD.getMainComponentDesc();
-      if (mainDescPath == null)
-        throw new RuntimeException("main descriptor path not specified");
-
-      String uimaClassPath = null;
-      if (uimaHomePath == null) {
-        // build UIMA classpath using application class path
-        uimaClassPath = System.getProperty("java.class.path", null);
-      } else {
-        // build UIMA classpath using UIMA_HOME env variable
-        uimaClassPath = buildUIMAClassPath(uimaHomePath);
-      }
-      if (uimaClassPath == null) {
-        throw new RuntimeException(UIMA_HOME_ENV + " variable not specified");
+      // check package browser parameters
+      if (pkgBrowser != null) {
+        if (pkgBrowser.getInstallationDescriptor() == null) {
+          throw new PackageInstallerException(PEAR_MESSAGE_RESOURCE_BUNDLE,
+                  "installation_verification_install_desc_not_available");
+        }
+        if (pkgBrowser.getInstallationDescriptor().getMainComponentDesc() == null) {
+          throw new PackageInstallerException(PEAR_MESSAGE_RESOURCE_BUNDLE,
+                  "installation_verification_main_desc_not_available", new Object[] { pkgBrowser
+                          .getInstallationDescriptor().getMainComponentId() });
+        }
+        if (pkgBrowser.getInstallationDescriptor().getMainComponentRoot() == null) {
+          throw new PackageInstallerException(PEAR_MESSAGE_RESOURCE_BUNDLE,
+                  "installation_verification_main_root_not_available", new Object[] { pkgBrowser
+                          .getInstallationDescriptor().getMainComponentId() });
+        }
       }
 
-      // build component classpath, including dlg components
-      String compClassPath = controller.buildComponentClassPath();
-
-      // set java.library.path, including dlg components
-      String javaLibPath = controller.buildComponentPath();
-      // set other required env vars
-      Properties tableOfEnvVars = controller.buildTableOfEnvVars();
-      // add CLASSPATH, PATH and LD_LIBRARY_PATH to the table of env.vars
-      if (compClassPath.length() > 0)
-        tableOfEnvVars.setProperty("CLASSPATH", compClassPath);
-      if (javaLibPath.length() > 0) {
-        tableOfEnvVars.setProperty("PATH", javaLibPath);
-        tableOfEnvVars.setProperty("LD_LIBRARY_PATH", javaLibPath);
-      }
-      return deployInstallationVerificationTest(mainRootDirPath, mainInsD, mainDescPath,
-              compClassPath, javaLibPath, tableOfEnvVars, uimaClassPath);
+      // create InstallationTester object
+      InstallationTester installTester = new InstallationTester(pkgBrowser);
+      TestStatus status = installTester.doTest();
+
+      return status;
+
     } catch (Throwable exc) {
       // print exception as 'verification message'
       StringWriter strWriter = new StringWriter();
       PrintWriter oWriter = new PrintWriter(strWriter);
       exc.printStackTrace(oWriter);
       TestStatus status = new TestStatus();
-      status.retCode = -1;
-      status.message = strWriter.toString();
+      status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL);
+      status.setMessage(strWriter.toString());
       return status;
     }
   }
@@ -1621,7 +1429,7 @@
       if (_mainPearFileLocation == null) // get PEAR file location
         _mainPearFileLocation = getPEARFileLocation(_mainComponentId, _packageSelector);
       // extract PEAR file in a specified directory
-      if (extractPEARFile(_mainComponentId, _mainPearFileLocation, _mainComponentRoot, this) == null) {
+      if (extractPEARFile(_mainPearFileLocation, _mainComponentRoot, this) == null) {
         // PEAR extraction failed
         // set error message
         setInstallationError(new IOException("PEAR extraction failed"));
@@ -1687,8 +1495,7 @@
       if (_mainPearFileLocation == null) // get PEAR file location
         _mainPearFileLocation = getPEARFileLocation(_mainComponentId, _packageSelector);
       // extract main XML descriptors in a specified directory
-      if (extractFilesFromPEARFile(_mainComponentId, _mainPearFileLocation, ".xml",
-              _mainComponentRoot, this) == null) {
+      if (extractFilesFromPEARFile(_mainPearFileLocation, ".xml", _mainComponentRoot, this) == null) {
         // PEAR extraction failed
         // set error message
         setInstallationError(new IOException("PEAR extraction failed"));
@@ -1722,9 +1529,6 @@
   /**
    * Performs installation of all separate delegate components for the specified main component.
    * 
-   * @return The <code>Hashtable</code> that contains the
-   *         <code>(component_id, root_directory)</code> pairs for the installed delegate
-   *         components.
    */
   protected synchronized void installDelegateComponents() {
     // get list of separate delegate components IDs
@@ -1798,25 +1602,26 @@
       _installationInsDs.put(componentId, dlgInsdObject);
     }
   }
-  
+
   /**
-   * generates the pearSpecifier to run the installed pear component. The descriptor that is created has
-   * the filename &lt;componentID&gt;_pear.xml and is created in the main component root directory. 
-   * If the file already exist, it will be overridden. 
+   * generates the pearSpecifier to run the installed pear component. The descriptor that is created
+   * has the filename &lt;componentID&gt;_pear.xml and is created in the main component root
+   * directory. If the file already exist, it will be overridden.
    * 
    * @param mainComponentRootPath
    *          main component root path where the pear was installed to
-   *           
+   * 
    * @param mainComponentId
    *          main component ID of the installed pear file
-   *          
+   * 
    * @throws IOException
    * @throws SAXException
    */
-  protected static synchronized void generatePearSpecifier(String mainComponentRootPath, String mainComponentId) throws IOException, SAXException{    
+  protected static synchronized void generatePearSpecifier(String mainComponentRootPath,
+          String mainComponentId) throws IOException, SAXException {
     PearSpecifier pearSpec = UIMAFramework.getResourceSpecifierFactory().createPearSpecifier();
     pearSpec.setPearPath(mainComponentRootPath);
-    File outputFile = new File(mainComponentRootPath, mainComponentId + PEAR_DESC_FILE_POSTFIX);      
+    File outputFile = new File(mainComponentRootPath, mainComponentId + PEAR_DESC_FILE_POSTFIX);
     pearSpec.toXML(new FileOutputStream(outputFile));
   }
 
@@ -1861,6 +1666,7 @@
         try {
           fWriter.close();
         } catch (Exception e) {
+          // ignore close exception
         }
       }
     }
@@ -1887,6 +1693,7 @@
           try {
             iStream.close();
           } catch (Exception e) {
+            // ignore close exception
           }
         }
       }
@@ -1912,6 +1719,7 @@
         try {
           oStream.close();
         } catch (Exception e) {
+          // ignore close exception
         }
       }
     }
@@ -2044,16 +1852,19 @@
     try {
       if (_installationMonitor != null) // notify monitor
         _installationMonitor.setInstallationStatus(_mainComponentId, VERIFICATION_IN_PROGRESS);
-      TestStatus status = verifyComponentInstallation(this, _uimaHomePath);
-      if (status.retCode == 0) {
+
+      // create PackageBrowser object for the installed PEAR
+      PackageBrowser installedPear = new PackageBrowser(this._mainComponentRoot);
+      TestStatus status = verifyComponentInstallation(installedPear);
+      if (status.getRetCode() == TestStatus.TEST_SUCCESSFUL) {
         // verification successful
         success = true;
         _verificationMsg = null;
         if (_installationMonitor != null) // notify monitor
           _installationMonitor.setInstallationStatus(_mainComponentId, VERIFICATION_COMPLETED);
-      } else if (status.retCode == -1) {
+      } else if (status.getRetCode() == TestStatus.TEST_NOT_SUCCESSFUL) {
         // verification failed
-        _verificationMsg = status.message;
+        _verificationMsg = status.getMessage();
         if (_installationMonitor != null) // notify monitor
           _installationMonitor.setInstallationStatus(_mainComponentId, VERIFICATION_FAILED);
       } else {

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/InstallationTester.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/InstallationTester.java?view=diff&rev=540648&r1=540647&r2=540648
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/InstallationTester.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/InstallationTester.java Tue May 22 10:06:43 2007
@@ -21,6 +21,8 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Iterator;
+import java.util.Properties;
 
 import org.apache.uima.UIMAException;
 import org.apache.uima.UIMAFramework;
@@ -32,69 +34,43 @@
 import org.apache.uima.collection.CollectionProcessingEngine;
 import org.apache.uima.collection.CollectionReader;
 import org.apache.uima.collection.metadata.CpeDescription;
+import org.apache.uima.internal.util.I18nUtil;
+import org.apache.uima.pear.tools.InstallationController.TestStatus;
 import org.apache.uima.pear.util.UIMAUtil;
 import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceManager;
 import org.apache.uima.resource.ResourceSpecifier;
 import org.apache.uima.resource.metadata.FsIndexDescription;
 import org.apache.uima.resource.metadata.TypePriorities;
 import org.apache.uima.resource.metadata.TypeSystemDescription;
 import org.apache.uima.util.CasCreationUtils;
 import org.apache.uima.util.InvalidXMLException;
-import org.apache.uima.util.Level;
 import org.apache.uima.util.XMLInputSource;
 
 /**
  * The <code>InstallationTester</code> application allows performing simple verification of the
  * installed UIMA compliant component by using standard UIMA framework interface.
  * 
- * @see org.apache.uima.pear.tools.InstallationController
- * @see org.apache.uima.pear.util.UIMAUtil
  */
 
 public class InstallationTester {
-  // attributes
-  private boolean _passed = false;
 
-  /**
-   * Starts the application. The application requires standard UIMA classpath settings as well as
-   * component specific environment settings.
-   * 
-   * @param args
-   *          component_descriptor_file
-   * @throws java.lang.Exception
-   *           if any exception occurred.
-   */
-  public static void main(String[] args) throws Exception {
-    if (System.getProperty("DEBUG") != null) {
-      System.out.println("<DBG> [InstallationTester]: arg=" + args[0] + "; CP="
-              + System.getProperty("java.class.path"));
-    }
-    UIMAFramework.getLogger().setLevel(Level.OFF);
-    try {
-      if (args.length < 1)
-        throw new IOException("Descriptor file not specified");
-      InstallationTester tester = new InstallationTester(args[0]);
-      if (tester._passed) {
-        if (System.getProperty("DEBUG") != null)
-          System.out.println("<DBG> [InstallationTester]: " + "test completed successfully");
-        System.exit(0);
-      } else {
-        if (System.getProperty("DEBUG") != null)
-          System.err.println("<DBG> [InstallationTester]: " + "test canceled");
-        System.exit(1);
-      }
-    } catch (Throwable err) {
-      err.printStackTrace(System.err);
-      System.exit(-1);
-    }
-  }
+  // main component descriptor type of the pear package
+  private String uimaCategory = null;
+
+  // package browser object of the installed pear package
+  private PackageBrowser pkgBrowser = null;
+
+  private Properties systemProps = null;
+
+  private static final String PEAR_MESSAGE_RESOURCE_BUNDLE = "org.apache.uima.pear.pear_messages";
 
   /**
    * Creates new instance of the <code>InstallationTester</code> class, identifies a specified
-   * component using UIMA API, and invokes appropriate method to test the specified component.
+   * component using UIMA API.
    * 
-   * @param compDescFilePath
-   *          The given component descriptor file path.
+   * @param pkgBrowser
+   *          packageBrowser object of an installed PEAR package
    * @throws java.io.IOException
    *           if any I/O exception occurred.
    * @throws org.apache.uima.util.InvalidXMLException
@@ -106,11 +82,18 @@
    * @throws org.apache.uima.UIMARuntimeException
    *           if this exception occurred while identifying UIMA component category.
    */
-  public InstallationTester(String compDescFilePath) throws IOException, InvalidXMLException,
+  public InstallationTester(PackageBrowser pkgBrowser) throws IOException, InvalidXMLException,
           ResourceInitializationException, UIMAException, UIMARuntimeException {
+
+    // set PackageBrowser
+    this.pkgBrowser = pkgBrowser;
+
+    // save System properties
+    this.systemProps = System.getProperties();
+
     // check UIMA category of the main component
-    File compDescFile = new File(compDescFilePath);
-    String uimaCategory = UIMAUtil.identifyUimaComponentCategory(compDescFile);
+    File compDescFile = new File(this.pkgBrowser.getInstallationDescriptor().getMainComponentDesc());
+    this.uimaCategory = UIMAUtil.identifyUimaComponentCategory(compDescFile);
     if (uimaCategory == null) {
       Exception err = UIMAUtil.getLastErrorForXmlDesc(compDescFile);
       if (err != null) {
@@ -121,29 +104,96 @@
         else
           throw new RuntimeException(err);
       }
-    } else if (uimaCategory.equals(UIMAUtil.ANALYSIS_ENGINE_CTG))
-      _passed = testAnalysisEngine(compDescFile);
-    else if (uimaCategory.equals(UIMAUtil.CAS_CONSUMER_CTG))
-      _passed = testCasConsumer(compDescFile);
-    else if (uimaCategory.equals(UIMAUtil.CAS_INITIALIZER_CTG))
-      _passed = testCasInitializer(compDescFile);
-    else if (uimaCategory.equals(UIMAUtil.COLLECTION_READER_CTG))
-      _passed = testCollectionReader(compDescFile);
-    else if (uimaCategory.equals(UIMAUtil.CPE_CONFIGURATION_CTG))
-      _passed = testCpeCongifuration(compDescFile);
-    else if (uimaCategory.equals(UIMAUtil.TYPE_SYSTEM_CTG))
-      _passed = testTypeSystem(compDescFile);
+    }
+  }
+
+  public TestStatus doTest() throws IOException, InvalidXMLException,
+          ResourceInitializationException {
+    if (uimaCategory.equals(UIMAUtil.ANALYSIS_ENGINE_CTG)) {
+      return testAnalysisEngine();
+    } else if (uimaCategory.equals(UIMAUtil.CAS_CONSUMER_CTG)) {
+      return testCasConsumer();
+    } else if (uimaCategory.equals(UIMAUtil.CAS_INITIALIZER_CTG)) {
+      return testCasInitializer();
+    } else if (uimaCategory.equals(UIMAUtil.COLLECTION_READER_CTG)) {
+      return testCollectionReader();
+    } else if (uimaCategory.equals(UIMAUtil.CPE_CONFIGURATION_CTG)) {
+      return testCpeCongifuration();
+    } else if (uimaCategory.equals(UIMAUtil.TYPE_SYSTEM_CTG)) {
+      return testTypeSystem();
+    }
+
+    // create Test status object
+    TestStatus status = new TestStatus();
+    status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE,
+            "installation_verification_type_not_detected", new Object[] { this.pkgBrowser
+                    .getInstallationDescriptor().getMainComponentId() }, null));
+
+    return status;
+  }
+
+  /**
+   * returns a valid ResourceManager with the information from the PackageBrowser object.
+   * 
+   * @param pkgBrowser
+   *          packageBrowser object of an installed PEAR package
+   * 
+   * @return a ResourceManager object with the information from the PackageBrowser object.
+   * 
+   * @throws IOException
+   */
+  private static ResourceManager getResourceManager(PackageBrowser pkgBrowser) throws IOException {
+    ResourceManager resourceMgr = UIMAFramework.newDefaultResourceManager();
+    // set component data path
+    if (pkgBrowser.getComponentDataPath() != null) {
+      resourceMgr.setDataPath(pkgBrowser.getComponentDataPath());
+    }
+    // set component classpath
+    if (pkgBrowser.buildComponentClassPath() != null) {
+      resourceMgr.setExtensionClassPath(pkgBrowser.buildComponentClassPath(), true);
+    }
+
+    return resourceMgr;
+  }
+
+  /**
+   * Set the environment variables that are specified in the PackageBrowser object as System
+   * properties
+   * 
+   * @param pkgBrowser
+   *          packageBrowser object of an installed PEAR package
+   * 
+   * @throws IOException
+   */
+  private static void setSystemProperties(PackageBrowser pkgBrowser) throws IOException {
+
+    // get pear env variables and set them as system properties
+    Properties props = pkgBrowser.getComponentEnvVars();
+    Iterator keyIterator = props.keySet().iterator();
+    while (keyIterator.hasNext()) {
+      String key = (String) keyIterator.next();
+      String value = (String) props.get(key);
+
+      // set new system property
+      System.setProperty(key, value);
+    }
   }
 
   /**
-   * Checks if a given AE specifier file can be used to produce an istance of AE. Returns
-   * <code>true</code>, if an AE can be instantiated and a CAS object can be created,
+   * reset the System properties as it was before the pear verification is executed.
+   */
+  private void resetSystemProperties() {
+    // reset system properties
+    System.setProperties(this.systemProps);
+  }
+
+  /**
+   * Checks if a given analysis engine specifier file can be used to produce an instance of analysis
+   * engine. Returns <code>true</code>, if an analysis engine can be instantiated,
    * <code>false</code> otherwise.
    * 
-   * @param aeSpecifierFile
-   *          The given AE specifier file.
-   * @return <code>true</code>, if an AE can be instantiated and a CAS object can be created,
-   *         <code>false</code> otherwise.
+   * @return <code>true</code>, if an AE can be instantiated, <code>false</code> otherwise.
+   * 
    * @throws IOException
    *           If an I/O exception occurred while creating <code>XMLInputSource</code>.
    * @throws InvalidXMLException
@@ -151,37 +201,45 @@
    * @throws ResourceInitializationException
    *           If the specified AE cannot be instantiated.
    */
-  public static boolean testAnalysisEngine(File aeSpecifierFile) throws IOException,
-          InvalidXMLException, ResourceInitializationException {
-    try {
-      XMLInputSource xmlIn = new XMLInputSource(aeSpecifierFile);
-      ResourceSpecifier aeSpecifier = UIMAFramework.getXMLParser().parseResourceSpecifier(xmlIn);
-      AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(aeSpecifier);
-      if (ae != null) {
-        CAS cas = ae.newCAS();
-        return cas != null;
-      } else
-        return false;
-    } catch (IOException ioE) {
-      System.err
-              .println("Error on creating XML source from descriptor file :: " + ioE.getMessage());
-      throw ioE;
-    } catch (InvalidXMLException inxE) {
-      System.err.println("Error on parsing the XML source file :: " + inxE.getMessage());
-      throw inxE;
-    } catch (ResourceInitializationException riE) {
-      System.err.println("Error on producing AE :: " + riE.getMessage());
-      throw riE;
+  private TestStatus testAnalysisEngine() throws IOException, InvalidXMLException,
+          ResourceInitializationException {
+
+    // set system properties
+    setSystemProperties(this.pkgBrowser);
+
+    // create analysis engine
+    XMLInputSource xmlIn = new XMLInputSource(this.pkgBrowser.getInstallationDescriptor()
+            .getMainComponentDesc());
+    ResourceSpecifier aeSpecifier = UIMAFramework.getXMLParser().parseResourceSpecifier(xmlIn);
+    AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(aeSpecifier,
+            getResourceManager(this.pkgBrowser), null);
+
+    // create Test status object
+    TestStatus status = new TestStatus();
+
+    if (ae != null) {
+      status.setRetCode(TestStatus.TEST_SUCCESSFUL);
+    } else {
+      status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL);
+      status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE,
+              "installation_verification_ae_not_created", new Object[] { this.pkgBrowser
+                      .getInstallationDescriptor().getMainComponentId() }, null));
     }
+
+    // reset system properties
+    this.resetSystemProperties();
+
+    // return status object
+    return status;
+
   }
 
   /**
    * Checks if a given CC specifier file can be used to produce an instance of CC. Returns
    * <code>true</code>, if a CC can be instantiated, <code>false</code> otherwise.
    * 
-   * @param ccSpecifierFile
-   *          The given CC specifier file.
    * @return <code>true</code>, if a CC can be instantiated, <code>false</code> otherwise.
+   * 
    * @throws IOException
    *           If an I/O exception occurred while creating <code>XMLInputSource</code>.
    * @throws InvalidXMLException
@@ -189,32 +247,39 @@
    * @throws ResourceInitializationException
    *           If the specified CC cannot be instantiated.
    */
-  public static boolean testCasConsumer(File ccSpecifierFile) throws IOException,
-          InvalidXMLException, ResourceInitializationException {
-    try {
-      XMLInputSource xmlIn = new XMLInputSource(ccSpecifierFile);
-      ResourceSpecifier ccSpecifier = UIMAFramework.getXMLParser().parseResourceSpecifier(xmlIn);
-      CasConsumer cc = UIMAFramework.produceCasConsumer(ccSpecifier);
-      return cc != null;
-    } catch (IOException ioE) {
-      System.err
-              .println("Error on creating XML source from descriptor file :: " + ioE.getMessage());
-      throw ioE;
-    } catch (InvalidXMLException inxE) {
-      System.err.println("Error on parsing the XML source file :: " + inxE.getMessage());
-      throw inxE;
-    } catch (ResourceInitializationException riE) {
-      System.err.println("Error on producing CC :: " + riE.getMessage());
-      throw riE;
+  private TestStatus testCasConsumer() throws IOException, InvalidXMLException,
+          ResourceInitializationException {
+    // set system properties
+    setSystemProperties(this.pkgBrowser);
+
+    XMLInputSource xmlIn = new XMLInputSource(this.pkgBrowser.getInstallationDescriptor()
+            .getMainComponentDesc());
+    ResourceSpecifier ccSpecifier = UIMAFramework.getXMLParser().parseResourceSpecifier(xmlIn);
+    CasConsumer cc = UIMAFramework.produceCasConsumer(ccSpecifier,
+            getResourceManager(this.pkgBrowser), null);
+    // create Test status object
+    TestStatus status = new TestStatus();
+
+    if (cc != null) {
+      status.setRetCode(TestStatus.TEST_SUCCESSFUL);
+    } else {
+      status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL);
+      status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE,
+              "installation_verification_cc_not_created", new Object[] { this.pkgBrowser
+                      .getInstallationDescriptor().getMainComponentId() }, null));
     }
+
+    // reset system properties
+    this.resetSystemProperties();
+
+    // return status object
+    return status;
   }
 
   /**
    * Checks if a given CI specifier file can be used to produce an instance of CI. Returns
    * <code>true</code>, if a CI can be instantiated, <code>false</code> otherwise.
    * 
-   * @param ciSpecifierFile
-   *          The given CI specifier file.
    * @return <code>true</code>, if a CI can be instantiated, <code>false</code> otherwise.
    * @throws IOException
    *           If an I/O exception occurred while creating <code>XMLInputSource</code>.
@@ -223,32 +288,39 @@
    * @throws ResourceInitializationException
    *           If the specified CI cannot be instantiated.
    */
-  public static boolean testCasInitializer(File ciSpecifierFile) throws IOException,
-          InvalidXMLException, ResourceInitializationException {
-    try {
-      XMLInputSource xmlIn = new XMLInputSource(ciSpecifierFile);
-      ResourceSpecifier ciSpecifier = UIMAFramework.getXMLParser().parseResourceSpecifier(xmlIn);
-      CasInitializer ci = UIMAFramework.produceCasInitializer(ciSpecifier);
-      return ci != null;
-    } catch (IOException ioE) {
-      System.err
-              .println("Error on creating XML source from descriptor file :: " + ioE.getMessage());
-      throw ioE;
-    } catch (InvalidXMLException inxE) {
-      System.err.println("Error on parsing the XML source file :: " + inxE.getMessage());
-      throw inxE;
-    } catch (ResourceInitializationException riE) {
-      System.err.println("Error on producing CC :: " + riE.getMessage());
-      throw riE;
+  private TestStatus testCasInitializer() throws IOException, InvalidXMLException,
+          ResourceInitializationException {
+    // set system properties
+    setSystemProperties(this.pkgBrowser);
+
+    XMLInputSource xmlIn = new XMLInputSource(this.pkgBrowser.getInstallationDescriptor()
+            .getMainComponentDesc());
+    ResourceSpecifier ciSpecifier = UIMAFramework.getXMLParser().parseResourceSpecifier(xmlIn);
+    CasInitializer ci = UIMAFramework.produceCasInitializer(ciSpecifier,
+            getResourceManager(this.pkgBrowser), null);
+    // create Test status object
+    TestStatus status = new TestStatus();
+
+    if (ci != null) {
+      status.setRetCode(TestStatus.TEST_SUCCESSFUL);
+    } else {
+      status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL);
+      status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE,
+              "installation_verification_ci_not_created", new Object[] { this.pkgBrowser
+                      .getInstallationDescriptor().getMainComponentId() }, null));
     }
+
+    // reset system properties
+    this.resetSystemProperties();
+
+    // return status object
+    return status;
   }
 
   /**
    * Checks if a given CR specifier file can be used to produce an instance of CR. Returns
    * <code>true</code>, if a CR can be instantiated, <code>false</code> otherwise.
    * 
-   * @param crSpecifierFile
-   *          The given CR specifier file.
    * @return <code>true</code>, if a CR can be instantiated, <code>false</code> otherwise.
    * @throws IOException
    *           If an I/O exception occurred while creating <code>XMLInputSource</code>.
@@ -257,33 +329,42 @@
    * @throws ResourceInitializationException
    *           If the specified CR cannot be instantiated.
    */
-  public static boolean testCollectionReader(File crSpecifierFile) throws IOException,
-          InvalidXMLException, ResourceInitializationException {
-    try {
-      XMLInputSource xmlIn = new XMLInputSource(crSpecifierFile);
-      ResourceSpecifier crSpecifier = UIMAFramework.getXMLParser().parseResourceSpecifier(xmlIn);
-      CollectionReader cr = UIMAFramework.produceCollectionReader(crSpecifier);
-      return cr != null;
-    } catch (IOException ioE) {
-      System.err
-              .println("Error on creating XML source from descriptor file :: " + ioE.getMessage());
-      throw ioE;
-    } catch (InvalidXMLException inxE) {
-      System.err.println("Error on parsing the XML source file :: " + inxE.getMessage());
-      throw inxE;
-    } catch (ResourceInitializationException riE) {
-      System.err.println("Error on producing CC :: " + riE.getMessage());
-      throw riE;
+  private TestStatus testCollectionReader() throws IOException, InvalidXMLException,
+          ResourceInitializationException {
+    // set system properties
+    setSystemProperties(this.pkgBrowser);
+
+    XMLInputSource xmlIn = new XMLInputSource(this.pkgBrowser.getInstallationDescriptor()
+            .getMainComponentDesc());
+    ResourceSpecifier crSpecifier = UIMAFramework.getXMLParser().parseResourceSpecifier(xmlIn);
+    CollectionReader cr = UIMAFramework.produceCollectionReader(crSpecifier,
+            getResourceManager(this.pkgBrowser), null);
+
+    // create Test status object
+    TestStatus status = new TestStatus();
+
+    if (cr != null) {
+      status.setRetCode(TestStatus.TEST_SUCCESSFUL);
+    } else {
+      status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL);
+      status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE,
+              "installation_verification_cr_not_created", new Object[] { this.pkgBrowser
+                      .getInstallationDescriptor().getMainComponentId() }, null));
     }
+
+    // reset system properties
+    this.resetSystemProperties();
+
+    // return status object
+    return status;
   }
 
   /**
    * Checks if a given CPE specifier file can be used to produce an instance of CPE. Returns
    * <code>true</code>, if a CPE can be instantiated, <code>false</code> otherwise.
    * 
-   * @param cpeSpecifierFile
-   *          The given CPE specifier file.
    * @return <code>true</code>, if a CPE can be instantiated, <code>false</code> otherwise.
+   * 
    * @throws IOException
    *           If an I/O exception occurred while creating <code>XMLInputSource</code>.
    * @throws InvalidXMLException
@@ -291,33 +372,40 @@
    * @throws ResourceInitializationException
    *           If the specified CPE cannot be instantiated.
    */
-  public static boolean testCpeCongifuration(File cpeSpecifierFile) throws IOException,
-          InvalidXMLException, ResourceInitializationException {
-    try {
-      XMLInputSource xmlIn = new XMLInputSource(cpeSpecifierFile);
-      CpeDescription cpeDescription = UIMAFramework.getXMLParser().parseCpeDescription(xmlIn);
-      CollectionProcessingEngine cpe = UIMAFramework
-              .produceCollectionProcessingEngine(cpeDescription);
-      return cpe != null;
-    } catch (IOException ioE) {
-      System.err
-              .println("Error on creating XML source from descriptor file :: " + ioE.getMessage());
-      throw ioE;
-    } catch (InvalidXMLException inxE) {
-      System.err.println("Error on parsing the XML source file :: " + inxE.getMessage());
-      throw inxE;
-    } catch (ResourceInitializationException riE) {
-      System.err.println("Error on producing CC :: " + riE.getMessage());
-      throw riE;
+  private TestStatus testCpeCongifuration() throws IOException, InvalidXMLException,
+          ResourceInitializationException {
+    // set system properties
+    setSystemProperties(this.pkgBrowser);
+
+    XMLInputSource xmlIn = new XMLInputSource(this.pkgBrowser.getInstallationDescriptor()
+            .getMainComponentDesc());
+    CpeDescription cpeDescription = UIMAFramework.getXMLParser().parseCpeDescription(xmlIn);
+    CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(
+            cpeDescription, getResourceManager(this.pkgBrowser), null);
+
+    // create Test status object
+    TestStatus status = new TestStatus();
+
+    if (cpe != null) {
+      status.setRetCode(TestStatus.TEST_SUCCESSFUL);
+    } else {
+      status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL);
+      status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE,
+              "installation_verification_cpe_not_created", new Object[] { this.pkgBrowser
+                      .getInstallationDescriptor().getMainComponentId() }, null));
     }
+
+    // reset system properties
+    this.resetSystemProperties();
+
+    // return status object
+    return status;
   }
 
   /**
    * Checks if a given TS specifier file can be used to create an instance of CAS. Returns
    * <code>true</code>, if a CAS can be created for a given TS, <code>false</code> otherwise.
    * 
-   * @param tsSpecifierFile
-   *          The given TS specifier file.
    * @return <code>true</code>, if a CAS can be created for the given TS, <code>false</code>
    *         otherwise.
    * @throws IOException
@@ -327,27 +415,36 @@
    * @throws ResourceInitializationException
    *           If the specified TS cannot be used to create a CAS.
    */
-  public static boolean testTypeSystem(File tsSpecifierFile) throws IOException,
-          InvalidXMLException, ResourceInitializationException {
-    try {
-      XMLInputSource xmlIn = new XMLInputSource(tsSpecifierFile);
-      TypeSystemDescription tsDescription = UIMAFramework.getXMLParser()
-              .parseTypeSystemDescription(xmlIn);
-      TypePriorities tPriorities = UIMAFramework.getResourceSpecifierFactory()
-              .createTypePriorities();
-      FsIndexDescription[] fsIndexes = new FsIndexDescription[0];
-      CAS cas = CasCreationUtils.createCas(tsDescription, tPriorities, fsIndexes);
-      return cas != null;
-    } catch (IOException ioE) {
-      System.err
-              .println("Error on creating XML source from descriptor file :: " + ioE.getMessage());
-      throw ioE;
-    } catch (InvalidXMLException inxE) {
-      System.err.println("Error on parsing the XML source file :: " + inxE.getMessage());
-      throw inxE;
-    } catch (ResourceInitializationException riE) {
-      System.err.println("Error on producing CC :: " + riE.getMessage());
-      throw riE;
+  private TestStatus testTypeSystem() throws IOException, InvalidXMLException,
+          ResourceInitializationException {
+    // set system properties
+    setSystemProperties(this.pkgBrowser);
+
+    XMLInputSource xmlIn = new XMLInputSource(this.pkgBrowser.getInstallationDescriptor()
+            .getMainComponentDesc());
+    TypeSystemDescription tsDescription = UIMAFramework.getXMLParser().parseTypeSystemDescription(
+            xmlIn);
+    TypePriorities tPriorities = UIMAFramework.getResourceSpecifierFactory().createTypePriorities();
+    FsIndexDescription[] fsIndexes = new FsIndexDescription[0];
+    CAS cas = CasCreationUtils.createCas(tsDescription, tPriorities, fsIndexes);
+
+    // create Test status object
+    TestStatus status = new TestStatus();
+
+    if (cas != null) {
+      status.setRetCode(TestStatus.TEST_SUCCESSFUL);
+    } else {
+      status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL);
+      status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE,
+              "installation_verification_cas_not_created", new Object[] { this.pkgBrowser
+                      .getInstallationDescriptor().getMainComponentId() }, null));
     }
+
+    // reset system properties
+    this.resetSystemProperties();
+
+    // return status object
+    return status;
   }
+
 }

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/LocalInstallationAgent.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/LocalInstallationAgent.java?view=diff&rev=540648&r1=540647&r2=540648
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/LocalInstallationAgent.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/LocalInstallationAgent.java Tue May 22 10:06:43 2007
@@ -28,7 +28,10 @@
 import java.util.Iterator;
 import java.util.Properties;
 
+import org.apache.uima.UIMAException;
+import org.apache.uima.pear.tools.InstallationController.TestStatus;
 import org.apache.uima.pear.util.FileUtil;
+import org.apache.uima.resource.ResourceInitializationException;
 
 /**
  * The <code>LocalInstallationAgent</code> allows localizing files of UIMA compliant components
@@ -292,6 +295,7 @@
         try {
           iStream.close();
         } catch (Exception e) {
+          //ignore close exception
         }
       }
     }
@@ -391,47 +395,39 @@
    * 
    * @throws IOException
    *           if any I/O exception occurred.
+   * 
+   * @throws ResourceInitializationException
+   *           if the specified component cannot be instantiated.
+   *           
+   * @throws UIMAException
+   *           if this exception occurred while identifying UIMA component category.
+   *           
    * @see org.apache.uima.pear.tools.InstallationTester
    */
-  public synchronized boolean verifyLocalizedComponent() throws IOException {
-    boolean success = false;
+  public synchronized boolean verifyLocalizedComponent() throws IOException,
+          ResourceInitializationException, UIMAException {
     // check input parameters
     if (_insdObject == null)
       throw new RuntimeException("null installation descriptor");
     if (_mainRootDir == null)
       throw new RuntimeException("main root directory not specified");
-    String mainRootDirPath = _mainRootDir.getAbsolutePath();
     String mainDescPath = _insdObject.getMainComponentDesc();
     if (mainDescPath == null)
       throw new RuntimeException("main descriptor path not specified");
-    if (_uimaHomePath == null)
-      throw new RuntimeException(InstallationController.UIMA_HOME_ENV + " variable not specified");
-    // build component classpath
-    String compClassPath = InstallationController.buildComponentClassPath(mainRootDirPath,
-            _insdObject);
-    // build UIMA classpath
-    String uimaClassPath = InstallationController.buildUIMAClassPath(_uimaHomePath);
-    // set java.library.path
-    String javaLibPath = InstallationController.buildComponentPath(mainRootDirPath, _insdObject);
-    // set other required env vars
-    Properties tableOfEnvVars = InstallationController.buildTableOfEnvVars(_insdObject);
-    // add CLASSPATH, PATH and LD_LIBRARY_PATH to the table of env.vars
-    if (compClassPath.length() > 0)
-      tableOfEnvVars.setProperty("CLASSPATH", compClassPath);
-    if (javaLibPath.length() > 0) {
-      tableOfEnvVars.setProperty("PATH", javaLibPath);
-      tableOfEnvVars.setProperty("LD_LIBRARY_PATH", javaLibPath);
-    }
-    // deploy and run installation verification test
-    InstallationController.TestStatus status = InstallationController
-            .deployInstallationVerificationTest(mainRootDirPath, _insdObject, mainDescPath,
-                    compClassPath, javaLibPath, tableOfEnvVars, uimaClassPath);
-    if (status.retCode != 0) {
+
+    // run installation verification test
+
+    InstallationTester installTester = new InstallationTester(new PackageBrowser(new File(
+            _mainRootDir.getAbsolutePath())));
+    TestStatus status = installTester.doTest();
+    
+    if (status.getRetCode() == TestStatus.TEST_SUCCESSFUL) {
+      return true;
+    } else {
       System.err.println("[LocalInstallationAgent]: " + "localization test failed =>");
-      System.out.println("> Error message: " + status.message);
-    } else
-      success = true;
-    return success;
+      System.out.println("> Error message: " + status.getMessage());
+      return false;
+    }
   }
 
   /**

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/pear/pear_messages.properties
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/pear/pear_messages.properties?view=diff&rev=540648&r1=540647&r2=540648
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/pear/pear_messages.properties (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/pear/pear_messages.properties Tue May 22 10:06:43 2007
@@ -29,7 +29,12 @@
 package_creator_datapath_not_valid_warning =  Warning: datapath entry contains ':', use ';' as path separator.
 package_creator_install_desc_created_info = Installation descriptor successfully created at {0}.
 package_creator_pear_created_info = PEAR package successfully created at {0}.
-
+installation_verification_ae_not_created = The analysis engine for component {0} could not be created.
+installation_verification_cc_not_created = The CAS consumer for component {0} could not be created.
+installation_verification_ci_not_created = The CAS initializer for component {0} could not be created.
+installation_verification_cr_not_created = The collection reader for component {0} could not be created.
+installation_verification_cas_not_created = The CAS for the type system of component {0} could not be created.
+installation_verification_type_not_detected = The installation verification could not detect the resource type of component {0}.
 
 #----------------------------------------
 #Catalog of UIMA pear exception messages
@@ -42,4 +47,6 @@
 error_verify_installation = The following error occured during the installation verification of component {0}: {1}
 error_package_creator_invalid_directory = {0} is not a valid directory.
 error_package_creator_creating_pear_package = Error while creating the pear package for pear ID {0}
-
+installation_verification_install_desc_not_available = Installation descriptor not available.
+installation_verification_main_desc_not_available = Main component descriptor not available for pear ID {0}.
+installation_verification_main_root_not_available = Main component root not available for pear ID {0}.

Added: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/pear/util/TestPearInstallationVerification.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/pear/util/TestPearInstallationVerification.java?view=auto&rev=540648
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/pear/util/TestPearInstallationVerification.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/pear/util/TestPearInstallationVerification.java Tue May 22 10:06:43 2007
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.pear.util;
+
+import java.io.File;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.uima.pear.tools.InstallationTester;
+import org.apache.uima.pear.tools.PackageBrowser;
+import org.apache.uima.pear.tools.PackageInstaller;
+import org.apache.uima.pear.tools.InstallationController.TestStatus;
+import org.apache.uima.test.junit_extension.JUnitExtension;
+
+/**
+ * Test the pear installation verification
+ * 
+ */
+public class TestPearInstallationVerification extends TestCase {
+
+  // Temporary working directory, used to install the pear package
+  private File tempInstallDir = null;
+
+  /**
+   * @see junit.framework.TestCase#setUp()
+   */
+  protected void setUp() throws Exception {
+    
+    // create temporary working directory
+    File tempFile = File.createTempFile("pear_verification_test_", "tmp");
+    if (tempFile.delete()) {
+      File tempDir = tempFile;
+      if (tempDir.mkdirs())
+        this.tempInstallDir = tempDir;
+    }
+  }
+
+  /**
+   * @see junit.framework.TestCase#tearDown()
+   */
+  protected void tearDown() throws Exception {
+    if (this.tempInstallDir != null) {
+      FileUtil.deleteDirectory(this.tempInstallDir);
+    }
+  }
+
+  
+  public void testAePearVerification() throws Exception {
+    
+     //get pear file to install
+    File pearFile = JUnitExtension.getFile("pearTests/DateTime.pear");
+    Assert.assertNotNull(pearFile);
+    
+    // Install PEAR package without verification
+    PackageBrowser instPear = PackageInstaller.installPackage(
+            this.tempInstallDir, pearFile, false);
+    
+    //check package browser
+    Assert.assertNotNull(instPear);
+       
+    InstallationTester installTester = new InstallationTester(instPear);
+    TestStatus status = installTester.doTest();
+    
+    Assert.assertEquals(status.getRetCode(), TestStatus.TEST_SUCCESSFUL);
+  }
+  
+  //TODO: create testcases for cc, ci, cr, cpe and ts pear packages
+
+}