Class ModuleJarIndex

java.lang.Object
com.ultikits.ultitools.manager.ModuleJarIndex

@Internal public final class ModuleJarIndex extends Object
Which JARs in the modules folder declare which module main class, as the module loader read them at start-up (#516).

The loader identifies a module JAR by nothing but the main: entry of its plugin.yml (#548/#549): it reads that entry and loads exactly that class. This index keeps what it read, per main class, together with the JAR the class was actually loaded from. It is how an uninstall knows every file on disk that belongs to a loaded module -- including a second copy whose plugin.yml declares a different name: -- and how the start-up warning about duplicate copies names all of them. Nothing here reads a class out of an archive.

Thread-safe: written by the start-up scan, read by /upm commands.

Since:
6.3.0
  • Field Details

    • jarsByMainClass

      private final Map<String,Map<String,File>> jarsByMainClass
      Main class name -> canonical path -> JAR, for every JAR whose plugin.yml declares it.
    • supplierByMainClass

      private final Map<String,File> supplierByMainClass
      Main class name -> the JAR its class was loaded from.
  • Constructor Details

    • ModuleJarIndex

      public ModuleJarIndex()
  • Method Details

    • record

      public void record(String mainClass, File jar)
      Records that jar's plugin.yml declares mainClass.
      Parameters:
      mainClass - the declared main class
      jar - the JAR declaring it
    • recordSupplier

      public void recordSupplier(String mainClass, File jar)
      Records the JAR the class mainClass was loaded from.
      Parameters:
      mainClass - the main class
      jar - the JAR its class came from
    • jarsDeclaring

      public List<File> jarsDeclaring(String mainClass)
      Every JAR recorded as declaring mainClass, in file-name order.
      Parameters:
      mainClass - the main class
      Returns:
      the JARs, possibly empty
    • supplierOf

      public File supplierOf(String mainClass)
      The JAR the class mainClass was loaded from, or null when it is not known.
      Parameters:
      mainClass - the main class
      Returns:
      the JAR, or null
    • mainClassOf

      public String mainClassOf(UltiToolsPlugin module)
      The main class the loader recorded for a loaded module: the nearest class in its hierarchy that some JAR declares -- the instance may be a subclass of the declared class, as a proxy is. When none is recorded (a module registered from code rather than from the modules folder), the instance's own class name.
      Parameters:
      module - a loaded module
      Returns:
      its main class name
    • duplicates

      public Map<String,List<File>> duplicates()
      The main classes two or more JARs declare, each with its JARs in file-name order.
      Returns:
      main class name -> its JARs; empty when there is no duplicate
    • canonicalPath

      private static String canonicalPath(File file)