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();
}
}
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);
}
}
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);
}
}
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;
}
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();
}
}
Aggregations