Search in sources :

Example 1 with MavenArtifactInfo

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;
}
Also used : MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with MavenArtifactInfo

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();
}
Also used : THashMap(gnu.trove.THashMap) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo)

Example 3 with MavenArtifactInfo

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);
}
Also used : ArrayList(java.util.ArrayList) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo)

Example 4 with MavenArtifactInfo

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;
}
Also used : ArrayList(java.util.ArrayList) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo)

Example 5 with MavenArtifactInfo

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);
}
Also used : ArrayList(java.util.ArrayList) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo)

Aggregations

MavenArtifactInfo (org.jetbrains.idea.maven.model.MavenArtifactInfo)15 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)5 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 THashMap (gnu.trove.THashMap)2 THashSet (gnu.trove.THashSet)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 RemoteException (java.rmi.RemoteException)2 Document (org.apache.lucene.document.Document)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 TopDocs (org.apache.lucene.search.TopDocs)2 ArchetypeDataSourceException (org.apache.maven.archetype.source.ArchetypeDataSourceException)2 IndexingContext (org.sonatype.nexus.index.context.IndexingContext)2 Gson (com.google.gson.Gson)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 File (java.io.File)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Matcher (java.util.regex.Matcher)1