com.izforge.izpack.compiler
Class Compiler

java.lang.Object
  extended by java.lang.Thread
      extended by com.izforge.izpack.compiler.Compiler
All Implemented Interfaces:
java.lang.Runnable

public class Compiler
extends java.lang.Thread

The IzPack compiler class. This is now a java bean style class that can be configured using the object representations of the install.xml configuration. The install.xml configuration is now handled by the CompilerConfig class.

Author:
Julien Ponge, Tino Schwarze, Chadwick McHenry
See Also:
CompilerConfig

Nested Class Summary
(package private) static class Compiler.CmdlinePackagerListener
          Used to handle the packager messages in the command-line mode.
private  class Compiler.Edge
          This class is used for the classification of the edges
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  java.lang.String basedir
          The base directory.
private  boolean compileFailed
          Error code, set to true if compilation succeeded.
private  java.lang.String compr_format
           
private  int compr_level
           
static java.lang.String IZPACK_HOME
          The IzPack home directory.
static java.lang.String IZPACK_VERSION
          The IzPack version.
protected  java.lang.String kind
          The installer kind.
protected  java.lang.String output
          The output jar filename.
private  IPackager packager
          Collects and packs files into installation jars, as told.
private  PackagerListener packagerlistener
           
private  java.util.Properties properties
          Key/values which are substituted at compile time in the install data
private  VariableSubstitutor propertySubstitutor
          Replaces the properties in the install.xml file prior to compiling
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Compiler(java.lang.String basedir, java.lang.String kind, java.lang.String output)
          The constructor.
Compiler(java.lang.String basedir, java.lang.String kind, java.lang.String output, java.lang.String compr_format)
          The constructor.
Compiler(java.lang.String basedir, java.lang.String kind, java.lang.String output, java.lang.String compr_format, int compr_level)
          The constructor.
 
Method Summary
 void addCustomJar(CustomData ca, java.net.URL url)
          Add a custom jar to the installation.
 void addCustomListener(int type, java.lang.String className, java.lang.String jarPath, java.util.List<OsConstraint> constraints)
          This method parses install.xml for defined listeners and put them in the right position.
 void addInstallerRequirement(java.util.List<InstallerRequirement> conditions)
           
 void addJarContent(java.net.URL content)
          Add jar content to the installation.
 void addJarContent(java.net.URL content, java.util.List<java.lang.String> files)
          Adds a jar file content to the installer.
 void addLangPack(java.lang.String locale, java.net.URL localeURL, java.net.URL flagURL)
          Add a lang pack to the installation.
 void addNativeLibrary(java.lang.String name, java.net.URL url)
          Add a native library to the installation.
 void addNativeUninstallerLibrary(CustomData data)
          Add an unistaller library.
 void addPack(PackInfo pack)
          Add a pack to the installation.
 void addPanelJar(Panel panel, java.net.URL url)
          Add a panel jar to the installation.
 boolean addProperty(java.lang.String name, java.lang.String value)
          Add a name value pair to the project property set.
 void addResource(java.lang.String name, java.net.URL url)
          Add a resource to the installation.
private  int checkBackEdges(java.util.Map<Compiler.Edge,java.lang.Integer> edges)
          This function checks for the existence of back edges.
 void checkDependencies()
          Checks whether the dependencies stated in the configuration file are correct.
 void checkDependencies(java.util.List<PackInfo> packs)
          Checks whether the dependencies among the given Packs.
 void checkExcludes()
          Checks whether the excluded packs exist.
 void checkExcludes(java.util.List<PackInfo> packs)
          This checks if there are more than one preselected packs per excludeGroup.
 void compile()
          Compiles.
 void createInstaller()
          Compiles the installation.
private  int dfs(java.util.List<PackInfo> packs, java.util.Map<java.lang.String,PackInfo> names)
          We use the dfs graph search algorithm to check whether the graph is acyclic as described in: Thomas H.
private  int dfsVisit(PackInfo u, java.util.Map<java.lang.String,PackInfo> names, java.util.Map<Compiler.Edge,java.lang.Integer> edges)
           
 java.net.URL findIzPackResource(java.lang.String path, java.lang.String desc)
          Look for an IzPack resource either in the compiler jar, or within IZPACK_HOME.
 java.util.Map<java.lang.String,Condition> getConditions()
           
