use of org.apache.maven.index.expr.StringSearchExpression in project archiva by apache.
the class ArchivaIndexingTaskExecutorTest method testPackagedIndex.
@Test
public void testPackagedIndex() throws Exception {
Path basePath = repo.getLocalPath();
IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
Path packedIndexDirectory = icf.getLocalPackedIndexPath();
Path indexerDirectory = icf.getLocalIndexPath();
Files.list(packedIndexDirectory).filter(path -> path.getFileName().toString().startsWith("nexus-maven-repository-index")).forEach(path -> {
try {
System.err.println("Deleting " + path);
Files.delete(path);
} catch (IOException e) {
e.printStackTrace();
}
});
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());
task.setExecuteOnEntireRepo(false);
indexingExecutor.executeTask(task);
task = new ArtifactIndexingTask(repo, null, ArtifactIndexingTask.Action.FINISH, repo.getIndexingContext());
task.setExecuteOnEntireRepo(false);
indexingExecutor.executeTask(task);
assertTrue(Files.exists(packedIndexDirectory));
assertTrue(Files.exists(indexerDirectory));
// test packed index file creation
// no more zip
// Assertions.assertThat(new File( indexerDirectory, "nexus-maven-repository-index.zip" )).exists();
Assertions.assertThat(Files.exists(packedIndexDirectory.resolve("nexus-maven-repository-index.properties")));
Assertions.assertThat(Files.exists(packedIndexDirectory.resolve("nexus-maven-repository-index.gz")));
assertFalse(Files.exists(packedIndexDirectory.resolve("nexus-maven-repository-index.1.gz")));
// unpack .zip index
// unzipIndex( indexerDirectory.getPath(), destDir.getPath() );
DefaultIndexUpdater.FileFetcher fetcher = new DefaultIndexUpdater.FileFetcher(packedIndexDirectory.toFile());
IndexUpdateRequest updateRequest = new IndexUpdateRequest(getIndexingContext(), fetcher);
// updateRequest.setLocalIndexCacheDir( indexerDirectory );
indexUpdater.fetchAndUpdateIndex(updateRequest);
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);
FlatSearchRequest request = new FlatSearchRequest(qb.build(), getIndexingContext());
FlatSearchResponse response = indexer.searchFlat(request);
assertEquals(1, response.getTotalHitsCount());
Set<ArtifactInfo> results = response.getResults();
ArtifactInfo artifactInfo = results.iterator().next();
assertEquals("org.apache.archiva", artifactInfo.getGroupId());
assertEquals("archiva-index-methods-jar-test", artifactInfo.getArtifactId());
assertEquals("test-repo", artifactInfo.getRepository());
}
use of org.apache.maven.index.expr.StringSearchExpression 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.expr.StringSearchExpression in project archiva by apache.
the class ArchivaIndexingTaskExecutorTest method testAddArtifactToIndex.
@Test
public void testAddArtifactToIndex() 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);
task = new ArtifactIndexingTask(repo, null, ArtifactIndexingTask.Action.FINISH, repo.getIndexingContext());
indexingExecutor.executeTask(task);
BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
queryBuilder.add(indexer.constructQuery(MAVEN.GROUP_ID, new StringSearchExpression("org.apache.archiva")), BooleanClause.Occur.SHOULD);
queryBuilder.add(indexer.constructQuery(MAVEN.ARTIFACT_ID, new StringSearchExpression("archiva-index-methods-jar-test")), BooleanClause.Occur.SHOULD);
BooleanQuery q = queryBuilder.build();
FlatSearchRequest request = new FlatSearchRequest(q, getIndexingContext());
FlatSearchResponse response = indexer.searchFlat(request);
assertTrue(Files.exists(basePath.resolve(".indexer")));
assertTrue(Files.exists(basePath.resolve(".index")));
assertEquals(1, response.getTotalHitsCount());
Set<ArtifactInfo> results = response.getResults();
ArtifactInfo artifactInfo = results.iterator().next();
assertEquals("org.apache.archiva", artifactInfo.getGroupId());
assertEquals("archiva-index-methods-jar-test", artifactInfo.getArtifactId());
assertEquals("test-repo", artifactInfo.getRepository());
}
use of org.apache.maven.index.expr.StringSearchExpression in project archiva by apache.
the class DownloadRemoteIndexTaskTest method downloadAndMergeRemoteIndexInEmptyIndex.
@Test
public void downloadAndMergeRemoteIndexInEmptyIndex() throws Exception {
RemoteRepository remoteRepository = getRemoteRepository();
remoteRepositoryAdmin.addRemoteRepository(remoteRepository, null);
downloadRemoteIndexScheduler.startup();
downloadRemoteIndexScheduler.scheduleDownloadRemote("test-repo-re", true, true);
((ThreadPoolTaskScheduler) downloadRemoteIndexScheduler.getTaskScheduler()).getScheduledExecutor().awaitTermination(10, TimeUnit.SECONDS);
remoteRepositoryAdmin.deleteRemoteRepository("test-repo-re", null);
// search
BooleanQuery.Builder iQuery = new BooleanQuery.Builder();
iQuery.add(indexer.constructQuery(MAVEN.GROUP_ID, new StringSearchExpression("commons-logging")), BooleanClause.Occur.SHOULD);
remoteRepositoryAdmin.addRemoteRepository(remoteRepository, null);
FlatSearchRequest rq = new FlatSearchRequest(iQuery.build());
rq.setContexts(Arrays.asList(repositoryRegistry.getRemoteRepository(remoteRepository.getId()).getIndexingContext().getBaseContext(IndexingContext.class)));
FlatSearchResponse response = indexer.searchFlat(rq);
log.info("returned hit count:{}", response.getReturnedHitsCount());
assertThat(response.getReturnedHitsCount()).isEqualTo(8);
}
Aggregations