Search in sources :

Example 31 with IndexingContext

use of org.apache.maven.index.context.IndexingContext in project archiva by apache.

the class MergedRemoteIndexesTask method execute.

public MergedRemoteIndexesTaskResult execute() throws IndexMergerException {
    IndexMerger indexMerger = mergedRemoteIndexesTaskRequest.getIndexMerger();
    IndexingContext indexingContext = indexMerger.buildMergedIndex(mergedRemoteIndexesTaskRequest.getIndexMergerRequest());
    return new MergedRemoteIndexesTaskResult(indexingContext);
}
Also used : IndexingContext(org.apache.maven.index.context.IndexingContext)

Example 32 with IndexingContext

use of org.apache.maven.index.context.IndexingContext in project archiva by apache.

the class DefaultIndexMerger method cleanTemporaryGroupIndex.

@Async
@Override
public void cleanTemporaryGroupIndex(TemporaryGroupIndex temporaryGroupIndex) {
    if (temporaryGroupIndex == null) {
        return;
    }
    try {
        Optional<IndexingContext> ctxOpt = temporaryContextes.stream().filter(ctx -> ctx.getId().equals(temporaryGroupIndex.getIndexId())).findFirst();
        if (ctxOpt.isPresent()) {
            IndexingContext ctx = ctxOpt.get();
            indexer.closeIndexingContext(ctx, true);
            temporaryGroupIndexes.remove(temporaryGroupIndex);
            temporaryContextes.remove(ctx);
            Path directory = temporaryGroupIndex.getDirectory();
            if (directory != null && Files.exists(directory)) {
                FileUtils.deleteDirectory(directory);
            }
        }
    } catch (IOException e) {
        log.warn("fail to delete temporary group index {}", temporaryGroupIndex.getIndexId(), e);
    }
}
Also used : Async(org.springframework.scheduling.annotation.Async) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) StaticContextMemberProvider(org.apache.maven.index.context.StaticContextMemberProvider) LoggerFactory(org.slf4j.LoggerFactory) IndexCreator(org.apache.maven.index.context.IndexCreator) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) FileUtils(org.apache.archiva.common.utils.FileUtils) IndexPackingRequest(org.apache.maven.index.packer.IndexPackingRequest) Path(java.nio.file.Path) Logger(org.slf4j.Logger) IndexPacker(org.apache.maven.index.packer.IndexPacker) Files(java.nio.file.Files) ContextMemberProvider(org.apache.maven.index.context.ContextMemberProvider) Collection(java.util.Collection) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) IOException(java.io.IOException) TemporaryGroupIndex(org.apache.archiva.indexer.merger.TemporaryGroupIndex) RepositoryType(org.apache.archiva.repository.RepositoryType) Collectors(java.util.stream.Collectors) IndexMerger(org.apache.archiva.indexer.merger.IndexMerger) IndexMergerException(org.apache.archiva.indexer.merger.IndexMergerException) Indexer(org.apache.maven.index.Indexer) Objects(java.util.Objects) List(java.util.List) IndexingContext(org.apache.maven.index.context.IndexingContext) IndexMergerRequest(org.apache.archiva.indexer.merger.IndexMergerRequest) StopWatch(org.apache.commons.lang.time.StopWatch) Optional(java.util.Optional) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Path(java.nio.file.Path) IndexingContext(org.apache.maven.index.context.IndexingContext) IOException(java.io.IOException) Async(org.springframework.scheduling.annotation.Async)

Example 33 with IndexingContext

use of org.apache.maven.index.context.IndexingContext in project archiva by apache.

the class ArchivaIndexManagerMock method executeUpdateFunction.

/*
     * This method is used to do some actions around the update execution code. And to make sure, that no other
     * method is running on the same index.
     */
private void executeUpdateFunction(ArchivaIndexingContext context, IndexUpdateConsumer function) throws IndexUpdateFailedException {
    IndexingContext indexingContext = null;
    try {
        indexingContext = getMvnContext(context);
    } catch (UnsupportedBaseContextException e) {
        throw new IndexUpdateFailedException("Maven index is not supported by this context", e);
    }
    final Path ctxPath = getIndexPath(context);
    int loop = MAX_WAIT;
    boolean active = false;
    while (loop-- > 0 && !active) {
        active = activeContexts.add(ctxPath);
        try {
            Thread.currentThread().sleep(WAIT_TIME);
        } catch (InterruptedException e) {
        // Ignore this
        }
    }
    if (active) {
        try {
            function.accept(indexingContext);
        } finally {
            activeContexts.remove(ctxPath);
        }
    } else {
        throw new IndexUpdateFailedException("Timeout while waiting for index release on context " + context.getId());
    }
}
Also used : Path(java.nio.file.Path) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException)

Example 34 with IndexingContext

use of org.apache.maven.index.context.IndexingContext in project archiva by apache.

the class ArchivaIndexingTaskExecutorTest method testUpdateArtifactInIndex.

