Class JarFileBuilder

java.lang.Object
simula.compiler.JarFileBuilder

public class JarFileBuilder extends Object
Utilities to build and manipulate jarFiles.
  • Field Details

    • programModule

      private ProgramModule programModule
      The ProgramModule.
    • outputJarFile

      private File outputJarFile
      The output .jar file
    • mainEntry

      String mainEntry
      Main entry name.
    • classFileMap

      private final HashMap<String,byte[]> classFileMap
      The intermediate classFileMap.
    • jarOutputStream

      private JarOutputStream jarOutputStream
      The target JarOutputStream.
    • TESTING

      private static final boolean TESTING
      Debug utility.
      See Also:
  • Constructor Details

    • JarFileBuilder

      public JarFileBuilder()
      Construct a new JarFileBuilder.
  • Method Details

    • open

      public void open(ProgramModule program) throws IOException
      Open the JarFileBuilder.
      Parameters:
      program - the relevant ProgramModule
      Throws:
      IOException - if something went wrong
    • putMapEntry

      public void putMapEntry(String entryName, byte[] bytes)
      Put a JarEntry to the intermediate classFileMap.
      Parameters:
      entryName - the entry name
      bytes - the bytes, may be null
    • writeJarEntry

      public void writeJarEntry(String entryName, byte[] bytes) throws IOException
      Write a JarEntry to the JarOutputStream.
      Parameters:
      entryName - the entry name
      bytes - the bytes, may be null
      Throws:
      IOException - if something went wrong
    • close

      public File close() throws IOException
      Close the JarFileBuilder by writing the .jar file.
      Returns:
      the outputJarFile
      Throws:
      IOException - if something went wrong
    • addTempClassFiles

      public void addTempClassFiles() throws IOException
      Add temp .class files to jarOutputStream.
      Throws:
      IOException - if something went wrong
    • add

      private void add(boolean doPut, File source, int pathSize) throws IOException
      Add directory or a file to a JarOutputStream, or Put it into the intermediate classFileMap.
      Parameters:
      doPut - true:put it, otherwise add it
      source - source file or directory
      pathSize - the path size
      Throws:
      IOException - if something went wrong
    • expandJarFile

      public void expandJarFile(JarFile jarFile) throws IOException
      Expand .jar file entries into the classFileMap.
      Parameters:
      jarFile - the .jar file to read
      Throws:
      IOException - if something went wrong
    • printClassFileMap

      private void printClassFileMap(String title)
      Debug utility: printClassFileMap.
      Parameters:
      title - the title String.
    • findJarFile

      public static File findJarFile(String identifier, String externalIdentifier)
      Find the .jar file containing an external class or procedure.
      Parameters:
      identifier - class or procedure identifier
      externalIdentifier - the external identifier if any
      Returns:
      the resulting File
    • addToIncludeQueue

      public static void addToIncludeQueue(JarFile jarFile) throws IOException
      Add the jarFile to the includeQueue.
      Parameters:
      jarFile - the jarFile to be added
      Throws:
      IOException - if something went wrong
    • addIncludeQueue

      public void addIncludeQueue() throws IOException
      Add the jarFiles in the includeQueue.
      Throws:
      IOException - if something went wrong
    • loadIncludeQueue

      public static void loadIncludeQueue() throws IOException
      Load the jarFiles in the includeQueue using simulaClassLoader.
      Throws:
      IOException - if something went wrong
    • loadRuntimeSystem

      public static void loadRuntimeSystem() throws IOException
      Load the Runtime System using simulaClassLoader.
      Throws:
      IOException - if something went wrong
    • loadJarEntries

      private static void loadJarEntries(JarFile jarFile, String packetName, SimulaClassLoader loader) throws IOException
      Load jarFile entries.
      Parameters:
      jarFile - the jarFile.
      packetName - the packet name.
      loader - the SimulaClassLoader to use.
      Throws:
      IOException - if something went wrong.
    • listJarFile

      public static void listJarFile(File file)
      Debug utility: List .jar file
      Parameters:
      file - the .jar file