use of org.apache.archiva.indexer.ArchivaIndexingContext in project archiva by apache.
the class ArchivaIndexManagerMock method removeArtifactsFromIndex.
@Override
public void removeArtifactsFromIndex(ArchivaIndexingContext context, Collection<URI> artifactReference) throws IndexUpdateFailedException {
final URI ctxUri = context.getPath();
executeUpdateFunction(context, indexingContext -> {
Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
try {
indexer.deleteArtifactsFromIndex(artifacts, indexingContext);
} catch (IOException e) {
log.error("IOException while removing artifact {}", e.getMessage(), e);
throw new IndexUpdateFailedException("Error occured while removing artifact from index of " + context.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""));
}
});
}
use of org.apache.archiva.indexer.ArchivaIndexingContext in project archiva by apache.
the class ArchivaIndexManagerMock 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);
}
MavenIndexContextMock context = new MavenIndexContextMock(repository, mvnCtx);
return context;
}
use of org.apache.archiva.indexer.ArchivaIndexingContext in project archiva by apache.
the class ArchivaIndexManagerMock method reset.
@Override
public ArchivaIndexingContext reset(ArchivaIndexingContext context) throws IndexUpdateFailedException {
ArchivaIndexingContext ctx;
executeUpdateFunction(context, indexingContext -> {
try {
indexingContext.close(true);
} catch (IOException e) {
log.warn("Index close failed");
}
try {
FileUtils.deleteDirectory(Paths.get(context.getPath()));
} catch (IOException e) {
throw new IndexUpdateFailedException("Could not delete index files");
}
});
try {
Repository repo = context.getRepository();
ctx = createContext(context.getRepository());
if (repo instanceof EditableRepository) {
((EditableRepository) repo).setIndexingContext(ctx);
}
} catch (IndexCreationFailedException e) {
throw new IndexUpdateFailedException("Could not create index");
}
return ctx;
}
Aggregations