Search in sources :

Example 21 with MetadataFacet

use of org.apache.archiva.metadata.model.MetadataFacet in project archiva by apache.

the class FileMetadataRepository method updateArtifactFacets.

private void updateArtifactFacets(ArtifactMetadata artifact, Properties properties) {
    String propertyPrefix = "artifact:facet:" + artifact.getId() + ":";
    for (MetadataFacet facet : artifact.getFacetList()) {
        for (Map.Entry<String, String> e : facet.toProperties().entrySet()) {
            String key = propertyPrefix + facet.getFacetId() + ":" + e.getKey();
            properties.setProperty(key, e.getValue());
        }
    }
}
Also used : MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with MetadataFacet

use of org.apache.archiva.metadata.model.MetadataFacet in project archiva by apache.

the class JcrMetadataRepository method updateProjectVersion.

@Override
public void updateProjectVersion(String repositoryId, String namespace, String projectId, ProjectVersionMetadata versionMetadata) throws MetadataRepositoryException {
    updateProject(repositoryId, namespace, projectId);
    try {
        Node versionNode = getOrAddProjectVersionNode(repositoryId, namespace, projectId, versionMetadata.getId());
        versionNode.setProperty("name", versionMetadata.getName());
        versionNode.setProperty("description", versionMetadata.getDescription());
        versionNode.setProperty("url", versionMetadata.getUrl());
        versionNode.setProperty("incomplete", versionMetadata.isIncomplete());
        // FIXME: decide how to treat these in the content repo
        if (versionMetadata.getScm() != null) {
            versionNode.setProperty("scm.connection", versionMetadata.getScm().getConnection());
            versionNode.setProperty("scm.developerConnection", versionMetadata.getScm().getDeveloperConnection());
            versionNode.setProperty("scm.url", versionMetadata.getScm().getUrl());
        }
        if (versionMetadata.getCiManagement() != null) {
            versionNode.setProperty("ci.system", versionMetadata.getCiManagement().getSystem());
            versionNode.setProperty("ci.url", versionMetadata.getCiManagement().getUrl());
        }
        if (versionMetadata.getIssueManagement() != null) {
            versionNode.setProperty("issue.system", versionMetadata.getIssueManagement().getSystem());
            versionNode.setProperty("issue.url", versionMetadata.getIssueManagement().getUrl());
        }
        if (versionMetadata.getOrganization() != null) {
            versionNode.setProperty("org.name", versionMetadata.getOrganization().getName());
            versionNode.setProperty("org.url", versionMetadata.getOrganization().getUrl());
        }
        int i = 0;
        for (License license : versionMetadata.getLicenses()) {
            versionNode.setProperty("license." + i + ".name", license.getName());
            versionNode.setProperty("license." + i + ".url", license.getUrl());
            i++;
        }
        i = 0;
        for (MailingList mailingList : versionMetadata.getMailingLists()) {
            versionNode.setProperty("mailingList." + i + ".archive", mailingList.getMainArchiveUrl());
            versionNode.setProperty("mailingList." + i + ".name", mailingList.getName());
            versionNode.setProperty("mailingList." + i + ".post", mailingList.getPostAddress());
            versionNode.setProperty("mailingList." + i + ".unsubscribe", mailingList.getUnsubscribeAddress());
            versionNode.setProperty("mailingList." + i + ".subscribe", mailingList.getSubscribeAddress());
            versionNode.setProperty("mailingList." + i + ".otherArchives", join(mailingList.getOtherArchives()));
            i++;
        }
        if (!versionMetadata.getDependencies().isEmpty()) {
            Node dependenciesNode = JcrUtils.getOrAddNode(versionNode, "dependencies");
            for (Dependency dependency : versionMetadata.getDependencies()) {
                // Note that we deliberately don't alter the namespace path - not enough dependencies for
                // number of nodes at a given depth to be an issue. Similarly, we don't add subnodes for each
                // component of the ID as that creates extra depth and causes a great cost in space and memory
                // FIXME: change group ID to namespace
                // FIXME: change to artifact's ID - this is constructed by the Maven 2 format for now.
                // This won't support types where the extension doesn't match the type.
                // (see also Maven2RepositoryStorage#readProjectVersionMetadata construction of POM)
                String id = dependency.getGroupId() + ";" + dependency.getArtifactId() + "-" + dependency.getVersion();
                if (dependency.getClassifier() != null) {
                    id += "-" + dependency.getClassifier();
                }
                id += "." + dependency.getType();
                Node n = JcrUtils.getOrAddNode(dependenciesNode, id);
                n.addMixin(DEPENDENCY_NODE_TYPE);
                // FIXME: remove temp code just to make it keep working
                n.setProperty("groupId", dependency.getGroupId());
                n.setProperty("artifactId", dependency.getArtifactId());
                n.setProperty("version", dependency.getVersion());
                n.setProperty("type", dependency.getType());
                n.setProperty("classifier", dependency.getClassifier());
                n.setProperty("scope", dependency.getScope());
                n.setProperty("systemPath", dependency.getSystemPath());
                n.setProperty("optional", dependency.isOptional());
            // node has no native content at this time, just facets
            // no need to list a type as it's implied by the path. Parents are Maven specific.
            // FIXME: add scope, systemPath, type, version, classifier & maven2 specific IDs as a facet
            // (should also have been added to the Dependency)
            // TODO: add a property that is a weak reference to the originating artifact, creating it if
            // necessary (without adding the archiva:artifact mixin so that it doesn't get listed as an
            // artifact, which gives a different meaning to "incomplete" which is a known local project
            // that doesn't have metadata yet but has artifacts). (Though we may want to give it the
            // artifact mixin and another property to identify all non-local artifacts for the closure
            // reports)
            }
        }
        for (MetadataFacet facet : versionMetadata.getFacetList()) {
            // recreate, to ensure properties are removed
            if (versionNode.hasNode(facet.getFacetId())) {
                versionNode.getNode(facet.getFacetId()).remove();
            }
            Node n = versionNode.addNode(facet.getFacetId());
            n.addMixin(FACET_NODE_TYPE);
            for (Map.Entry<String, String> entry : facet.toProperties().entrySet()) {
                n.setProperty(entry.getKey(), entry.getValue());
            }
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Node(javax.jcr.Node) License(org.apache.archiva.metadata.model.License) MailingList(org.apache.archiva.metadata.model.MailingList) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Dependency(org.apache.archiva.metadata.model.Dependency) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 23 with MetadataFacet

use of org.apache.archiva.metadata.model.MetadataFacet in project archiva by apache.

the class JcrMetadataRepository method removeArtifact.

@Override
public void removeArtifact(String repositoryId, String namespace, String project, String projectVersion, MetadataFacet metadataFacet) throws MetadataRepositoryException {
    try {
        Node root = getJcrSession().getRootNode();
        String path = getProjectVersionPath(repositoryId, namespace, project, projectVersion);
        if (root.hasNode(path)) {
            Node node = root.getNode(path);
            for (Node n : JcrUtils.getChildNodes(node)) {
                if (n.isNodeType(ARTIFACT_NODE_TYPE)) {
                    ArtifactMetadata artifactMetadata = getArtifactFromNode(repositoryId, n);
                    log.debug("artifactMetadata: {}", artifactMetadata);
                    MetadataFacet metadataFacetToRemove = artifactMetadata.getFacet(metadataFacet.getFacetId());
                    if (metadataFacetToRemove != null && metadataFacet.equals(metadataFacetToRemove)) {
                        n.remove();
                    }
                }
            }
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Node(javax.jcr.Node) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 24 with MetadataFacet

use of org.apache.archiva.metadata.model.MetadataFacet in project archiva by apache.

the class JcrMetadataRepository method getProjectVersion.

@Override
public ProjectVersionMetadata getProjectVersion(String repositoryId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
    ProjectVersionMetadata versionMetadata;
    try {
        Node root = getJcrSession().getRootNode();
        String path = getProjectVersionPath(repositoryId, namespace, projectId, projectVersion);
        if (!root.hasNode(path)) {
            return null;
        }
        Node node = root.getNode(path);
        versionMetadata = new ProjectVersionMetadata();
        versionMetadata.setId(projectVersion);
        versionMetadata.setName(getPropertyString(node, "name"));
        versionMetadata.setDescription(getPropertyString(node, "description"));
        versionMetadata.setUrl(getPropertyString(node, "url"));
        versionMetadata.setIncomplete(node.hasProperty("incomplete") && node.getProperty("incomplete").getBoolean());
        // FIXME: decide how to treat these in the content repo
        String scmConnection = getPropertyString(node, "scm.connection");
        String scmDeveloperConnection = getPropertyString(node, "scm.developerConnection");
        String scmUrl = getPropertyString(node, "scm.url");
        if (scmConnection != null || scmDeveloperConnection != null || scmUrl != null) {
            Scm scm = new Scm();
            scm.setConnection(scmConnection);
            scm.setDeveloperConnection(scmDeveloperConnection);
            scm.setUrl(scmUrl);
            versionMetadata.setScm(scm);
        }
        String ciSystem = getPropertyString(node, "ci.system");
        String ciUrl = getPropertyString(node, "ci.url");
        if (ciSystem != null || ciUrl != null) {
            CiManagement ci = new CiManagement();
            ci.setSystem(ciSystem);
            ci.setUrl(ciUrl);
            versionMetadata.setCiManagement(ci);
        }
        String issueSystem = getPropertyString(node, "issue.system");
        String issueUrl = getPropertyString(node, "issue.url");
        if (issueSystem != null || issueUrl != null) {
            IssueManagement issueManagement = new IssueManagement();
            issueManagement.setSystem(issueSystem);
            issueManagement.setUrl(issueUrl);
            versionMetadata.setIssueManagement(issueManagement);
        }
        String orgName = getPropertyString(node, "org.name");
        String orgUrl = getPropertyString(node, "org.url");
        if (orgName != null || orgUrl != null) {
            Organization org = new Organization();
            org.setName(orgName);
            org.setUrl(orgUrl);
            versionMetadata.setOrganization(org);
        }
        boolean done = false;
        int i = 0;
        while (!done) {
            String licenseName = getPropertyString(node, "license." + i + ".name");
            String licenseUrl = getPropertyString(node, "license." + i + ".url");
            if (licenseName != null || licenseUrl != null) {
                License license = new License();
                license.setName(licenseName);
                license.setUrl(licenseUrl);
                versionMetadata.addLicense(license);
            } else {
                done = true;
            }
            i++;
        }
        done = false;
        i = 0;
        while (!done) {
            String mailingListName = getPropertyString(node, "mailingList." + i + ".name");
            if (mailingListName != null) {
                MailingList mailingList = new MailingList();
                mailingList.setName(mailingListName);
                mailingList.setMainArchiveUrl(getPropertyString(node, "mailingList." + i + ".archive"));
                String n = "mailingList." + i + ".otherArchives";
                if (node.hasProperty(n)) {
                    mailingList.setOtherArchives(Arrays.asList(getPropertyString(node, n).split(",")));
                } else {
                    mailingList.setOtherArchives(Collections.<String>emptyList());
                }
                mailingList.setPostAddress(getPropertyString(node, "mailingList." + i + ".post"));
                mailingList.setSubscribeAddress(getPropertyString(node, "mailingList." + i + ".subscribe"));
                mailingList.setUnsubscribeAddress(getPropertyString(node, "mailingList." + i + ".unsubscribe"));
                versionMetadata.addMailingList(mailingList);
            } else {
                done = true;
            }
            i++;
        }
        if (node.hasNode("dependencies")) {
            Node dependenciesNode = node.getNode("dependencies");
            for (Node n : JcrUtils.getChildNodes(dependenciesNode)) {
                if (n.isNodeType(DEPENDENCY_NODE_TYPE)) {
                    Dependency dependency = new Dependency();
                    // FIXME: correct these properties
                    dependency.setArtifactId(getPropertyString(n, "artifactId"));
                    dependency.setGroupId(getPropertyString(n, "groupId"));
                    dependency.setClassifier(getPropertyString(n, "classifier"));
                    dependency.setOptional(Boolean.valueOf(getPropertyString(n, "optional")));
                    dependency.setScope(getPropertyString(n, "scope"));
                    dependency.setSystemPath(getPropertyString(n, "systemPath"));
                    dependency.setType(getPropertyString(n, "type"));
                    dependency.setVersion(getPropertyString(n, "version"));
                    versionMetadata.addDependency(dependency);
                }
            }
        }
        for (Node n : JcrUtils.getChildNodes(node)) {
            if (n.isNodeType(FACET_NODE_TYPE)) {
                String name = n.getName();
                MetadataFacetFactory factory = metadataFacetFactories.get(name);
                if (factory == null) {
                    log.error("Attempted to load unknown project version metadata facet: {}", name);
                } else {
                    MetadataFacet facet = factory.createMetadataFacet();
                    Map<String, String> map = new HashMap<>();
                    for (Property property : JcrUtils.getProperties(n)) {
                        String p = property.getName();
                        if (!p.startsWith("jcr:")) {
                            map.put(p, property.getString());
                        }
                    }
                    facet.fromProperties(map);
                    versionMetadata.addFacet(facet);
                }
            }
        }
    } catch (RepositoryException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
    return versionMetadata;
}
Also used : Organization(org.apache.archiva.metadata.model.Organization) HashMap(java.util.HashMap) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) Node(javax.jcr.Node) License(org.apache.archiva.metadata.model.License) MailingList(org.apache.archiva.metadata.model.MailingList) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Dependency(org.apache.archiva.metadata.model.Dependency) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) CiManagement(org.apache.archiva.metadata.model.CiManagement) Scm(org.apache.archiva.metadata.model.Scm) Property(javax.jcr.Property) IssueManagement(org.apache.archiva.metadata.model.IssueManagement)

Example 25 with MetadataFacet

use of org.apache.archiva.metadata.model.MetadataFacet in project archiva by apache.

the class JcrMetadataRepository method getArtifactFromNode.

private ArtifactMetadata getArtifactFromNode(String repositoryId, Node artifactNode) throws RepositoryException {
    String id = artifactNode.getName();
    ArtifactMetadata artifact = new ArtifactMetadata();
    artifact.setId(id);
    artifact.setRepositoryId(repositoryId == null ? artifactNode.getAncestor(2).getName() : repositoryId);
    Node projectVersionNode = artifactNode.getParent();
    Node projectNode = projectVersionNode.getParent();
    Node namespaceNode = projectNode.getParent();
    artifact.setNamespace(namespaceNode.getProperty("namespace").getString());
    artifact.setProject(projectNode.getName());
    artifact.setProjectVersion(projectVersionNode.getName());
    artifact.setVersion(artifactNode.hasProperty("version") ? artifactNode.getProperty("version").getString() : projectVersionNode.getName());
    if (artifactNode.hasProperty(JCR_LAST_MODIFIED)) {
        artifact.setFileLastModified(artifactNode.getProperty(JCR_LAST_MODIFIED).getDate().getTimeInMillis());
    }
    if (artifactNode.hasProperty("whenGathered")) {
        artifact.setWhenGathered(artifactNode.getProperty("whenGathered").getDate().getTime());
    }
    if (artifactNode.hasProperty("size")) {
        artifact.setSize(artifactNode.getProperty("size").getLong());
    }
    if (artifactNode.hasProperty("md5")) {
        artifact.setMd5(artifactNode.getProperty("md5").getString());
    }
    if (artifactNode.hasProperty("sha1")) {
        artifact.setSha1(artifactNode.getProperty("sha1").getString());
    }
    for (Node n : JcrUtils.getChildNodes(artifactNode)) {
        if (n.isNodeType(FACET_NODE_TYPE)) {
            String name = n.getName();
            MetadataFacetFactory factory = metadataFacetFactories.get(name);
            if (factory == null) {
                log.error("Attempted to load unknown project version metadata facet: {}", name);
            } else {
                MetadataFacet facet = factory.createMetadataFacet();
                Map<String, String> map = new HashMap<>();
                for (Property p : JcrUtils.getProperties(n)) {
                    String property = p.getName();
                    if (!property.startsWith("jcr:")) {
                        map.put(property, p.getString());
                    }
                }
                facet.fromProperties(map);
                artifact.addFacet(facet);
            }
        }
    }
    return artifact;
}
Also used : HashMap(java.util.HashMap) Node(javax.jcr.Node) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Property(javax.jcr.Property) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory)

Aggregations

MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)25 HashMap (java.util.HashMap)19 GenericMetadataFacet (org.apache.archiva.metadata.generic.GenericMetadataFacet)11 MetadataFacetFactory (org.apache.archiva.metadata.model.MetadataFacetFactory)10 Map (java.util.Map)8 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)8 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)8 Test (org.junit.Test)7 Node (javax.jcr.Node)6 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)6 ArrayList (java.util.ArrayList)5 RepositoryException (javax.jcr.RepositoryException)5 MailingList (org.apache.archiva.metadata.model.MailingList)4 IOException (java.io.IOException)3 Properties (java.util.Properties)3 Property (javax.jcr.Property)3 OrderedRows (me.prettyprint.hector.api.beans.OrderedRows)3 CiManagement (org.apache.archiva.metadata.model.CiManagement)3 Dependency (org.apache.archiva.metadata.model.Dependency)3 IssueManagement (org.apache.archiva.metadata.model.IssueManagement)3