Skip to content

Commit d5861f8

Browse files
committed
Make POM.getPOM work when G/A is unknown
We can scan for hits beneath META-INF/maven.
1 parent 2b0c5bf commit d5861f8

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,24 @@ public static POM getPOM(final Class<?> c, final String groupId,
232232
location.toString().endsWith(".jar"))
233233
{
234234
// look for pom.xml in JAR's META-INF/maven subdirectory
235-
final String pomPath =
236-
"META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml";
237-
final URL pomURL =
238-
new URL("jar:" + location.toString() + "!/" + pomPath);
239-
return new POM(pomURL);
235+
if (groupId == null || artifactId == null) {
236+
// groupId and/or artifactId is unknown; scan for the POM
237+
final URL pomBase = new URL("jar:" + //
238+
location.toString() + "!/META-INF/maven");
239+
for (final URL url : FileUtils.listContents(pomBase, true, true)) {
240+
if (url.toExternalForm().endsWith("/pom.xml")) {
241+
return new POM(url);
242+
}
243+
}
244+
}
245+
else {
246+
// known groupId and artifactId; grab it directly
247+
final String pomPath =
248+
"META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml";
249+
final URL pomURL =
250+
new URL("jar:" + location.toString() + "!/" + pomPath);
251+
return new POM(pomURL);
252+
}
240253
}
241254
// look for the POM in the class's base directory
242255
final File file = FileUtils.urlToFile(location);

0 commit comments

Comments
 (0)