Search in sources :

Example 36 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class MavenIndexManager 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) FileUtils(org.apache.archiva.common.utils.FileUtils) 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) RepositoryStorage(org.apache.archiva.repository.storage.RepositoryStorage) 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) Objects(java.util.Objects) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) List(java.util.List) HttpConfiguration(org.apache.maven.wagon.shared.http.HttpConfiguration) AssetType(org.apache.archiva.repository.storage.AssetType) 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) StaticContextMemberProvider(org.apache.maven.index.context.StaticContextMemberProvider) ArtifactContextProducer(org.apache.maven.index.ArtifactContextProducer) IndexUpdater(org.apache.maven.index.updater.IndexUpdater) 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) ContextMemberProvider(org.apache.maven.index.context.ContextMemberProvider) 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) 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 37 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class MavenIndexManager method move.

@Override
public ArchivaIndexingContext move(ArchivaIndexingContext context, Repository repo) throws IndexCreationFailedException {
    if (context == null) {
        return null;
    }
    if (context.supports(IndexingContext.class)) {
        try {
            StorageAsset newPath = getIndexPath(repo);
            IndexingContext ctx = context.getBaseContext(IndexingContext.class);
            Path oldPath = ctx.getIndexDirectoryFile().toPath();
            Path newFilePath = newPath.getFilePath();
            if (oldPath.equals(newFilePath)) {
                // Nothing to do, if path does not change
                return context;
            }
            if (!Files.exists(oldPath)) {
                return createContext(repo);
            } else if (context.isEmpty()) {
                context.close();
                return createContext(repo);
            } else {
                context.close(false);
                if (Files.exists(newFilePath)) {
                    FileUtils.copyContent(oldPath, newFilePath);
                    FileUtils.deleteDirectory(oldPath);
                } else {
                    Files.move(oldPath, newFilePath);
                }
                return createContext(repo);
            }
        } catch (IOException e) {
            log.error("IOException while moving index directory {}", e.getMessage(), e);
            throw new IndexCreationFailedException("Could not recreated the index.", e);
        } catch (UnsupportedBaseContextException e) {
            throw new IndexCreationFailedException("The given context, is not a maven context.");
        }
    } else {
        throw new IndexCreationFailedException("Bad context type. This is not a maven context.");
    }
}
Also used : Path(java.nio.file.Path) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) 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 38 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class MavenIndexManager method createRemoteContext.

private IndexingContext createRemoteContext(RemoteRepository remoteRepository) throws IOException {
    String contextKey = "remote-" + remoteRepository.getId();
    // create remote repository path
    Path repoDir = remoteRepository.getRoot().getFilePath();
    if (!Files.exists(repoDir)) {
        Files.createDirectories(repoDir);
    }
    StorageAsset indexDirectory;
    // is there configured indexDirectory ?
    if (remoteRepository.supportsFeature(RemoteIndexFeature.class)) {
        RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class);
        indexDirectory = getIndexPath(remoteRepository);
        String remoteIndexUrl = calculateIndexRemoteUrl(remoteRepository.getLocation(), rif);
        try {
            return getIndexingContext(remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl);
        } 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", remoteRepository.getId());
            org.apache.archiva.common.utils.FileUtils.deleteDirectory(indexDirectory.getFilePath());
            return getIndexingContext(remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl);
        }
    } else {
        throw new IOException("No remote 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) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) IOException(java.io.IOException)

Example 39 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class MavenIndexManager method getIndexPath.

private StorageAsset getIndexPath(URI indexDirUri, RepositoryStorage repoStorage, String defaultDir) throws IOException {
    StorageAsset rootAsset = repoStorage.getRoot();
    RepositoryStorage storage = rootAsset.getStorage();
    Path indexDirectory;
    Path repositoryPath = rootAsset.getFilePath().toAbsolutePath();
    StorageAsset indexDir;
    if (!StringUtils.isEmpty(indexDirUri.toString())) {
        indexDirectory = PathUtil.getPathFromUri(indexDirUri);
        // not absolute so create it in repository directory
        if (indexDirectory.isAbsolute() && !indexDirectory.startsWith(repositoryPath)) {
            if (storage instanceof FilesystemStorage) {
                FilesystemStorage fsStorage = (FilesystemStorage) storage;
                FilesystemStorage indexStorage = new FilesystemStorage(indexDirectory.getParent(), fsStorage.getFileLockManager());
                indexDir = indexStorage.getAsset(indexDirectory.getFileName().toString());
            } else {
                throw new IOException("The given storage is not file based.");
            }
        } else if (indexDirectory.isAbsolute()) {
            indexDir = storage.getAsset(repositoryPath.relativize(indexDirectory).toString());
        } else {
            indexDir = storage.getAsset(indexDirectory.toString());
        }
    } else {
        indexDir = storage.getAsset(defaultDir);
    }
    if (!indexDir.exists()) {
        indexDir.create(AssetType.CONTAINER);
    }
    return indexDir;
}
Also used : Path(java.nio.file.Path) RepositoryStorage(org.apache.archiva.repository.storage.RepositoryStorage) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) IOException(java.io.IOException)

Example 40 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class MavenIndexManager 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;
    if (repository.supportsFeature(IndexCreationFeature.class)) {
        indexDirectory = getIndexPath(repository);
        log.debug("Preparing index at {}", indexDirectory);
        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)

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