Search in sources :

Example 26 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class ArchivaMetadataCreationConsumer method processFile.

@Override
public void processFile(String path) throws ConsumerException {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        // note that we do minimal processing including checksums and POM information for performance of
        // the initial scan. Any request for this information will be intercepted and populated on-demand
        // or picked up by subsequent scans
        ArtifactMetadata artifact = repositoryStorage.readArtifactMetadataFromPath(repoId, path);
        ProjectMetadata project = new ProjectMetadata();
        project.setNamespace(artifact.getNamespace());
        project.setId(artifact.getProject());
        String projectVersion = VersionUtil.getBaseVersion(artifact.getVersion());
        MetadataRepository metadataRepository = repositorySession.getRepository();
        boolean createVersionMetadata = false;
        // FIXME: maybe not too efficient since it may have already been read and stored for this artifact
        ProjectVersionMetadata versionMetadata = null;
        try {
            ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(artifact.getNamespace()).projectId(artifact.getProject()).projectVersion(projectVersion);
            versionMetadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
            createVersionMetadata = true;
        } catch (RepositoryStorageMetadataNotFoundException e) {
            log.warn("Missing or invalid POM for artifact:{} (repository:{}); creating empty metadata", path, repoId);
            versionMetadata = new ProjectVersionMetadata();
            versionMetadata.setId(projectVersion);
            versionMetadata.setIncomplete(true);
            createVersionMetadata = true;
        } catch (RepositoryStorageMetadataInvalidException e) {
            log.warn("Error occurred resolving POM for artifact:{} (repository:{}); message: {}", new Object[] { path, repoId, e.getMessage() });
        }
        // read the metadata and update it if it is newer or doesn't exist
        artifact.setWhenGathered(whenGathered);
        metadataRepository.updateArtifact(repoId, project.getNamespace(), project.getId(), projectVersion, artifact);
        if (createVersionMetadata) {
            metadataRepository.updateProjectVersion(repoId, project.getNamespace(), project.getId(), versionMetadata);
        }
        metadataRepository.updateProject(repoId, project);
        repositorySession.save();
    } catch (MetadataRepositoryException e) {
        log.warn("Error occurred persisting metadata for artifact:{} (repository:{}); message: {}", path, repoId, e.getMessage(), e);
        repositorySession.revert();
    } catch (RepositoryStorageRuntimeException e) {
        log.warn("Error occurred persisting metadata for artifact:{} (repository:{}); message: {}", path, repoId, e.getMessage(), e);
        repositorySession.revert();
    } finally {
        repositorySession.close();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryStorageRuntimeException(org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) RepositoryStorageMetadataInvalidException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) RepositoryStorageMetadataNotFoundException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 27 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class Maven2RepositoryMerger method getConflictingArtifacts.

