Class VeryPrettyClassPathPrinter
It manages its own list of JarHandlers to recover metadata from within the JARs,
allowing for a rich, environment-agnostic representation of the classpath.
This class follows a reactive pattern: calling setRaw(String) automatically
triggers a re-build of the pretty-printed representation via the update() method.
- Author:
- anahata
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<JarHandler> The list of specialized handlers used to extract metadata (IDs, versions, vendors) from within the JARs.private StringThe formatted, token-optimized version of the classpath.private StringThe original, unformatted classpath string as provided by the system. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new printer with default handlers (Maven, Selenium, Default). -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHandler(JarHandler handler) Adds a new JAR handler to the printer.private voidprivate StringfindCommonRoot(Set<String> paths) private StringformatLexicalGroups(List<JarMetadata> jars, String indent) Formats a list of JAR metadata into lexical groups for a specific directory.private StringgetCommonPrefix(String id1, String id2) private Stringprivate JarMetadataInspects a single JAR file using all registered handlers.private voidprintNode(VeryPrettyClassPathPrinter.DirectoryNode node, String indent, StringBuilder sb) voidSets the raw classpath string.toString()update()Re-builds the pretty-printed string using the current set of handlers and the current raw classpath.
-
Field Details
-
raw
The original, unformatted classpath string as provided by the system. -
pretty
The formatted, token-optimized version of the classpath. This is the version intended for AI context consumption. -
handlers
The list of specialized handlers used to extract metadata (IDs, versions, vendors) from within the JARs.
-
-
Constructor Details
-
VeryPrettyClassPathPrinter
public VeryPrettyClassPathPrinter()Constructs a new printer with default handlers (Maven, Selenium, Default).
-
-
Method Details
-
setRaw
-
addHandler
Adds a new JAR handler to the printer. The new handler is added at the beginning of the list to give it priority over existing handlers.Note: You should call
update()after adding a handler if you want the changes to be reflected immediately in theprettystring.- Parameters:
handler- The handler to add.
-
update
Re-builds the pretty-printed string using the current set of handlers and the current raw classpath.This method builds a collapsed directory tree and then groups JARs by lexical prefix within each node to minimize token usage.
- Returns:
- The updated pretty string.
-
collapse
-
printNode
private void printNode(VeryPrettyClassPathPrinter.DirectoryNode node, String indent, StringBuilder sb) -
findCommonRoot
-
inspect
Inspects a single JAR file using all registered handlers.It uses a "Best Effort" strategy, collecting metadata from all handlers and picking the one that provides the most information (version, vendor, etc.).
- Parameters:
jarFile- The file to inspect.- Returns:
- The extracted metadata, or null if no handler could process it.
-
formatLexicalGroups
Formats a list of JAR metadata into lexical groups for a specific directory. It factors out common versions and prefixes to minimize token usage.This implementation uses a "Majority Version" rule: it promotes the most frequent version to the group level to save tokens.
- Parameters:
jars- The list of JARs in the directory.indent- The current indentation string.- Returns:
- A formatted string listing the JARs by prefix and version.
-
getFirstSegment
-
getCommonPrefix
-
toString
-

