Package org.kiwiproject.jar
Class KiwiJars
- java.lang.Object
-
- org.kiwiproject.jar.KiwiJars
-
public class KiwiJars extends Object
Utilities for working with Java JAR files.
-
-
Constructor Summary
Constructors Constructor Description KiwiJars()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Optional<String>getDirectoryPath(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.static Optional<String>getPath(Class<?> classInJar)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.static List<String>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.static Optional<String>readSingleValueFromJarManifest(ClassLoader classLoader, String manifestEntryName)Resolves a given entry name from the manifest file (if found) from the given class loader.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.static Optional<String>readSingleValueFromJarManifest(String manifestEntryName)Resolves a given entry name from the manifest file (if found) in the current class loader.static Map<String,String>readValuesFromJarManifest(ClassLoader classLoader, String... manifestEntryNames)Resolves all of the given entry names from the manifest (if found) from the given class loader.static Map<String,String>readValuesFromJarManifest(ClassLoader classLoader, Predicate<URL> manifestFilter, String... manifestEntryNames)Resolves all of the given entry names from the manifest (if found) from the given class loader.static Map<String,String>readValuesFromJarManifest(String... manifestEntryNames)Resolves all of the given entry names from the manifest (if found) from the current class loader.
-
-
-
Method Detail
-
getPathComponents
public static List<String> 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.- 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
public static Optional<String> getPath(Class<?> classInJar)
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
public static Optional<String> getDirectoryPath(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.- 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
public static Optional<String> readSingleValueFromJarManifest(String manifestEntryName)
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
public static Map<String,String> readValuesFromJarManifest(String... manifestEntryNames)
Resolves all of 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 of 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 of 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.
-
-