public class ClosureCompilerImpl extends Object implements ClosureCompiler
ClassFile
to find out dependencies of a class. For each references class
name, it loads the corresponding ClassFile using the ClassFileLoader passed
to it in constructor. Then it recurssively computes the dependencies until it
visits either Java primitive classes or the class name matches the exclude
list. Example of using this class is given below...
String classpath="your own classpath"; ClassFileLoader cfl=ClassFileLoaderFactory.newInstance(new Object[]{classpath}); ClosureCompilerImpl cc=new ClosureCompilerImpl(cfl); cc.addExcludePattern("java.");//exclude all classes that start with java. Most of the J2SE classes will be excluded thus. cc.addExcludePattern("javax.");//Most of the J2EE classes can be excluded like this. cc.addExcludePackage("org.omg.CORBA");//Exclude classes whose package name is org.omg.CORBA cc.addExcludeClass("mypackage.Foo");//Exclude class whose name is myPackage.Foo boolean successful=cc.buildClosure("a.b.MyEjb"); successful=cc.buildClosure("a.b.YourEjb") && successful; //note the order of &&. Collection closure=cc.getClosure();//now closure contains the union of closure for the two classes. Map failed=cc.getFailed();//now failure contains the union of failures for the two classes. cc.reset();//clear the results collected so far so that we can start afresh. //Now you can again start computing closure of another set of classes. //The excluded stuff are still valid.
Constructor and Description |
---|
ClosureCompilerImpl(ClassFileLoader loader) |
ClosureCompilerImpl(ClosureCompilerImplBase imp)
I don't expect this constructor to be used.
|
Modifier and Type | Method and Description |
---|---|
void |
addExcludedClass(String className) |
void |
addExcludedPackage(String pkgName) |
void |
addExcludedPattern(String pattern) |
boolean |
buildClosure(JarFile jar) |
boolean |
buildClosure(String className) |
Collection |
getClosure() |
Map |
getFailed() |
Collection<String> |
getNativeMethods() |
static void |
main(String[] args) |
void |
reset()
Reset the closure for next closure computation.
|
String |
toString() |
public ClosureCompilerImpl(ClassFileLoader loader)
loader
- the ClassFileLoader that is used to load the referenced
classes.public ClosureCompilerImpl(ClosureCompilerImplBase imp)
imp
- the implementation in the bridge design pattern.public void addExcludedClass(String className)
className
- the class name to be excluded from closure
computation. It is in the external class name format
(i.e. java.util.Map$Entry instead of java.util.Map.Entry).
When the closure compiler sees a class matches this
name, it does not try to compute its closure any
more. It merely adds this name to the closure. So the
final closure will contain this class name, but not
its dependencies.public void addExcludedPackage(String pkgName)
pkgName
- the package name of classes to be excluded from
closure computation. It is in the external format
(i.e. java.lang (See no trailing '.'). When the
closure compiler sees a class whose package name
matches this name, it does not try to compute the
closure of that class any more. It merely adds that
class name to the closure. So the final closure will
contain that class name, but not its dependencies.public void addExcludedPattern(String pattern)
pattern
- the pattern for the names of classes to be excluded from
closure computation. It is in the external format (i.e.
org.apache.). When the closure compiler sees a class whose
name begins with this pattern, it does not try to compute
the closure of that class any more. It merely adds that
class name to the closure. So the final closure will
contain that class name, but not its dependencies. Among
all the excluded list, it is given the lowest priority in
search order.public boolean buildClosure(String className)
buildClosure
in interface ClosureCompiler
className
- class name (in external format) whose closure will
be computed.ClosureCompiler.reset()
is called).public boolean buildClosure(JarFile jar) throws IOException
jar
- whose classes it will try to build closure of. This is a
convenience method which iterates over all the entries in a
jar file and computes their closure.IOException
public Collection getClosure()
getClosure
in interface ClosureCompiler
public Map getFailed()
getFailed
in interface ClosureCompiler
public void reset()
reset
in interface ClosureCompiler
public Collection<String> getNativeMethods()
public static void main(String[] args)
Copyright © 2009–2023 Oracle Corporation. All rights reserved.