com.izforge.izpack.compiler
Class CompilerConfig

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

public class CompilerConfig
extends java.lang.Thread

A parser for the installer xml configuration. This parses a document conforming to the installation.dtd and populates a Compiler instance to perform the install compilation.

Version:
$Revision: 1391 $
Author:
Scott Stark

Nested Class Summary
private  class CompilerConfig.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  Compiler compiler
          The installer packager compiler
protected  java.util.List compilerListeners
          List of CompilerListeners which should be called at packaging
private  java.lang.String filename
          The xml install file
private  java.lang.String installText
          The xml install configuration text
private static boolean NO
          Constant for checking attributes.
static java.lang.String STANDARD
          Standard installer.
static java.lang.String VERSION
          The compiler version.
static java.lang.String WEB
          Web installer.
private static boolean YES
          Constant for checking attributes.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CompilerConfig(java.lang.String basedir, java.lang.String kind, java.lang.String output, PackagerListener listener, java.lang.String installText)
           
CompilerConfig(java.lang.String filename, java.lang.String basedir, java.lang.String kind, java.lang.String output)
          The constructor.
CompilerConfig(java.lang.String filename, java.lang.String basedir, java.lang.String kind, java.lang.String output, PackagerListener listener)
          The constructor.
CompilerConfig(java.lang.String filename, java.lang.String basedir, java.lang.String kind, java.lang.String output, java.lang.String compr_format, int compr_level, PackagerListener listener, java.lang.String installText)
           
CompilerConfig(java.lang.String filename, java.lang.String base, java.lang.String kind, java.lang.String output, java.lang.String compr_format, PackagerListener listener)
           
CompilerConfig(java.lang.String filename, java.lang.String basedir, java.lang.String kind, java.lang.String output, java.lang.String compr_format, PackagerListener listener, java.lang.String installText)
           
 
Method Summary
private  void addCompilerListener(CompilerListener pe)
          Add a CompilerListener.
private  void addCustomListeners(XMLElement data)
          This method parses install.xml for defined listeners and put them in the right position.
protected  void addGUIPrefs(XMLElement data)
          Returns the GUIPrefs.
protected  void addInfo(XMLElement data)
          Builds the Info class from the XML tree.
protected  void addJars(XMLElement data)
          Add project specific external jar files to the installer.
protected  void addLangpacks(XMLElement data)
          Adds the ISO3 codes of the langpacks and associated resources.
protected  void addNativeLibraries(XMLElement data)
          Add native libraries to the installer.
protected  void addPacks(XMLElement data)
          Add packs and their contents to the installer.
protected  void addPanels(XMLElement data)
          Parse panels and their paramters, locate the panels resources and add to the Packager.
 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.
protected  void addResources(XMLElement data)
          Adds the resources.
protected  void addVariables(XMLElement data)
          Variable declaration is a fragment of the xml file.
private  int checkBackEdges(java.util.Map edges)
          This function checks for the existence of back edges.
 void checkDependencies(java.util.List packs)
          Checks whether the dependencies stated in the configuration file are correct.
 void compile()
          Compile 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)
           
 void executeCompiler()
          Compiles the installation.
private  java.net.URL findIzPackResource(java.lang.String path, java.lang.String desc, XMLElement parent)
          Look for an IzPack resource either in the compiler jar, or within IZPACK_HOME.
private  java.net.URL findProjectResource(java.lang.String path, java.lang.String desc, XMLElement parent)
          Look for a project specified resources, which, if not absolute, are sought relative to the projects basedir.
private  java.util.Map getAdditionals(XMLElement f)
          Calls the reviseAdditionalDataMap method of all registered CompilerListener's.
 Compiler getCompiler()
          Access the install compiler
private  java.lang.Object[] getCompilerListenerInstance(XMLElement var)
          Returns the compiler listener which is defined in the xml element.
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.
protected  int getOverrideValue(XMLElement f)
           
 PackagerListener getPackagerListener()
          Retrieves the packager listener
protected  XMLElement getXMLTree()
          Returns the XMLElement representing the installation XML file.
static void main(java.lang.String[] args)
          The main method if the compiler is invoked by a command-line call.
private  void notifyCompilerListener(java.lang.String callerName, int state, XMLElement data)
          Calls all defined compile listeners notify method with the given data
protected  void parseError(java.lang.String message)
          Create parse error with consistent messages.
protected  void parseError(XMLElement parent, java.lang.String message)
          Create parse error with consistent messages.
protected  void parseError(XMLElement parent, java.lang.String message, java.lang.Throwable cause)
          Create a chained parse error with consistent messages.
protected  void parseWarn(XMLElement parent, java.lang.String message)
          Create a parse warning with consistent messages.
