Skip to content

Commit 20de332

Browse files
committed
ModuleSearcher: expose iconPath & location helpers
These will be useful for the OpSearcher of imagej-ops.
1 parent b6a1b9d commit 20de332

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>scijava-search</artifactId>
13-
<version>0.2.1-SNAPSHOT</version>
13+
<version>0.3.0-SNAPSHOT</version>
1414

1515
<name>SciJava Search</name>
1616
<description>Search framework for SciJava applications.</description>

src/main/java/org/scijava/search/module/ModuleSearchResult.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,10 @@
4646
public class ModuleSearchResult implements SearchResult {
4747

4848
private final ModuleInfo info;
49-
private final String baseDir;
5049
private final Map<String, String> props;
5150

5251
public ModuleSearchResult(final ModuleInfo info, final String baseDir) {
5352
this.info = info;
54-
this.baseDir = baseDir;
5553

5654
props = new LinkedHashMap<>();
5755
final MenuPath menuPath = info.getMenuPath();
@@ -66,7 +64,7 @@ public ModuleSearchResult(final ModuleInfo info, final String baseDir) {
6664
}
6765
}
6866
props.put("Identifier", info.getIdentifier());
69-
props.put("Location", getLocation());
67+
props.put("Location", ModuleSearcher.location(info, baseDir));
7068
}
7169

7270
public ModuleInfo info() {
@@ -86,12 +84,7 @@ public String identifier() {
8684

8785
@Override
8886
public String iconPath() {
89-
final String iconPath = info.getIconPath();
90-
if (iconPath != null) return iconPath;
91-
if (info.getMenuPath() != null && info.getMenuPath().getLeaf() != null) {
92-
return info.getMenuPath().getLeaf().getIconPath();
93-
}
94-
return null;
87+
return ModuleSearcher.iconPath(info);
9588
}
9689

9790
@Override
@@ -101,17 +94,6 @@ public Map<String, String> properties() {
10194

10295
// -- Helper methods --
10396

104-
private String getLocation() {
105-
String path = info.getLocation();
106-
if (path == null) return null;
107-
if (path.startsWith("file:/")) path = path.replaceFirst("file:/+", "/");
108-
if (baseDir != null && path.startsWith(baseDir)) {
109-
if (path.length() == baseDir.length()) return "";
110-
path = path.substring(baseDir.length() + 1);
111-
}
112-
return path;
113-
}
114-
11597
private String getMenuPath(boolean includeLeaf) {
11698
final MenuPath menuPath = info.getMenuPath();
11799
if (menuPath == null) return "";

src/main/java/org/scijava/search/module/ModuleSearcher.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,27 @@ public static String title(final ModuleInfo info) {
128128
return null;
129129
}
130130

131+
/** Gets the icon path associated with the given module. */
132+
public static String iconPath(final ModuleInfo info) {
133+
final String iconPath = info.getIconPath();
134+
if (iconPath != null) return iconPath;
135+
final MenuPath menuPath = info.getMenuPath();
136+
return menuPath == null || menuPath.getLeaf() == null ? //
137+
null : menuPath.getLeaf().getIconPath();
138+
}
139+
140+
/** Gets an abbreviated location for the given module. */
141+
public static String location(final ModuleInfo info, final String baseDir) {
142+
String path = info.getLocation();
143+
if (path == null) return null;
144+
if (path.startsWith("file:/")) path = path.replaceFirst("file:/+", "/");
145+
if (baseDir != null && path.startsWith(baseDir)) {
146+
if (path.length() == baseDir.length()) return "";
147+
path = path.substring(baseDir.length() + 1);
148+
}
149+
return path;
150+
}
151+
131152
// -- Helper methods --
132153

133154
private boolean isGoodModule(final ModuleInfo info) {

0 commit comments

Comments
 (0)