Class LoaderIndex

java.lang.Object
de.oktoflow.platform.tools.lib.loader.LoaderIndex
All Implemented Interfaces:
Serializable

public class LoaderIndex extends Object implements Serializable
Represents the class loader index.
Author:
Holger Eichelberger, SSE
See Also:
  • Field Details

  • Constructor Details

    • LoaderIndex

      public LoaderIndex()
  • Method Details

    • createIndex

      public static LoaderIndex createIndex(List<Path> jars) throws IOException
      Creates an index for a given set of JAR files. Paths will be stored relatively to ease relocation.
      Parameters:
      jars - list of jar files
      Returns:
      plugin index
      Throws:
      IOException - if adding files fails
    • addToIndex

      public static LoaderIndex addToIndex(LoaderIndex index, List<Path> jars) throws IOException
      Adds the given jars to index. Paths will be stored relatively to ease relocation.
      Parameters:
      index - the index to add the information to
      jars - list of jar files
      Returns:
      index
      Throws:
      IOException - if adding files fails
    • addToIndex

      public static void addToIndex(LoaderIndex index, File jarFile, String location) throws IOException
      Adds the given jarFile to index. If given, location replaces the relative path of jarFile in the index entry.
      Parameters:
      index - the index
      jarFile - the jarFile to index
      location - optional actual location of jarFile, e.g., for relocation; if null or empty, use the relative path of jarFile instead
      Throws:
      IOException - if jarFile cannot be opened
    • addToIndex

      private static void addToIndex(LoaderIndex index, Map<String,String> map, String name, String location)
      Adds the resource name in location to map and adjusts the location index in index.
      Parameters:
      index - the index instance
      map - the map to modify
      name - the resource name-key
      location - the resource file location-value
    • relocateIndex

      public static void relocateIndex(LoaderIndex index, String prefix, String replacement)
      Relocates an index instance.
      Parameters:
      index - the index
      prefix - the path prefix indicating a path to relocate
      replacement - the replacement for prefix if prefix was found at the beginning of a path
    • relocateIndex

      private static void relocateIndex(Map<String,String> index, String prefix, String replacement)
      Relocates an index map.
      Parameters:
      index - the index map, entry values may be modified as a side effect
      prefix - the path prefix indicating a path to relocate
      replacement - the replacement for prefix if prefix was found at the beginning of a path
    • fromFile

      public static LoaderIndex fromFile(File indexFile) throws IOException
      Reads an index file, basically via serialization.
      Parameters:
      indexFile - the index file
      Returns:
      the index object
      Throws:
      IOException - if the file cannot be read
    • toFile

      public static void toFile(LoaderIndex index, File file) throws IOException
      Saves index to file.
      Parameters:
      index - the index to write
      file - the file to write to
      Throws:
      IOException - if the index cannot be written
    • addToIndex

      public static void addToIndex(LoaderIndex index, boolean isClass, String name, String location)
      Adds the resource name in location in index. [testing]
      Parameters:
      index - the index instance
      isClass - whether we shall register a class or a resource
      name - the resource name-key
      location - the resource file location-value
    • getLocationIndex

      Map<String,String> getLocationIndex()
      Returns the location index.
      Returns:
      the locationIndex
    • getClassIndex

      Map<String,String> getClassIndex()
      Returns the class index.
      Returns:
      the classIndex
    • getResourceIndex

      Map<String,String> getResourceIndex()
      Returns the resource index.
      Returns:
      the resourceIndex