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