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