Package org.machanism.machai.gw.maven.tools


package org.machanism.machai.gw.maven.tools
Supplies Maven-integrated function tools for discovering Java classes and inspecting their reflective metadata.

The package is organized around two collaborating types:

  • ClassFunctionalTools is the function-tool facade exposed to callers. It associates each registered Maven project base directory with a metadata holder and provides the find-class and get-class-info operations.
  • ClassInfoHolder owns the project-specific class loader, classpath scan, class-origin mappings, and source-path lookup logic.

When a project is registered, the facade stores a holder under MavenProject.getBasedir(). The holder lazily creates a dedicated URLClassLoader using the project's resolved compile classpath, test output directory, and main output directory. Guava's classpath scanner then supplies the classes visible to discovery and class loading. The registration map is mutable and unsynchronized; callers that register projects or invoke tools concurrently must provide their own synchronization.

Origin metadata is collected separately from class discovery. The holder scans the main output directory and resolved dependency artifacts, recording paths and, for dependency classes, Maven coordinates when available. Only loadable public and protected classes are recorded in those origin maps. Missing or unloadable entries are skipped. Source lookup searches only the project's compile source roots; a nested class is mapped to the source file of its top-level class. Re-register a project after changing compiled output, dependencies, or classpath configuration so subsequent requests use a fresh holder.

findClass applies a regular expression to the simple name of each discovered class and returns fully qualified names. It rejects an unregistered project, an invalid pattern, an empty result, or more than ten matches. getClassInfo loads a fully qualified name and returns a map containing the class name, modifiers, direct superclass, direct interfaces, declared non-private fields and methods, all declared constructors, annotations, and any available path, artifact, and source metadata. The reflective member lists describe declarations on the requested class rather than inherited members.

Typical usage

 MavenProject project = ...;
 ClassFunctionalTools tools = new ClassFunctionalTools(project);
 List<String> matches = tools.findClass(".*Mojo", project.getBasedir());
 Map<String, Object> metadata = tools.getClassInfo(matches.get(0),
         project.getBasedir());
 
See Also:
  • Classes
    Class
    Description
    Provides function-tool integrations for discovering Java classes and reading reflective metadata from the classpath of one or more Maven projects.
    Holds class discovery and lookup data for a single Maven project.