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 String
getRelease
(String version) Some projects are packaged with an additional release beyond their effective version number, separated by a single hyphen.static String
getVersion
(Class<?> clazz, String groupId, String artifactId) Gets the version from a Mavenpom.properties
file, falling back toPackage.getImplementationVersion()
thenPackage.getSpecificationVersion()
.static String
getVersion
(Class<?> clazz, String groupId, String artifactId, String def) Gets the version from a Mavenpom.properties
file, falling back toPackage.getImplementationVersion()
thenPackage.getSpecificationVersion()
then the provided default.static String
getVersion
(ClassLoader cl, String groupId, String artifactId) Gets the version from a Mavenpom.properties
file and the given classloader.static String
getVersion
(ClassLoader cl, String groupId, String artifactId, String def) Gets the version from a Mavenpom.properties
file and the given classloader, falling back to the provided default.static String
getVersion
(Package pk) Gets the version fromPackage.getImplementationVersion()
, falling back toPackage.getSpecificationVersion()
.static String
getVersion
(Package pk, String def) Gets the version fromPackage.getImplementationVersion()
, falling back toPackage.getSpecificationVersion()
then the provided default.static String
getVersion
(String groupId, String artifactId) Gets the version from a Mavenpom.properties
file.static String
getVersion
(String groupId, String artifactId, String def) Gets the version from a Mavenpom.properties
file, falling back to the provided default.static String
readVersion
(String resource, InputStream in, String groupId, String artifactId) Reads thepom.properties
from the given input stream.static String
readVersion
(Function<String, InputStream> getResourceAsStream, String groupId, String artifactId) Reads thepom.properties
from the given source.static String
stripRelease
(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.properties
from the given input stream.- Throws:
IOException
-
readVersion
public static String readVersion(Function<String, InputStream> getResourceAsStream, String groupId, String artifactId) throws IOExceptionReads thepom.properties
from the given source.- Throws:
IOException
-
getVersion
Gets the version from a Mavenpom.properties
file and the given classloader.- Parameters:
cl
- The classloader to use. Whennull
, will useClassLoader.getSystemResourceAsStream(java.lang.String)
.- Returns:
- The version or
null
when not found.
-
getVersion
Gets the version from a Mavenpom.properties
file 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
null
when not found.
-
getVersion
Gets the version from a Mavenpom.properties
file.Searches the unnamed module via
ClassLoader.getResourceAsStream(java.lang.String)
.- Returns:
- The version or
null
when not found.
-
getVersion
Gets the version from a Mavenpom.properties
file, falling back to the provided default.Searches the unnamed module via
ClassLoader.getResourceAsStream(java.lang.String)
.- Returns:
- The version or
null
when not found.
-
getVersion
Gets the version fromPackage.getImplementationVersion()
, falling back toPackage.getSpecificationVersion()
.- Returns:
- The version or
null
when not found.
-
getVersion
Gets the version fromPackage.getImplementationVersion()
, falling back toPackage.getSpecificationVersion()
then the provided default.- Returns:
- The version or
null
when not found.
-
getVersion
Gets the version from a Mavenpom.properties
file, falling back toPackage.getImplementationVersion()
thenPackage.getSpecificationVersion()
.Supports named modules via
Class.getResourceAsStream(java.lang.String)
.- Returns:
- The version or
null
when not found.
-
getVersion
Gets the version from a Mavenpom.properties
file, falling back toPackage.getImplementationVersion()
thenPackage.getSpecificationVersion()
then the provided default.Supports named modules via
Class.getResourceAsStream(java.lang.String)
.- Returns:
- The version or
null
when 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.
-