Class PackageCreator


  • public class PackageCreator
    extends java.lang.Object
    Utility class to generate a pear package.
    • Constructor Summary

      Constructors 
      Constructor Description
      PackageCreator()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String addMacro​(java.lang.String s)
      adds the $main_root/ macro as a prefix to the given string
      static java.lang.String createInstallDescriptor​(java.lang.String componentID, java.lang.String mainComponentDesc, java.lang.String classpath, java.lang.String datapath, java.lang.String mainComponentDir, java.util.Properties envVars)
      Creates the installation descriptor with the given information and save it in the metadata folder of the mainComponentDir.
      static java.lang.String createPearPackage​(java.lang.String componentID, java.lang.String mainComponentDir, java.lang.String targetDir)
      create pear package based on the given information.
      static void generatePearPackage​(java.lang.String componentID, java.lang.String mainComponentDesc, java.lang.String classpath, java.lang.String datapath, java.lang.String mainComponentDir, java.lang.String targetDir, java.util.Properties envVars)
      Default method to generate a pear package.
      private static java.lang.String getRelativePath​(java.lang.String mainDir, java.io.File currentPath)
      returns a postfix path of the currendPath based on the mainDir prefix.
      private static void zipDirectory​(java.lang.String componentID, java.lang.String mainDir, java.io.File sourceDir, java.util.zip.ZipOutputStream zipOut)
      adds recursivly all files and directories based on the source directory to the ZipOutputStream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PEAR_MESSAGE_RESOURCE_BUNDLE

        private static final java.lang.String PEAR_MESSAGE_RESOURCE_BUNDLE
        See Also:
        Constant Field Values
    • Constructor Detail

      • PackageCreator

        public PackageCreator()
    • Method Detail

      • generatePearPackage

        public static void generatePearPackage​(java.lang.String componentID,
                                               java.lang.String mainComponentDesc,
                                               java.lang.String classpath,
                                               java.lang.String datapath,
                                               java.lang.String mainComponentDir,
                                               java.lang.String targetDir,
                                               java.util.Properties envVars)
                                        throws PackageCreatorException
        Default method to generate a pear package. With the given information first the installation descriptor is created and then the pear package is built.
        Parameters:
        componentID - Specify a componentID for this component
        mainComponentDesc - Specify the main component descriptor path that is used to start the component. The path must be specified relative to the mainComponentDir parameter.
        classpath - Specify the classpath for this component. Use macros like $main_root to specify the classpath entries.
        datapath - Specify the datapath for this component. Use macros like $main_root to specify the datapath entities.
        mainComponentDir - Specify the main component root directory that contains all the resources for the component. The mainComponentDir is packaged to the pear file.
        targetDir - Specify the target directory where the generated pear file is written to.
        envVars - Specify additional environment variables for the pear component. May also use macros like $main_root to specify the key values if necessary.
        Throws:
        PackageCreatorException - if an error occurs while create the pear package
      • createInstallDescriptor

        public static java.lang.String createInstallDescriptor​(java.lang.String componentID,
                                                               java.lang.String mainComponentDesc,
                                                               java.lang.String classpath,
                                                               java.lang.String datapath,
                                                               java.lang.String mainComponentDir,
                                                               java.util.Properties envVars)
                                                        throws PackageCreatorException
        Creates the installation descriptor with the given information and save it in the metadata folder of the mainComponentDir.
        Parameters:
        componentID - Specify a componentID for this component
        mainComponentDesc - Specify the main component descriptor path that is used to start the component. The path must be specified relative to the mainComponentDir parameter.
        classpath - Specify the classpath for this component. Use macros like $main_root to specify the classpath entries.
        datapath - Specify the datapath for this component. Use macros like $main_root to specify the datapath entities.
        mainComponentDir - Specify the main component root directory that contains all the resources for the component. The mainComponentDir is packaged to the pear file.
        envVars - Specify additional environment variables for the pear component. May also use macros like $main_root to specify the key values if necessary.
        Returns:
        Path to the created installation descriptor.
        Throws:
        PackageCreatorException - if an error occurs while creating the installation descriptor
      • createPearPackage

        public static java.lang.String createPearPackage​(java.lang.String componentID,
                                                         java.lang.String mainComponentDir,
                                                         java.lang.String targetDir)
                                                  throws PackageCreatorException
        create pear package based on the given information. This method can be called if a installation descriptor is already available or generated. The method will not generate the installation descriptor if it is not present.
        Parameters:
        componentID - Specify a componentID for this component
        mainComponentDir - Specify the main component root directory that contains all the resources for the component. The mainComponentDir is packaged to the pear file.
        targetDir - Specify the target directory where the generated pear file is written to.
        Returns:
        Retuns path absolute path to the created pear package.
        Throws:
        PackageCreatorException - if the pear package can not be created successfully.
      • addMacro

        private static java.lang.String addMacro​(java.lang.String s)
        adds the $main_root/ macro as a prefix to the given string
        Parameters:
        s - a String representing a relative path to the project root
        Returns:
        The String with the macro
      • getRelativePath

        private static java.lang.String getRelativePath​(java.lang.String mainDir,
                                                        java.io.File currentPath)
        returns a postfix path of the currendPath based on the mainDir prefix.
        Parameters:
        mainDir - Main directory - this prefix is cut from the currentPath
        currentPath - a Path element that has the mainDir as prefix.
        Returns:
        returns the postfix of the currendPath based on the mainDir prefix.
      • zipDirectory

        private static void zipDirectory​(java.lang.String componentID,
                                         java.lang.String mainDir,
                                         java.io.File sourceDir,
                                         java.util.zip.ZipOutputStream zipOut)
                                  throws PackageCreatorException
        adds recursivly all files and directories based on the source directory to the ZipOutputStream.
        Parameters:
        componentID - componentID of the pear package.
        mainDir - Main directory path that should be zipped.
        sourceDir - Source directory that should be zipped.
        zipOut - zip file output stream
        Throws:
        PackageCreatorException - if an error occurs while adding the file and directories to the zip file.