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;
}
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);
}
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());
}
}
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);
}
}
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();
}
Aggregations