Search in sources :

Example 6 with MetadataResolutionException

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;
}
Also used : ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Node(javax.jcr.Node) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 7 with MetadataResolutionException

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;
}
Also used : Node(javax.jcr.Node) ArrayList(java.util.ArrayList) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 8 with MetadataResolutionException

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Node(javax.jcr.Node) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 9 with MetadataResolutionException

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);
    }
}
Also used : LayoutException(org.apache.archiva.repository.LayoutException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ConsumerException(org.apache.archiva.consumers.ConsumerException) ArtifactReference(org.apache.archiva.model.ArtifactReference) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 10 with MetadataResolutionException

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();
    }
}
Also used : Path(java.nio.file.Path) RepositoryListener(org.apache.archiva.repository.events.RepositoryListener) HashMap(java.util.HashMap) ContentNotFoundException(org.apache.archiva.repository.ContentNotFoundException) IOException(java.io.IOException) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Collection(java.util.Collection) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ArtifactReference(org.apache.archiva.model.ArtifactReference)

Aggregations

MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)26 ArrayList (java.util.ArrayList)14 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)13 Path (java.nio.file.Path)10 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)8 Properties (java.util.Properties)8 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)8 LinkedHashSet (java.util.LinkedHashSet)7 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)7 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)7 Date (java.util.Date)6 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)6 MetadataFacetFactory (org.apache.archiva.metadata.model.MetadataFacetFactory)6 ProjectMetadata (org.apache.archiva.metadata.model.ProjectMetadata)6 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)6 ProjectVersionReference (org.apache.archiva.metadata.model.ProjectVersionReference)6 MetadataResolver (org.apache.archiva.metadata.repository.MetadataResolver)6 Map (java.util.Map)5