com.izforge.izpack.compiler
Class Compiler

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.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
 
Field Summary
protected  java.lang.String basedir
          The base directory.
private  boolean compileFailed
          Error code, set to true if compilation succeeded.
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  Packager packager
          Collects and packs files into installation jars, as told.
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 constraints)
          This method parses install.xml for defined listeners and put them in the right position.
 void addJarContent(java.net.URL content)
          Add jar content to the installation.
 void addJarContent(java.net.URL content, java.util.List files)
          Add jar content to the installation.
 void addLangPack(java.lang.String iso3, java.net.URL iso3xmlURL, java.net.URL iso3FlagURL)
          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.
protected  void addRecursively(java.io.File file, java.lang.String targetdir, java.util.List osList, int override, PackInfo pack, java.util.Map additionals)
          Recursive method to add files in a pack.
 void addResource(java.lang.String name, java.net.URL url)
          Add a resource to the installation.
private  int checkBackEdges(java.util.Map 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 packs)
          Checks whether the dependencies among the given Packs.
 void compile()
          Compiles.
 void createInstaller()
          Compiles the installation.
private  int dfs(java.util.List packs, java.util.Map 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 names, java.util.Map 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.
private  java.util.List getContainedFilePaths(java.net.URL url)
          Returns a list which contains the pathes of all files which are included in the given url.
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.
 Packager getPackager()
          Get the install packager.
 PackagerListener getPackagerListener()
          Retrieves the packager listener
 java.util.Properties getProperties()
          Get 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.
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)
           
 java.lang.String replaceProperties(java.lang.String value)
           
 void run()
          The run() method.
 void setGUIPrefs(GUIPrefs prefs)
           
 void setInfo(Info info)
           
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()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, 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 Packager 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

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

getPackagerListener

public PackagerListener getPackagerListener()
Retrieves 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.


createInstaller

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

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

wasSuccessful

public boolean wasSuccessful()

replaceProperties

public java.lang.String replaceProperties(java.lang.String value)
                                   throws CompilerException
Throws:
CompilerException

setGUIPrefs

public void setGUIPrefs(GUIPrefs prefs)

setInfo

public void setInfo(Info info)
             throws java.lang.Exception
Throws:
java.lang.Exception

getPackager

public Packager getPackager()
Get the install packager.

Returns:
the install packager.

getProperties

public java.util.Properties getProperties()
Get 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.

Parameters:
name - the name of the property
value - the value to set
Returns:
true

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 files)
Add jar content to the installation.

Parameters:
content -

addCustomJar

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

Parameters:
ca -
url -

addLangPack

public void addLangPack(java.lang.String iso3,
                        java.net.URL iso3xmlURL,
                        java.net.URL iso3FlagURL)
Add a lang pack to the installation.

Parameters:
iso3 -
iso3xmlURL -
iso3FlagURL -

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

checkDependencies

public void checkDependencies(java.util.List 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 packs,
                java.util.Map 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

checkBackEdges

private int checkBackEdges(java.util.Map edges)
This function checks for the existence of back edges.


dfsVisit

private int dfsVisit(PackInfo u,
                     java.util.Map names,
                     java.util.Map edges)

addRecursively

protected void addRecursively(java.io.File file,
                              java.lang.String targetdir,
                              java.util.List osList,
                              int override,
                              PackInfo pack,
                              java.util.Map additionals)
                       throws java.io.IOException
Recursive method to add files in a pack.

Parameters:
file - The file to add.
targetdir - The relative path to the parent.
osList - The target OS constraints.
override - Overriding behaviour.
pack - Pack to be packed into
additionals - Map which contains additional data
Throws:
FileNotFoundException - if the file does not exist
java.io.IOException

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
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 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 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