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/04/23 13:48:22 UTC

svn commit: r531441 - in /incubator/uima/uimaj/trunk/uimaj-core/src/main: java/org/apache/uima/pear/tools/PackageCreator.java resources/org/apache/uima/pear/pear_messages.properties

Author: mbaessler
Date: Mon Apr 23 04:48:20 2007
New Revision: 531441

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

add logging

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

Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/PackageCreator.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/PackageCreator.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/PackageCreator.java?view=diff&rev=531441&r1=531440&r2=531441
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/PackageCreator.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/pear/tools/PackageCreator.java Mon Apr 23 04:48:20 2007
@@ -30,8 +30,10 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
+import org.apache.uima.UIMAFramework;
 import org.apache.uima.internal.util.I18nUtil;
 import org.apache.uima.resource.RelativePathResolver;
+import org.apache.uima.util.Level;
 
 /**
  * Utility class to generate a pear package.
@@ -115,11 +117,16 @@
    * 
    * @throws PackageCreatorException
    *           if an error occurs while creating the installation descriptor
+   *           
+   * @return Path to the created installation descriptor.
    */
-  public static void createInstallDescriptor(String componentID, String mainComponentDesc,
+  public static String createInstallDescriptor(String componentID, String mainComponentDesc,
           String classpath, String datapath, String mainComponentDir, Properties envVars)
           throws PackageCreatorException {
 
+    //installation descriptor file path
+    String installationDesc = null;
+    
     // create new install descriptor
     InstallationDescriptor insd = new InstallationDescriptor();
 
@@ -140,27 +147,34 @@
 
     // add classpath setting to the installation descriptor
     if (classpath != null) {
-      //classpath setting should use ";" as separator if it contains ":" as separator throw an exception.
-      if(classpath.indexOf(":") == -1) {
-        InstallationDescriptor.ActionInfo actionInfo = new InstallationDescriptor.ActionInfo(
-                InstallationDescriptor.ActionInfo.SET_ENV_VARIABLE_ACT);
-        actionInfo.params.put(InstallationDescriptorHandler.VAR_NAME_TAG,
-                InstallationController.CLASSPATH_VAR);
-        actionInfo.params.put(InstallationDescriptorHandler.VAR_VALUE_TAG, classpath);
-        String commentMessage = I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE,
-                "package_creator_env_setting", new Object[] { InstallationController.CLASSPATH_VAR });
-        actionInfo.params.put(InstallationDescriptorHandler.COMMENTS_TAG, commentMessage);
-        insd.addInstallationAction(actionInfo);  
+      // classpath setting should use ";" as separator
+      if (classpath.indexOf(":") != -1) {
+        // log warning that ";" as separator should be used.
+        UIMAFramework.getLogger(PackageCreator.class).logrb(Level.WARNING, "PackageCreator",
+                "createInstallDescriptor", PEAR_MESSAGE_RESOURCE_BUNDLE,
+                "package_creator_classpath_not_valid_warning");
       }
-      else {
-        //throw an exception, classpath should only contain ";" as delimiter not ":"
-        throw new PackageCreatorException(PEAR_MESSAGE_RESOURCE_BUNDLE,
-                "error_package_creator_classpath_not_valid");
-      }     
+      InstallationDescriptor.ActionInfo actionInfo = new InstallationDescriptor.ActionInfo(
+              InstallationDescriptor.ActionInfo.SET_ENV_VARIABLE_ACT);
+      actionInfo.params.put(InstallationDescriptorHandler.VAR_NAME_TAG,
+              InstallationController.CLASSPATH_VAR);
+      actionInfo.params.put(InstallationDescriptorHandler.VAR_VALUE_TAG, classpath);
+      String commentMessage = I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE,
+              "package_creator_env_setting", new Object[] { InstallationController.CLASSPATH_VAR });
+      actionInfo.params.put(InstallationDescriptorHandler.COMMENTS_TAG, commentMessage);
+      insd.addInstallationAction(actionInfo);
+
     }
-    
+
     // add datapath settings to the installation descriptor
     if (datapath != null) {
+      // datapath setting should use ";" as separator
+      if (datapath.indexOf(":") != -1) {
+        // log warning that ";" as separator should be used.
+        UIMAFramework.getLogger(PackageCreator.class).logrb(Level.WARNING, "PackageCreator",
+                "createInstallDescriptor", PEAR_MESSAGE_RESOURCE_BUNDLE,
+                "package_creator_datapath_not_valid_warning");
+      }
       InstallationDescriptor.ActionInfo actionInfo = new InstallationDescriptor.ActionInfo(
               InstallationDescriptor.ActionInfo.SET_ENV_VARIABLE_ACT);
       actionInfo.params.put(InstallationDescriptorHandler.VAR_NAME_TAG,
@@ -196,13 +210,22 @@
       if (!metaDataDir.exists()) {
         metaDataDir.mkdir();
       }
-      InstallationDescriptorHandler.saveInstallationDescriptor(insd, new File(mainComponentDir,
-              InstallationProcessor.INSD_FILE_PATH));
+      File installDesc = new File(mainComponentDir, InstallationProcessor.INSD_FILE_PATH);
+      InstallationDescriptorHandler.saveInstallationDescriptor(insd, installDesc);
+      
+      UIMAFramework.getLogger(PackageCreator.class).logrb(Level.INFO, "PackageCreator",
+              "createInstallDescriptor", PEAR_MESSAGE_RESOURCE_BUNDLE,
+              "package_creator_install_desc_created_info", new Object[] {installDesc});
+      
+      //set installation descriptor file path
+      installationDesc = installDesc.getAbsolutePath();
+      
     } catch (IOException ex) {
       throw new PackageCreatorException(PEAR_MESSAGE_RESOURCE_BUNDLE,
               "error_package_creator_creating_pear_package", new Object[] { componentID }, ex);
-    }
-
+    }   
+    
+    return installationDesc;
   }
 
   /**
@@ -222,18 +245,25 @@
    * 
    * @throws PackageCreatorException
    *           if the pear package can not be created successfully.
+   * 
+   * @return Retuns path absolute path to the created pear package.
    */
