Package org.kiwiproject.jar
Class KiwiJars
java.lang.Object
org.kiwiproject.jar.KiwiJars
Utilities for working with Java JAR files.
-
Method Summary
Modifier and TypeMethodDescriptiongetDirectoryPath(Class<?> classInJar) Get the directory path of the JAR file that the given class lives in, or an emptyOptionalif the path could not be obtained for any reason.Get the path of the JAR file that the given class lives in, or an emptyOptionalif the path could not be obtained for any reason.getPathComponents(Class<?> classInJar) Get the path components of the JAR file path that the given class lives in, or an empty list if the path components could not be obtained.Get the values of all main attributes from the manifest (if found) from the current class loader.readAllMainAttributesFromJarManifest(ClassLoader classLoader) Get the values of all main attributes from the manifest (if found) from the given class loader.readAllMainAttributesFromJarManifest(ClassLoader classLoader, @Nullable Predicate<URL> manifestFilter) Get the values of all main attributes from the manifest (if found) from the given class loader and filtering manifests using the given Predicate.readSingleValueFromJarManifest(ClassLoader classLoader, String mainAttributeName) Get the value of a main attribute from the manifest file (if found) from the given class loader.readSingleValueFromJarManifest(ClassLoader classLoader, String mainAttributeName, @Nullable Predicate<URL> manifestFilter) Get the value of a main attribute from the manifest file (if found) from the given class loader and filtering manifests using the given Predicate.readSingleValueFromJarManifest(String mainAttributeName) Get the value of a main attribute from the manifest file (if found) in the current class loader.readValuesFromJarManifest(ClassLoader classLoader, @Nullable Predicate<URL> manifestFilter, String... mainAttributeNames) Get the values of the given main attribute names from the manifest (if found) from the given class loader and filtering manifests using the given Predicate.readValuesFromJarManifest(ClassLoader classLoader, String... mainAttributeNames) Get the values of the given main attribute names from the manifest (if found) from the given class loader.readValuesFromJarManifest(String... mainAttributeNames) Get the values of the given main attribute names from the manifest (if found) from the current class loader.
-
Method Details
-
getPathComponents
Get the path components of the JAR file path that the given class lives in, or an empty list if the path components could not be obtained.- Parameters:
classInJar- the class which resides in the JAR you want to find- Returns:
- a mutable list of path components if found, or an immutable empty list if not found or an exception is thrown attempting to get the path
-
getPath
Get the path of the JAR file that the given class lives in, or an emptyOptionalif the path could not be obtained for any reason.- Parameters:
classInJar- the class which resides in the JAR you want to find- Returns:
- optional containing the path if found, or an empty optional
-
getDirectoryPath
Get the directory path of the JAR file that the given class lives in, or an emptyOptionalif the path could not be obtained for any reason.- Parameters:
classInJar- the class which resides in the JAR you want to find- Returns:
- optional containing the directory path if found, or an empty optional
-
readSingleValueFromJarManifest
Get the value of a main attribute from the manifest file (if found) in the current class loader.- Parameters:
mainAttributeName- The name of the main attribute to resolve- Returns:
- an
Optionalcontaining the resolved value orOptional.empty()if not
-
readSingleValueFromJarManifest
public static Optional<String> readSingleValueFromJarManifest(ClassLoader classLoader, String mainAttributeName) Get the value of a main attribute from the manifest file (if found) from the given class loader.- Parameters:
classLoader- The class loader to find the manifest file to searchmainAttributeName- The name of the main attribute to resolve- Returns:
- an
Optionalcontaining the resolved value orOptional.empty()if not
-
readSingleValueFromJarManifest
public static Optional<String> readSingleValueFromJarManifest(ClassLoader classLoader, String mainAttributeName, @Nullable Predicate<URL> manifestFilter) Get the value of a main attribute from the manifest file (if found) from the given class loader and filtering manifests using the given Predicate.- Parameters:
classLoader- The class loader to find the manifest file to searchmainAttributeName- The name of the main attribute to resolvemanifestFilter- An optional filter that can be used to filter down manifest files if there are more than one.- Returns:
- an
Optionalcontaining the resolved value orOptional.empty()if not - Implementation Note:
- If this code is called from a "fat-jar" with a single manifest file, then the filter predicate is unnecessary. The predicate filter is really only necessary if there are multiple jars loaded in the classpath all containing manifest files.
-
readValuesFromJarManifest
Get the values of the given main attribute names from the manifest (if found) from the current class loader.- Parameters:
mainAttributeNames- an array of main attribute names to resolve from the manifest- Returns:
- a
Map<String, String>of resolved main attributes
-
readValuesFromJarManifest
public static Map<String,String> readValuesFromJarManifest(ClassLoader classLoader, String... mainAttributeNames) Get the values of the given main attribute names from the manifest (if found) from the given class loader.- Parameters:
classLoader- the classloader to search for manifest files inmainAttributeNames- an array of names to resolve from the manifest- Returns:
- a
Map<String, String>of resolved main attributes
-
readValuesFromJarManifest
public static Map<String,String> readValuesFromJarManifest(ClassLoader classLoader, @Nullable Predicate<URL> manifestFilter, String... mainAttributeNames) Get the values of the given main attribute names from the manifest (if found) from the given class loader and filtering manifests using the given Predicate.- Parameters:
classLoader- the classloader to search for manifest files inmanifestFilter- a predicate filter used to limit which jar files to search for a manifest filemainAttributeNames- an array of names to resolve from the manifest- Returns:
- a
Map<String, String>of resolved main attributes - Implementation Note:
- If this code is called from a "fat-jar" with a single manifest file, then the filter predicate is unnecessary. The predicate filter is really only necessary if there are multiple jars loaded in the classpath all containing manifest files.
-
readAllMainAttributesFromJarManifest
Get the values of all main attributes from the manifest (if found) from the current class loader.- Returns:
- a
Map<String, String>of all main attributes
-
readAllMainAttributesFromJarManifest
Get the values of all main attributes from the manifest (if found) from the given class loader.- Parameters:
classLoader- the classloader to search for manifest files in- Returns:
- a
Map<String, String>of all main attributes
-
readAllMainAttributesFromJarManifest
public static Map<String,String> readAllMainAttributesFromJarManifest(ClassLoader classLoader, @Nullable Predicate<URL> manifestFilter) Get the values of all main attributes from the manifest (if found) from the given class loader and filtering manifests using the given Predicate.- Parameters:
classLoader- the classloader to search for manifest files inmanifestFilter- a predicate filter used to limit which jar files to search for a manifest file- Returns:
- a
Map<String, String>of all main attributes
-