JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.jarmaster
Class JarTask

java.lang.Object
  |
  +--com.klg.jclass.jarmaster.JarTask
All Implemented Interfaces:
EventListener, FilenameFilter, JCProgressListener

public class JarTask
extends Object
implements FilenameFilter, JCProgressListener


Field Summary
static int ARCHIVE_CREATION_ERROR
           
protected  String classPath
           
protected  boolean compression
           
protected  int compressionLevel
           
protected  boolean createJar
           
protected static int DATE_COLUMN
           
protected  String errorString
           
protected  ArrayList exclusions
           
protected  String[] filenames
           
protected  boolean includeDefaultExclusions
           
protected  File jarFile
           
protected  String jarName
           
protected  com.klg.jclass.jarmaster.JarMasterLocaleManager lm
           
protected  String mainClass
           
protected  ArrayList manifestFiles
           
static int MISSING_FILES_ERROR
           
protected  String[] missingFiles
           
static int PROCESSING_ABORTED
           
static int PROCESSING_COMPLETED_WITH_NO_ERRORS
           
protected static int SIZE_COLUMN
           
protected static int TIME_COLUMN
           
 
Constructor Summary
JarTask()
          Default constructor
 
Method Summary
 boolean accept(File dir, String name)
          Prevents files other than class files from being stored in a directory list.
 void addExclusion(String exclusion)
          Add a string tto the list of exclusions
 void addManifestFile(String manifest)
          Add a new file name to the list of manifest file names
 int buildJar()
          Builds the jar based on the current properties of this object.
