com.izforge.izpack.compiler
Class Packager

java.lang.Object
  extended by com.izforge.izpack.compiler.Packager

public class Packager
extends java.lang.Object

The packager class. The packager is used by the compiler to put files into an installer, and create the actual installer files.

Author:
Julien Ponge, Chadwick McHenry

Field Summary
private  java.util.HashMap alreadyWrittenFiles
          Files which are always written into the container file
private  java.io.File baseFile
          Base file name of all jar files.
private  PackCompressor compressor
          The compression format to be used for pack compression
private  java.util.List customDataList
          The ordered custom actions informations.
private  GUIPrefs guiPrefs
          Gui preferences of instatller.
private  java.util.Set includedJarURLs
          Jar file URLs who's contents will be copied into the installer.
private  Info info
          Basic installer info.
private  java.util.Map installerResourceURLMap
          The langpack URLs keyed by ISO3 name.
private  java.util.List langpackNameList
          The ordered langpack ISO3 names.
private  PackagerListener listener
          The listeners.
private  boolean packJarsSeparate
          Each pack is created in a separte jar if webDirURL is non-null.
private  java.util.List packsList
          The ordered packs informations (as PackInfo objects).
private  java.util.List panelList
          The ordered panels informations.
private  JarOutputStream primaryJarStream
          Executable zipped output stream.
static java.lang.String SKELETON_SUBPATH
          Path to the skeleton installer.
private  java.util.Properties variables
          The variables used in the project
 
Constructor Summary
Packager()
          The constructor.
Packager(java.lang.String compr_format)
          Extended constructor.
Packager(java.lang.String compr_format, int compr_level)
          Extended constructor.
 
Method Summary
 void addCustomJar(CustomData ca, java.net.URL url)
          Add a custom data like custom actions, where order is important.
 void addJarContent(java.net.URL jarURL)
          Adds a jar file content to the installer.
 void addJarContent(java.net.URL jarURL, java.util.List files)
          Adds a jar file content to the installer.
 void addLangPack(java.lang.String iso3, java.net.URL xmlURL, java.net.URL flagURL)
          Adds a language pack.
 void addNativeLibrary(java.lang.String name, java.net.URL url)
          Adds a native library.
 void addNativeUninstallerLibrary(CustomData data)
          Marks a native library to be added to the uninstaller.
 void addPack(PackInfo pack)
          Adds a pack, order is mostly irrelevant.
 void addPanelJar(Panel panel, java.net.URL jarURL)
          Add a panel, where order is important.
 void addResource(java.lang.String resId, java.net.URL url)
          Adds a resource.
private  long copyStream(java.io.InputStream in, java.io.OutputStream out)
          Copies all the data from the specified input stream to the specified output stream.
private  void copyZip(java.util.zip.ZipInputStream zin, org.apache.tools.zip.ZipOutputStream out)
          Copies contents of one jar to another.
private  void copyZip(java.util.zip.ZipInputStream zin, org.apache.tools.zip.ZipOutputStream out, java.util.List files)
          Copies specified contents of one jar to another.
 void createInstaller(java.io.File primaryFile)
          Create the installer, beginning with the specified jar.
 PackCompressor getCompressor()
          Returns the current pack compressor
private  JarOutputStream getJarOutputStream(java.lang.String name)
          Return a stream for the next jar.
 PackagerListener getPackagerListener()
          Get the PackagerListener.
 java.util.List getPacksList()
          Gets the packages list
 java.util.Properties getVariables()
          Allows access to add, remove and update the variables for the project, which are maintained in the packager.
private  void sendMsg(java.lang.String job)
          Dispatches a message to the listeners.
private  void sendMsg(java.lang.String job, int priority)
          Dispatches a message to the listeners at specified priority.
private  void sendStart()
          Dispatches a start event to the listeners.
private  void sendStop()
          Dispatches a stop event to the listeners.
 void setGUIPrefs(GUIPrefs prefs)
          Sets the GUI preferences.
 void setInfo(Info info)
          Sets the informations related to this installation.
 void setPackagerListener(PackagerListener listener)
          Adds a listener.
private  void writeIncludedJars()
          Copy included jars to primary jar.
private  void writeInstallerObject(java.lang.String entryName, java.lang.Object object)
          Write an arbitrary object to primary jar.
