Skip to content

Commit 43407c1

Browse files
committed
Manifest: implement the Versioned interface
This migrates the version determination logic from VersionUtils into the org.scijava.util.Manifest class directly. And updates VersionUtils to lean on it.
1 parent a7f49c6 commit 43407c1

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@
4040
import java.util.Map;
4141
import java.util.jar.Attributes;
4242

43+
import org.scijava.Versioned;
44+
4345
/**
4446
* Helper class for working with JAR manifests.
4547
*
4648
* @author Curtis Rueden
4749
*/
48-
public class Manifest {
50+
public class Manifest implements Versioned {
4951

5052
/** The JAR manifest backing this object. */
5153
private final java.util.jar.Manifest manifest;
@@ -165,4 +167,24 @@ private static Manifest getManifest(final URL jarURL) throws IOException {
165167
return new Manifest(conn.getManifest());
166168
}
167169

170+
// -- Versioned methods --
171+
172+
@Override
173+
public String getVersion() {
174+
final String v = getBaseVersion();
175+
if (v == null || !v.endsWith("-SNAPSHOT")) return v;
176+
177+
// append commit hash to differentiate between development versions
178+
final String buildNumber = getImplementationBuild();
179+
return buildNumber == null ? v : v + "-" + buildNumber;
180+
}
181+
182+
// -- Helper methods --
183+
184+
private String getBaseVersion() {
185+
final String manifestVersion = getImplementationVersion();
186+
if (manifestVersion != null) return manifestVersion;
187+
return getSpecificationVersion();
188+
}
189+
168190
}

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,7 @@ public static String getVersion(final Class<?> c, final String groupId,
8080
*/
8181
public static String getVersionFromManifest(final Class<?> c) {
8282
final Manifest m = Manifest.getManifest(c);
83-
if (m == null) return null;
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;
83+
return m == null ? null : m.getVersion();
9084
}
9185

9286
/**
@@ -115,18 +109,7 @@ public static String getVersionFromPOM(final Class<?> c,
115109
* @return Build number of specified {@link Class} or null if not found.
116110
*/
117111
public static String getBuildNumber(final Class<?> c) {
118-
return getBuildNumber(Manifest.getManifest(c));
119-
}
120-
121-
// -- Helper methods --
122-
123-
private static String getVersionFromManifest(final Manifest m) {
124-
final String manifestVersion = m.getImplementationVersion();
125-
if (manifestVersion != null) return manifestVersion;
126-
return m.getSpecificationVersion();
127-
}
128-
129-
private static String getBuildNumber(final Manifest m) {
112+
final Manifest m = Manifest.getManifest(c);
130113
return m == null ? null : m.getImplementationBuild();
131114
}
132115

0 commit comments

Comments
 (0)