- java.lang.Object
-
- com.aoapps.lang.Projects
-
public final class Projects extends Object
Utilities that help when working withPackageand/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 StringgetRelease(String version)Some projects are packaged with an additional release beyond their effective version number, separated by a single hypen.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 hypen.
-
-
-
Method Detail
-
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 IOException
Reads thepom.propertiesfrom the given source.- Throws:
IOException
-
getVersion
public static String getVersion(ClassLoader cl, String groupId, String artifactId)
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
public static String getVersion(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.- Parameters:
cl- The classloader to use. Whennull, will useClassLoader.getSystemResourceAsStream(java.lang.String).- Returns:
- The version or
nullwhen not found.
-
getVersion
public static String getVersion(String groupId, String artifactId)
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
public static String getVersion(String groupId, String artifactId, String def)
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
public static String getVersion(Package pk)
Gets the version fromPackage.getImplementationVersion(), falling back toPackage.getSpecificationVersion().- Returns:
- The version or
nullwhen 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
nullwhen not found.
-
getVersion
public static String getVersion(Class<?> clazz, String groupId, String artifactId)
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
public static String getVersion(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.Supports named modules via
Class.getResourceAsStream(java.lang.String).- Returns:
- The version or
nullwhen 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 hypen. This release is optional, and expected to be numeric only.
-
-