private  void writeInstallerResources()
          Write the data referenced by URL to primary jar.
private  void writePacks()
          Write Packs to primary jar or each to a separate jar.
private  void writeSkeletonInstaller()
          Write skeleton installer to primary jar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SKELETON_SUBPATH

public static final java.lang.String SKELETON_SUBPATH
Path to the skeleton installer.

See Also:
Constant Field Values

baseFile

private java.io.File baseFile
Base file name of all jar files. This has no ".jar" suffix.


primaryJarStream

private JarOutputStream primaryJarStream
Executable zipped output stream. First to open, last to close. Attention! This is our own JarOutputStream, not the java standard!


info

private Info info
Basic installer info.


guiPrefs

private GUIPrefs guiPrefs
Gui preferences of instatller.


variables

private java.util.Properties variables
The variables used in the project


panelList

private java.util.List panelList
The ordered panels informations.


packsList

private java.util.List packsList
The ordered packs informations (as PackInfo objects).


langpackNameList

private java.util.List langpackNameList
The ordered langpack ISO3 names.


customDataList

private java.util.List customDataList
The ordered custom actions informations.


installerResourceURLMap

private java.util.Map installerResourceURLMap
The langpack URLs keyed by ISO3 name.


includedJarURLs

private java.util.Set includedJarURLs
Jar file URLs who's contents will be copied into the installer.


packJarsSeparate

private boolean packJarsSeparate
Each pack is created in a separte jar if webDirURL is non-null.


listener

private PackagerListener listener
The listeners.


compressor

private PackCompressor compressor
The compression format to be used for pack compression


alreadyWrittenFiles

private java.util.HashMap alreadyWrittenFiles
Files which are always written into the container file

Constructor Detail

Packager

public Packager()
         throws CompilerException
The constructor.

Throws:
CompilerException

Packager

public Packager(java.lang.String compr_format)
         throws CompilerException
Extended constructor.

Parameters:
compr_format - Compression format to be used for packs compression format (if supported)
Throws:
CompilerException

Packager

public Packager(java.lang.String compr_format,
                int compr_level)
         throws CompilerException
Extended constructor.

Parameters:
compr_format - Compression format to be used for packs
compr_level - Compression level to be used with the chosen compression format (if supported)
Throws:
CompilerException
Method Detail

createInstaller

public void createInstaller(java.io.File primaryFile)
                     throws java.lang.Exception
Create the installer, beginning with the specified jar. If the name specified does not end in ".jar", it is appended. If secondary jars are created for packs (if the Info object added has a webDirURL set), they are created in the same directory, named sequentially by inserting ".pack#" (where '#' is the pack number) ".jar" suffix: e.g. "foo.pack1.jar". If any file exists, it is overwritten.

Throws:
java.lang.Exception

getPackagerListener

public PackagerListener getPackagerListener()
Get the PackagerListener.

Returns:
the current PackagerListener

setPackagerListener

public void setPackagerListener(PackagerListener listener)
Adds a listener.

Parameters:
listener - The listener.

sendMsg

private void sendMsg(java.lang.String job)
Dispatches a message to the listeners.

Parameters:
job - The job description.

sendMsg

private void sendMsg(java.lang.String job,
                     int priority)
Dispatches a message to the listeners at specified priority.

Parameters:
job - The job description.
priority - The message priority.

sendStart

private void sendStart()
Dispatches a start event to the listeners.


sendStop

private void sendStop()
Dispatches a stop event to the listeners.


setInfo

public void setInfo(Info info)
             throws java.lang.Exception
Sets the informations related to this installation.

Parameters:
info - The info section.
Throws:
java.lang.Exception - Description of the Exception

setGUIPrefs

public void setGUIPrefs(GUIPrefs prefs)
Sets the GUI preferences.

Parameters:
prefs - The new gUIPrefs value
Throws:
java.lang.Exception - Description of the Exception

getVariables

public java.util.Properties getVariables()
Allows access to add, remove and update the variables for the project, which are maintained in the packager.

Returns:
map of variable names to values

addPanelJar

public void addPanelJar(Panel panel,
                        java.net.URL jarURL)
Add a panel, where order is important. Only one copy of the class files neeed are inserted in the installer.


addCustomJar

public void addCustomJar(CustomData ca,
                         java.net.URL url)
