2929
3030package org .scijava .search ;
3131
32- import java .io .File ;
33- import java .io .IOException ;
3432import java .net .MalformedURLException ;
3533import java .net .URL ;
3634
37- import javax .xml .parsers .ParserConfigurationException ;
38-
3935import org .scijava .log .Logger ;
40- import org .scijava .util .AppUtils ;
41- import org .scijava .util .FileUtils ;
4236import org .scijava .util .Manifest ;
4337import org .scijava .util .POM ;
44- import org .scijava .util .Types ;
45- import org .xml .sax .SAXException ;
4638
4739/**
4840 * Static utility class for finding source URL of a given class.
@@ -63,7 +55,7 @@ public static URL sourceLocation(final Class<?> c, final Logger log)
6355 throws SourceNotFoundException
6456 {
6557 try {
66- final POM pom = getPOM (c , null , null );
58+ final POM pom = POM . getPOM (c );
6759 if (pom == null ) {
6860 log .debug ("No Maven POM found for class: " + c .getName ());
6961 throw new SourceNotFoundException (c , null );
@@ -124,51 +116,4 @@ private static String coord(final POM pom) {
124116 return g + ":" + a + ":" + v ;
125117 }
126118
127- // TODO: Use org.scijava.util.POM.getPOM from scijava-common 2.77.0.
128-
129- /**
130- * Gets the Maven POM associated with the given class.
131- *
132- * @param c The class to use as a base when searching for a pom.xml.
133- * @param groupId The Maven groupId of the desired POM.
134- * @param artifactId The Maven artifactId of the desired POM.
135- */
136- private static POM getPOM (final Class <?> c , final String groupId ,
137- final String artifactId )
138- {
139- try {
140- final URL location = Types .location (c );
141- if (!location .getProtocol ().equals ("file" ) ||
142- location .toString ().endsWith (".jar" ))
143- {
144- // look for pom.xml in JAR's META-INF/maven subdirectory
145- if (groupId == null || artifactId == null ) {
146- // groupId and/or artifactId is unknown; scan for the POM
147- final URL pomBase = new URL ("jar:" + //
148- location .toString () + "!/META-INF/maven" );
149- for (final URL url : FileUtils .listContents (pomBase , true , true )) {
150- if (url .toExternalForm ().endsWith ("/pom.xml" )) {
151- return new POM (url );
152- }
153- }
154- }
155- else {
156- // known groupId and artifactId; grab it directly
157- final String pomPath =
158- "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml" ;
159- final URL pomURL =
160- new URL ("jar:" + location .toString () + "!/" + pomPath );
161- return new POM (pomURL );
162- }
163- }
164- // look for the POM in the class's base directory
165- final File file = FileUtils .urlToFile (location );
166- final File baseDir = AppUtils .getBaseDirectory (file , null );
167- final File pomFile = new File (baseDir , "pom.xml" );
168- return new POM (pomFile );
169- }
170- catch (final IOException | ParserConfigurationException | SAXException e ) {
171- return null ;
172- }
173- }
174119}
0 commit comments