Skip to content

Commit 82e1a36

Browse files
committed
VersionUtils: append build number to SNAPSHOTs
This provides a more robust (i.e., more unique) version number when working with development versions.
1 parent f576257 commit 82e1a36

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/main/java/org/scijava/util/VersionUtils.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
public class VersionUtils {
4242

4343
/**
44-
* Looks up the version of the specified class using any means available. Will
45-
* only search POMs in the base directory.
44+
* Looks up the version of the specified class using any means available,
45+
* appending the build number to any {@code SNAPSHOT} version. Will only
46+
* search POMs in the base directory.
4647
*
4748
* @param c - Look up this class's version
4849
* @return Version of specified {@link Class} or null if not found.
@@ -52,9 +53,10 @@ public static String getVersion(final Class<?> c) {
5253
}
5354

5455
/**
55-
* Looks up the version of the specified class using any means available.
56-
* The {@code groupId} and {@code artifactId} parameters allow
57-
* specification of the POM lookup path.
56+
* Looks up the version of the specified class using any means available,
57+
* appending the build number to any {@code SNAPSHOT} version. The
58+
* {@code groupId} and {@code artifactId} parameters allow specification of
59+
* the POM lookup path.
5860
*
5961
* @param c - Look up this class's version
6062
* @param groupId - Maven group ID containing class
@@ -71,15 +73,20 @@ public static String getVersion(final Class<?> c, final String groupId,
7173

7274
/**
7375
* Looks up the version of the specified class using a JAR manifest if
74-
* available.
76+
* available, appending the build number to any {@code SNAPSHOT} version.
7577
*
7678
* @param c - Look up this class's version
7779
* @return Version of specified {@link Class} or null if not found.
7880
*/
7981
public static String getVersionFromManifest(final Class<?> c) {
8082
final Manifest m = Manifest.getManifest(c);
8183
if (m == null) return null;
82-
return getVersionFromManifest(m);
84+
final String version = getVersionFromManifest(m);
85+
if (version == null || !version.endsWith("-SNAPSHOT")) return version;
86+
87+
// append commit hash to differentiate between development versions
88+
final String buildNumber = getBuildNumber(m);
89+
return buildNumber == null ? version : version + "-" + buildNumber;
8390
}
8491

8592
/**

0 commit comments

Comments
 (0)