protected  java.lang.String requireAttribute(XMLElement element, java.lang.String attribute)
          Call getAttribute on an element, producing a meaningful error message if not present, or empty.
protected  XMLElement requireChildNamed(XMLElement parent, java.lang.String name)
          Call getFirstChildNamed on the parent, producing a meaningful error message on failure.
protected  java.lang.String requireContent(XMLElement element)
          Call getContent on an element, producing a meaningful error message if not present, or empty.
protected  int requireIntAttribute(XMLElement element, java.lang.String attribute)
          Get a required attribute of an element, ensuring it is an integer.
protected  java.net.URL requireURLContent(XMLElement element)
          Call getContent on an element, producing a meaningful error message if not present, or empty, or a valid URL.
protected  boolean requireYesNoAttribute(XMLElement element, java.lang.String attribute)
          Call getAttribute on an element, producing a meaningful error message if not present, or one of "yes" or "no".
 void run()
          The run() method.
static void setIzpackHome(java.lang.String izHome)
          Set the IzPack home directory
protected  void substituteAllProperties(XMLElement element)
          Perform recursive substitution on all properties
protected  void substituteProperties(XMLElement data)
          Properties declaration is a fragment of the xml file.
protected  boolean validateYesNoAttribute(XMLElement element, java.lang.String attribute, boolean defaultValue)
          Call getAttribute on an element, producing a meaningful warning if not "yes" or "no".
 boolean wasSuccessful()
           
 
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

VERSION

public static final java.lang.String VERSION
The compiler version.

See Also:
Constant Field Values

STANDARD

public static final java.lang.String STANDARD
Standard installer.

See Also:
Constant Field Values

WEB

public static final java.lang.String WEB
Web installer.

See Also:
Constant Field Values

YES

private static boolean YES
Constant for checking attributes.


NO

private static boolean NO
Constant for checking attributes.


filename

private java.lang.String filename
The xml install file


installText

private java.lang.String installText
The xml install configuration text


basedir

protected java.lang.String basedir
The base directory.


compiler

private Compiler compiler
The installer packager compiler


compilerListeners

protected java.util.List compilerListeners
List of CompilerListeners which should be called at packaging

Constructor Detail

CompilerConfig

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

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

CompilerConfig

public CompilerConfig(java.lang.String filename,
                      java.lang.String basedir,
                      java.lang.String kind,
                      java.lang.String output,
                      PackagerListener listener)
               throws CompilerException
The constructor.

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

CompilerConfig

public CompilerConfig(java.lang.String filename,
                      java.lang.String base,
                      java.lang.String kind,
                      java.lang.String output,
                      java.lang.String compr_format,
                      PackagerListener listener)
               throws CompilerException
Parameters:
filename - The XML filename.
kind - The installer kind.
output - The installer filename.
compr_format - The compression format to be used for packs.
listener - The PackagerListener.
Throws:
CompilerException

CompilerConfig

public CompilerConfig(java.lang.String basedir,
                      java.lang.String kind,
                      java.lang.String output,
                      PackagerListener listener,
                      java.lang.String installText)
               throws CompilerException
Parameters:
basedir - The base directory.
kind - The installer kind.
output - The installer filename.
listener - The PackagerListener.
installText - The install xml configuration text
Throws:
CompilerException

CompilerConfig

public CompilerConfig(java.lang.String filename,
                      java.lang.String basedir,
                      java.lang.String kind,
                      java.lang.String output,
                      java.lang.String compr_format,
                      PackagerListener listener,
                      java.lang.String installText)
               throws CompilerException
Parameters:
filename - The XML filename.
basedir - The base directory.
kind - The installer kind.
output - The installer filename.
compr_format - The compression format to be used for packs.
listener - The PackagerListener.
installText - The install xml configuration text
Throws:
CompilerException

CompilerConfig

public CompilerConfig(java.lang.String filename,
                      java.lang.String basedir,
                      java.lang.String kind,
                      java.lang.String output,
                      java.lang.String compr_format,
                      int compr_level,
                      PackagerListener listener,
                      java.lang.String installText)
               throws CompilerException
Parameters:
filename - The XML filename.
basedir - The base directory.
kind - The installer kind.
output - The installer filename.
compr_format - The compression format to be used for packs.
compr_level - Compression level to be used if supported.
listener - The PackagerListener.
installText - The install xml configuration text
Throws:
CompilerException
Method Detail

setIzpackHome

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

Parameters:
izHome - - the izpack home directory

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

getCompiler

public Compiler getCompiler()
Access the install compiler

Returns:
the install compiler

getPackagerListener

