Skip to content

Commit

Permalink
fix: make sure we search only for JARs
Browse files Browse the repository at this point in the history
  • Loading branch information
quintesse committed Jul 12, 2024
1 parent b335a6d commit ac37101
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/main/java/org/codejive/jpm/util/SearchUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static SearchResult select(String query, int start, int count) throws IO
}
String searchUrl =
String.format(
"https://search.maven.org/solrsearch/select?start=%d&rows=%d&q=%s",
"https://search.maven.org/solrsearch/select?start=%d&rows=%d&q=p:jar+AND+%s",
start, count, URLEncoder.encode(finalQuery, "UTF-8"));
if (parts.length >= 3) {
searchUrl += "&core=gav";
Expand All @@ -90,23 +90,23 @@ private static SearchResult select(String query, int start, int count) throws IO
}
List<DefaultArtifact> artifacts =
result.response.docs.stream()
.filter(
d ->
parts.length != 2
|| d.g.contains(parts[0])
&& d.a.contains(parts[1]))
.map(
d ->
new DefaultArtifact(
d.g,
d.a,
"",
d.v != null ? d.v : d.latestVersion))
.filter(d -> acceptDoc(d, parts))
.map(SearchUtils::toArtifact)
.collect(Collectors.toList());
return new SearchResult(artifacts, query, start, count, result.response.numFound);
}
}
}

private static boolean acceptDoc(MsrDoc d, String[] parts) {
return d.ec != null
&& d.ec.contains(".jar")
&& (parts.length != 2 || d.g.contains(parts[0]) && d.a.contains(parts[1]));
}

private static DefaultArtifact toArtifact(MsrDoc d) {
return new DefaultArtifact(d.g, d.a, "", d.v != null ? d.v : d.latestVersion);
}
}

class MvnSearchResult {
Expand All @@ -129,4 +129,6 @@ class MsrDoc {
public String a;
public String v;
public String latestVersion;
public String p;
public List<String> ec;
}

0 comments on commit ac37101

Please sign in to comment.