protected  int buildJar(boolean isCommandLine)
          Creates a list of files and builds the jar.
 void compareJars(String file1, String file2)
          Compares two jars and outputs the differences to System.out.
 String getClassPath()
          Return the current class path (i.e.
 int getCompressionLevel()
          Get the current compression level.
 boolean getCreateJar()
          Return whether a jar file or zip file is created.
 String getErrorString()
          If an error has occured, the error string points to a message further explaining the error
 ArrayList getExclusions()
          Get the current list of exlusions.
 String[] getFiles()
          Get the current list of files or directories to be processed
 boolean getIncludeDefaultExclusions()
          Return whether default exclusions "java/", "javax/", "com/sun/java/", "com/sun/image" are included in the exclusion list.
 File getJarFile()
          Return the current jarFile.
 Iterator getJarListIterator()
          Gets an interator containing a list of class files for the current jarName.
 Iterator getJarListIterator(String name)
          Gets an interator containing a list of class files for the jar with the given name.
protected  Iterator getJarListIterator(String name, boolean isCommandLine)
          Gets an interator containing a list of class files for the jar with the given name.
 String getJarName()
          Return the current jar name.
 String getMainClass()
          Get the main class for the jar/zip.
 ArrayList getManifestFiles()
          Get the current list of manifest files.
 String[] getMissingFiles()
          Returns a list of files that could not be found in the search path but were found to be dependencies.
protected  String[] getStringsFromArrayList(ArrayList arrayList)
          Get a Strings array from an ArrayList that contains Strings
 void listJar(boolean verbose)
          Lists the jar contents of jarName to System.out.
 void listJar(String name, boolean verbose)
          Lists the jar contents with given name to System.out.
protected static void printError(boolean isCommandLine, String error)
           
static void printHelp(String error)
          Prints the command line help.
 boolean processCommandLineArgs(String[] args)
          Processes the command line arguments.
 void processingBegin(com.klg.jclass.util.progress.JCProgressEvent e)
          Invoked when a process has begun.
 void processingEnd(com.klg.jclass.util.progress.JCProgressEvent e)
          Invoked when the process has been compeleted.
 void processingError(com.klg.jclass.util.progress.JCProgressEvent e)
          Invoked when a process encounters an error.
 void processingUnit(com.klg.jclass.util.progress.JCProgressEvent e)
          Invoked when a process unit has been completed.
protected  int processOption(String[] args, int index)
          Process all command line options.
 void removeExclusion(String exclusion)
          Remove a string from the list of exclusions
 void removeManifestFile(String manifest)
          Remove a file name from the list of manifest file names.
 void setClassPath(String classPath)
          Set the current class path (i.e.
 void setCompressionLevel(int compressionLevel)
          Set the current compression level.
 void setCreateJar(boolean createJar)
          Set whether a jar file or zip file is created.
 void setFiles(String[] files)
          Set the list of files or directories to be processed
 void setIncludeDefaultExclusions(boolean includeDefaultExclusions)
          Set whether default exclusions "java/", "javax/", "com/sun/java/", "com/sun/image" are included in the exclusion list.
 void setJarFile(File jarFile)
          Set the output jar as File.
 void setJarName(String jarName)
          Set the output jar as a string.
 void setMainClass(String mainClass)
          Set the main class for the jar/zip.
 void updateJar()
          Refreshes the jar with name jarName.
 void updateJar(String name)
          Refreshes the jar with given name.
protected  void updateJar(String name, boolean isCommandLine)
          Refreshes the jar with name jarName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROCESSING_COMPLETED_WITH_NO_ERRORS

public static final int PROCESSING_COMPLETED_WITH_NO_ERRORS
See Also:
Constant Field Values

MISSING_FILES_ERROR

public static final int MISSING_FILES_ERROR
See Also:
Constant Field Values

ARCHIVE_CREATION_ERROR

public static final int ARCHIVE_CREATION_ERROR
See Also:
Constant Field Values

PROCESSING_ABORTED

public static final int PROCESSING_ABORTED
See Also:
Constant Field Values

SIZE_COLUMN

protected static final int SIZE_COLUMN
See Also:
Constant Field Values

DATE_COLUMN

protected static final int DATE_COLUMN
See Also:
Constant Field Values

TIME_COLUMN

protected static final int TIME_COLUMN
See Also:
Constant Field Values

jarName

protected String jarName

jarFile

protected File jarFile

manifestFiles

protected ArrayList manifestFiles

filenames

protected String[] filenames

exclusions

protected ArrayList exclusions

createJar

protected boolean createJar

includeDefaultExclusions

protected boolean includeDefaultExclusions

compressionLevel

protected int compressionLevel

compression

protected boolean compression

mainClass

protected String mainClass

classPath

protected String classPath

errorString

protected String errorString

missingFiles

protected String[] missingFiles

lm

protected com.klg.jclass.jarmaster.JarMasterLocaleManager lm
Constructor Detail

JarTask

public JarTask()
Default constructor

Method Detail

processCommandLineArgs

public boolean processCommandLineArgs(String[] args)
Processes the command line arguments.


setFiles

public void setFiles(String[] files)
Set the list of files or directories to be processed

Parameters:
files - A list of files and directories

getFiles

public String[] getFiles()
Get the current list of files or directories to be processed

Returns:
A list of strings representing the list of files and directories to be processed.

getJarFile

public File getJarFile()
Return the current jarFile. If this property is null, the jarName will be used to get a jar file.

Returns:
The current output jar as File

setJarFile

public void setJarFile(File jarFile)
Set the output jar as File. If this property is null, the jarName will be used to get a jar file. Setting this property has the side effect of setting the jarName to the absolute path of the jarFile.

Parameters:
jarFile - The new jarFile

getJarName

public String getJarName()
Return the current jar name. Note that this property will not be used if the jarFile property is non-null.

Returns:
The current ouput jar as a string.

setJarName

public void setJarName(String jarName)
Set the output jar as a string. Note that this property will not be used if the jarFile property is non-null.

Parameters:
jarName - The new jar name

getIncludeDefaultExclusions

public boolean getIncludeDefaultExclusions()
Return whether default exclusions "java/", "javax/", "com/sun/java/", "com/sun/image" are included in the exclusion list. Default is true.

Returns:
If true, default exclusions are included in the exclusion list

setIncludeDefaultExclusions

public void setIncludeDefaultExclusions(boolean includeDefaultExclusions)
Set whether default exclusions "java/", "javax/", "com/sun/java/", "com/sun/image" are included in the exclusion list.

Parameters:
includeDefaultExclusions - If true, default exclusions are included in the exclusion list

getCreateJar

public boolean getCreateJar()
Return whether a jar file or zip file is created.

Returns:
If true, a jar file is created. Otherwise a zip file is created.

setCreateJar

public void setCreateJar(boolean createJar)
Set whether a jar file or zip file is created.

Parameters:
createJar - If true, a jar file is created. Otherwise a zip file is created.

getCompressionLevel

public int getCompressionLevel()
Get the current compression level. Ranges from 0 (no compression) to 9 (the most compression). Default is 9.

Returns:
The current compression level.

setCompressionLevel

public void setCompressionLevel(int compressionLevel)
Set the current compression level. Ranges from 0 (no compression) to 9 (the most compression). Default is 9.

Parameters:
compressionLevel - The new compression level.

getMainClass

public String getMainClass()
Get the main class for the jar/zip. This is the class who's main method is run when the jar/zip is executed.

Returns:
The current main class

setMainClass

public void setMainClass(String mainClass)
Set the main class for the jar/zip. This is the class who's main method is run when the jar/zip is executed.

Parameters:
mainClass - The new main class.

getClassPath

public String getClassPath()
Return the current class path (i.e. search path) used when creating the jar. If this value is null, the current system class path is used.

Returns:
The current search path

setClassPath

public void setClassPath(String classPath)
Set the current class path (i.e. search path) used when creating the jar. If this value is null, the current system class path is used.

Parameters:
classPath - The new search path

getMissingFiles

public String[] getMissingFiles()
Returns a list of files that could not be found in the search path but were found to be dependencies.

Returns:
A list of missing files. Null if no missing files.

getErrorString

public String getErrorString()
If an error has occured, the error string points to a message further explaining the error

Returns:
The error string of the last error encountered.

addManifestFile

public void addManifestFile(String manifest)
Add a new file name to the list of manifest file names

Parameters:
manifest - The manifest file name to add

removeManifestFile

public void removeManifestFile(String manifest)
Remove a file name from the list of manifest file names.

Parameters:
manifest - The manifest file name to remove

getManifestFiles

public ArrayList getManifestFiles()
Get the current list of manifest files. The returned ArrayList should be considered readonly.

Returns:
The current manifest file ArrayList

addExclusion

public void addExclusion(String exclusion)
Add a string tto the list of exclusions

Parameters:
exclusion - The new exclusion string

removeExclusion

public void removeExclusion(String exclusion)
Remove a string from the list of exclusions

Parameters:
exclusion - The exclusion string to remove

getExclusions

public ArrayList getExclusions()
Get the current list of exlusions. The returned ArrayList should be considered readonly.

Returns:
The current exclusion ArrayList

accept

public boolean accept(File dir,
                      String name)
Prevents files other than class files from being stored in a directory list. This is used when the contents are retrieved from a File class.

Specified by:
accept in interface FilenameFilter
See Also:
buildJar()

getStringsFromArrayList

protected String[] getStringsFromArrayList(ArrayList arrayList)
Get a Strings array from an ArrayList that contains Strings

Parameters:
arrayList - The array list from which to get the Strings
Returns:
The newly created String array

buildJar

public int buildJar()
Builds the jar based on the current properties of this object.

Returns:
PROCESSING_COMPLETED_WITH_NO_ERRORS if jar built with no errors. Otherwise returns MISSING_FILES_ERROR if the jar is incomplete due to files that could not be find, ARCHIVE_CREATION_ERROR if the jar could not be created for some reason, or PROCESSING_ABORTED if the user aborted the jar create process for some reason.

buildJar

protected int buildJar(boolean isCommandLine)
Creates a list of files and builds the jar.

Parameters:
isCommandLine - If true, it is assumed that this method is called from the command line. On error, help is printed to System.out. If no, jar name has been specified, a list of dependencies is printed to standard out.

printError

protected static void printError(boolean isCommandLine,
                                 String error)

printHelp

public static void printHelp(String error)
Prints the command line help.


processOption

protected int processOption(String[] args,
                            int index)
Process all command line options.


getJarListIterator

public Iterator getJarListIterator()
                            throws IOException
Gets an interator containing a list of class files for the current jarName. Each member of the list is a JarEntry object.

Returns:
An interator containing a list of class files. Return's null if jarName is null or empty.
Throws:
IOException - if jarName could not be opened as a jar or zip file
See Also:
JarEntry

getJarListIterator

public Iterator getJarListIterator(String name)
                            throws IOException
Gets an interator containing a list of class files for the jar with the given name. Each member of the list is a JarEntry object.

Parameters:
name - The name of the jar or zip file
Returns:
An interator containing a list of class files. Return's null if jarName is null or empty.
Throws:
IOException - if name could not be opened as a jar or zip file
See Also:
JarEntry

getJarListIterator

protected Iterator getJarListIterator(String name,
                                      boolean isCommandLine)
                               throws IOException
Gets an interator containing a list of class files for the jar with the given name.

Parameters:
name - The name of the jar or zip file
isCommandLine - True, if this method was called from the commandline
Returns:
An interator containing a list of class files. Return's null if name is null or empty, or if there were problems
Throws:
IOException - if name could not be opened as a jar or zip file
See Also:
JarEntry

listJar

public void listJar(boolean verbose)
             throws IOException
Lists the jar contents of jarName to System.out. Does nothing if jarName is null.

Parameters:
verbose - If true, use verbose output
Throws:
IOException - If problems accessing the jar or zip file

listJar

public void listJar(String name,
                    boolean verbose)
             throws IOException
Lists the jar contents with given name to System.out. Does nothing if name is null.

Parameters:
name - The name of the jar or zip file
verbose - If true, use verbose output
Throws:
IOException - If problems accessing the jar or zip file

updateJar

public void updateJar()
               throws IOException
Refreshes the jar with name jarName. Does nothing if jarName is null. Make sure that jarName is not explicitly listed in the classpath referenced by this object's classpath property (by default it is your system classpath). If it is, the update procedure will update the JAR's contents with the same.

Throws:
IOException - If unable to access jarName

updateJar

public void updateJar(String name)
               throws IOException
Refreshes the jar with given name. Does nothing if name is null. Make sure the JAR you want to update is not explicitly listed in the classpath referenced by this object's classpath property (by default it is your system classpath). If it is, the update procedure will update the JAR's contents with the same files. files.

Parameters:
name - The name of the jar or zip file
Throws:
IOException - If unable to access the jar or zip file

updateJar

protected void updateJar(String name,
                         boolean isCommandLine)
                  throws IOException
Refreshes the jar with name jarName. Does nothing if jarName is null. Make sure the JAR you want to update is not explicitly listed in the classpath referenced by this object's classpath property (by default it is your system classpath). If it is, the update procedure will update the JAR's contents with the same files.

Parameters:
name - The name of the jar or zip file
isCommandLine - True, if this method was called from the commandline
Throws:
IOException - If unable to access the jar or zip file

compareJars

public void compareJars(String file1,
                        String file2)
                 throws IOException
Compares two jars and outputs the differences to System.out.

Parameters:
file1 - The filename of the first file to compare
file2 - The filename of the second file to compare
Throws:
IOException - if one or both of the jars cannot be accessed.

processingBegin

public void processingBegin(com.klg.jclass.util.progress.JCProgressEvent e)
Invoked when a process has begun.

Specified by:
processingBegin in interface JCProgressListener
Parameters:
e -
See Also:
JCProgressEvent

processingUnit

public void processingUnit(com.klg.jclass.util.progress.JCProgressEvent e)
Invoked when a process unit has been completed.

Specified by:
processingUnit in interface JCProgressListener
Parameters:
e -
See Also:
JCProgressEvent

processingEnd

public void processingEnd(com.klg.jclass.util.progress.JCProgressEvent e)
Invoked when the process has been compeleted.

Specified by:
processingEnd in interface JCProgressListener
Parameters:
e -
See Also:
JCProgressEvent

processingError

public void processingError(com.klg.jclass.util.progress.JCProgressEvent e)
Invoked when a process encounters an error.

Specified by:
processingError in interface JCProgressListener
Parameters:
e -
See Also:
JCProgressEvent

Copyright © 2004 Quest Software Inc..
All rights reserved.