Class JarManifests

java.lang.Object
org.kiwiproject.beta.base.jar.JarManifests

@Beta public final class JarManifests extends Object
Static utilities related to JAR manifests.

If you need to be able to mock the functionality in this class for testing, consider using JarManifestHelper instead.

See Also:
  • Method Details

    • getMainAttributeValueOrThrow

      public static String getMainAttributeValueOrThrow(Class<?> theClass, String name)
      Get the main attribute value in a Manifest, using the given Class to locate the associated MANIFEST.MF file.
      Parameters:
      theClass - the Class to use for finding the Manifest
      name - the name of the main attribute
      Returns:
      the value of the attribute
      Throws:
      IllegalStateException - if the lookup failed or the attribute does not exist
    • getMainAttributeValue

      public static Optional<String> getMainAttributeValue(Class<?> theClass, String name)
      Get the main attribute value in a Manifest, using the given Class to locate the associated MANIFEST.MF file.
      Parameters:
      theClass - the Class to use for finding the Manifest
      name - the name of the main attribute
      Returns:
      an Optional containing the value, or an empty Optional if the looked failed
    • getMainAttributeValue

      public static Optional<String> getMainAttributeValue(Manifest manifest, String name)
      Get the main attribute value in a Manifest having the given name.
      Parameters:
      manifest - the Manifest
      name - the name of the main attribute
      Returns:
      an Optional containing the value, or an empty Optional if the lookup failed
    • getMainAttributesAsMapOrThrow

      public static Map<String,String> getMainAttributesAsMapOrThrow(Class<?> theClass)
      Return the main attributes of the Manifest, using the given Class to locate the associated MANIFEST.MF file.
      Parameters:
      theClass - the Class to use for finding the Manifest
      Returns:
      a map containing the main attributes
      Throws:
      IllegalStateException - if the lookup fails for any reason
    • getMainAttributesAsMap

      public static Map<String,String> getMainAttributesAsMap(Manifest manifest)
      Return the main attributes of the Manifest, using the given Class to locate the associated MANIFEST.MF file.
      Parameters:
      manifest - the manifest
      Returns:
      a map containing the main attributes
    • getManifestOrThrow

      public static Manifest getManifestOrThrow(Class<?> theClass)
      Use the given Class to locate the associated MANIFEST.MF file.
      Parameters:
      theClass - the Class to use for finding the Manifest
      Returns:
      the Manifest
      Throws:
      IllegalStateException - if the lookup fails for any reason
    • getManifest

      public static Optional<Manifest> getManifest(Class<?> theClass)
      Use the given Class to locate the associated MANIFEST.MF file.
      Parameters:
      theClass - the Class to use for finding the Manifest
      Returns:
      an Optional containing the Manifest, or an empty Optional if the lookup failed
    • getManifest

      public static Optional<Manifest> getManifest(URI jarFileURI)
      Use the given URI to locate the associated MANIFEST.MF file.
      Parameters:
      jarFileURI - the URI of the JAR file in which the manifest resides
      Returns:
      an Optional containing the Manifest, or an empty Optional if any error occurs