@Override
public List<ArtifactMetadata> getConflictingArtifacts(MetadataRepository metadataRepository, String sourceRepo, String targetRepo) throws RepositoryMergerException {
    try {
        List<ArtifactMetadata> targetArtifacts = metadataRepository.getArtifacts(targetRepo);
        List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts(sourceRepo);
        List<ArtifactMetadata> conflictsArtifacts = new ArrayList<>();
        for (ArtifactMetadata targetArtifact : targetArtifacts) {
            for (ArtifactMetadata sourceArtifact : sourceArtifacts) {
                if (isEquals(targetArtifact, sourceArtifact)) {
                    if (!conflictsArtifacts.contains(sourceArtifact)) {
                        conflictsArtifacts.add(sourceArtifact);
                    }
                }
            }
        }
        sourceArtifacts.removeAll(conflictsArtifacts);
        return conflictsArtifacts;
    } catch (MetadataRepositoryException e) {
        throw new RepositoryMergerException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 28 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class Maven2RepositoryMerger method merge.

@Override
public void merge(MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId) throws RepositoryMergerException {
    try {
        List<ArtifactMetadata> artifactsInSourceRepo = metadataRepository.getArtifacts(sourceRepoId);
        for (ArtifactMetadata artifactMetadata : artifactsInSourceRepo) {
            artifactMetadata.setRepositoryId(targetRepoId);
            createFolderStructure(sourceRepoId, targetRepoId, artifactMetadata);
        }
    } catch (MetadataRepositoryException e) {
        throw new RepositoryMergerException(e.getMessage(), e);
    } catch (IOException e) {
        throw new RepositoryMergerException(e.getMessage(), e);
    } catch (RepositoryException e) {
        throw new RepositoryMergerException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) IOException(java.io.IOException) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 29 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class DefaultManagedRepositoryAdmin method deleteManagedRepository.

private Boolean deleteManagedRepository(ManagedRepositoryConfiguration repository, boolean deleteContent, Configuration config, boolean stagedOne) throws RepositoryAdminException {
    if (!stagedOne) {
        RepositorySession repositorySession = getRepositorySessionFactory().createSession();
        try {
            MetadataRepository metadataRepository = repositorySession.getRepository();
            metadataRepository.removeRepository(repository.getId());
            // invalidate cache
            namespacesCache.remove(repository.getId());
            log.debug("call repositoryStatisticsManager.deleteStatistics");
            getRepositoryStatisticsManager().deleteStatistics(metadataRepository, repository.getId());
            repositorySession.save();
        } catch (MetadataRepositoryException e) {
            // throw new RepositoryAdminException( e.getMessage(), e );
            log.warn("skip error during removing repository from MetadataRepository:{}", e.getMessage(), e);
        } finally {
            repositorySession.close();
        }
    }
    if (deleteContent) {
        // TODO could be async ? as directory can be huge
        Path dir = Paths.get(repository.getLocation());
        org.apache.archiva.common.utils.FileUtils.deleteQuietly(dir);
    }
    // olamy: copy list for reading as a unit test in webapp fail with ConcurrentModificationException
    List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>(config.getProxyConnectors());
    for (ProxyConnectorConfiguration proxyConnector : proxyConnectors) {
        if (StringUtils.equals(proxyConnector.getSourceRepoId(), repository.getId())) {
            config.removeProxyConnector(proxyConnector);
        }
    }
    Map<String, List<String>> repoToGroupMap = config.getRepositoryToGroupMap();
    if (repoToGroupMap != null) {
        if (repoToGroupMap.containsKey(repository.getId())) {
            List<String> repoGroups = repoToGroupMap.get(repository.getId());
            for (String repoGroup : repoGroups) {
                // copy to prevent UnsupportedOperationException
                RepositoryGroupConfiguration repositoryGroupConfiguration = config.findRepositoryGroupById(repoGroup);
                List<String> repos = new ArrayList<>(repositoryGroupConfiguration.getRepositories());
                config.removeRepositoryGroup(repositoryGroupConfiguration);
                repos.remove(repository.getId());
                repositoryGroupConfiguration.setRepositories(repos);
                config.addRepositoryGroup(repositoryGroupConfiguration);
            }
        }
    }
    try {
        removeRepositoryRoles(repository);
    } catch (RoleManagerException e) {
        throw new RepositoryAdminException("fail to remove repository roles for repository " + repository.getId() + " : " + e.getMessage(), e);
    }
    try {
        final RepositoryRegistry reg = getRepositoryRegistry();
        if (reg.getManagedRepository(repository.getId()) != null) {
            reg.removeRepository(reg.getManagedRepository(repository.getId()));
        }
    } catch (RepositoryException e) {
        throw new RepositoryAdminException("Removal of repository " + repository.getId() + " failed: " + e.getMessage());
    }
    saveConfiguration(config);
    return Boolean.TRUE;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Path(java.nio.file.Path) RepositoryGroupConfiguration(org.apache.archiva.configuration.RepositoryGroupConfiguration) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) List(java.util.List) ArrayList(java.util.ArrayList) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException)

Example 30 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class DefaultReportRepositoriesService method getMultipleRepositoriesReport.

private List<RepositoryStatistics> getMultipleRepositoriesReport(List<String> repositoriesId, int rowCount) {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        MetadataRepository metadataRepository = repositorySession.getRepository();
        List<RepositoryStatistics> stats = new ArrayList<>();
        for (String repo : repositoriesId) {
            try {
                stats.add(repositoryStatisticsManager.getLastStatistics(metadataRepository, repo));
            } catch (MetadataRepositoryException e) {
                log.warn("Unable to retrieve stats, assuming is empty: {}", e.getMessage(), e);
            }
        }
        return stats.subList(0, stats.size() > rowCount ? rowCount : stats.size());
    } finally {
        repositorySession.close();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ArrayList(java.util.ArrayList) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics)

Aggregations

MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)65 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)24 RepositoryException (javax.jcr.RepositoryException)22 Node (javax.jcr.Node)21 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)19 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)18 Path (java.nio.file.Path)15 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)13 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)10 HashMap (java.util.HashMap)8 RepositoryException (org.apache.archiva.repository.RepositoryException)8 Map (java.util.Map)6 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)6 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)6 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)6 Date (java.util.Date)5 Query (javax.jcr.query.Query)5 QueryResult (javax.jcr.query.QueryResult)5 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5