use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class ErrorHandlingTest method performDownload.
private StorageAsset performDownload(String path) throws ProxyDownloadException, LayoutException {
// Attempt the proxy fetch.
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), layout.getArtifact(path));
return downloadedFile;
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class ErrorHandlingTest method confirmSuccess.
private void confirmSuccess(String path, Path expectedFile, String basedir) throws Exception {
StorageAsset downloadedFile = performDownload(path);
Path proxied1File = Paths.get(basedir, path);
assertFileEquals(expectedFile, downloadedFile.getFilePath(), proxied1File);
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class ArchivaIndexManagerMock method removeArtifactsFromIndex.
@Override
public void removeArtifactsFromIndex(ArchivaIndexingContext context, Collection<URI> artifactReference) throws IndexUpdateFailedException {
final StorageAsset ctxUri = context.getPath();
executeUpdateFunction(context, indexingContext -> {
Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.getFilePath().toUri().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.archiva.repository.storage.StorageAsset in project archiva by apache.
the class ArchivaIndexManagerMock method createManagedContext.
private IndexingContext createManagedContext(ManagedRepository repository) throws IOException {
IndexingContext context;
// take care first about repository location as can be relative
Path repositoryDirectory = repository.getRoot().getFilePath();
if (!Files.exists(repositoryDirectory)) {
try {
Files.createDirectories(repositoryDirectory);
} catch (IOException e) {
log.error("Could not create directory {}", repositoryDirectory);
}
}
StorageAsset indexDirectory = null;
if (repository.supportsFeature(IndexCreationFeature.class)) {
indexDirectory = getIndexPath(repository);
String indexUrl = repositoryDirectory.toUri().toURL().toExternalForm();
try {
context = getIndexingContext(repository, repository.getId(), repositoryDirectory, indexDirectory, indexUrl);
context.setSearchable(repository.isScanned());
} catch (IndexFormatTooOldException e) {
// existing index with an old lucene format so we need to delete it!!!
// delete it first then recreate it.
//
log.warn(//
"the index of repository {} is too old we have to delete and recreate it", repository.getId());
org.apache.archiva.common.utils.FileUtils.deleteDirectory(indexDirectory.getFilePath());
context = getIndexingContext(repository, repository.getId(), repositoryDirectory, indexDirectory, indexUrl);
context.setSearchable(repository.isScanned());
}
return context;
} else {
throw new IOException("No repository index defined");
}
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class ArchivaIndexManagerMock method addArtifactsToIndex.
@Override
public void addArtifactsToIndex(final ArchivaIndexingContext context, final Collection<URI> artifactReference) throws IndexUpdateFailedException {
final StorageAsset ctxUri = context.getPath();
executeUpdateFunction(context, indexingContext -> {
Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.getFilePath().toUri().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() : ""));
}
});
}
Aggregations