Search in sources :

Example 6 with IndexingContext

use of org.sonatype.nexus.index.context.IndexingContext in project intellij-community by JetBrains.

the class Maven2ServerIndexerImpl method updateIndex.

public void updateIndex(int id, MavenServerSettings settings, MavenServerProgressIndicator indicator) throws MavenServerIndexerException, MavenServerProcessCanceledException, RemoteException {
    IndexingContext index = getIndex(id);
    try {
        if (isLocal(index)) {
            File repository = index.getRepository();
            if (repository != null && repository.exists()) {
                indicator.setIndeterminate(true);
                try {
                    myIndexer.scan(index, new MyScanningListener(indicator), false);
                } finally {
                    indicator.setIndeterminate(false);
                }
            }
        } else {
            IndexUpdateRequest request = new IndexUpdateRequest(index);
            Maven2ServerEmbedderImpl embedder = Maven2ServerEmbedderImpl.create(settings);
            try {
                request.setResourceFetcher(new Maven2ServerIndexFetcher(index.getRepositoryId(), index.getRepositoryUrl(), embedder.getComponent(WagonManager.class), new TransferListenerAdapter(indicator) {

                    @Override
                    protected void downloadProgress(long downloaded, long total) {
                        super.downloadProgress(downloaded, total);
                        try {
                            myIndicator.setFraction(((double) downloaded) / total);
                        } catch (RemoteException e) {
                            throw new RuntimeRemoteException(e);
                        }
                    }

                    @Override
                    public void transferCompleted(TransferEvent event) {
                        super.transferCompleted(event);
                        try {
                            myIndicator.setText2("Processing indices...");
                        } catch (RemoteException e) {
                            throw new RuntimeRemoteException(e);
                        }
                    }
                }));
                myUpdater.fetchAndUpdateIndex(request);
            } finally {
                embedder.release();
            }
        }
    } catch (RuntimeRemoteException e) {
        throw e.getCause();
    } catch (ProcessCanceledException e) {
        throw new MavenServerProcessCanceledException();
    } catch (Exception e) {
        throw new MavenServerIndexerException(wrapException(e));
    }
}
Also used : IndexUpdateRequest(org.sonatype.nexus.index.updater.IndexUpdateRequest) TransferEvent(org.apache.maven.wagon.events.TransferEvent) 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) IndexingContext(org.sonatype.nexus.index.context.IndexingContext) RemoteException(java.rmi.RemoteException) File(java.io.File) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 7 with IndexingContext

use of org.sonatype.nexus.index.context.IndexingContext 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 8 with IndexingContext

use of org.sonatype.nexus.index.context.IndexingContext 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 9 with IndexingContext

use of org.sonatype.nexus.index.context.IndexingContext in project intellij-community by JetBrains.

the class Maven3ServerIndexerImpl method updateIndex.

