additional parsing of the data from Central was used to determine if the POM file is available in Central (part of the patch for issue #196)

Former-commit-id: 1805be75b101546b166c9eb4ad1efc30e53983cf
This commit is contained in:
Jeremy Long
2015-02-18 20:08:14 -05:00
parent d136aeda84
commit 40beec2e40

View File

@@ -60,8 +60,8 @@ public class CentralSearch {
/**
* Creates a NexusSearch for the given repository URL.
*
* @param rootURL the URL of the repository on which searches should execute. Only parameters are added to this (so
* it should end in /select)
* @param rootURL the URL of the repository on which searches should execute. Only parameters are added to this (so it should
* end in /select)
*/
public CentralSearch(URL rootURL) {
this.rootURL = rootURL;
@@ -75,13 +75,12 @@ public class CentralSearch {
}
/**
* Searches the configured Central URL for the given sha1 hash. If the artifact is found, a
* <code>MavenArtifact</code> is populated with the GAV.
* Searches the configured Central URL for the given sha1 hash. If the artifact is found, a <code>MavenArtifact</code> is
* populated with the GAV.
*
* @param sha1 the SHA-1 hash string for which to search
* @return the populated Maven GAV.
* @throws IOException if it's unable to connect to the specified repository or if the specified artifact is not
* found.
* @throws IOException if it's unable to connect to the specified repository or if the specified artifact is not found.
*/
public List<MavenArtifact> searchSha1(String sha1) throws IOException {
if (null == sha1 || !sha1.matches("^[0-9A-Fa-f]{40}$")) {
@@ -124,8 +123,19 @@ public class CentralSearch {
final String a = xpath.evaluate("./str[@name='a']", docs.item(i));
LOGGER.finest(String.format("ArtifactId: %s", a));
final String v = xpath.evaluate("./str[@name='v']", docs.item(i));
final NodeList atts = (NodeList) xpath.evaluate("./arr[@name='ec']/str", docs.item(i), XPathConstants.NODESET);
boolean pomAvailable = false;
boolean jarAvailable = false;
for (int x = 0; x < atts.getLength(); x++) {
final String tmp = xpath.evaluate(".", atts.item(x));
if (".pom".equals(tmp)) {
pomAvailable = true;
} else if (".jar".equals(tmp)) {
jarAvailable = true;
}
}
LOGGER.finest(String.format("Version: %s", v));
result.add(new MavenArtifact(g, a, v, url.toString()));
result.add(new MavenArtifact(g, a, v, jarAvailable, pomAvailable));
}
return result;