Skip to content

Commit 3469e92

Browse files
committed
Make common module types implement Locatable
1 parent 0433736 commit 3469e92

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/main/java/org/scijava/command/CommandInfo.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.scijava.Identifiable;
4646
import org.scijava.InstantiableException;
4747
import org.scijava.ItemVisibility;
48+
import org.scijava.Locatable;
4849
import org.scijava.ValidityProblem;
4950
import org.scijava.event.EventService;
5051
import org.scijava.module.Module;
@@ -76,7 +77,7 @@
7677
* commands and the rich {@link Module} interface.
7778
*/
7879
public class CommandInfo extends PluginInfo<Command> implements ModuleInfo,
79-
Identifiable
80+
Identifiable, Locatable
8081
{
8182

8283
/** Wrapped {@link PluginInfo}, if any. */
@@ -422,6 +423,18 @@ public String getIdentifier() {
422423
return sb.toString();
423424
}
424425

426+
// -- Locatable methods --
427+
428+
@Override
429+
public String getLocation() {
430+
try {
431+
return ClassUtils.getLocation(loadDelegateClass()).toExternalForm();
432+
}
433+
catch (final ClassNotFoundException exc) {
434+
return null;
435+
}
436+
}
437+
425438
// -- Helper methods --
426439

427440
/**

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
3939

4040
import org.scijava.AbstractUIDetails;
4141
import org.scijava.Identifiable;
42+
import org.scijava.Locatable;
4243
import org.scijava.ValidityProblem;
4344
import org.scijava.event.EventService;
4445
import org.scijava.module.event.ModulesUpdatedEvent;
46+
import org.scijava.util.ClassUtils;
4547
import org.scijava.util.ConversionUtils;
4648

4749
/**
@@ -54,7 +56,7 @@
5456
* @author Curtis Rueden
5557
*/
5658
public abstract class AbstractModuleInfo extends AbstractUIDetails implements
57-
ModuleInfo, Identifiable
59+
ModuleInfo, Identifiable, Locatable
5860
{
5961

6062
/** Table of inputs, keyed on name. */
@@ -170,6 +172,21 @@ public String getIdentifier() {
170172
return "module:" + getDelegateClassName();
171173
}
172174

175+
// -- Locatable methods --
176+
177+
@Override
178+
public String getLocation() {
179+
// NB: By default, we use the location of the delegate class.
180+
// If the same delegate class is used for more than one module, though,
181+
// it may need to override this method to indicate a different location.
182+
try {
183+
return ClassUtils.getLocation(loadDelegateClass()).toExternalForm();
184+
}
185+
catch (final ClassNotFoundException exc) {
186+
return null;
187+
}
188+
}
189+
173190
// -- Internal methods --
174191

175192
/**

src/main/java/org/scijava/script/ScriptInfo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ public String getIdentifier() {
277277
return "script:" + path;
278278
}
279279

280+
// -- Locatable methods --
281+
282+
@Override
283+
public String getLocation() {
284+
return new File(path).toURI().normalize().toString();
285+
}
286+
280287
// -- Helper methods --
281288

282289
private void parseParam(final String param) throws ScriptException {

0 commit comments

Comments
 (0)