private  java.util.List<java.lang.String> getContainedFilePaths(java.net.URL url)
          Returns a list which contains the pathes of all files which are included in the given url.
 java.util.Map<java.lang.String,java.util.List<DynamicVariable>> getDynamicVariables()
           
private  java.lang.String getFullClassName(java.net.URL url, java.lang.String className)
          Returns the qualified class name for the given class.
 java.lang.String getKind()
          Access the installation kind.
 IPackager getPackager()
          Returns the install packager.
 PackagerListener getPackagerListener()
          Returns the packager listener.
 java.util.Properties getProperties()
          Returns the properties currently known to the compileer.
 java.lang.String getProperty(java.lang.String name)
          Get the value of a property currerntly known to izpack.
 java.util.Properties getVariables()
          Get the packager variables.
 void initPackager(java.lang.String classname)
          Initializes the given packager class
static void main(java.lang.String[] args)
          The main method if the compiler is invoked by a command-line call.
 void parseError(java.lang.String message)
          Create parse error with consistent messages.
 void parseError(java.lang.String message, java.lang.Throwable how)
          Create parse error with consistent messages.
 java.lang.String replaceProperties(java.lang.String value)
          Replaces placeholder in the given string with the associated strings.
 void run()
          The run() method.
 void setConditions(java.util.Map<java.lang.String,Condition> conditions)
           
 void setDynamicVariables(java.util.Map<java.lang.String,java.util.List<DynamicVariable>> dynamicvariables)
           
 void setGUIPrefs(GUIPrefs prefs)
          Sets GUI preferences to the packager.
 void setInfo(Info info)
          Sets an Info object to the packager.
static void setIzpackHome(java.lang.String izHome)
          Set the IzPack home directory
 void setPackagerListener(PackagerListener listener)
          Sets the packager listener.
 boolean setProperty(java.lang.String name, java.lang.String value)
          Add a name value pair to the project property set.
 boolean wasSuccessful()
          Returns whether the installation was successful or not.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IZPACK_VERSION

public static final java.lang.String IZPACK_VERSION
The IzPack version.

See Also:
Constant Field Values

IZPACK_HOME

public static java.lang.String IZPACK_HOME
The IzPack home directory.


basedir

protected java.lang.String basedir
The base directory.


kind

protected java.lang.String kind
The installer kind.


output

protected java.lang.String output
The output jar filename.


packager

private IPackager packager
Collects and packs files into installation jars, as told.


compileFailed

private boolean compileFailed
Error code, set to true if compilation succeeded.


properties

private java.util.Properties properties
Key/values which are substituted at compile time in the install data


propertySubstitutor

private VariableSubstitutor propertySubstitutor
Replaces the properties in the install.xml file prior to compiling


compr_format

private java.lang.String compr_format

compr_level

private int compr_level

packagerlistener

private PackagerListener packagerlistener
Constructor Detail

Compiler

public Compiler(java.lang.String basedir,
                java.lang.String kind,
                java.lang.String output)
         throws CompilerException
The constructor.

Parameters:
basedir - The base directory.
kind - The installer kind.
output - The installer filename.
Throws:
CompilerException

Compiler

public Compiler(java.lang.String basedir,
                java.lang.String kind,
                java.lang.String output,
                java.lang.String compr_format)
         throws CompilerException
The constructor.

Parameters:
basedir - The base directory.
kind - The installer kind.
output - The installer filename.
compr_format - The format which should be used for the packs.
Throws:
CompilerException

Compiler

public Compiler(java.lang.String basedir,
                java.lang.String kind,
                java.lang.String output,
                java.lang.String compr_format,
                int compr_level)
         throws CompilerException
The constructor.

Parameters:
basedir - The base directory.
kind - The installer kind.
output - The installer filename.
compr_format - The format which should be used for the packs.
compr_level - Compression level to be used if supported.
Throws:
CompilerException
Method Detail

setIzpackHome

public static void setIzpackHome(java.lang.String izHome)
Set the IzPack home directory

Parameters:
izHome - - the izpack home directory

initPackager

public void initPackager(java.lang.String classname)
                  throws CompilerException
Initializes the given packager class

Parameters:
classname -
Throws:
CompilerException

getPackagerListener

public PackagerListener getPackagerListener()
Returns the packager listener.

Returns:
the packager listener

setPackagerListener