@Test
public void testUpdateArtifactInIndex() throws Exception {
    Path basePath = repo.getLocalPath();
    Path artifactFile = basePath.resolve("org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar");
    ArtifactIndexingTask task = new ArtifactIndexingTask(repo, artifactFile, ArtifactIndexingTask.Action.ADD, repo.getIndexingContext());
    indexingExecutor.executeTask(task);
    indexingExecutor.executeTask(task);
    BooleanQuery.Builder qb = new BooleanQuery.Builder();
    qb.add(indexer.constructQuery(MAVEN.GROUP_ID, new StringSearchExpression("org.apache.archiva")), BooleanClause.Occur.SHOULD);
    qb.add(indexer.constructQuery(MAVEN.ARTIFACT_ID, new StringSearchExpression("archiva-index-methods-jar-test")), BooleanClause.Occur.SHOULD);
    IndexingContext ctx = getIndexingContext();
    IndexSearcher searcher = ctx.acquireIndexSearcher();
    TopDocs topDocs = searcher.search(qb.build(), 10);
    // searcher.close();
    ctx.releaseIndexSearcher(searcher);
    assertTrue(Files.exists(basePath.resolve(".indexer")));
    assertTrue(Files.exists(basePath.resolve(".index")));
    // should only return 1 hit!
    assertEquals(1, topDocs.totalHits);
}
Also used : Path(java.nio.file.Path) IndexSearcher(org.apache.maven.index_shaded.lucene.search.IndexSearcher) TopDocs(org.apache.maven.index_shaded.lucene.search.TopDocs) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) StringSearchExpression(org.apache.maven.index.expr.StringSearchExpression) Test(org.junit.Test)

Example 35 with IndexingContext

use of org.apache.maven.index.context.IndexingContext in project archiva by apache.

the class ArchivaIndexingTaskExecutorTest method testRemoveArtifactFromIndex.

@Test
public void testRemoveArtifactFromIndex() throws Exception {
    Path basePath = repo.getLocalPath();
    Path artifactFile = basePath.resolve("org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar");
    ArtifactIndexingTask task = new ArtifactIndexingTask(repo, artifactFile, ArtifactIndexingTask.Action.ADD, repo.getIndexingContext());
    // add artifact to index
    indexingExecutor.executeTask(task);
    BooleanQuery.Builder qb = new BooleanQuery.Builder();
    qb.add(indexer.constructQuery(MAVEN.GROUP_ID, new SourcedSearchExpression("org.apache.archiva")), BooleanClause.Occur.SHOULD);
    // q.add(
    // indexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression( "archiva-index-methods-jar-test" ) ),
    // Occur.SHOULD );
    IndexingContext ctx = repo.getIndexingContext().getBaseContext(IndexingContext.class);
    FlatSearchRequest flatSearchRequest = new FlatSearchRequest(qb.build(), ctx);
    FlatSearchResponse response = indexer.searchFlat(flatSearchRequest);
    assertTrue(Files.exists(basePath.resolve(".indexer")));
    assertTrue(Files.exists(basePath.resolve(".index")));
    // should return 1 hit
    assertEquals(1, response.getTotalHitsCount());
    // remove added artifact from index
    task = new ArtifactIndexingTask(repo, artifactFile, ArtifactIndexingTask.Action.DELETE, repo.getIndexingContext());
    indexingExecutor.executeTask(task);
    task = new ArtifactIndexingTask(repo, artifactFile, ArtifactIndexingTask.Action.FINISH, repo.getIndexingContext());
    indexingExecutor.executeTask(task);
    qb = new BooleanQuery.Builder();
    qb.add(indexer.constructQuery(MAVEN.GROUP_ID, new SourcedSearchExpression("org.apache.archiva")), BooleanClause.Occur.SHOULD);
    qb.add(indexer.constructQuery(MAVEN.ARTIFACT_ID, new SourcedSearchExpression("archiva-index-methods-jar-test")), BooleanClause.Occur.SHOULD);
    assertTrue(Files.exists(basePath.resolve(".indexer")));
    assertTrue(Files.exists(basePath.resolve(".index")));
    flatSearchRequest = new FlatSearchRequest(qb.build(), getIndexingContext());
    response = indexer.searchFlat(flatSearchRequest);
    // artifact should have been removed from the index!
    // .totalHits );
    assertEquals(0, response.getTotalHitsCount());
// TODO: test it was removed from the packaged index also
}
Also used : Path(java.nio.file.Path) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) SourcedSearchExpression(org.apache.maven.index.expr.SourcedSearchExpression) FlatSearchResponse(org.apache.maven.index.FlatSearchResponse) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) FlatSearchRequest(org.apache.maven.index.FlatSearchRequest) Test(org.junit.Test)

Aggregations

IndexingContext (org.apache.maven.index.context.IndexingContext)38 Path (java.nio.file.Path)30 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)27 IOException (java.io.IOException)24 UnsupportedBaseContextException (org.apache.archiva.indexer.UnsupportedBaseContextException)21 IndexCreationFailedException (org.apache.archiva.indexer.IndexCreationFailedException)15 RemoteRepository (org.apache.archiva.repository.RemoteRepository)15 ManagedRepository (org.apache.archiva.repository.ManagedRepository)14 Inject (javax.inject.Inject)12 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)12 UnsupportedRepositoryTypeException (org.apache.archiva.repository.UnsupportedRepositoryTypeException)12 Indexer (org.apache.maven.index.Indexer)12 IndexPacker (org.apache.maven.index.packer.IndexPacker)12 IndexPackingRequest (org.apache.maven.index.packer.IndexPackingRequest)12 IndexFormatTooOldException (org.apache.maven.index_shaded.lucene.index.IndexFormatTooOldException)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 Service (org.springframework.stereotype.Service)12 URI (java.net.URI)11 Files (java.nio.file.Files)11