java.lang.Object
com.aoapps.lang.Projects
Utilities that help when working with
Package and/or Maven projects.
See java - Get Maven artifact version at runtime - Stack Overflow.
- Author:
- AO Industries, Inc.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetRelease(String version) Some projects are packaged with an additional release beyond their effective version number, separated by a single hyphen.static StringgetVersion(Class<?> clazz, String groupId, String artifactId) Gets the version from a Mavenpom.propertiesfile, falling back toPackage.getImplementationVersion()thenPackage.getSpecificationVersion().static StringgetVersion(Class<?> clazz, String groupId, String artifactId, String def) Gets the version from a Mavenpom.propertiesfile, falling back toPackage.getImplementationVersion()thenPackage.getSpecificationVersion()then the provided default.static StringgetVersion(ClassLoader cl, String groupId, String artifactId) Gets the version from a Mavenpom.propertiesfile and the given classloader.static StringgetVersion(ClassLoader cl, String groupId, String artifactId, String def) Gets the version from a Mavenpom.propertiesfile and the given classloader, falling back to the provided default.static StringgetVersion(Package pk) Gets the version fromPackage.getImplementationVersion(), falling back toPackage.getSpecificationVersion().static StringgetVersion(Package pk, String def) Gets the version fromPackage.getImplementationVersion(), falling back toPackage.getSpecificationVersion()then the provided default.static StringgetVersion(String groupId, String artifactId) Gets the version from a Mavenpom.propertiesfile.static StringgetVersion(String groupId, String artifactId, String def) Gets the version from a Mavenpom.propertiesfile, falling back to the provided default.static StringreadVersion(String resource, InputStream in, String groupId, String artifactId) Reads thepom.propertiesfrom the given input stream.static StringreadVersion(Function<String, InputStream> getResourceAsStream, String groupId, String artifactId) Reads thepom.propertiesfrom the given source.static StringstripRelease(String version) Some projects are packaged with an additional release beyond their effective version number, separated by a single hyphen.
-
Method Details
-
readVersion
public static String readVersion(String resource, InputStream in, String groupId, String artifactId) throws IOException Reads thepom.propertiesfrom the given input stream.- Throws:
IOException
-
readVersion
public static String readVersion(Function<String, InputStream> getResourceAsStream, String groupId, String artifactId) throws IOExceptionReads thepom.propertiesfrom the given source.- Throws:
IOException
-
getVersion
Gets the version from a Mavenpom.propertiesfile and the given classloader.- Parameters:
cl- The classloader to use. Whennull, will useClassLoader.getSystemResourceAsStream(java.lang.String).- Returns:
- The version or
nullwhen not found.
-
getVersion
Gets the version from a Mavenpom.propertiesfile and the given classloader, falling back to the provided default.- Parameters:
cl- The classloader to use. Whennull, will useClassLoader.getSystemResourceAsStream(java.lang.String).- Returns:
- The version or
nullwhen not found.
-
getVersion
Gets the version from a Mavenpom.propertiesfile.Searches the unnamed module via
ClassLoader.getResourceAsStream(java.lang.String).- Returns:
- The version or
nullwhen not found.
-
getVersion
Gets the version from a Mavenpom.propertiesfile, falling back to the provided default.Searches the unnamed module via
ClassLoader.getResourceAsStream(java.lang.String).- Returns:
- The version or
nullwhen not found.
-
getVersion
Gets the version fromPackage.getImplementationVersion(), falling back toPackage.getSpecificationVersion().- Returns:
- The version or
nullwhen not found.
-
getVersion
Gets the version fromPackage.getImplementationVersion(), falling back toPackage.getSpecificationVersion()then the provided default.- Returns:
- The version or
nullwhen not found.
-
getVersion
Gets the version from a Mavenpom.propertiesfile, falling back toPackage.getImplementationVersion()thenPackage.getSpecificationVersion().Supports named modules via
Class.getResourceAsStream(java.lang.String).- Returns:
- The version or
nullwhen not found.
-
getVersion
Gets the version from a Mavenpom.propertiesfile, falling back toPackage.getImplementationVersion()thenPackage.getSpecificationVersion()then the provided default.Supports named modules via
Class.getResourceAsStream(java.lang.String).- Returns:
- The version or
nullwhen not found.
-
stripRelease
Some projects are packaged with an additional release beyond their effective version number, separated by a single hyphen. This release is optional, and expected to be numeric only. -
getRelease
Some projects are packaged with an additional release beyond their effective version number, separated by a single hyphen. This release is optional, and expected to be numeric only.
-
