use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.
the class JcrMetadataRepository method getProject.
@Override
public ProjectMetadata getProject(String repositoryId, String namespace, String projectId) throws MetadataResolutionException {
ProjectMetadata metadata = null;
try {
Node root = getJcrSession().getRootNode();
// basically just checking it exists
String path = getProjectPath(repositoryId, namespace, projectId);
if (root.hasNode(path)) {
metadata = new ProjectMetadata();
metadata.setId(projectId);
metadata.setNamespace(namespace);
}
} catch (RepositoryException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
return metadata;
}
use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.
the class JcrMetadataRepository method getNodeNames.
private Collection<String> getNodeNames(String path, String nodeType) throws MetadataResolutionException {
List<String> names = new ArrayList<>();
try {
Node root = getJcrSession().getRootNode();
Node nodeAtPath = root.getNode(path);
for (Node node : JcrUtils.getChildNodes(nodeAtPath)) {
if (node.isNodeType(nodeType)) {
names.add(node.getName());
}
}
} catch (PathNotFoundException e) {
// ignore repo not found for now
} catch (RepositoryException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
return names;
}
use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.
the class JcrMetadataRepository method getArtifactVersions.
@Override
public Collection<String> getArtifactVersions(String repositoryId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
Set<String> versions = new LinkedHashSet<String>();
try {
Node root = getJcrSession().getRootNode();
Node node = root.getNode(getProjectVersionPath(repositoryId, namespace, projectId, projectVersion));
for (Node n : JcrUtils.getChildNodes(node)) {
versions.add(n.getProperty("version").getString());
}
} catch (PathNotFoundException e) {
// ignore repo not found for now
} catch (RepositoryException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
return versions;
}
use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.
the class SimpleArtifactConsumer method processFile.
public void processFile(String path, boolean executeOnEntireRepo) throws ConsumerException {
log.info("Processing entry [{}] from repository [{}]", path, this.repository.getId());
try {
ManagedRepositoryContent repositoryContent = repository.getContent();
ArtifactReference artifact = repositoryContent.toArtifactReference(path);
repositorySession.getRepository().getArtifacts(repository.getId(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
} catch (LayoutException | MetadataResolutionException e) {
throw new ConsumerException(e.getLocalizedMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.
the class AbstractRepositoryPurge method purge.
/**
* Purge the repo. Update db and index of removed artifacts.
*
* @param references
*/
protected void purge(Set<ArtifactReference> references) {
if (references != null && !references.isEmpty()) {
MetadataRepository metadataRepository = repositorySession.getRepository();
Map<ArtifactInfo, ArtifactMetadata> metaRemovalList = new HashMap<>();
Map<String, Collection<ArtifactMetadata>> metaResolved = new HashMap<>();
for (ArtifactReference reference : references) {
String baseVersion = VersionUtil.getBaseVersion(reference.getVersion());
// Needed for tracking in the hashmap
String metaBaseId = reference.getGroupId() + "/" + reference.getArtifactId() + "/" + baseVersion;
if (!metaResolved.containsKey(metaBaseId)) {
try {
metaResolved.put(metaBaseId, metadataRepository.getArtifacts(repository.getId(), reference.getGroupId(), reference.getArtifactId(), baseVersion));
} catch (MetadataResolutionException e) {
log.error("Error during metadata retrieval {}: {}", metaBaseId, e.getMessage());
}
}
Path artifactFile = repository.toFile(reference);
for (RepositoryListener listener : listeners) {
listener.deleteArtifact(metadataRepository, repository.getId(), reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), artifactFile.getFileName().toString());
}
try {
Files.delete(artifactFile);
log.debug("File deleted: {}", artifactFile.toAbsolutePath());
} catch (IOException e) {
log.error("Could not delete file {}: {}", artifactFile.toAbsolutePath(), e.getMessage(), e);
continue;
}
try {
repository.deleteArtifact(reference);
} catch (ContentNotFoundException e) {
log.warn("skip error deleting artifact {}: {}", reference, e.getMessage());
}
boolean snapshotVersion = VersionUtil.isSnapshot(reference.getVersion());
// If this is a snapshot we have to search for artifacts with the same version. And remove all of them.
if (snapshotVersion) {
Collection<ArtifactMetadata> artifacts = metaResolved.get(metaBaseId);
if (artifacts != null) {
// cleanup snapshots metadata
for (ArtifactMetadata artifactMetadata : artifacts) {
// Artifact metadata and reference version should match.
if (artifactMetadata.getVersion().equals(reference.getVersion())) {
ArtifactInfo info = new ArtifactInfo(artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifactMetadata.getProjectVersion(), artifactMetadata.getVersion());
if (StringUtils.isNotBlank(reference.getClassifier())) {
info.setClassifier(reference.getClassifier());
metaRemovalList.put(info, artifactMetadata);
} else {
// metadataRepository.removeArtifact( artifactMetadata, baseVersion );
metaRemovalList.put(info, artifactMetadata);
}
}
}
}
} else // otherwise we delete the artifact version
{
ArtifactInfo info = new ArtifactInfo(reference.getGroupId(), reference.getArtifactId(), baseVersion, reference.getVersion());
for (ArtifactMetadata metadata : metaResolved.get(metaBaseId)) {
metaRemovalList.put(info, metadata);
}
}
triggerAuditEvent(repository.getRepository().getId(), ArtifactReference.toKey(reference), AuditEvent.PURGE_ARTIFACT);
purgeSupportFiles(artifactFile);
}
purgeMetadata(metadataRepository, metaRemovalList);
repositorySession.save();
}
}
Aggregations