Search in sources :

Example 26 with MetadataResolutionException

use of org.apache.archiva.metadata.repository.MetadataResolutionException 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)

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