public void setPackagerListener(PackagerListener listener)
Sets the packager listener.

Parameters:
listener - The listener.

getKind

public java.lang.String getKind()
Access the installation kind.

Returns:
the installation kind.

getVariables

public java.util.Properties getVariables()
Get the packager variables.

Returns:
the packager variables

compile

public void compile()
Compiles.


run

public void run()
The run() method.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

createInstaller

public void createInstaller()
                     throws java.lang.Exception
Compiles the installation.

Throws:
java.lang.Exception - Description of the Exception

wasSuccessful

public boolean wasSuccessful()
Returns whether the installation was successful or not.

Returns:
whether the installation was successful or not

replaceProperties

public java.lang.String replaceProperties(java.lang.String value)
Replaces placeholder in the given string with the associated strings.

Parameters:
value - to be substituted
Returns:
the substituted string

setGUIPrefs

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

Parameters:
prefs - preferences to be set

setInfo

public void setInfo(Info info)
             throws java.lang.Exception
Sets an Info object to the packager.

Parameters:
info - Info object to be set
Throws:
java.lang.Exception

getPackager

public IPackager getPackager()
Returns the install packager.

Returns:
the install packager.

getProperties

public java.util.Properties getProperties()
Returns the properties currently known to the compileer.

Returns:
the properties currently known to the compileer

getProperty

public java.lang.String getProperty(java.lang.String name)
Get the value of a property currerntly known to izpack.

Parameters:
name - the name of the property
Returns:
the value of the property, or null

setProperty

public boolean setProperty(java.lang.String name,
                           java.lang.String value)
Add a name value pair to the project property set. Overwriting any existing value except system properties.

Parameters:
name - the name of the property
value - the value to set
Returns:
an indicator if the name value pair was added.

addProperty

public boolean addProperty(java.lang.String name,
                           java.lang.String value)
Add a name value pair to the project property set. It is not replaced it is already in the set of properties.

Parameters:
name - the name of the property
value - the value to set
Returns:
true if the property was not already set

addJarContent

public void addJarContent(java.net.URL content)
Add jar content to the installation.

Parameters:
content -

addJarContent

public void addJarContent(java.net.URL content,
                          java.util.List<java.lang.String> files)
Adds a jar file content to the installer. Package structure is maintained. Need mechanism to copy over signed entry information. If the given file list is null the hole contents of the jar file will be copied else only the listed.

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

addCustomJar

public void addCustomJar(CustomData ca,
                         java.net.URL url)
Add a custom jar to the installation.

Parameters:
ca -
url -

addInstallerRequirement

public void addInstallerRequirement(java.util.List<InstallerRequirement> conditions)

addLangPack

public void addLangPack(java.lang.String locale,
                        java.net.URL localeURL,
                        java.net.URL flagURL)
Add a lang pack to the installation.

Parameters:
locale -
localeURL -
flagURL -

addNativeLibrary

public void addNativeLibrary(java.lang.String name,
                             java.net.URL url)
                      throws java.lang.Exception
Add a native library to the installation.

Parameters:
name -
url -
Throws:
java.lang.Exception

addNativeUninstallerLibrary

public void addNativeUninstallerLibrary(CustomData data)
Add an unistaller library.

Parameters:
data -

addPack

public void addPack(PackInfo pack)
Add a pack to the installation.

Parameters:
pack -

addPanelJar

public void addPanelJar(Panel panel,
                        java.net.URL url)
Add a panel jar to the installation.

Parameters:
panel -
url -

addResource

public void addResource(java.lang.String name,
                        java.net.URL url)
Add a resource to the installation.

Parameters:
name -
url -

checkDependencies

public void checkDependencies()
                       throws CompilerException
Checks whether the dependencies stated in the configuration file are correct. Specifically it checks that no pack point to a non existent pack and also that there are no circular dependencies in the packs.

Throws:
CompilerException

checkExcludes

public void checkExcludes()
                   throws CompilerException
Checks whether the excluded packs exist. (simply calles the other function)

Throws:
CompilerException

checkExcludes

public void checkExcludes(java.util.List<PackInfo> packs)
                   throws CompilerException
This checks if there are more than one preselected packs per excludeGroup.

Parameters:
packs - list of packs which should be checked
Throws:
CompilerException

checkDependencies

