Search in sources :

Example 1 with StringSearchExpression

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());
}
Also used : Path(java.nio.file.Path) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) RunWith(org.junit.runner.RunWith) ArtifactInfo(org.apache.maven.index.ArtifactInfo) DefaultIndexUpdater(org.apache.maven.index.updater.DefaultIndexUpdater) IndexUpdater(org.apache.maven.index.updater.IndexUpdater) Inject(javax.inject.Inject) FlatSearchResponse(org.apache.maven.index.FlatSearchResponse) ReleaseScheme(org.apache.archiva.repository.ReleaseScheme) After(org.junit.After) MAVEN(org.apache.maven.index.MAVEN) TopDocs(org.apache.maven.index_shaded.lucene.search.TopDocs) Assertions(org.assertj.core.api.Assertions) TestCase(junit.framework.TestCase) Path(java.nio.file.Path) Before(org.junit.Before) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) Files(java.nio.file.Files) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) BooleanClause(org.apache.maven.index_shaded.lucene.search.BooleanClause) Set(java.util.Set) ArchivaSpringJUnit4ClassRunner(org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) Test(org.junit.Test) IOException(java.io.IOException) SourcedSearchExpression(org.apache.maven.index.expr.SourcedSearchExpression) Indexer(org.apache.maven.index.Indexer) ManagedRepository(org.apache.archiva.repository.ManagedRepository) IndexUpdateRequest(org.apache.maven.index.updater.IndexUpdateRequest) IndexingContext(org.apache.maven.index.context.IndexingContext) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) IndexSearcher(org.apache.maven.index_shaded.lucene.search.IndexSearcher) FlatSearchRequest(org.apache.maven.index.FlatSearchRequest) BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) StringSearchExpression(org.apache.maven.index.expr.StringSearchExpression) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) FlatSearchResponse(org.apache.maven.index.FlatSearchResponse) IndexUpdateRequest(org.apache.maven.index.updater.IndexUpdateRequest) IOException(java.io.IOException) FlatSearchRequest(org.apache.maven.index.FlatSearchRequest) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ArtifactInfo(org.apache.maven.index.ArtifactInfo) DefaultIndexUpdater(org.apache.maven.index.updater.DefaultIndexUpdater) StringSearchExpression(org.apache.maven.index.expr.StringSearchExpression) Test(org.junit.Test)

Example 2 with StringSearchExpression

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);
}
Also used : Path(java.nio.file.Path) IndexSearcher(org.apache.maven.index_shaded.lucene.search.IndexSearcher) TopDocs(org.apache.maven.index_shaded.lucene.search.TopDocs) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) StringSearchExpression(org.apache.maven.index.expr.StringSearchExpression) Test(org.junit.Test)

Example 3 with StringSearchExpression

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());
}
Also used : Path(java.nio.file.Path) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) ArtifactInfo(org.apache.maven.index.ArtifactInfo) FlatSearchResponse(org.apache.maven.index.FlatSearchResponse) FlatSearchRequest(org.apache.maven.index.FlatSearchRequest) StringSearchExpression(org.apache.maven.index.expr.StringSearchExpression) Test(org.junit.Test)

Example 4 with StringSearchExpression

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);
}
Also used : BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) FlatSearchResponse(org.apache.maven.index.FlatSearchResponse) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) FlatSearchRequest(org.apache.maven.index.FlatSearchRequest) StringSearchExpression(org.apache.maven.index.expr.StringSearchExpression) Test(org.junit.Test)

Aggregations

StringSearchExpression (org.apache.maven.index.expr.StringSearchExpression)4 BooleanQuery (org.apache.maven.index_shaded.lucene.search.BooleanQuery)4 Test (org.junit.Test)4 Path (java.nio.file.Path)3 FlatSearchRequest (org.apache.maven.index.FlatSearchRequest)3 FlatSearchResponse (org.apache.maven.index.FlatSearchResponse)3 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)2 ArtifactInfo (org.apache.maven.index.ArtifactInfo)2 IndexingContext (org.apache.maven.index.context.IndexingContext)2 IndexSearcher (org.apache.maven.index_shaded.lucene.search.IndexSearcher)2 TopDocs (org.apache.maven.index_shaded.lucene.search.TopDocs)2 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 Set (java.util.Set)1 Inject (javax.inject.Inject)1 TestCase (junit.framework.TestCase)1 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)1 UnsupportedBaseContextException (org.apache.archiva.indexer.UnsupportedBaseContextException)1 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)1