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