use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.
the class FileMetadataRepository method getProjectVersion.
@Override
public ProjectVersionMetadata getProjectVersion(String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
try {
Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + projectVersion);
Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
String id = properties.getProperty("id");
ProjectVersionMetadata versionMetadata = null;
if (id != null) {
versionMetadata = new ProjectVersionMetadata();
versionMetadata.setId(id);
versionMetadata.setName(properties.getProperty("name"));
versionMetadata.setDescription(properties.getProperty("description"));
versionMetadata.setUrl(properties.getProperty("url"));
versionMetadata.setIncomplete(Boolean.valueOf(properties.getProperty("incomplete", "false")));
String scmConnection = properties.getProperty("scm.connection");
String scmDeveloperConnection = properties.getProperty("scm.developerConnection");
String scmUrl = properties.getProperty("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 = properties.getProperty("ci.system");
String ciUrl = properties.getProperty("ci.url");
if (ciSystem != null || ciUrl != null) {
CiManagement ci = new CiManagement();
ci.setSystem(ciSystem);
ci.setUrl(ciUrl);
versionMetadata.setCiManagement(ci);
}
String issueSystem = properties.getProperty("issue.system");
String issueUrl = properties.getProperty("issue.url");
if (issueSystem != null || issueUrl != null) {
IssueManagement issueManagement = new IssueManagement();
issueManagement.setSystem(issueSystem);
issueManagement.setUrl(issueUrl);
versionMetadata.setIssueManagement(issueManagement);
}
String orgName = properties.getProperty("org.name");
String orgUrl = properties.getProperty("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 = properties.getProperty("license." + i + ".name");
String licenseUrl = properties.getProperty("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 = properties.getProperty("mailingList." + i + ".name");
if (mailingListName != null) {
MailingList mailingList = new MailingList();
mailingList.setName(mailingListName);
mailingList.setMainArchiveUrl(properties.getProperty("mailingList." + i + ".archive"));
String p = properties.getProperty("mailingList." + i + ".otherArchives");
if (p != null && p.length() > 0) {
mailingList.setOtherArchives(Arrays.asList(p.split(",")));
} else {
mailingList.setOtherArchives(Collections.emptyList());
}
mailingList.setPostAddress(properties.getProperty("mailingList." + i + ".post"));
mailingList.setSubscribeAddress(properties.getProperty("mailingList." + i + ".subscribe"));
mailingList.setUnsubscribeAddress(properties.getProperty("mailingList." + i + ".unsubscribe"));
versionMetadata.addMailingList(mailingList);
} else {
done = true;
}
i++;
}
done = false;
i = 0;
while (!done) {
String dependencyArtifactId = properties.getProperty("dependency." + i + ".artifactId");
if (dependencyArtifactId != null) {
Dependency dependency = new Dependency();
dependency.setArtifactId(dependencyArtifactId);
dependency.setGroupId(properties.getProperty("dependency." + i + ".groupId"));
dependency.setClassifier(properties.getProperty("dependency." + i + ".classifier"));
dependency.setOptional(Boolean.valueOf(properties.getProperty("dependency." + i + ".optional")));
dependency.setScope(properties.getProperty("dependency." + i + ".scope"));
dependency.setSystemPath(properties.getProperty("dependency." + i + ".systemPath"));
dependency.setType(properties.getProperty("dependency." + i + ".type"));
dependency.setVersion(properties.getProperty("dependency." + i + ".version"));
dependency.setOptional(Boolean.valueOf(properties.getProperty("dependency." + i + ".optional")));
versionMetadata.addDependency(dependency);
} else {
done = true;
}
i++;
}
String facetIds = properties.getProperty("facetIds", "");
if (facetIds.length() > 0) {
for (String facetId : facetIds.split(",")) {
MetadataFacetFactory factory = metadataFacetFactories.get(facetId);
if (factory == null) {
log.error("Attempted to load unknown project version metadata facet: {}", facetId);
} else {
MetadataFacet facet = factory.createMetadataFacet();
Map<String, String> map = new HashMap<>();
for (Object key : new ArrayList<>(properties.keySet())) {
String property = (String) key;
if (property.startsWith(facet.getFacetId())) {
map.put(property.substring(facet.getFacetId().length() + 1), properties.getProperty(property));
}
}
facet.fromProperties(map);
versionMetadata.addFacet(facet);
}
}
}
updateProjectVersionFacets(versionMetadata, properties);
}
return versionMetadata;
} catch (IOException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.model.ProjectVersionMetadata 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.ProjectVersionMetadata in project archiva by apache.
the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo.
@Test
public void testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo() throws Exception {
copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-module-a", "target/test-repository/com/example/test/test-artifact-module-a");
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(TEST_REPO_ID).namespace("com.example.test").projectId("missing-parent").projectVersion("1.1");
ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(readMetadataRequest);
assertEquals("1.1", metadata.getId());
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet(MavenProjectFacet.FACET_ID);
assertNotNull(facet);
assertEquals("com.example.test", facet.getGroupId());
assertEquals("missing-parent", facet.getArtifactId());
assertEquals("jar", facet.getPackaging());
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.ProjectVersionMetadata 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.ProjectVersionMetadata in project archiva by apache.
the class Maven2RepositoryMetadataResolverMRM1411Test method testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed.
@Test
public void testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed() throws Exception {
testRepo.setSnapshots(false);
configuration.save(c);
repositoryRegistry.reload();
assertFalse(c.getManagedRepositories().get(0).isSnapshots());
copyTestArtifactWithParent("target/test-classes/com/example/test/test-snapshot-artifact-module-a", "target/test-repository/com/example/test/test-snapshot-artifact-module-a");
try {
ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a", "1.1-SNAPSHOT"));
fail("Should not be found");
} catch (RepositoryStorageRuntimeException e) {
}
List<String> paths = new ArrayList<>();
paths.add("target/test-repository/com/example/test/test-snapshot-artifact-module-a");
paths.add("target/test-repository/com/example/test/test-snapshot-artifact-root");
deleteTestArtifactWithParent(paths);
}
Aggregations