use of org.apache.archiva.metadata.model.Dependency 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);
}
}
use of org.apache.archiva.metadata.model.Dependency 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;
}
use of org.apache.archiva.metadata.model.Dependency in project archiva by apache.
the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method testGetProjectVersionMetadataWithParentSnapshotVersion.
@Test
public void testGetProjectVersionMetadataWithParentSnapshotVersion() throws Exception {
copyTestArtifactWithParent("target/test-classes/com/example/test/test-snapshot-artifact-module-a", "target/test-repositorys/com/example/test/test-snapshot-artifact-module-a");
copyTestArtifactWithParent("target/test-classes/com/example/test/test-snapshot-artifact-root", "target/test-repositorys/com/example/test/test-snapshot-artifact-root");
copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-parent", "target/test-repositorys/com/example/test/test-artifact-parent");
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest(TEST_SNAP_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a", "1.1-SNAPSHOT");
ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(readMetadataRequest);
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet(MavenProjectFacet.FACET_ID);
assertEquals("jar", facet.getPackaging());
assertEquals("com.example.test", facet.getParent().getGroupId());
assertEquals("test-snapshot-artifact-root", facet.getParent().getArtifactId());
assertEquals("1.1-SNAPSHOT", facet.getParent().getVersion());
assertEquals("test-snapshot-artifact-module-a", facet.getArtifactId());
assertEquals("com.example.test", facet.getGroupId());
assertNull(metadata.getCiManagement());
assertNotNull(metadata.getDescription());
checkApacheLicense(metadata);
assertEquals("1.1-SNAPSHOT", metadata.getId());
assertEquals("Test Snapshot Artifact :: Module A", metadata.getName());
String path = "test-snapshot-artifact/trunk/test-snapshot-artifact-module-a";
assertEquals(TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection());
assertEquals(TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection());
assertEquals(TEST_SCM_URL_BASE + path, metadata.getScm().getUrl());
List<Dependency> dependencies = metadata.getDependencies();
assertEquals(2, dependencies.size());
assertDependency(dependencies.get(0), "commons-io", "commons-io", "1.4");
assertDependency(dependencies.get(1), "junit", "junit", "3.8.1", "test");
List<String> paths = new ArrayList<>();
paths.add("target/test-repositorys/com/example/test/test-snapshot-artifact-module-a");
paths.add("target/test-repositorys/com/example/test/test-snapshot-artifact-root");
deleteTestArtifactWithParent(paths);
}
use of org.apache.archiva.metadata.model.Dependency in project archiva by apache.
the class Maven2RepositoryMetadataResolverMRM1411Test method testGetProjectVersionMetadataWithParentSuccessful.
// Tests for MRM-1411 - START
@Test
public void testGetProjectVersionMetadataWithParentSuccessful() throws Exception {
copyTestArtifactWithParent("target/test-classes/com/example/test/test-artifact-module-a", "target/test-repository/com/example/test/test-artifact-module-a");
ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0"));
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet(MavenProjectFacet.FACET_ID);
assertEquals("jar", facet.getPackaging());
assertEquals("http://maven.apache.org", metadata.getUrl());
assertEquals("com.example.test", facet.getParent().getGroupId());
assertEquals("test-artifact-root", facet.getParent().getArtifactId());
assertEquals("1.0", facet.getParent().getVersion());
assertEquals("test-artifact-module-a", facet.getArtifactId());
assertEquals("com.example.test", facet.getGroupId());
assertNull(metadata.getCiManagement());
assertNotNull(metadata.getDescription());
checkApacheLicense(metadata);
assertEquals("1.0", metadata.getId());
assertEquals("Test Artifact :: Module A", metadata.getName());
String path = "test-artifact/trunk/test-artifact-module-a";
assertEquals(TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection());
assertEquals(TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection());
assertEquals(TEST_SCM_URL_BASE + path, metadata.getScm().getUrl());
List<Dependency> dependencies = metadata.getDependencies();
assertEquals(2, dependencies.size());
assertDependency(dependencies.get(0), "commons-io", "commons-io", "1.4");
assertDependency(dependencies.get(1), "junit", "junit", "3.8.1", "test");
List<String> paths = new ArrayList<>();
paths.add("target/test-repository/com/example/test/test-artifact-module-a");
paths.add("target/test-repository/com/example/test/test-artifact-parent");
paths.add("target/test-repository/com/example/test/test-artifact-root");
deleteTestArtifactWithParent(paths);
}
use of org.apache.archiva.metadata.model.Dependency in project archiva by apache.
the class Maven2RepositoryMetadataResolverTest method testGetProjectVersionMetadata.
@Test
public void testGetProjectVersionMetadata() throws Exception {
ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(new ReadMetadataRequest(TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1"));
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet(MavenProjectFacet.FACET_ID);
assertEquals("jar", facet.getPackaging());
assertEquals("http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl());
assertEquals("org.apache.archiva", facet.getParent().getGroupId());
assertEquals("archiva-base", facet.getParent().getArtifactId());
assertEquals("1.2.1", facet.getParent().getVersion());
assertEquals("archiva-common", facet.getArtifactId());
assertEquals("org.apache.archiva", facet.getGroupId());
assertEquals("continuum", metadata.getCiManagement().getSystem());
assertEquals("http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl());
assertNotNull(metadata.getDescription());
// TODO: this would be better
// assertEquals(
// "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
// metadata.getDescription() );
assertEquals("1.2.1", metadata.getId());
assertEquals("jira", metadata.getIssueManagement().getSystem());
assertEquals("http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl());
checkApacheLicense(metadata);
assertEquals("Archiva Base :: Common", metadata.getName());
String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
assertEquals(ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection());
assertEquals(ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection());
assertEquals(ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl());
checkOrganizationApache(metadata);
assertEquals(4, metadata.getMailingLists().size());
assertMailingList("users", metadata.getMailingLists().get(0), "Archiva User List", true, "http://www.nabble.com/archiva-users-f16426.html");
assertMailingList("dev", metadata.getMailingLists().get(1), "Archiva Developer List", true, "http://www.nabble.com/archiva-dev-f16427.html");
assertMailingList("commits", metadata.getMailingLists().get(2), "Archiva Commits List", false, null);
assertMailingList("issues", metadata.getMailingLists().get(3), "Archiva Issues List", false, "http://www.nabble.com/Archiva---Issues-f29617.html");
List<Dependency> dependencies = metadata.getDependencies();
assertEquals(10, dependencies.size());
assertDependency(dependencies.get(0), "commons-lang", "commons-lang", "2.2");
assertDependency(dependencies.get(1), "commons-io", "commons-io", "1.4");
assertDependency(dependencies.get(2), "org.slf4j", "slf4j-api", "1.5.0");
assertDependency(dependencies.get(3), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22");
assertDependency(dependencies.get(4), "org.codehaus.plexus", "plexus-spring", "1.2", "test");
assertDependency(dependencies.get(5), "xalan", "xalan", "2.7.0");
assertDependency(dependencies.get(6), "dom4j", "dom4j", "1.6.1", "test");
assertDependency(dependencies.get(7), "junit", "junit", "3.8.1", "test");
assertDependency(dependencies.get(8), "easymock", "easymock", "1.2_Java1.3", "test");
assertDependency(dependencies.get(9), "easymock", "easymockclassextension", "1.2", "test");
assertEquals(8, metadata.getProperties().size());
assertEquals("http://www.apache.org/images/asf_logo_wide.gif", metadata.getProperties().get("organization.logo"));
}
Aggregations