Don't Assume. Audit!
Unlike an IRS audit, a classpath audit will actually profit you. By applying the auditor utility, you'll avoid lots of hard-to-discover class conflicts. The auditor is a command line utility that you invoke using the following commands:
GUI - java jar jar_auditor-2.0.jar gui [root dir to audit c:/audittest]
XML - java jar jar_auditor-2.0.jar xml [root dir to audit c:/audittest] [XML file output path]
The auditor recursively walks the directory tree that you specified in the second argument and filters out jars for auditing. It doesn't audit class files that aren't packaged in jar files because you could easily find an individual class file by executing a brute force search of the file system. Without a utility like the auditor, you'd have no simple way to interrogate jar files.
When the command line 'gui' argument specifies output to a GUI (see Listing 1), the constructor of the GUI builds the tree node, which will display in a split pane view. The
createNodes() method invokes a recursive walk of the specified directory tree, filtering out the jar files for auditing.
As it walks the directory tree (see Listing 2), the auditor makes a callback to a WalkObserverImpl object, which essentially is the link between the walk of the file system and the work of the AuditMaster class that audits and inventories the jar files it encounters.
The call to the observer passes the file being evaluated. The observer discerns whether the file is a jar file or not. If the file is a jar file, an object of class AuditableJarFile, which extends java.util.jar.JarFile, is instantiated. An instance of the AuditMaster class then adds the file to the audit:
JarFile jar = new AuditableJarFile(root);
The constructor of the AuditableJarFile class invokes the
setExplodedContents() method to build an instance variable ArrayList of the exploded contents of the jar (see Listing 3).
The AuditMaster uses a variety of TreeMap data structures to track the jar file names, file path locations of the jars, and the class names encountered in the exploded contents. The addJarFileToAudit method shown in Listing 4 administers all of these details.
After the traversal of the specified directory tree is complete and the audit data structures are populated, the code returns to the JarGui or XMLBuilder to finish preparing the results for display in the appropriate format. The JarGui class iterates over the maps and builds the appropriate JTree nodes, and the XMLBuilder similarly creates an identical nested structure of tags for writing out to the specified file location.