Search in sources :

Example 21 with RepositoryException

use of org.apache.archiva.repository.RepositoryException in project archiva by apache.

the class DefaultBrowseService method getArtifactContentText.

@Override
public ArtifactContent getArtifactContentText(String groupId, String artifactId, String version, String classifier, String type, String path, String repositoryId) throws ArchivaRestServiceException {
    List<String> selectedRepos = getSelectedRepos(repositoryId);
    try {
        for (String repoId : selectedRepos) {
            ManagedRepositoryContent managedRepositoryContent = null;
            try {
                managedRepositoryContent = getManagedRepositoryContent(repoId);
            } catch (RepositoryException e) {
                log.error("No repository content found for " + repoId);
                continue;
            }
            ArchivaArtifact archivaArtifact = new ArchivaArtifact(groupId, artifactId, version, classifier, StringUtils.isEmpty(type) ? "jar" : type, repoId);
            Path file = managedRepositoryContent.toFile(archivaArtifact);
            if (!Files.exists(file)) {
                log.debug("file: {} not exists for repository: {} try next repository", file, repoId);
                continue;
            }
            if (StringUtils.isNotBlank(path)) {
                // zip entry of the path -> path must a real file entry of the archive
                JarFile jarFile = new JarFile(file.toFile());
                ZipEntry zipEntry = jarFile.getEntry(path);
                try (InputStream inputStream = jarFile.getInputStream(zipEntry)) {
                    return new ArtifactContent(IOUtils.toString(inputStream, ARTIFACT_CONTENT_ENCODING), repoId);
                } finally {
                    closeQuietly(jarFile);
                }
            }
            return new ArtifactContent(new String(Files.readAllBytes(file), ARTIFACT_CONTENT_ENCODING), repoId);
        }
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
    log.debug("artifact: {}:{}:{}:{}:{} not found", groupId, artifactId, version, classifier, type);
    // 404 ?
    return new ArtifactContent();
}
Also used : Path(java.nio.file.Path) ArtifactContent(org.apache.archiva.rest.api.model.ArtifactContent) ArchivaArtifact(org.apache.archiva.model.ArchivaArtifact) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile)

Example 22 with RepositoryException

use of org.apache.archiva.repository.RepositoryException in project archiva by apache.

the class MetadataUpdaterConsumer method beginScan.

