Search in sources :

Example 76 with StorageAsset

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;
}
Also used : BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset)

Example 77 with StorageAsset

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);
}
Also used : Path(java.nio.file.Path) StorageAsset(org.apache.archiva.repository.storage.StorageAsset)

Example 78 with StorageAsset

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() : ""));
        }
    });
}
Also used : AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) ArtifactContext(org.apache.maven.index.ArtifactContext) PathUtil(org.apache.archiva.common.utils.PathUtil) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) LoggerFactory(org.slf4j.LoggerFactory) IndexCreator(org.apache.maven.index.context.IndexCreator) ArchivaIndexManager(org.apache.archiva.indexer.ArchivaIndexManager) StringUtils(org.apache.commons.lang3.StringUtils) Map(java.util.Map) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) UnsupportedRepositoryTypeException(org.apache.archiva.repository.UnsupportedRepositoryTypeException) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) URI(java.net.URI) TransferFailedException(org.apache.maven.wagon.TransferFailedException) Path(java.nio.file.Path) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) AbstractHttpClientWagon(org.apache.maven.wagon.shared.http.AbstractHttpClientWagon) TransferEvent(org.apache.maven.wagon.events.TransferEvent) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) HttpMethodConfiguration(org.apache.maven.wagon.shared.http.HttpMethodConfiguration) ProxyRegistry(org.apache.archiva.proxy.ProxyRegistry) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Collection(java.util.Collection) ConnectionException(org.apache.maven.wagon.ConnectionException) AuthorizationException(org.apache.maven.wagon.authorization.AuthorizationException) NetworkProxy(org.apache.archiva.proxy.model.NetworkProxy) WagonFactory(org.apache.archiva.maven.common.proxy.WagonFactory) PasswordCredentials(org.apache.archiva.repository.base.PasswordCredentials) Collectors(java.util.stream.Collectors) Indexer(org.apache.maven.index.Indexer) FileNotFoundException(java.io.FileNotFoundException) ManagedRepository(org.apache.archiva.repository.ManagedRepository) IndexUpdateRequest(org.apache.maven.index.updater.IndexUpdateRequest) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) List(java.util.List) HttpConfiguration(org.apache.maven.wagon.shared.http.HttpConfiguration) IndexFormatTooOldException(org.apache.maven.index_shaded.lucene.index.IndexFormatTooOldException) IndexerEngine(org.apache.maven.index.IndexerEngine) EditableRepository(org.apache.archiva.repository.EditableRepository) Scanner(org.apache.maven.index.Scanner) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ArtifactContextProducer(org.apache.maven.index.ArtifactContextProducer) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) Inject(javax.inject.Inject) Repository(org.apache.archiva.repository.Repository) RemoteRepository(org.apache.archiva.repository.RemoteRepository) Service(org.springframework.stereotype.Service) WagonFactoryRequest(org.apache.archiva.maven.common.proxy.WagonFactoryRequest) IndexPackingRequest(org.apache.maven.index.packer.IndexPackingRequest) ResourceFetcher(org.apache.maven.index.updater.ResourceFetcher) StreamWagon(org.apache.maven.wagon.StreamWagon) Logger(org.slf4j.Logger) IndexPacker(org.apache.maven.index.packer.IndexPacker) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) DefaultScannerListener(org.apache.maven.index.DefaultScannerListener) ScanningRequest(org.apache.maven.index.ScanningRequest) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo) IOException(java.io.IOException) RepositoryType(org.apache.archiva.repository.RepositoryType) IndexingContext(org.apache.maven.index.context.IndexingContext) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) Paths(java.nio.file.Paths) TransferListener(org.apache.maven.wagon.events.TransferListener) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Wagon(org.apache.maven.wagon.Wagon) WagonFactoryException(org.apache.archiva.maven.common.proxy.WagonFactoryException) ScanningResult(org.apache.maven.index.ScanningResult) InputStream(java.io.InputStream) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ArtifactContext(org.apache.maven.index.ArtifactContext) IOException(java.io.IOException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException)

Example 79 with StorageAsset

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");
    }
}
Also used : Path(java.nio.file.Path) IndexFormatTooOldException(org.apache.maven.index_shaded.lucene.index.IndexFormatTooOldException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) IOException(java.io.IOException)