public PackagerListener getPackagerListener()
Retrieves the packager listener


compile

public void compile()
Compile the installation


run

public void run()
The run() method.

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

executeCompiler

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

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

wasSuccessful

public boolean wasSuccessful()

addGUIPrefs

protected void addGUIPrefs(XMLElement data)
                    throws CompilerException
Returns the GUIPrefs.

Parameters:
data - The XML data.
Throws:
CompilerException - Description of the Exception

addJars

protected void addJars(XMLElement data)
                throws java.lang.Exception
Add project specific external jar files to the installer.

Parameters:
data - The XML data.
Throws:
java.lang.Exception

addNativeLibraries

protected void addNativeLibraries(XMLElement data)
                           throws java.lang.Exception
Add native libraries to the installer.

Parameters:
data - The XML data.
Throws:
java.lang.Exception

addPacks

protected void addPacks(XMLElement data)
                 throws CompilerException
Add packs and their contents to the installer.

Parameters:
data - The XML data.
Throws:
CompilerException

checkDependencies

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

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:
java.io.FileNotFoundException - if the file does not exist
java.io.IOException

addPanels

protected void addPanels(XMLElement data)
                  throws CompilerException
Parse panels and their paramters, locate the panels resources and add to the Packager.

Parameters:
data - The XML data.
Throws:
CompilerException - Description of the Exception

addResources

protected void addResources(XMLElement data)
                     throws CompilerException
Adds the resources.

Parameters:
data - The XML data.
Throws:
CompilerException - Description of the Exception

addLangpacks

protected void addLangpacks(XMLElement data)
                     throws CompilerException
Adds the ISO3 codes of the langpacks and associated resources.

Parameters:
data - The XML data.
Throws:
CompilerException - Description of the Exception

addInfo

protected void addInfo(XMLElement data)
                throws java.lang.Exception
Builds the Info class from the XML tree.

Parameters:
data - The XML data. return The Info.
Throws:
java.lang.Exception - Description of the Exception

addVariables

protected void addVariables(XMLElement data)
                     throws CompilerException
Variable declaration is a fragment of the xml file. For example:
 
  
   
    
        <variables>
          <variable name="nom" value="value"/>
          <variable name="foo" value="pippo"/>
        </variables>
      
    
   
  
 
variable declared in this can be referred to in parsable files.

Parameters:
data - The XML data.
Throws:
CompilerException - Description of the Exception

substituteProperties

protected void substituteProperties(XMLElement data)
                             throws CompilerException
Properties declaration is a fragment of the xml file. For example:
 
  
   
    
        <properties>
          <property name="app.name" value="Property Laden Installer"/>
          <!-- Ant styles 'location' and 'refid' are not yet supported -->
          <property file="filename-relative-to-install?"/>
          <property file="filename-relative-to-install?" prefix="prefix"/>
          <!-- Ant style 'url' and 'resource' are not yet supported -->
          <property environment="prefix"/>
        </properties>
      
    
   
  
 
variable declared in this can be referred to in parsable files.

Parameters:
data - The XML data.
Throws:
CompilerException - Description of the Exception

substituteAllProperties

protected void substituteAllProperties(XMLElement element)
                                throws CompilerException
Perform recursive substitution on all properties

Throws:
CompilerException

getXMLTree

protected XMLElement getXMLTree()
                         throws CompilerException,
                                java.io.IOException
Returns the XMLElement representing the installation XML file.

Returns:
The XML tree.
Throws:
CompilerException - For problems with the installation file
java.io.IOException - for errors reading the installation file

getOverrideValue

protected int getOverrideValue(XMLElement f)
                        throws CompilerException
Throws:
CompilerException

findProjectResource

private java.net.URL findProjectResource(java.lang.String path,
                                         java.lang.String desc,
                                         XMLElement parent)
                                  throws CompilerException
Look for a project specified resources, which, if not absolute, are sought relative to the projects basedir. The path should use '/' as the fileSeparator. 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
parent - the XMLElement the resource is specified in, used to report errors
Returns:
a URL to the resource.
Throws:
CompilerException

findIzPackResource

private java.net.URL findIzPackResource(java.lang.String path,
                                        java.lang.String desc,
                                        XMLElement parent)
                                 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
parent - the XMLElement the resource is specified in, used to report errors
Returns:
a URL to the resource.
Throws:
CompilerException

parseError

protected 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

protected void parseError(XMLElement parent,
                          java.lang.String message)
                   throws CompilerException
Create parse error with consistent messages. Includes file name and line # of parent. It is an error for 'parent' to be null.

Parameters:
parent - The element in which the error occured
message - Brief message explaining error
Throws:
CompilerException

parseError

