Skip to content

Commit 90a744b

Browse files
committed
PluginInfo: implement more interfaces
All plugins are Identifiable, Locatable and Versioned, since they correspond to a Java class which we can track down in those fashions.
1 parent 3cd706c commit 90a744b

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/main/java/org/scijava/plugin/PluginInfo.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@
3434
import java.net.URL;
3535

3636
import org.scijava.AbstractUIDetails;
37+
import org.scijava.Identifiable;
3738
import org.scijava.Instantiable;
3839
import org.scijava.InstantiableException;
40+
import org.scijava.Locatable;
3941
import org.scijava.MenuEntry;
4042
import org.scijava.MenuPath;
4143
import org.scijava.Priority;
4244
import org.scijava.UIDetails;
45+
import org.scijava.Versioned;
4346
import org.scijava.input.Accelerator;
4447
import org.scijava.util.ClassUtils;
4548
import org.scijava.util.StringMaker;
49+
import org.scijava.util.VersionUtils;
4650

4751
/**
4852
* A collection of metadata about a particular plugin.
@@ -61,7 +65,7 @@
6165
* @see PluginService
6266
*/
6367
public class PluginInfo<PT extends SciJavaPlugin> extends AbstractUIDetails
64-
implements Instantiable<PT>
68+
implements Instantiable<PT>, Identifiable, Locatable, Versioned
6569
{
6670

6771
/** Fully qualified class name of this plugin. */
@@ -304,6 +308,42 @@ public PT createInstance() throws InstantiableException {
304308
return instance;
305309
}
306310

311+
// -- Identifiable methods --
312+
313+
@Override
314+
public String getIdentifier() {
315+
try {
316+
return "plugin:" + loadClass();
317+
}
318+
catch (final InstantiableException exc) {
319+
return null;
320+
}
321+
}
322+
323+
// -- Locatable methods --
324+
325+
@Override
326+
public String getLocation() {
327+
try {
328+
return ClassUtils.getLocation(loadClass()).toExternalForm();
329+
}
330+
catch (InstantiableException exc) {
331+
return null;
332+
}
333+
}
334+
335+
// -- Versioned methods --
336+
337+
@Override
338+
public String getVersion() {
339+
try {
340+
return VersionUtils.getVersion(loadClass());
341+
}
342+
catch (InstantiableException exc) {
343+
return null;
344+
}
345+
}
346+
307347
// -- Helper methods --
308348

309349
/** Populates the entry to match the associated @{@link Plugin} annotation. */

0 commit comments

Comments
 (0)