Class ArchiveUtils

java.lang.Object
com.isomorphic.maven.util.ArchiveUtils

public class ArchiveUtils
extends Object
A collection of static utilities useful for working with JAR/ZIP archives.
  • Constructor Summary

    Constructors 
    Constructor Description
    ArchiveUtils()  
  • Method Summary

    Modifier and Type Method Description
    static void jar​(File directory, File output)
    Builds a JAR file from the contents of a directory on the filesystem (recursively).
    static String rewritePath​(String oldValue, String newValue)
    Derives a new file path, in whole or in part, from an existing path.
    static void unzip​(File source, File target)
    Unzips the source file to the target directory.
    static void zip​(File directory, File output)
    Builds a ZIP file from the contents of a directory on the filesystem (recursively).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • jar

      public static void jar​(File directory, File output) throws IOException
      Builds a JAR file from the contents of a directory on the filesystem (recursively). Adapted from stackoverflow solution.

      Refer to http://stackoverflow.com/questions/1281229/how-to-use-jaroutputstream-to-create-a-jar-file

      Parameters:
      directory - the directory containing the content to be xzipped up
      output - the zip file to be written to
      Throws:
      IOException - when any I/O error occurs
    • zip

      public static void zip​(File directory, File output) throws IOException
      Builds a ZIP file from the contents of a directory on the filesystem (recursively).

      Refer to http://stackoverflow.com/questions/1281229/how-to-use-jaroutputstream-to-create-a-jar-file

      Parameters:
      directory - the directory containing the content to be xzipped up
      output - the zip file to be written to
      Throws:
      IOException - when any I/O error occurs
    • unzip

      public static void unzip​(File source, File target) throws IOException
      Unzips the source file to the target directory.
      Parameters:
      source - The file to be unzipped
      target - The directory to which the source file should be unzipped
      Throws:
      IOException - when any I/O error occurs
    • rewritePath

      public static String rewritePath​(String oldValue, String newValue)
      Derives a new file path, in whole or in part, from an existing path. The following use cases are supported explicitly:
      • Rename a file (example: smartgwt-lgpl.jar)

        ArchiveUtils.rewritePath("smartgwtee-4.1d/lib/smartgwt.jar", "smartgwt-lgpl.jar");

      • Move to another directory (example: target/smartgwt.jar)

        ArchiveUtils.rewritePath("smartgwtee-4.1d/lib/smartgwt.jar", "target");

      • Move and rename (example: target/smartgwt-lgpl.jar)

        ArchiveUtils.rewritePath("smartgwtee-4.1d/lib/smartgwt.jar", "target/smartgwt-lgpl.jar");

      • Move to new root directory, preserving some part of the existing path
        • example: doc/api/com/isomorphic/servlet/IDACall.html

          ArchiveUtils.rewritePath("smartgwtee-4.1d/doc/javadoc/com/isomorphic/servlet/IDACall.html","doc/api/#javadoc");

        • example: doc/api/com/isomorphic/servlet/network/FileAssembly.html

          ArchiveUtils.rewritePath("smartgwtee-4.1d/doc/javadoc/com/isomorphic/servlet/CompressionFilter.html", "doc/api/#javadoc/network");

      Parameters:
      oldValue - the existing path
      newValue - the value to use for the new path, including optional tokens
      Returns:
      the new path