-  public static void createPearPackage(String componentID, String mainComponentDir, String targetDir)
+  public static String createPearPackage(String componentID, String mainComponentDir, String targetDir)
           throws PackageCreatorException {
     // package pear file with all data from the mainComponentDir
     ZipOutputStream zipFile;
+    File pearFile;
+    
     try {
-      zipFile = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(new File(
-              targetDir, componentID + ".pear"))));
+      pearFile = new File(targetDir, componentID + ".pear");
+      zipFile = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(pearFile)));
       File mainDir = new File(mainComponentDir);
       zipDirectory(componentID, mainDir.getAbsolutePath(), mainDir, zipFile);
       zipFile.close();
-
+      
+      UIMAFramework.getLogger(PackageCreator.class).logrb(Level.INFO, "PackageCreator",
+              "createInstallDescriptor", PEAR_MESSAGE_RESOURCE_BUNDLE,
+              "package_creator_pear_created_info", new Object[] {pearFile});
     } catch (FileNotFoundException ex) {
       throw new PackageCreatorException(PEAR_MESSAGE_RESOURCE_BUNDLE,
               "error_package_creator_creating_pear_package", new Object[] { componentID }, ex);
@@ -241,7 +271,8 @@
       throw new PackageCreatorException(PEAR_MESSAGE_RESOURCE_BUNDLE,
               "error_package_creator_creating_pear_package", new Object[] { componentID }, ex);
     }
-
+    
+    return pearFile.getAbsolutePath();
   }
 
   /**

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=531441&r1=531440&r2=531441
==============================================================================
--- 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 Mon Apr 23 04:48:20 2007
@@ -25,6 +25,11 @@
 package_installer_message = Package installer message: {0}
 package_installer_error = Package installer error: {0}
 package_creator_env_setting = component {0} setting
+package_creator_classpath_not_valid_warning = Warning: classpath entry contains ':', use ';' as path separator.
+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}.
+
 
 #----------------------------------------
 #Catalog of UIMA pear exception messages
@@ -37,5 +42,4 @@
 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}
-error_package_creator_classpath_not_valid = Error while parsing the classapth settings. Use ';' as path separator.