public void checkDependencies(java.util.List<PackInfo> packs)
                       throws CompilerException
Checks whether the dependencies among the given Packs. Specifically it checks that no pack point to a non existent pack and also that there are no circular dependencies in the packs.

Parameters:
packs - - List representing the packs in the installation
Throws:
CompilerException

dfs

private int dfs(java.util.List<PackInfo> packs,
                java.util.Map<java.lang.String,PackInfo> names)
We use the dfs graph search algorithm to check whether the graph is acyclic as described in: Thomas H. Cormen, Charles Leiserson, Ronald Rivest and Clifford Stein. Introduction to algorithms 2nd Edition 540-549,MIT Press, 2001

Parameters:
packs - The graph
names - The name map
Returns:
-2 if back edges exist, else 0

checkBackEdges

private int checkBackEdges(java.util.Map<Compiler.Edge,java.lang.Integer> edges)
This function checks for the existence of back edges.

Parameters:
edges - map to be checked
Returns:
-2 if back edges exist, else 0

dfsVisit

private int dfsVisit(PackInfo u,
                     java.util.Map<java.lang.String,PackInfo> names,
                     java.util.Map<Compiler.Edge,java.lang.Integer> edges)

findIzPackResource

public java.net.URL findIzPackResource(java.lang.String path,
                                       java.lang.String desc)
                                throws CompilerException
Look for an IzPack resource either in the compiler jar, or within IZPACK_HOME. The path must not be absolute. The path must use '/' as the fileSeparator (it's used to access the jar file). If the resource is not found, a CompilerException is thrown indicating fault in the parent element.

Parameters:
path - the relative path (using '/' as separator) to the resource.
desc - the description of the resource used to report errors
Returns:
a URL to the resource.
Throws:
CompilerException

parseError

public void parseError(java.lang.String message)
                throws CompilerException
Create parse error with consistent messages. Includes file name. For use When parent is unknown.

Parameters:
message - Brief message explaining error
Throws:
CompilerException

parseError

public void parseError(java.lang.String message,
                       java.lang.Throwable how)
                throws CompilerException
Create parse error with consistent messages. Includes file name. For use When parent is unknown.

Parameters:
message - Brief message explaining error
how - throwable which was catched
Throws:
CompilerException

main

public static void main(java.lang.String[] args)
The main method if the compiler is invoked by a command-line call. This simply calls the CompilerConfig.main method.

Parameters:
args - The arguments passed on the command-line.

addCustomListener

public void addCustomListener(int type,
                              java.lang.String className,
                              java.lang.String jarPath,
                              java.util.List<OsConstraint> constraints)
                       throws java.lang.Exception
This method parses install.xml for defined listeners and put them in the right position. If posible, the listeners will be validated. Listener declaration is a fragmention in install.xml like : <listeners> <listener compiler="PermissionCompilerListener" installer="PermissionInstallerListener"/1gt; </listeners>

Parameters:
type - The listener type.
className - The class name.
jarPath - The jar path.
constraints - The list of constraints.
Throws:
java.lang.Exception - Thrown in case an error occurs.

getContainedFilePaths

private java.util.List<java.lang.String> getContainedFilePaths(java.net.URL url)
                                                        throws java.lang.Exception
Returns a list which contains the pathes of all files which are included in the given url. This method expects as the url param a jar.

Parameters:
url - url of the jar file
Returns:
full qualified paths of the contained files
Throws:
java.lang.Exception

getFullClassName

private java.lang.String getFullClassName(java.net.URL url,
                                          java.lang.String className)
                                   throws java.lang.Exception
Returns the qualified class name for the given class. This method expects as the url param a jar file which contains the given class. It scans the zip entries of the jar file.

Parameters:
url - url of the jar file which contains the class
className - short name of the class for which the full name should be resolved
Returns:
full qualified class name
Throws:
java.lang.Exception

getConditions

public java.util.Map<java.lang.String,Condition> getConditions()
Returns:
the conditions

setConditions

public void setConditions(java.util.Map<java.lang.String,Condition> conditions)
Parameters:
conditions - the conditions to set

getDynamicVariables

public java.util.Map<java.lang.String,java.util.List<DynamicVariable>> getDynamicVariables()

setDynamicVariables

public void setDynamicVariables(java.util.Map<java.lang.String,java.util.List<DynamicVariable>> dynamicvariables)