@Override
public void beginScan(ManagedRepository repoConfig, Date whenGathered) throws ConsumerException {
    try {
        ManagedRepository repo = repositoryRegistry.getManagedRepository(repoConfig.getId());
        if (repo == null) {
            throw new RepositoryNotFoundException("Repository not found: " + repoConfig.getId());
        }
        this.repository = repo.getContent();
        if (this.repository == null) {
            throw new RepositoryNotFoundException("Repository content not found: " + repoConfig.getId());
        }
        this.repositoryDir = Paths.get(repository.getRepoRoot());
        this.scanStartTimestamp = System.currentTimeMillis();
    } catch (RepositoryException e) {
        throw new ConsumerException(e.getMessage(), e);
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) RepositoryException(org.apache.archiva.repository.RepositoryException) ConsumerException(org.apache.archiva.consumers.ConsumerException) RepositoryNotFoundException(org.apache.archiva.repository.RepositoryNotFoundException)

Example 23 with RepositoryException

use of org.apache.archiva.repository.RepositoryException in project archiva by apache.

the class DefaultNetworkProxyAdmin method deleteNetworkProxy.

@Override
public void deleteNetworkProxy(String networkProxyId, AuditInformation auditInformation) throws RepositoryAdminException {
    NetworkProxy networkProxy = getNetworkProxy(networkProxyId);
    if (networkProxy == null) {
        throw new RepositoryAdminException("cannot delete NetworkProxy with id " + networkProxyId + " as not exist");
    }
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration(networkProxy);
    configuration.removeNetworkProxy(networkProxyConfiguration);
    for (RemoteRepository repo : repositoryRegistry.getRemoteRepositories()) {
        if (repo.supportsFeature(RemoteIndexFeature.class)) {
            RemoteIndexFeature rif = repo.getFeature(RemoteIndexFeature.class).get();
            if (networkProxyId.equals(rif.getProxyId())) {
                rif.setProxyId(null);
                try {
                    repositoryRegistry.putRepository(repo, configuration);
                } catch (RepositoryException e) {
                    log.error("Could not update repository {}", repo.getId(), e);
                }
            }
        }
    }
    triggerAuditEvent(networkProxy.getId(), null, AuditEvent.DELETE_NETWORK_PROXY, auditInformation);
    saveConfiguration(configuration);
}
Also used : Configuration(org.apache.archiva.configuration.Configuration) NetworkProxyConfiguration(org.apache.archiva.configuration.NetworkProxyConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.NetworkProxyConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RemoteRepository(org.apache.archiva.repository.RemoteRepository) RepositoryException(org.apache.archiva.repository.RepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) NetworkProxy(org.apache.archiva.admin.model.beans.NetworkProxy)

Example 24 with RepositoryException

use of org.apache.archiva.repository.RepositoryException in project archiva by apache.

the class DefaultRemoteRepositoryAdmin method deleteRemoteRepository.

@Override
public Boolean deleteRemoteRepository(String repositoryId, AuditInformation auditInformation) throws RepositoryAdminException {
    triggerAuditEvent(repositoryId, null, AuditEvent.DELETE_REMOTE_REPO, auditInformation);
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    RemoteRepository repo = repositoryRegistry.getRemoteRepository(repositoryId);
    if (repo == null) {
        throw new RepositoryAdminException("Could not delete repository " + repositoryId + ". The repository does not exist.");
    }
    try {
        repositoryRegistry.removeRepository(repo, configuration);
    } catch (RepositoryException e) {
        log.error("Deletion of remote repository failed {}: {}", repo.getId(), e.getMessage(), e);
        throw new RepositoryAdminException("Could not delete remote repository" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
    }
    saveConfiguration(configuration);
    return Boolean.TRUE;
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) RepositoryException(org.apache.archiva.repository.RepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 25 with RepositoryException

use of org.apache.archiva.repository.RepositoryException in project archiva by apache.

the class DefaultManagedRepositoryAdmin method deleteManagedRepository.

@Override
public Boolean deleteManagedRepository(String repositoryId, AuditInformation auditInformation, boolean deleteContent) throws RepositoryAdminException {
    Configuration config = getArchivaConfiguration().getConfiguration();
    ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById(repositoryId);
    if (repoConfig != null) {
        log.debug("Repo location " + repoConfig.getLocation());
        org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository(repositoryId);
        org.apache.archiva.repository.ManagedRepository stagingRepository = null;
        if (repo != null) {
            try {
                if (repo.supportsFeature(StagingRepositoryFeature.class)) {
                    stagingRepository = repo.getFeature(StagingRepositoryFeature.class).get().getStagingRepository();
                }
                repositoryRegistry.removeRepository(repo, config);
            } catch (RepositoryException e) {
                log.error("Removal of repository {} failed: {}", repositoryId, e.getMessage(), e);
                throw new RepositoryAdminException("Removal of repository " + repositoryId + " failed.");
            }
        } else {
            throw new RepositoryAdminException("A repository with that id does not exist");
        }
        triggerAuditEvent(repositoryId, null, AuditEvent.DELETE_MANAGED_REPO, auditInformation);
        if (repoConfig != null) {
            deleteManagedRepository(repoConfig, deleteContent, config, false);
        }
        // stage repo exists ?
        if (stagingRepository != null) {
            // do not trigger event when deleting the staged one
            ManagedRepositoryConfiguration stagingRepositoryConfig = config.findManagedRepositoryById(stagingRepository.getId());
            try {
                repositoryRegistry.removeRepository(stagingRepository);
                if (stagingRepositoryConfig != null) {
                    deleteManagedRepository(stagingRepositoryConfig, deleteContent, config, true);
                }
            } catch (RepositoryException e) {
                log.error("Removal of staging repository {} failed: {}", stagingRepository.getId(), e.getMessage(), e);
            }
        }
        try {
            saveConfiguration(config);
        } catch (Exception e) {
            throw new RepositoryAdminException("Error saving configuration for delete action" + e.getMessage(), e);
        }
        return Boolean.TRUE;
    } else {
        return Boolean.FALSE;
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.RepositoryGroupConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) TaskQueueException(org.apache.archiva.redback.components.taskqueue.TaskQueueException) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositoryException(org.apache.archiva.repository.RepositoryException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException) IOException(java.io.IOException)

Aggregations

RepositoryException (org.apache.archiva.repository.RepositoryException)33 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)14 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)13 Path (java.nio.file.Path)12 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)12 IOException (java.io.IOException)11 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)11 Configuration (org.apache.archiva.configuration.Configuration)7 ArtifactReference (org.apache.archiva.model.ArtifactReference)7 URI (java.net.URI)6 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)6 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)6 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)6 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)6 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)6 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)5 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)5 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)4 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)4 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)4