public final class ClassResolver extends Object implements TraversalRoot
ClassRoot
objects for which
each represents a classes directory or a JAR file. And it has two HashMaps
for all the packages and classes contained in any of these roots. The key
used for theses HashMaps is the fully qualified class or package name.
The ClassPackage
has a collection of all classes subpackages it contains.
Thus it provides direct access to all classes and subpackages of some package
within some root.
Each ClassPackage
or ClassEntry
belongs to one root. The
same class or package name may appear within different roots. In that case the
ClassPackage or ClassEntry has LinkedList
of all entries with the
same name. This lists can be accessed by ClassPackage.getAlternatives()
or ClassEntry.getAlternatives()
respectively. Each entry points
to the same list of alternatives. If there are no alternatives the corresponding
list is null.
Typically one of the static of methods should be used to create a ClassResolver.
Constructor and Description |
---|
ClassResolver() |
Modifier and Type | Method and Description |
---|---|
void |
add(File file) |
void |
add(String path) |
void |
addBootClassPath() |
void |
addClassPath() |
void |
addJavaRuntimeModules()
Adds all modules form the Java Runtime System.
|
void |
addManifestClassPath(org.dessertj.resolve.JarRoot jarRoot)
Adds all entries from the Class-Path attribute of the JAR's Manifest file.
|
void |
addRoot(ClassRoot root) |
void |
freeze()
After freezing any modification to the path represented by this resolver will
result in an
IllegalStateException . |
int |
getClassCount() |
ClassEntry |
getClassEntry(File root,
String classname) |
ClassEntry |
getClassEntry(String classname) |
Map<String,List<ClassEntry>> |
getDuplicates() |
ClassPackage |
getPackage(File root,
String packageName) |
ClassPackage |
getPackage(String packageName) |
int |
getPackageCount() |
List<ClassRoot> |
getPath() |
ClassRoot |
getRoot(File file) |
Set<File> |
getRootDirs() |
Set<File> |
getRootFiles() |
Set<File> |
getRootFiles(Predicate<File> predicate) |
Set<File> |
getRootJars() |
boolean |
isIgnoreManifest() |
static boolean |
isJrtFileSystemAvailable() |
static ClassResolver |
of(String path)
Creates a ClassResolver for some arbitrary path.
|
static ClassResolver |
ofClassPath()
Creates a ClassResolver based on the java.class.path system-property.
|
static ClassResolver |
ofClassPathAndJavaRuntime()
Creates a ClassResolver with all entries for
ofClassPath() and all entries
from the sun.boot.class.path system-properties for java 8 and before or
all java runtime modules from Java 9 on. |
static ClassResolver |
ofClassPathIgnoringManifests()
Creates a ClassResolver similar to
ofClassPath() , but without the entries
from the Class-Path attribute of any Manifest file. |
static ClassResolver |
ofClassPathWithoutJars()
Creates a ClassResolver containing only the directories on the java.class.path system-property.
|
void |
setIgnoreManifest(boolean ignoreManifest)
If set the Class-Path attribute of JAR's Manifest files will be ignored.
|
String |
toString() |
void |
traverse(NamePattern pattern,
ClassVisitor visitor) |
public static ClassResolver of(String path)
path
- the path to scan using the system specific classpath formatpublic static ClassResolver ofClassPath()
ResolveException
- if a directory or jar file could not be readpublic static ClassResolver ofClassPathAndJavaRuntime()
ofClassPath()
and all entries
from the sun.boot.class.path system-properties for java 8 and before or
all java runtime modules from Java 9 on.ResolveException
- if a directory or jar file could not be readpublic static ClassResolver ofClassPathWithoutJars()
ResolveException
- if a directory or jar file could not be readpublic static ClassResolver ofClassPathIgnoringManifests()
ofClassPath()
, but without the entries
from the Class-Path attribute of any Manifest file. The isIgnoreManifest()
flag of the resulting ClassResolver will be true.ResolveException
- if a directory or jar file could not be readpublic void addClassPath()
public void addBootClassPath()
public void addJavaRuntimeModules()
ResolveException
- modules could not be readpublic static boolean isJrtFileSystemAvailable()
public void add(String path)
public void add(File file)
public void addRoot(ClassRoot root) throws IOException
IOException
public void addManifestClassPath(org.dessertj.resolve.JarRoot jarRoot) throws IOException
isIgnoreManifest()
has been set.
Use getRoot(File)
to get the JarRoot
for a file.jarRoot
- the jar to processIOException
- if the Manifest could not be readpublic boolean isIgnoreManifest()
public void setIgnoreManifest(boolean ignoreManifest)
ignoreManifest
- the flagpublic void freeze()
IllegalStateException
.public ClassPackage getPackage(String packageName)
public ClassPackage getPackage(File root, String packageName)
public ClassEntry getClassEntry(String classname)
public ClassEntry getClassEntry(File root, String classname)
public void traverse(NamePattern pattern, ClassVisitor visitor)
traverse
in interface TraversalRoot
public Map<String,List<ClassEntry>> getDuplicates()
public int getPackageCount()
public int getClassCount()
Copyright © 2017–2023 Hans Jörg Heßmann. All rights reserved.