Skip to content

Commit 6be13e4

Browse files
committed
AbstractModuleInfo: implement Versioned interface
The default implementation just uses the delegate class, analogous to how the default implementation of Locatable works. This behavior will need to be overridden in ScriptInfo, since it uses the same delegate class (ScriptModule) for all scripts.
1 parent a829fff commit 6be13e4

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/main/java/org/scijava/module/AbstractModuleInfo.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@
4141
import org.scijava.Identifiable;
4242
import org.scijava.Locatable;
4343
import org.scijava.ValidityProblem;
44+
import org.scijava.Versioned;
4445
import org.scijava.event.EventService;
4546
import org.scijava.module.event.ModulesUpdatedEvent;
4647
import org.scijava.util.ClassUtils;
4748
import org.scijava.util.ConversionUtils;
49+
import org.scijava.util.Manifest;
4850

4951
/**
5052
* Abstract superclass of {@link ModuleInfo} implementation.
@@ -56,7 +58,7 @@
5658
* @author Curtis Rueden
5759
*/
5860
public abstract class AbstractModuleInfo extends AbstractUIDetails implements
59-
ModuleInfo, Identifiable, Locatable
61+
ModuleInfo, Identifiable, Locatable, Versioned
6062
{
6163

6264
/** Table of inputs, keyed on name. */
@@ -187,6 +189,22 @@ public String getLocation() {
187189
}
188190
}
189191

192+
// -- Versioned methods --
193+
194+
@Override
195+
public String getVersion() {
196+
// NB: By default, we use the version of the delegate class's JAR archive.
197+
// If the same delegate class is used for more than one module, though,
198+
// it may need to override this method to indicate a different version.
199+
try {
200+
final Manifest m = Manifest.getManifest(loadDelegateClass());
201+
return m == null ? null : m.getImplementationVersion();
202+
}
203+
catch (final ClassNotFoundException exc) {
204+
return null;
205+
}
206+
}
207+
190208
// -- Internal methods --
191209

192210
/**

0 commit comments

Comments
 (0)