Add a custom data like custom actions, where order is important. Only one copy of the class files neeed are inserted in the installer.

Parameters:
ca - custom action object
url - the URL to include once

addPack

public void addPack(PackInfo pack)
Adds a pack, order is mostly irrelevant.

Parameters:
pack - contains all the files and items that go with a pack

getPacksList

public java.util.List getPacksList()
Gets the packages list


addLangPack

public void addLangPack(java.lang.String iso3,
                        java.net.URL xmlURL,
                        java.net.URL flagURL)
Adds a language pack.

Parameters:
iso3 - The ISO3 code.
xmlURL - The location of the xml local info
flagURL - The location of the flag image resource
Throws:
java.lang.Exception - Description of the Exception

addResource

public void addResource(java.lang.String resId,
                        java.net.URL url)
Adds a resource.

Parameters:
resId - The resource Id.
url - The location of the data
Throws:
java.lang.Exception - Description of the Exception

addNativeLibrary

public void addNativeLibrary(java.lang.String name,
                             java.net.URL url)
                      throws java.lang.Exception
Adds a native library.

Parameters:
name - The native library name.
url - The url to get the data from.
Throws:
java.lang.Exception - Description of the Exception

addJarContent

public void addJarContent(java.net.URL jarURL)
Adds a jar file content to the installer. Package structure is maintained. Need mechanism to copy over signed entry information.

Parameters:
jarURL - The url of the jar to add to the installer. We use a URL so the jar may be nested within another.

addJarContent

public void addJarContent(java.net.URL jarURL,
                          java.util.List files)
Adds a jar file content to the installer. Package structure is maintained. Need mechanism to copy over signed entry information.

Parameters:
jarURL - The url of the jar to add to the installer. We use a URL so the jar may be nested within another.

addNativeUninstallerLibrary

public void addNativeUninstallerLibrary(CustomData data)
Marks a native library to be added to the uninstaller.

Parameters:
data - the describing custom action data object

writeSkeletonInstaller

private void writeSkeletonInstaller()
                             throws java.io.IOException
Write skeleton installer to primary jar. It is just an included jar, except that we copy the META-INF as well.

Throws:
java.io.IOException

writeInstallerObject

private void writeInstallerObject(java.lang.String entryName,
                                  java.lang.Object object)
                           throws java.io.IOException
Write an arbitrary object to primary jar.

Throws:
java.io.IOException

writeInstallerResources

private void writeInstallerResources()
                              throws java.io.IOException
Write the data referenced by URL to primary jar.

Throws:
java.io.IOException

writeIncludedJars

private void writeIncludedJars()
                        throws java.io.IOException
Copy included jars to primary jar.

Throws:
java.io.IOException

writePacks

private void writePacks()
                 throws java.lang.Exception
Write Packs to primary jar or each to a separate jar.

Throws:
java.lang.Exception

getJarOutputStream

private JarOutputStream getJarOutputStream(java.lang.String name)
                                    throws java.io.IOException
Return a stream for the next jar.

Throws:
java.io.IOException

copyZip

private void copyZip(java.util.zip.ZipInputStream zin,
                     org.apache.tools.zip.ZipOutputStream out)
              throws java.io.IOException
Copies contents of one jar to another.

TODO: it would be useful to be able to keep signature information from signed jar files, can we combine manifests and still have their content signed?

Throws:
java.io.IOException
See Also:
copyStream(InputStream, OutputStream)

copyZip

private void copyZip(java.util.zip.ZipInputStream zin,
                     org.apache.tools.zip.ZipOutputStream out,
                     java.util.List files)
              throws java.io.IOException
Copies specified contents of one jar to another.

TODO: it would be useful to be able to keep signature information from signed jar files, can we combine manifests and still have their content signed?

Throws:
java.io.IOException
See Also:
copyStream(InputStream, OutputStream)

copyStream

private long copyStream(java.io.InputStream in,
                        java.io.OutputStream out)
                 throws java.io.IOException
Copies all the data from the specified input stream to the specified output stream.

Parameters:
in - the input stream to read
out - the output stream to write
Returns:
the total number of bytes copied
Throws:
java.io.IOException - if an I/O error occurs

getCompressor

public PackCompressor getCompressor()
Returns the current pack compressor

Returns:
Returns the current pack compressor.