Multiple Install Types

The Multiple Install Types are intended primarily for internal use by JExpress. If you do want to create your own custom panel to manage multiple install types, then here is some information that will help.

JExpress provides unparalleled flexibility to developers in setting up their install types. There are some fairly advanced data structures needed to provide that flexibility.

You set up install types, file groups, and file sets using the Advanced interface. The JExpress Installer then uses that information. An install type is a list of file groups. A file group is a list of files sets. A file set is a wildcard file specification, a directory, or a single file. Each file set with a wildcard may or may not include matching files in subdirectories.

Below you'll find an example of how to traverse the installer's properties to access the associated folders and file sets with the user selected install type. There are 3 properties which contain all the information about install types, folders, and file sets: FileGroupsTypes, FileGroupsFolders, and relativeFileMap. The FileGroupsTypes and the FileGroupsFolders contain a list of FileGroups.

If you look at the documentation for the FileGroup, you'll see that it consists of a property list containing a name, description, and elements. For the install types (i.e., the FileGroupsFolders property), the elements are the names of the folders associated with the install type. Similarly, the elements of the folders (i.e., the FileGroupsFolders property), contain the names of the file sets associated with the folder. A file set is one item on the Files panel.

Remember that the same folder can be associated with multiple install types. Also, the same file set can be associated with multiple folders.

To tell whether multiple install types are available in a custom install panel use:

        boolean available = CustomInstaller. multipleFileGroups ();

JExpress creates creates 2 compressed files when it builds an installer: install.jar and the gzip file that has the application files. The application gzip file is initially inside install.jar. In a native installation install.jar is inside the native executable file.

You must extract the gzip file with your application files from install.jar before you can extract any files for your application gzip file. You can get the application gzip file's name by including the following method in your custom panel:

        String getJarFilename () {
        return getPropertyList (). getProperty (
SafePackageName ) +
               JarFileSuffix +
               "." +
               JarFileExtension;
        }

You can extract the application's gzip file with the following method:

    String applicationDirectoryName = getPropertyList (). getProperty (
ApplicationDirectory );
    File appDir = new File ( applicationDirectoryName );
    File f = new File ( appDir, getJarFilename () );
    boolean ok = extractJarFile ( f, appDir );


    boolean extractJarFile ( File f,
                             File directory ) {

        boolean ok = true;

        try {

            // the full JarFile class is not part of the standard API,
            // but the following methods are documented here for your use

            // pass the name of the JAR file that you want to manage
            JarFile jarFile = new JarFile ( getInstallerJarFilename () );

            // remove the file name (passed as the first parameter)
            // into the directory (passed as the second parameter)
            jarFile. unarchiveFileToDirectory ( getJarFilename (),
                                                directory );

            // close the JAR file
            jarFile. close ();
        }

        catch ( Exception e ) {

            if ( ! CustomInstaller.getResourceAsFile (
getJarFilename (),
                                                      f. getPath () ) ) {
                String msg = "Unable to extract " +
                             getJarFilename () +
                             " from " +
                             getInstallerJarFilename ();
                logException ( msg, e );
                ok = false;
            }
        }

        return ok;

    }


    String getInstallerJarFilename () {
        return StandalonePureJavaPrefix +
               "." +
               JarFileExtension;
    }

A custom panel gets the names and descriptions of available types like this:

        FileGroupsListEditor fileGroups = new FileGroupsListEditor ( new
ListEditor () );
        fileGroups. fromString ( getPropertyList (). getProperty (
FileGroupsTypes, "" ) );

        Enumeration types = fileGroups. getItems (). elements ();
        while ( types. hasMoreElements () ) {

            FileGroup type = (FileGroup) types. nextElement ();
            String name = type. getName ();
            String description = type. getDescription ();

            // put your code to do something with the names and descriptions here

         }

If you use the built-in multiple install types panel, then the user's selected install type is in the InstallType property. Of course, if you write a custom panel to manage the user's selection of the multiple install types, then you can store the information in any property that you'd like. You get the currently selected install type from the built-in multiple install types panel from:

        String typeName = getPropertyList (). getProperty (
InstallType );

When JExpress creates an installation JAR file, it uses file sets which are based on the developer's file system. The jar file stores these files with only the directory information that is needed on a user's system. The data structure thats maps between the developer's and user's system is called a relativeFileMap.

Using these data structures to extract the files for a particular install type is straight forward:

    {
        // get the install type the user selected
        String installType = getPropertyList (). getProperty (
InstallType, "" );

        // map the install types into a manageable structure
        FileGroupsListEditor typeGroups = new FileGroupsListEditor ( new
ListEditor () );
        typeGroups. fromString ( getPropertyList (). getProperty (
FileGroupsTypes, "" ) );

        // map the folders
        FileGroupsListEditor folderGroups = new FileGroupsListEditor ( new
ListEditor () );
        folderGroups. fromString ( getPropertyList (). getProperty (
FileGroupsFolders, "" ) );

        // map the file sets
        String fileMapString = getPropertyList (). getProperty (
RelativeFileMap, "" );
        Hashtable relativeFileMap = StringConversions. toHashtable ( fileMapString );

        // find the matching install type
        FileGroup type = getNamedFileGroup ( typeGroups, installType );

        // open the JAR file that we extracted earlier so we can get the individual files
        File f = new File ( applicationDirectory, getJarFilename () );
        JarFile jarFile = new JarFile ( f. getPath () );

        // get the folder names for this install type
        Enumeration folderNames = type. getElements (). elements ();
        while ( folderNames != null &&
                folderNames. hasMoreElements () ) {

            // get the matching folder
            String folderName = (String) folderNames. nextElement ();
            FileGroup folder = getNamedFileGroup ( folderGroups, folderName );

            // get the filesets for this folder
            Enumeration fileSets = folder. getElements (). elements ();
            while ( fileSets != null &&
                    fileSets. hasMoreElements () ) {

                String fileSet = (String) fileSets. nextElement ();

                // get the files for this file set
                Vector files = (Vector) relativeFileMap. get ( fileSet );
                if ( files != null ) {

                    Enumeration enum = files. elements ();
                    while ( enum != null &&
                            enum. hasMoreElements () ) {

                        // get the name of a file that's part of the install type's folder
                        String toFilepath = (String) enum. nextElement ();

                        // unarchive the toFilepath to the application/installation directory
                        jarFile. unarchiveFileToDirectory ( toFilepath, applicationDirectory );
                }

            }

            // close the JAR file
            jarFile. close ();
        }
    }


    FileGroup getNamedFileGroup ( FileGroupsListEditor groupList,
                                  String name ) {

        Enumeration groups = groupList. getItems (). elements ();
        FileGroup group = null;
        while ( groups. hasMoreElements () &&
                group == null ) {

            FileGroup g = (FileGroup) groups. nextElement ();
            if ( g. getName (). equals ( name ) ) {
                group = g;
            }
        }

        return group;
    }

If you have questions or need any additional information, please send e-mail to DeNova's support email account.