- java.lang.Object
-
- com.aoapps.lang.Projects
-
public final class Projects extends Object
Utilities that help when working withPackage
and/or Maven projects.See java - Get Maven artifact version at runtime - Stack Overflow.
- Author:
- AO Industries, Inc.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 Detail
-
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 IOException
Reads thepom.properties
from the given source.- Throws:
IOException
-
getVersion
public static String getVersion(ClassLoader cl, String groupId, String artifactId)
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
public 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.- Parameters:
cl
- The classloader to use. Whennull
, will useClassLoader.getSystemResourceAsStream(java.lang.String)
.- Returns:
- The version or
null
when not found.
-
getVersion
public static String getVersion(String groupId, String artifactId)
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
public static String getVersion(String groupId, String artifactId, String def)
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
public static String getVersion(Package pk)
Gets the version fromPackage.getImplementationVersion()
, falling back toPackage.getSpecificationVersion()
.- Returns:
- The version or
null
when not found.
-
getVersion
public static String getVersion(Package pk, String def)
Gets the version fromPackage.getImplementationVersion()
, falling back toPackage.getSpecificationVersion()
then the provided default.- Returns:
- The version or
null
when not found.
-
getVersion
public static String getVersion(Class<?> clazz, String groupId, String artifactId)
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
public 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.Supports named modules via
Class.getResourceAsStream(java.lang.String)
.- Returns:
- The version or
null
when not found.
-
stripRelease
public static String stripRelease(String version)
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.
-
-