protected void parseError(XMLElement parent,
                          java.lang.String message,
                          java.lang.Throwable cause)
                   throws CompilerException
Create a chained parse error with consistent messages. Includes file name and line # of parent. It is an error for 'parent' to be null.

Parameters:
parent - The element in which the error occured
message - Brief message explaining error
Throws:
CompilerException

parseWarn

protected void parseWarn(XMLElement parent,
                         java.lang.String message)
Create a parse warning with consistent messages. Includes file name and line # of parent. It is an error for 'parent' to be null.

Parameters:
parent - The element in which the warning occured
message - Warning message

requireChildNamed

protected XMLElement requireChildNamed(XMLElement parent,
                                       java.lang.String name)
                                throws CompilerException
Call getFirstChildNamed on the parent, producing a meaningful error message on failure. It is an error for 'parent' to be null.

Parameters:
parent - The element to search for a child
name - Name of the child element to get
Throws:
CompilerException

requireURLContent

protected java.net.URL requireURLContent(XMLElement element)
                                  throws CompilerException
Call getContent on an element, producing a meaningful error message if not present, or empty, or a valid URL. It is an error for 'element' to be null.

Parameters:
element - The element to get content of
Throws:
CompilerException

requireContent

protected java.lang.String requireContent(XMLElement element)
                                   throws CompilerException
Call getContent on an element, producing a meaningful error message if not present, or empty. It is an error for 'element' to be null.

Parameters:
element - The element to get content of
Throws:
CompilerException

requireAttribute

protected java.lang.String requireAttribute(XMLElement element,
                                            java.lang.String attribute)
                                     throws CompilerException
Call getAttribute on an element, producing a meaningful error message if not present, or empty. It is an error for 'element' or 'attribute' to be null.

Parameters:
element - The element to get the attribute value of
attribute - The name of the attribute to get
Throws:
CompilerException

requireIntAttribute

protected int requireIntAttribute(XMLElement element,
                                  java.lang.String attribute)
                           throws CompilerException
Get a required attribute of an element, ensuring it is an integer. A meaningful error message is generated as a CompilerException if not present or parseable as an int. It is an error for 'element' or 'attribute' to be null.

Parameters:
element - The element to get the attribute value of
attribute - The name of the attribute to get
Throws:
CompilerException

requireYesNoAttribute

protected boolean requireYesNoAttribute(XMLElement element,
                                        java.lang.String attribute)
                                 throws CompilerException
Call getAttribute on an element, producing a meaningful error message if not present, or one of "yes" or "no". It is an error for 'element' or 'attribute' to be null.

Parameters:
element - The element to get the attribute value of
attribute - The name of the attribute to get
Throws:
CompilerException

validateYesNoAttribute

protected boolean validateYesNoAttribute(XMLElement element,
                                         java.lang.String attribute,
                                         boolean defaultValue)
Call getAttribute on an element, producing a meaningful warning if not "yes" or "no". If the 'element' or 'attribute' are null, the default value is returned.

Parameters:
element - The element to get the attribute value of
attribute - The name of the attribute to get
defaultValue - Value returned if attribute not present or invalid

main

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

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

addCustomListeners

private void addCustomListeners(XMLElement data)
                         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 :

Parameters:
data - the XML data
Throws:
java.lang.Exception - Description of the Exception

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

getCompilerListenerInstance

private java.lang.Object[] getCompilerListenerInstance(XMLElement var)
                                                throws java.lang.Exception
Returns the compiler listener which is defined in the xml element. As xml element a "listner" node will be expected. Additional it is expected, that either "findIzPackResource" returns an url based on "bin/customActions/[className].jar", or that the listener element has a jar attribute specifying the listener jar path. The class will be loaded via an URLClassLoader.

Parameters:
var - the xml element of the "listener" node
Returns:
instance of the defined compiler listener
Throws:
java.lang.Exception

addCompilerListener

private void addCompilerListener(CompilerListener pe)
Add a CompilerListener. A registered CompilerListener will be called at every enhancmend point of compiling.

Parameters:
pe - CompilerListener which should be added

notifyCompilerListener

private void notifyCompilerListener(java.lang.String callerName,
                                    int state,
                                    XMLElement data)
                             throws CompilerException
Calls all defined compile listeners notify method with the given data

Parameters:
callerName - name of the calling method as string
state - CompileListener.BEGIN or END
data - current install data
Throws:
CompilerException

getAdditionals

private java.util.Map getAdditionals(XMLElement f)
                              throws CompilerException
Calls the reviseAdditionalDataMap method of all registered CompilerListener's.

Parameters:
f - file releated XML node
Returns:
a map with the additional attributes
Throws:
CompilerException