Class JarToolModularJarArchiver

All Implemented Interfaces:
Archiver, FinalizerEnabled

@Named("mjar") public class JarToolModularJarArchiver extends ModularJarArchiver
A ModularJarArchiver implementation that uses the jar tool provided by java.util.spi.ToolProvider to create modular JAR files.

The basic JAR archive is created by JarArchiver and the jar tool is used to upgrade it to modular JAR.

If the JAR file does not contain module descriptor or the JDK does not provide the jar tool (for example JDK prior to Java 9), then the archive created by JarArchiver is left unchanged.

  • Field Details

    • MODULE_DESCRIPTOR_FILE_NAME

      private static final String MODULE_DESCRIPTOR_FILE_NAME
      See Also:
    • MRJAR_VERSION_AREA

      private static final Pattern MRJAR_VERSION_AREA
    • jarTool

      private Object jarTool
    • moduleDescriptorFound

      private boolean moduleDescriptorFound
    • hasJarDateOption

      private boolean hasJarDateOption
  • Constructor Details

    • JarToolModularJarArchiver

      public JarToolModularJarArchiver()
  • Method Details

    • zipFile

      protected void zipFile(org.apache.commons.compress.parallel.InputStreamSupplier is, ConcurrentJarCreator zOut, String vPath, long lastModified, File fromArchive, int mode, String symlinkDestination, boolean addInParallel) throws IOException, ArchiverException
      Description copied from class: JarArchiver
      Overridden from Zip class to deal with manifests and index lists.
      Overrides:
      zipFile in class JarArchiver
      Parameters:
      is - the stream to read data for the entry from.
      zOut - the stream to write to.
      vPath - the name this entry shall have in the archive.
      lastModified - last modification time for the entry.
      fromArchive - the original archive we are copying this
      symlinkDestination -
      addInParallel - Indicates if the entry should be add in parallel. If set to false it is added synchronously. If the entry is symbolic link this parameter is ignored.
      Throws:
      IOException
      ArchiverException
    • postCreateArchive

      protected void postCreateArchive() throws ArchiverException
      Description copied from class: AbstractArchiver
      This method is called after the archive creation completes successfully (no exceptions are thrown). Subclasses may override this method in order to augment or validate the archive after it is created.
      Overrides:
      postCreateArchive in class AbstractArchiver
      Throws:
      ArchiverException
    • fixLastModifiedTimeZipEntries

      private void fixLastModifiedTimeZipEntries() throws IOException
      Fallback to rewrite the JAR file with the correct timestamp if the --date option is not available.
      Throws:
      IOException
    • isModuleDescriptor

      private boolean isModuleDescriptor(String path)
      Returns true if path is a module descriptor.
    • getJarToolArguments

      private String[] getJarToolArguments() throws IOException
      Prepares the arguments for the jar tool. It takes into account the module version, main class, etc.
      Throws:
      IOException
    • revertToLocalTime

      private static FileTime revertToLocalTime(FileTime time)
    • isJarDateOptionSupported

      private boolean isJarDateOptionSupported(Method runMethod)
      Check support for --date option introduced since Java 17.0.3 (JDK-8279925).
      Returns:
      true if the JAR tool supports the --date option