use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class MavenArtifactSearcher method getResultsFromIdeaCache.
@NotNull
private static List<MavenArtifactSearchResult> getResultsFromIdeaCache(Project project, String pattern, int maxResult) {
List<String> parts = new ArrayList<>();
for (String each : StringUtil.tokenize(pattern, " :")) {
parts.add(each);
}
List<MavenArtifactSearchResult> searchResults = ContainerUtil.newSmartList();
MavenProjectIndicesManager m = MavenProjectIndicesManager.getInstance(project);
int count = 0;
for (String groupId : m.getGroupIds()) {
if (count >= maxResult)
break;
if (parts.size() < 1 || StringUtil.contains(groupId, parts.get(0))) {
for (String artifactId : m.getArtifactIds(groupId)) {
if (parts.size() < 2 || StringUtil.contains(artifactId, parts.get(1))) {
List<MavenArtifactInfo> versions = ContainerUtil.newSmartList();
for (String version : m.getVersions(groupId, artifactId)) {
if (parts.size() < 3 || StringUtil.contains(version, parts.get(2))) {
versions.add(new MavenArtifactInfo(groupId, artifactId, version, "jar", null));
if (++count >= maxResult)
break;
}
}
if (!versions.isEmpty()) {
MavenArtifactSearchResult searchResult = new MavenArtifactSearchResult();
searchResult.versions.addAll(versions);
searchResults.add(searchResult);
}
}
if (count >= maxResult)
break;
}
}
}
return searchResults;
}
use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class MavenArtifactSearcher method processResults.
protected Collection<MavenArtifactSearchResult> processResults(Set<MavenArtifactInfo> infos, String pattern, int maxResult) {
Map<String, MavenArtifactSearchResult> result = new THashMap<>();
for (MavenArtifactInfo each : infos) {
if (!StringUtil.isEmptyOrSpaces(each.getClassifier())) {
// todo skip for now
continue;
}
String key = makeKey(each);
MavenArtifactSearchResult searchResult = result.get(key);
if (searchResult == null) {
searchResult = new MavenArtifactSearchResult();
result.put(key, searchResult);
}
searchResult.versions.add(each);
}
return result.values();
}
use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class MavenIndicesTest method assertSearchResults.
private static void assertSearchResults(MavenIndex i, Query query, String... expectedArtifacts) {
List<String> actualArtifacts = new ArrayList<>();
for (MavenArtifactInfo each : i.search(query, 100)) {
actualArtifacts.add(each.getGroupId() + ":" + each.getArtifactId() + ":" + each.getVersion());
}
assertUnorderedElementsAreEqual(actualArtifacts, expectedArtifacts);
}
use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class MavenSearcherTest method getClassSearchResults.
private List<String> getClassSearchResults(String pattern) {
List<String> actualArtifacts = new ArrayList<>();
for (MavenClassSearchResult eachResult : new MavenClassSearcher().search(myProject, pattern, 100)) {
StringBuilder s = new StringBuilder(eachResult.className + "(" + eachResult.packageName + ")");
for (MavenArtifactInfo eachVersion : eachResult.versions) {
if (s.length() > 0)
s.append(" ");
s.append(eachVersion.getGroupId()).append(":").append(eachVersion.getArtifactId()).append(":").append(eachVersion.getVersion());
}
actualArtifacts.add(s.toString());
}
return actualArtifacts;
}
use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class MavenSearcherTest method assertArtifactSearchResults.
private void assertArtifactSearchResults(String pattern, String... expected) {
List<String> actual = new ArrayList<>();
for (MavenArtifactSearchResult eachResult : new MavenArtifactSearcher(true).search(myProject, pattern, 100)) {
StringBuilder s = new StringBuilder();
for (MavenArtifactInfo eachVersion : eachResult.versions) {
if (s.length() > 0)
s.append(" ");
s.append(eachVersion.getGroupId()).append(":").append(eachVersion.getArtifactId()).append(":").append(eachVersion.getVersion());
}
actual.add(s.toString());
}
assertOrderedElementsAreEqual(actual, expected);
}
Aggregations