Example 80 with StorageAsset

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() : ""));
        }
    });
}
Also used : AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) ArtifactContext(org.apache.maven.index.ArtifactContext) PathUtil(org.apache.archiva.common.utils.PathUtil) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) LoggerFactory(org.slf4j.LoggerFactory) IndexCreator(org.apache.maven.index.context.IndexCreator) ArchivaIndexManager(org.apache.archiva.indexer.ArchivaIndexManager) StringUtils(org.apache.commons.lang3.StringUtils) Map(java.util.Map) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) UnsupportedRepositoryTypeException(org.apache.archiva.repository.UnsupportedRepositoryTypeException) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) URI(java.net.URI) TransferFailedException(org.apache.maven.wagon.TransferFailedException) Path(java.nio.file.Path) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) AbstractHttpClientWagon(org.apache.maven.wagon.shared.http.AbstractHttpClientWagon) TransferEvent(org.apache.maven.wagon.events.TransferEvent) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) HttpMethodConfiguration(org.apache.maven.wagon.shared.http.HttpMethodConfiguration) ProxyRegistry(org.apache.archiva.proxy.ProxyRegistry) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Collection(java.util.Collection) ConnectionException(org.apache.maven.wagon.ConnectionException) AuthorizationException(org.apache.maven.wagon.authorization.AuthorizationException) NetworkProxy(org.apache.archiva.proxy.model.NetworkProxy) WagonFactory(org.apache.archiva.maven.common.proxy.WagonFactory) PasswordCredentials(org.apache.archiva.repository.base.PasswordCredentials) Collectors(java.util.stream.Collectors) Indexer(org.apache.maven.index.Indexer) FileNotFoundException(java.io.FileNotFoundException) ManagedRepository(org.apache.archiva.repository.ManagedRepository) IndexUpdateRequest(org.apache.maven.index.updater.IndexUpdateRequest) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) List(java.util.List) HttpConfiguration(org.apache.maven.wagon.shared.http.HttpConfiguration) IndexFormatTooOldException(org.apache.maven.index_shaded.lucene.index.IndexFormatTooOldException) IndexerEngine(org.apache.maven.index.IndexerEngine) EditableRepository(org.apache.archiva.repository.EditableRepository) Scanner(org.apache.maven.index.Scanner) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ArtifactContextProducer(org.apache.maven.index.ArtifactContextProducer) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) Inject(javax.inject.Inject) Repository(org.apache.archiva.repository.Repository) RemoteRepository(org.apache.archiva.repository.RemoteRepository) Service(org.springframework.stereotype.Service) WagonFactoryRequest(org.apache.archiva.maven.common.proxy.WagonFactoryRequest) IndexPackingRequest(org.apache.maven.index.packer.IndexPackingRequest) ResourceFetcher(org.apache.maven.index.updater.ResourceFetcher) StreamWagon(org.apache.maven.wagon.StreamWagon) Logger(org.slf4j.Logger) IndexPacker(org.apache.maven.index.packer.IndexPacker) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) DefaultScannerListener(org.apache.maven.index.DefaultScannerListener) ScanningRequest(org.apache.maven.index.ScanningRequest) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo) IOException(java.io.IOException) RepositoryType(org.apache.archiva.repository.RepositoryType) IndexingContext(org.apache.maven.index.context.IndexingContext) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) Paths(java.nio.file.Paths) TransferListener(org.apache.maven.wagon.events.TransferListener) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Wagon(org.apache.maven.wagon.Wagon) WagonFactoryException(org.apache.archiva.maven.common.proxy.WagonFactoryException) ScanningResult(org.apache.maven.index.ScanningResult) InputStream(java.io.InputStream) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ArtifactContext(org.apache.maven.index.ArtifactContext) IOException(java.io.IOException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException)

Aggregations

StorageAsset (org.apache.archiva.repository.storage.StorageAsset)191 Path (java.nio.file.Path)91 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)61 IOException (java.io.IOException)59 Test (org.junit.Test)59 Artifact (org.apache.archiva.repository.content.Artifact)54 ManagedRepository (org.apache.archiva.repository.ManagedRepository)27 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)22 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)22 List (java.util.List)20 Inject (javax.inject.Inject)20 RepositoryMetadataException (org.apache.archiva.repository.metadata.RepositoryMetadataException)20 Collectors (java.util.stream.Collectors)19 RemoteRepository (org.apache.archiva.repository.RemoteRepository)19 IndexingContext (org.apache.maven.index.context.IndexingContext)19 FilesystemStorage (org.apache.archiva.repository.storage.fs.FilesystemStorage)18 StringUtils (org.apache.commons.lang3.StringUtils)18 Logger (org.slf4j.Logger)18 LoggerFactory (org.slf4j.LoggerFactory)18 Map (java.util.Map)17