@Override
public void updateIndex(int id, MavenServerSettings settings, final MavenServerProgressIndicator indicator) throws RemoteException, MavenServerIndexerException, MavenServerProcessCanceledException {
    final IndexingContext index = getIndex(id);
    try {
        File repository = index.getRepository();
        if (repository != null) {
            // is local repository
            if (repository.exists()) {
                indicator.setIndeterminate(true);
                try {
                    myIndexer.scan(index, new MyScanningListener(indicator), false);
                } finally {
                    indicator.setIndeterminate(false);
                }
            }
        } else {
            final Maven3ServerEmbedder embedder = createEmbedder(settings);
            MavenExecutionRequest r = embedder.createRequest(null, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
            final IndexUpdateRequest request = new IndexUpdateRequest(index);
            try {
                embedder.executeWithMavenSession(r, new Runnable() {

                    @Override
                    public void run() {
                        request.setResourceFetcher(new Maven3ServerIndexFetcher(index.getRepositoryId(), index.getRepositoryUrl(), embedder.getComponent(WagonManager.class), embedder.getComponent(RepositorySystem.class), new WagonTransferListenerAdapter(indicator) {

                            @Override
                            protected void downloadProgress(long downloaded, long total) {
                                super.downloadProgress(downloaded, total);
                                try {
                                    myIndicator.setFraction(((double) downloaded) / total);
                                } catch (RemoteException e) {
                                    throw new RuntimeRemoteException(e);
                                }
                            }

                            @Override
                            public void transferCompleted(TransferEvent event) {
                                super.transferCompleted(event);
                                try {
                                    myIndicator.setText2("Processing indices...");
                                } catch (RemoteException e) {
                                    throw new RuntimeRemoteException(e);
                                }
                            }
                        }));
                        try {
                            myUpdater.fetchAndUpdateIndex(request);
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    }
                });
            } finally {
                embedder.release();
            }
        }
    } catch (RuntimeRemoteException e) {
        throw e.getCause();
    } catch (ProcessCanceledException e) {
        throw new MavenServerProcessCanceledException();
    } catch (Exception e) {
        throw new MavenServerIndexerException(wrapException(e));
    }
}
Also used : MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) IndexUpdateRequest(org.sonatype.nexus.index.updater.IndexUpdateRequest) TransferEvent(org.apache.maven.wagon.events.TransferEvent) IOException(java.io.IOException) 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) RepositorySystem(org.apache.maven.repository.RepositorySystem) WagonManager(org.apache.maven.artifact.manager.WagonManager) IndexingContext(org.sonatype.nexus.index.context.IndexingContext) RemoteException(java.rmi.RemoteException) File(java.io.File) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 10 with IndexingContext

use of org.sonatype.nexus.index.context.IndexingContext in project intellij-community by JetBrains.

the class Maven3ServerIndexerImpl method createIndex.

@Override
public int createIndex(@NotNull String indexId, @NotNull String repositoryId, @Nullable File file, @Nullable String url, @NotNull File indexDir) throws RemoteException, MavenServerIndexerException {
    try {
        IndexingContext context = myIndexer.addIndexingContextForced(indexId, repositoryId, file, indexDir, url, // repo update url
        null, Arrays.asList(new MinimalArtifactInfoIndexCreator(), new JarFileContentsIndexCreator()));
        int id = System.identityHashCode(context);
        myIndices.put(id, context);
        return id;
    } catch (Exception e) {
        throw new MavenServerIndexerException(wrapException(e));
    }
}
Also used : IndexingContext(org.sonatype.nexus.index.context.IndexingContext) MinimalArtifactInfoIndexCreator(org.sonatype.nexus.index.creator.MinimalArtifactInfoIndexCreator) JarFileContentsIndexCreator(org.sonatype.nexus.index.creator.JarFileContentsIndexCreator) 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)

Aggregations

IndexingContext (org.sonatype.nexus.index.context.IndexingContext)14 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)8 IOException (java.io.IOException)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 RemoteException (java.rmi.RemoteException)8 ArchetypeDataSourceException (org.apache.maven.archetype.source.ArchetypeDataSourceException)8 File (java.io.File)5 Document (org.apache.lucene.document.Document)4 IndexUpdateRequest (org.sonatype.nexus.index.updater.IndexUpdateRequest)3 THashSet (gnu.trove.THashSet)2 IndexReader (org.apache.lucene.index.IndexReader)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 TopDocs (org.apache.lucene.search.TopDocs)2 TransferEvent (org.apache.maven.wagon.events.TransferEvent)2 MavenArtifactInfo (org.jetbrains.idea.maven.model.MavenArtifactInfo)2 MavenId (org.jetbrains.idea.maven.model.MavenId)2 org.sonatype.nexus.index (org.sonatype.nexus.index)2 ArrayList (java.util.ArrayList)1 Term (org.apache.lucene.index.Term)1 WagonManager (org.apache.maven.artifact.manager.WagonManager)1