Search in sources :

Example 11 with MavenArtifactInfo

use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.

the class Maven2ServerIndexerImpl method search.

public Set<MavenArtifactInfo> search(int indexId, Query query, int maxResult) throws MavenServerIndexerException {
    try {
        IndexingContext index = getIndex(indexId);
        TopDocs docs = null;
        try {
            BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
            docs = index.getIndexSearcher().search(query, null, maxResult);
        } catch (BooleanQuery.TooManyClauses ignore) {
        // this exception occurs when too wide wildcard is used on too big data.
        }
        if (docs == null || docs.scoreDocs.length == 0)
            return Collections.emptySet();
        Set<MavenArtifactInfo> result = new THashSet<MavenArtifactInfo>();
        for (int i = 0; i < docs.scoreDocs.length; i++) {
            int docIndex = docs.scoreDocs[i].doc;
            Document doc = index.getIndexReader().document(docIndex);
            ArtifactInfo a = IndexUtils.constructArtifactInfo(doc, index);
            if (a == null)
                continue;
            a.repository = getRepositoryPathOrUrl(index);
            result.add(Maven2ModelConverter.convertArtifactInfo(a));
        }
        return result;
    } catch (Exception e) {
        throw new MavenServerIndexerException(wrapException(e));
    }
}
Also used : TopDocs(org.apache.lucene.search.TopDocs) BooleanQuery(org.apache.lucene.search.BooleanQuery) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo) IndexingContext(org.sonatype.nexus.index.context.IndexingContext) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo) Document(org.apache.lucene.document.Document) THashSet(gnu.trove.THashSet) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ArchetypeDataSourceException(org.apache.maven.archetype.source.ArchetypeDataSourceException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException)

Example 12 with MavenArtifactInfo

use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.

the class Maven3ServerIndexerImpl method search.

@Override
public Set<MavenArtifactInfo> search(int indexId, Query query, int maxResult) throws RemoteException, MavenServerIndexerException {
    try {
        IndexingContext index = getIndex(indexId);
        TopDocs docs = null;
        try {
            BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
            docs = index.getIndexSearcher().search(query, null, maxResult);
        } catch (BooleanQuery.TooManyClauses ignore) {
        // this exception occurs when too wide wildcard is used on too big data.
        }
        if (docs == null || docs.scoreDocs.length == 0)
            return Collections.emptySet();
        Set<MavenArtifactInfo> result = new THashSet<MavenArtifactInfo>();
        for (int i = 0; i < docs.scoreDocs.length; i++) {
            int docIndex = docs.scoreDocs[i].doc;
            Document doc = index.getIndexReader().document(docIndex);
            ArtifactInfo a = IndexUtils.constructArtifactInfo(doc, index);
            if (a == null)
                continue;
            a.repository = getRepositoryPathOrUrl(index);
            result.add(MavenModelConverter.convertArtifactInfo(a));
        }
        return result;
    } catch (Exception e) {
        throw new MavenServerIndexerException(wrapException(e));
    }
}
Also used : TopDocs(org.apache.lucene.search.TopDocs) BooleanQuery(org.apache.lucene.search.BooleanQuery) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo) IndexingContext(org.sonatype.nexus.index.context.IndexingContext) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo) Document(org.apache.lucene.document.Document) THashSet(gnu.trove.THashSet) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ArchetypeDataSourceException(org.apache.maven.archetype.source.ArchetypeDataSourceException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException)

Example 13 with MavenArtifactInfo

use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.

the class ArtifactoryRepositoryService method findArtifacts.

@NotNull
@Override
public List<MavenArtifactInfo> findArtifacts(@NotNull String url, @NotNull MavenArtifactInfo template) throws IOException {
    try {
        final String packaging = StringUtil.notNullize(template.getPackaging());
        final ArrayList<MavenArtifactInfo> artifacts = new ArrayList<>();
        final Gson gson = new Gson();
        final String className = template.getClassNames();
        if (className == null || className.length() == 0) {
            final String name = StringUtil.join(Arrays.asList(template.getGroupId(), template.getArtifactId(), template.getVersion()), ":");
            final InputStream stream = new Endpoint.Search.Artifact(url).getArtifactSearchResultJson(name, null).getInputStream();
            final ArtifactoryModel.GavcResults results = stream == null ? null : gson.fromJson(new InputStreamReader(stream), ArtifactoryModel.GavcResults.class);
            if (results != null && results.results != null) {
                for (ArtifactoryModel.GavcResult result : results.results) {
                    if (!result.uri.endsWith(packaging))
                        continue;
                    artifacts.add(convertArtifactInfo(result.uri, url, null));
                }
            }
        } else {
            // IDEA-58225
            final String searchString = className.endsWith("*") || className.endsWith("?") ? className : className + ".class";
            final InputStream stream = new Endpoint.Search.Archive(url).getArchiveSearchResultJson(searchString, null).getInputStream();
            final ArtifactoryModel.ArchiveResults results = stream == null ? null : gson.fromJson(new InputStreamReader(stream), ArtifactoryModel.ArchiveResults.class);
            if (results != null && results.results != null) {
                for (ArtifactoryModel.ArchiveResult result : results.results) {
                    for (String uri : result.archiveUris) {
                        if (!uri.endsWith(packaging))
                            continue;
                        artifacts.add(convertArtifactInfo(uri, url, result.entry));
                    }
                }
            }
        }
        return artifacts;
    } catch (JsonSyntaxException e) {
        return Collections.emptyList();
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo) Gson(com.google.gson.Gson) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with MavenArtifactInfo

use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.

the class NexusRepositoryService method findArtifacts.

@NotNull
@Override
public List<MavenArtifactInfo> findArtifacts(@NotNull String url, @NotNull MavenArtifactInfo template) throws IOException {
    try {
        final String packaging = StringUtil.notNullize(template.getPackaging());
        final String name = StringUtil.join(Arrays.asList(template.getGroupId(), template.getArtifactId(), template.getVersion()), ":");
        final SearchResults results = new Endpoint.DataIndex(url).getArtifactlistAsSearchResults(name, template.getGroupId(), template.getArtifactId(), template.getVersion(), null, template.getClassNames());
        boolean tooManyResults = results.isTooManyResults();
        final SearchResults.Data data = results.getData();
        final ArrayList<MavenArtifactInfo> result = new ArrayList<>();
        if (data != null) {
            for (ArtifactType each : data.getArtifact()) {
                if (!Comparing.equal(each.packaging, packaging))
                    continue;
                result.add(convertArtifactInfo(each));
            }
        }
        if (tooManyResults)
            result.add(null);
        return result;
    } catch (UnmarshalException e) {
        return Collections.emptyList();
    } catch (JAXBException e) {
        throw new IOException(e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo) IOException(java.io.IOException) UnmarshalException(javax.xml.bind.UnmarshalException) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with MavenArtifactInfo

use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.

the class RepositoryAttachDialog method getRepositories.

@NotNull
public List<MavenRepositoryInfo> getRepositories() {
    final Pair<MavenArtifactInfo, MavenRepositoryInfo> artifactAndRepo = myCoordinates.get(getCoordinateText());
    final MavenRepositoryInfo repository = artifactAndRepo == null ? null : artifactAndRepo.second;
    return repository != null ? Collections.singletonList(repository) : ContainerUtil.findAll(myRepositories.values(), Condition.NOT_NULL);
}
Also used : MavenRepositoryInfo(org.jetbrains.idea.maven.model.MavenRepositoryInfo) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo) NotNull(org.jetbrains.annotations.NotNull)

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