use of org.apache.maven.index.context.IndexingContext in project archiva by apache.
the class MavenIndexManager 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.maven.index.context.IndexingContext in project archiva by apache.
the class MavenIndexManager 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.maven.index.context.IndexingContext in project archiva by apache.
the class MavenIndexManager method addArtifactsToIndex.
@Override
public void addArtifactsToIndex(final ArchivaIndexingContext context, final 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.addArtifactsToIndex(artifacts, indexingContext);
} catch (IOException e) {
log.error("IOException while adding artifact {}", e.getMessage(), e);
throw new IndexUpdateFailedException("Error occured while adding artifact to index of " + context.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""));
}
});
}
use of org.apache.maven.index.context.IndexingContext in project archiva by apache.
the class MavenIndexManagerTest method scan.
@Test
public void scan() throws Exception {
createTestContext();
Path destDir = repository.getLocalPath().resolve("org/apache/archiva/archiva-webapp/1.0");
Path srcDir = Paths.get("src/test/maven-search-test-repo/org/apache/archiva/archiva-webapp/1.0");
org.apache.commons.io.FileUtils.copyDirectory(srcDir.toFile(), destDir.toFile());
mavenIndexManager.scan(ctx);
IndexingContext mvnCtx = mavenIndexManager.getMvnContext(ctx);
String term = "org.apache.archiva";
Query q = new BooleanQuery.Builder().add(queryCreator.constructQuery(MAVEN.GROUP_ID, new UserInputSearchExpression(term)), BooleanClause.Occur.SHOULD).build();
assertEquals(4, mvnCtx.acquireIndexSearcher().count(q));
}
use of org.apache.maven.index.context.IndexingContext in project archiva by apache.
the class MavenIndexManagerTest method addArtifactsToIndex.
@Test
public void addArtifactsToIndex() throws Exception {
ArchivaIndexingContext ctx = createTestContext();
Path destDir = repository.getLocalPath().resolve("org/apache/archiva/archiva-search/1.0");
Path srcDir = Paths.get("src/test/maven-search-test-repo/org/apache/archiva/archiva-search/1.0");
org.apache.commons.io.FileUtils.copyDirectory(srcDir.toFile(), destDir.toFile());
List<URI> uriList = new ArrayList<>();
uriList.add(destDir.resolve("archiva-search-1.0.jar").toUri());
uriList.add(destDir.resolve("archiva-search-1.0-sources.jar").toUri());
mavenIndexManager.addArtifactsToIndex(ctx, uriList);
IndexingContext mvnCtx = mavenIndexManager.getMvnContext(ctx);
String term = "org.apache.archiva";
Query q = new BooleanQuery.Builder().add(queryCreator.constructQuery(MAVEN.GROUP_ID, new UserInputSearchExpression(term)), BooleanClause.Occur.SHOULD).build();
assertEquals(2, mvnCtx.acquireIndexSearcher().count(q));
}
Aggregations