Class ClassInfoHolder
java.lang.Object
org.machanism.machai.gw.maven.tools.ClassInfoHolder
Holds class discovery and lookup data for a single Maven project.
This class builds a dedicated URLClassLoader from the project's
compile classpath together with its main and test output directories. It then
scans visible classes and records the physical location and artifact
coordinates for public and protected classes that can be loaded from that
classpath.
-
Constructor Summary
ConstructorsConstructorDescriptionClassInfoHolder(org.apache.maven.project.MavenProject project) Creates a holder for the supplied Maven project and eagerly initializes class discovery metadata. -
Method Summary
Modifier and TypeMethodDescriptionList<com.google.common.reflect.ClassPath.ClassInfo> findClasses(String className) Finds classes whose simple names match the supplied regular expression.getArtifactId(String className) Returns the Maven artifact coordinates associated with the supplied fully qualified class name.getClassPath(String className) Returns the originating path for the supplied fully qualified class name.getSourcePath(String className) Returns the source file path for the supplied fully qualified class name.Class<?> Loads a class by its fully qualified name using the holder's class loader.voidscanClassesByPath(String path, String id) Scans a directory of compiled classes or a jar file and records eligible classes that can be loaded by this holder's class loader.
-
Constructor Details
-
ClassInfoHolder
public ClassInfoHolder(org.apache.maven.project.MavenProject project) Creates a holder for the supplied Maven project and eagerly initializes class discovery metadata.- Parameters:
project- the Maven project whose classpath and artifacts are inspected
-
-
Method Details
-
scanClassesByPath
Scans a directory of compiled classes or a jar file and records eligible classes that can be loaded by this holder's class loader.Only public and protected classes are added to the internal path and artifact maps. Missing paths are ignored.
- Parameters:
path- the directory or jar file to scanid- the dependency coordinates associated with the path, ornullfor project output classes- Throws:
IOException- if the path cannot be read
-
findClasses
Finds classes whose simple names match the supplied regular expression.- Parameters:
className- the regular expression applied to simple class names- Returns:
- matching class metadata entries
-
loadClass
Loads a class by its fully qualified name using the holder's class loader.- Parameters:
className- the fully qualified class name- Returns:
- the resolved class
- Throws:
ClassNotFoundException- if the class cannot be loaded
-
getClassPath
Returns the originating path for the supplied fully qualified class name.- Parameters:
className- the fully qualified class name- Returns:
- the directory or jar path for the class, or
nullif unknown
-
getSourcePath
Returns the source file path for the supplied fully qualified class name.The method searches the Maven project's compile source roots for a matching Java source file. For nested classes, the top-level declaring class source file is returned.
- Parameters:
className- the fully qualified class name- Returns:
- the source file path, or
nullif no source file exists in the project source roots
-
getArtifactId
Returns the Maven artifact coordinates associated with the supplied fully qualified class name.- Parameters:
className- the fully qualified class name- Returns:
- artifact coordinates in
groupId:artifactId:versionform, ornullwhen the class does not originate from a dependency
-