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.readSingleValueFromJarManifest(ClassLoader classLoader, String manifestEntryName) Resolves a given entry name from the manifest file (if found) from the given class loader.readSingleValueFromJarManifest(ClassLoader classLoader, String manifestEntryName, Predicate<URL> manifestFilter) Resolves a given entry name from the manifest file (if found) from the given class loader.readSingleValueFromJarManifest(String manifestEntryName) Resolves a given entry name from the manifest file (if found) in the current class loader.readValuesFromJarManifest(ClassLoader classLoader, String... manifestEntryNames) Resolves all the given entry names from the manifest (if found) from the given class loader.readValuesFromJarManifest(ClassLoader classLoader, Predicate<URL> manifestFilter, String... manifestEntryNames) Resolves all the given entry names from the manifest (if found) from the given class loader.readValuesFromJarManifest(String... manifestEntryNames) Resolves all the given entry 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
Resolves a given entry name from the manifest file (if found) in the current class loader.- Parameters:
manifestEntryName- The name of the property to resolve- Returns:
- an
Optionalcontaining the resolved value orOptional.empty()if not
-
readSingleValueFromJarManifest
public static Optional<String> readSingleValueFromJarManifest(ClassLoader classLoader, String manifestEntryName) Resolves a given entry name from the manifest file (if found) from the given class loader.- Parameters:
classLoader- The class loader to find the manifest file to searchmanifestEntryName- The name of the property to resolve- Returns:
- an
Optionalcontaining the resolved value orOptional.empty()if not
-
readSingleValueFromJarManifest
public static Optional<String> readSingleValueFromJarManifest(ClassLoader classLoader, String manifestEntryName, Predicate<URL> manifestFilter) Resolves a given entry name from the manifest file (if found) from the given class loader.- Parameters:
classLoader- The class loader to find the manifest file to searchmanifestEntryName- The name of the property 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 single manifest file, then the filter predicate is not needed. The predicate filter is really only needed if there are multiple jars loaded in the classpath all containing manifest files.
-
readValuesFromJarManifest
Resolves all the given entry names from the manifest (if found) from the current class loader.- Parameters:
manifestEntryNames- an array of names to resolve from the manifest- Returns:
- a
Map<String,String>of resolved entries
-
readValuesFromJarManifest
public static Map<String,String> readValuesFromJarManifest(ClassLoader classLoader, String... manifestEntryNames) Resolves all the given entry names from the manifest (if found) from the given class loader.- Parameters:
classLoader- the classloader to search for manifest files inmanifestEntryNames- an array of names to resolve from the manifest- Returns:
- a
Map<String,String>of resolved entries
-
readValuesFromJarManifest
public static Map<String,String> readValuesFromJarManifest(ClassLoader classLoader, Predicate<URL> manifestFilter, String... manifestEntryNames) Resolves all the given entry names from the manifest (if found) from the given class loader.- Parameters:
classLoader- the classloader to search for manifest files inmanifestFilter- a predicate filter used to limit which jar files to search for a manifest filemanifestEntryNames- an array of names to resolve from the manifest- Returns:
- a
Map<String,String>of resolved entries - Implementation Note:
- If this code is called from a "fat-jar" with single manifest file, then the filter predicate is not needed. The predicate filter is really only needed if there are multiple jars loaded in the classpath all containing manifest files.
-