use of org.apache.maven.index.ArtifactContext in project archiva by apache.
the class ArchivaIndexManagerMock method addArtifactsToIndex.
@Override
public void addArtifactsToIndex(final ArchivaIndexingContext context, final Collection<URI> artifactReference) throws IndexUpdateFailedException {
final URI ctxUri = context.getPath();
executeUpdateFunction(context, indexingContext -> {
Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
try {
indexer.addArtifactsToIndex(artifacts, indexingContext);
} catch (IOException e) {
log.error("IOException while adding artifact {}", e.getMessage(), e);
throw new IndexUpdateFailedException("Error occured while adding artifact to index of " + context.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""));
}
});
}
use of org.apache.maven.index.ArtifactContext in project archiva by apache.
the class MavenIndexManager method removeArtifactsFromIndex.
@Override
public void removeArtifactsFromIndex(ArchivaIndexingContext context, Collection<URI> artifactReference) throws IndexUpdateFailedException {
final URI ctxUri = context.getPath();
executeUpdateFunction(context, indexingContext -> {
Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
try {
indexer.deleteArtifactsFromIndex(artifacts, indexingContext);
} catch (IOException e) {
log.error("IOException while removing artifact {}", e.getMessage(), e);
throw new IndexUpdateFailedException("Error occured while removing artifact from index of " + context.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""));
}
});
}
use of org.apache.maven.index.ArtifactContext in project archiva by apache.
the class MavenIndexManager method addArtifactsToIndex.
@Override
public void addArtifactsToIndex(final ArchivaIndexingContext context, final Collection<URI> artifactReference) throws IndexUpdateFailedException {
final URI ctxUri = context.getPath();
executeUpdateFunction(context, indexingContext -> {
Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
try {
indexer.addArtifactsToIndex(artifacts, indexingContext);
} catch (IOException e) {
log.error("IOException while adding artifact {}", e.getMessage(), e);
throw new IndexUpdateFailedException("Error occured while adding artifact to index of " + context.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""));
}
});
}
use of org.apache.maven.index.ArtifactContext in project archiva by apache.
the class AbstractMavenRepositorySearch method createIndex.
protected void createIndex(String repository, List<Path> filesToBeIndexed, boolean scan, Path indexDir) throws Exception {
Repository rRepo = repositoryRegistry.getRepository(repository);
IndexCreationFeature icf = rRepo.getFeature(IndexCreationFeature.class).get();
IndexingContext context = rRepo.getIndexingContext().getBaseContext(IndexingContext.class);
if (context != null) {
context.close(true);
}
Path repoDir = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir()).resolve("target").resolve("repos").resolve(repository);
Path indexerDirectory = repoDir.resolve(".indexer");
if (Files.exists(indexerDirectory)) {
FileUtils.deleteDirectory(indexerDirectory);
}
assertFalse(Files.exists(indexerDirectory));
Path lockFile = repoDir.resolve(".indexer/write.lock");
if (Files.exists(lockFile)) {
Files.delete(lockFile);
}
assertFalse(Files.exists(lockFile));
Path repo = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + repository);
assertTrue(Files.exists(repo));
org.apache.commons.io.FileUtils.copyDirectory(repo.toFile(), repoDir.toFile());
if (indexDir == null) {
Path indexDirectory = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/index/test-" + Long.toString(System.currentTimeMillis()));
indexDirectory.toFile().deleteOnExit();
FileUtils.deleteDirectory(indexDirectory);
icf.setIndexPath(indexDirectory.toUri());
} else {
icf.setIndexPath(indexDir.toUri());
}
context = rRepo.getIndexingContext().getBaseContext(IndexingContext.class);
// context.getIndexWriter().setRAMBufferSizeMB( 1 );
for (Path artifactFile : filesToBeIndexed) {
assertTrue("file not exists " + artifactFile, Files.exists(artifactFile));
ArtifactContext ac = artifactContextProducer.getArtifactContext(context, artifactFile.toFile());
if (artifactFile.toString().endsWith(".pom")) {
ac.getArtifactInfo().setFileExtension("pom");
ac.getArtifactInfo().setPackaging("pom");
ac.getArtifactInfo().setClassifier("pom");
}
indexer.addArtifactToIndex(ac, context);
context.updateTimestamp(true);
}
if (scan) {
DefaultScannerListener listener = new DefaultScannerListener(context, indexerEngine, true, new ArtifactScanListener());
ScanningRequest req = new ScanningRequest(context, listener);
scanner.scan(req);
context.commit();
}
// force flushing
context.commit();
// context.getIndexWriter().commit();
context.setSearchable(true);
}
use of org.apache.maven.index.ArtifactContext in project archiva by apache.
the class ArchivaIndexManagerMock method removeArtifactsFromIndex.
@Override
public void removeArtifactsFromIndex(ArchivaIndexingContext context, Collection<URI> artifactReference) throws IndexUpdateFailedException {
final URI ctxUri = context.getPath();
executeUpdateFunction(context, indexingContext -> {
Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
try {
indexer.deleteArtifactsFromIndex(artifacts, indexingContext);
} catch (IOException e) {
log.error("IOException while removing artifact {}", e.getMessage(), e);
throw new IndexUpdateFailedException("Error occured while removing artifact from index of " + context.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""));
}
});
}
Aggregations