public class ZipLock extends Object
ZipLock will read each class file and search the internal structures for all references to outside classes and resources. The checks are recursive, so all classes will be examined. A list of dependencies will be returned.
None of the java.* classes will be examined. Additional system
packages may be excluded with setExcludes()
.
In addition to classes, we look for other resources loaded via
Class.getResource()
or
Class.getResourceAsStream()
. If a class calls these
methods, then every String constant in the class is checked to see
if a file by that name exists on the CLASSPATH in the same directory
as the class - in other words where getResource
would
find it. This heuristic only works if your resource names appear
as String constants - which seems to be the case in my practice so far.
We can optionally write all the classes and resources
found to a zip or jar, or the list of files can be retrieved
with getDependencies()
.
Original version Copyright (c) 1998 Karl Moss. All Rights Reserved.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
ZipLock.HandleTable |
static class |
ZipLock.IntList |
(package private) static class |
ZipLock.Pair |
Modifier and Type | Field and Description |
---|---|
private static FilenameFilter |
classFilter |
private ZipLock.IntList |
classInfo |
private static String[] |
classPath |
private static String[] |
default_exclude |
private static String |
filesep |
private ZipOutputStream |
m_archiveStream |
private Hashtable |
m_dep |
private String[] |
m_excludePackageList |
private int |
m_level |
private Vector |
methInfo |
private Vector |
rootSet |
private ZipLock.IntList |
stringTbl |
private static Hashtable |
ziptbl |
Constructor and Description |
---|
ZipLock() |
Modifier and Type | Method and Description |
---|---|
void |
addClass(String name)
Add a class to the root set.
|
private void |
addToArchive(String name,
byte[] buf)
Adds the given buffer to the archive with the given
name
|
void |
clear()
Clear the root set and the list of dependencies - leaving this
object ready for reuse.
|
protected static ZipFile |
findJar(String jarFile) |
static String[] |
getClassPath()
Return the system class path as an array of strings.
|
static String[] |
getClassPath(String path)
Convert a class path to an array of strings.
|
private String[] |
getClassResources(byte[] buf,
String className)
Examine a class file to see what resources it uses, especially other
classes.
|
String[] |
getDependencies()
Return the list of class and other resources with their dependencies.
|
String[] |
getRootSet()
Return the list of classes in the root set.
|
boolean |
isClassProcessed(String name)
Determine if the given class is in our list or is part
of a system package such as java.* or a package specified
with
|
private void |
log(String name)
For display purposes, return a string to indent the proper
number of spaces
|
static void |
main(String[] argv) |
protected static byte[] |
openResource(String name)
Given a class name, open it and return a buffer with
the contents.
|
protected static byte[] |
openResource(String name,
String path)
Given a resource name and path, open the resource and
return a buffer with the contents.
|
protected static byte[] |
openResourceFromJar(String name,
String jarFile)
Given a resource name and jar file name, open the jar file
and return a buffer containing the contents.
|
static String[] |
packageList(String pkg)
Return a list of classes found in the current class path for
a given package.
|
protected void |
processClass(String className,
byte[] buf)
Given a class or resource name and buffer containing the contents,
process the raw bytes of the class file.
|
private void |
setClassProcessed(String name)
Mark a class or other resource as processed.
|
void |
setExcludes(String[] e)
Sets the list of package names to exclude.
|
void |
start(String m_archive)
Start the roll call.
|
private void |
storeClass(String className) |
private static final String[] default_exclude
private String[] m_excludePackageList
private int m_level
private ZipOutputStream m_archiveStream
private final ZipLock.IntList classInfo
private final ZipLock.IntList stringTbl
private static final FilenameFilter classFilter
public ZipLock()
public static String[] getClassPath()
public static String[] getClassPath(String path)
path.separator
system property.public void setExcludes(String[] e)
Sets the list of package names to exclude. If the package of the class starts with any of the names given, the class will be excluded. An example would be "foo.package".
excludeList
- An array of package names to exclude.public void start(String m_archive) throws Exception
Start the roll call. After the class list and package exclude list have been set, this method will perform the class examination. Once complete, call getDependencies() to get a full list of class dependencies. If an archive file was specified, the archive file will contain all of the dependencies.
m_archive
- the output archive or nullException
- An error occurred while processinggetDependencies()
public String[] getRootSet()
public void clear()
public String[] getDependencies()
private void storeClass(String className) throws Exception
Exception
protected static byte[] openResource(String name) throws Exception
Exception
protected static byte[] openResource(String name, String path) throws Exception
Exception
protected static ZipFile findJar(String jarFile) throws IOException
IOException
protected static byte[] openResourceFromJar(String name, String jarFile) throws Exception
Exception
protected void processClass(String className, byte[] buf) throws Exception
Exception
private String[] getClassResources(byte[] buf, String className) throws Exception
Exception
public boolean isClassProcessed(String name)
private void setClassProcessed(String name)
private void addToArchive(String name, byte[] buf) throws Exception
Exception
private void log(String name)
public static String[] packageList(String pkg)
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses