Search in sources :

Example 1 with ArtifactInfo

use of org.apache.maven.index.ArtifactInfo 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 ArtifactInfo

use of org.apache.maven.index.ArtifactInfo in project archiva by apache.

the class MavenRepositorySearch method convertToSearchResults.

private SearchResults convertToSearchResults(FlatSearchResponse response, SearchResultLimits limits, List<? extends ArtifactInfoFilter> artifactInfoFilters, List<String> selectedRepos, boolean includePoms) throws RepositoryAdminException {
    SearchResults results = new SearchResults();
    Set<ArtifactInfo> artifactInfos = response.getResults();
    for (ArtifactInfo artifactInfo : artifactInfos) {
        if (StringUtils.equalsIgnoreCase("pom", artifactInfo.getFileExtension()) && !includePoms) {
            continue;
        }
        String id = // 
        SearchUtil.getHitId(// 
        artifactInfo.getGroupId(), // 
        artifactInfo.getArtifactId(), // 
        artifactInfo.getClassifier(), artifactInfo.getPackaging());
        Map<String, SearchResultHit> hitsMap = results.getHitsMap();
        if (!applyArtifactInfoFilters(artifactInfo, artifactInfoFilters, hitsMap)) {
            continue;
        }
        SearchResultHit hit = hitsMap.get(id);
        if (hit != null) {
            if (!hit.getVersions().contains(artifactInfo.getVersion())) {
                hit.addVersion(artifactInfo.getVersion());
            }
        } else {
            hit = new SearchResultHit();
            hit.setArtifactId(artifactInfo.getArtifactId());
            hit.setGroupId(artifactInfo.getGroupId());
            hit.setRepositoryId(artifactInfo.getRepository());
            hit.addVersion(artifactInfo.getVersion());
            hit.setBundleExportPackage(artifactInfo.getBundleExportPackage());
            hit.setBundleExportService(artifactInfo.getBundleExportService());
            hit.setBundleSymbolicName(artifactInfo.getBundleSymbolicName());
            hit.setBundleVersion(artifactInfo.getBundleVersion());
            hit.setBundleDescription(artifactInfo.getBundleDescription());
            hit.setBundleDocUrl(artifactInfo.getBundleDocUrl());
            hit.setBundleRequireBundle(artifactInfo.getBundleRequireBundle());
            hit.setBundleImportPackage(artifactInfo.getBundleImportPackage());
            hit.setBundleLicense(artifactInfo.getBundleLicense());
            hit.setBundleName(artifactInfo.getBundleName());
            hit.setContext(artifactInfo.getContext());
            hit.setGoals(artifactInfo.getGoals());
            hit.setPrefix(artifactInfo.getPrefix());
            hit.setPackaging(artifactInfo.getPackaging());
            hit.setClassifier(artifactInfo.getClassifier());
            hit.setFileExtension(artifactInfo.getFileExtension());
            hit.setUrl(getBaseUrl(artifactInfo, selectedRepos));
        }
        results.addHit(id, hit);
    }
    results.setTotalHits(response.getTotalHitsCount());
    results.setTotalHitsMapSize(results.getHitsMap().values().size());
    results.setReturnedHitsCount(response.getReturnedHitsCount());
    results.setLimits(limits);
    if (limits == null || limits.getSelectedPage() == SearchResultLimits.ALL_PAGES) {
        return results;
    } else {
        return paginate(results);
    }
}
Also used : ArtifactInfo(org.apache.maven.index.ArtifactInfo) SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) SearchResults(org.apache.archiva.indexer.search.SearchResults)

Example 3 with ArtifactInfo

use of org.apache.maven.index.ArtifactInfo 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)

Aggregations

ArtifactInfo (org.apache.maven.index.ArtifactInfo)3 Path (java.nio.file.Path)2 FlatSearchRequest (org.apache.maven.index.FlatSearchRequest)2 FlatSearchResponse (org.apache.maven.index.FlatSearchResponse)2 StringSearchExpression (org.apache.maven.index.expr.StringSearchExpression)2 BooleanQuery (org.apache.maven.index_shaded.lucene.search.BooleanQuery)2 Test (org.junit.Test)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 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)1 UnsupportedBaseContextException (org.apache.archiva.indexer.UnsupportedBaseContextException)1 SearchResultHit (org.apache.archiva.indexer.search.SearchResultHit)1 SearchResults (org.apache.archiva.indexer.search.SearchResults)1 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)1 ManagedRepository (org.apache.archiva.repository.ManagedRepository)1 ReleaseScheme (org.apache.archiva.repository.ReleaseScheme)1