Search in sources :

Example 21 with ArchivaIndexingContext

use of org.apache.archiva.indexer.ArchivaIndexingContext in project archiva by apache.

the class MavenIndexManager method createContext.

@Override
public ArchivaIndexingContext createContext(Repository repository) throws IndexCreationFailedException {
    log.debug("Creating context for repo {}, type: {}", repository.getId(), repository.getType());
    if (repository.getType() != RepositoryType.MAVEN) {
        throw new UnsupportedRepositoryTypeException(repository.getType());
    }
    IndexingContext mvnCtx = null;
    try {
        if (repository instanceof RemoteRepository) {
            mvnCtx = createRemoteContext((RemoteRepository) repository);
        } else if (repository instanceof ManagedRepository) {
            mvnCtx = createManagedContext((ManagedRepository) repository);
        }
    } catch (IOException e) {
        log.error("IOException during context creation " + e.getMessage(), e);
        throw new IndexCreationFailedException("Could not create index context for repository " + repository.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""), e);
    }
    MavenIndexContext context = new MavenIndexContext(repository, mvnCtx);
    return context;
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) RemoteRepository(org.apache.archiva.repository.RemoteRepository) IOException(java.io.IOException) UnsupportedRepositoryTypeException(org.apache.archiva.repository.UnsupportedRepositoryTypeException)

Example 22 with ArchivaIndexingContext

use of org.apache.archiva.indexer.ArchivaIndexingContext in project archiva by apache.

the class MavenIndexManagerTest method createContext.

@Test
public void createContext() throws Exception {
    ArchivaIndexingContext ctx = createTestContext();
    assertNotNull(ctx);
    assertEquals(repository, ctx.getRepository());
    assertEquals("test-repo", ctx.getId());
    assertEquals(indexPath.toAbsolutePath(), Paths.get(ctx.getPath()).toAbsolutePath());
    assertTrue(Files.exists(indexPath));
    List<Path> li = Files.list(indexPath).collect(Collectors.toList());
    assertTrue(li.size() > 0);
}
Also used : Path(java.nio.file.Path) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) Test(org.junit.Test)

Example 23 with ArchivaIndexingContext

use of org.apache.archiva.indexer.ArchivaIndexingContext 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 24 with ArchivaIndexingContext

use of org.apache.archiva.indexer.ArchivaIndexingContext in project archiva by apache.

the class RepositoryRegistry method raise.

@Override
public <T> void raise(RepositoryEvent<T> event) {
    if (event instanceof IndexCreationEvent) {
        if (managedRepositories.containsKey(event.getRepository().getId()) || remoteRepositories.containsKey(event.getRepository().getId())) {
            EditableRepository repo = (EditableRepository) event.getRepository();
            if (repo != null && repo.getIndexingContext() != null) {
                try {
                    ArchivaIndexManager idxmgr = getIndexManager(repo.getType());
                    if (idxmgr != null) {
                        ArchivaIndexingContext newCtx = idxmgr.move(repo.getIndexingContext(), repo);
                        repo.setIndexingContext(newCtx);
                        idxmgr.updateLocalIndexPath(repo);
                    }
                } catch (IndexCreationFailedException e) {
                    log.error("Could not move index to new directory {}", e.getMessage(), e);
                }
            }
        }
    }
    for (RepositoryEventListener listener : listeners) {
        listener.raise(event);
    }
}
Also used : IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexCreationEvent(org.apache.archiva.repository.features.IndexCreationEvent) ArchivaIndexManager(org.apache.archiva.indexer.ArchivaIndexManager)

Example 25 with ArchivaIndexingContext

use of org.apache.archiva.indexer.ArchivaIndexingContext in project archiva by apache.

the class AbstractRepository method close.

@Override
public void close() {
    ArchivaIndexingContext ctx = getIndexingContext();
    if (ctx != null) {
        try {
            ctx.close();
        } catch (IOException e) {
            log.warn("Error during index context close.", e);
        }
    }
    if (supportsFeature(StagingRepositoryFeature.class)) {
        StagingRepositoryFeature sf = getFeature(StagingRepositoryFeature.class).get();
        if (sf.getStagingRepository() != null) {
            sf.getStagingRepository().close();
        }
    }
    clearListeners();
}
Also used : IOException(java.io.IOException) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext)

Aggregations

ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)28 IndexingContext (org.apache.maven.index.context.IndexingContext)21 IOException (java.io.IOException)20 Path (java.nio.file.Path)19 IndexCreationFailedException (org.apache.archiva.indexer.IndexCreationFailedException)19 UnsupportedBaseContextException (org.apache.archiva.indexer.UnsupportedBaseContextException)16 ManagedRepository (org.apache.archiva.repository.ManagedRepository)16 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)15 RemoteRepository (org.apache.archiva.repository.RemoteRepository)15 EditableRepository (org.apache.archiva.repository.EditableRepository)12 Repository (org.apache.archiva.repository.Repository)12 UnsupportedRepositoryTypeException (org.apache.archiva.repository.UnsupportedRepositoryTypeException)12 URI (java.net.URI)11 Inject (javax.inject.Inject)10 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)10 ArtifactContext (org.apache.maven.index.ArtifactContext)10 FileNotFoundException (java.io.FileNotFoundException)9 InputStream (java.io.InputStream)9 MalformedURLException (java.net.MalformedURLException)9 Files (java.nio.file.Files)9