use of org.apache.archiva.metadata.model.License in project archiva by apache.
the class FileMetadataRepository method updateProjectVersion.
@Override
public void updateProjectVersion(String repoId, String namespace, String projectId, ProjectVersionMetadata versionMetadata) {
try {
updateProject(repoId, namespace, projectId);
Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + versionMetadata.getId());
Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
// remove properties that are not references or artifacts
for (Object key : new ArrayList<>(properties.keySet())) {
String name = (String) key;
if (!name.contains(":") && !name.equals("facetIds")) {
properties.remove(name);
}
// clear the facet contents so old properties are no longer written
clearMetadataFacetProperties(versionMetadata.getFacetList(), properties, "");
}
properties.setProperty("id", versionMetadata.getId());
setProperty(properties, "name", versionMetadata.getName());
setProperty(properties, "description", versionMetadata.getDescription());
setProperty(properties, "url", versionMetadata.getUrl());
setProperty(properties, "incomplete", String.valueOf(versionMetadata.isIncomplete()));
if (versionMetadata.getScm() != null) {
setProperty(properties, "scm.connection", versionMetadata.getScm().getConnection());
setProperty(properties, "scm.developerConnection", versionMetadata.getScm().getDeveloperConnection());
setProperty(properties, "scm.url", versionMetadata.getScm().getUrl());
}
if (versionMetadata.getCiManagement() != null) {
setProperty(properties, "ci.system", versionMetadata.getCiManagement().getSystem());
setProperty(properties, "ci.url", versionMetadata.getCiManagement().getUrl());
}
if (versionMetadata.getIssueManagement() != null) {
setProperty(properties, "issue.system", versionMetadata.getIssueManagement().getSystem());
setProperty(properties, "issue.url", versionMetadata.getIssueManagement().getUrl());
}
if (versionMetadata.getOrganization() != null) {
setProperty(properties, "org.name", versionMetadata.getOrganization().getName());
setProperty(properties, "org.url", versionMetadata.getOrganization().getUrl());
}
int i = 0;
for (License license : versionMetadata.getLicenses()) {
setProperty(properties, "license." + i + ".name", license.getName());
setProperty(properties, "license." + i + ".url", license.getUrl());
i++;
}
i = 0;
for (MailingList mailingList : versionMetadata.getMailingLists()) {
setProperty(properties, "mailingList." + i + ".archive", mailingList.getMainArchiveUrl());
setProperty(properties, "mailingList." + i + ".name", mailingList.getName());
setProperty(properties, "mailingList." + i + ".post", mailingList.getPostAddress());
setProperty(properties, "mailingList." + i + ".unsubscribe", mailingList.getUnsubscribeAddress());
setProperty(properties, "mailingList." + i + ".subscribe", mailingList.getSubscribeAddress());
setProperty(properties, "mailingList." + i + ".otherArchives", join(mailingList.getOtherArchives()));
i++;
}
i = 0;
ProjectVersionReference reference = new ProjectVersionReference();
reference.setNamespace(namespace);
reference.setProjectId(projectId);
reference.setProjectVersion(versionMetadata.getId());
reference.setReferenceType(ProjectVersionReference.ReferenceType.DEPENDENCY);
for (Dependency dependency : versionMetadata.getDependencies()) {
setProperty(properties, "dependency." + i + ".classifier", dependency.getClassifier());
setProperty(properties, "dependency." + i + ".scope", dependency.getScope());
setProperty(properties, "dependency." + i + ".systemPath", dependency.getSystemPath());
setProperty(properties, "dependency." + i + ".artifactId", dependency.getArtifactId());
setProperty(properties, "dependency." + i + ".groupId", dependency.getGroupId());
setProperty(properties, "dependency." + i + ".version", dependency.getVersion());
setProperty(properties, "dependency." + i + ".type", dependency.getType());
setProperty(properties, "dependency." + i + ".optional", String.valueOf(dependency.isOptional()));
updateProjectReference(repoId, dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), reference);
i++;
}
Set<String> facetIds = new LinkedHashSet<>(versionMetadata.getFacetIds());
facetIds.addAll(Arrays.asList(properties.getProperty("facetIds", "").split(",")));
properties.setProperty("facetIds", join(facetIds));
updateProjectVersionFacets(versionMetadata, properties);
writeProperties(properties, directory, PROJECT_VERSION_METADATA_KEY);
} catch (IOException e) {
log.error("Could not update project version {}, {}, {}: {}", repoId, namespace, versionMetadata.getId(), e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.model.License in project archiva by apache.
the class CassandraMetadataRepository method recordLicenses.
protected void recordLicenses(String projectVersionMetadataKey, List<License> licenses) {
if (licenses == null || licenses.isEmpty()) {
return;
}
Mutator<String> licenseMutator = this.licenseTemplate.createMutator();
for (License license : licenses) {
// we don't care about the key as the real used one with the projectVersionMetadata
String keyLicense = UUID.randomUUID().toString();
String cfLicense = cassandraArchivaManager.getLicenseFamilyName();
addInsertion(licenseMutator, keyLicense, cfLicense, "projectVersionMetadataModel.key", projectVersionMetadataKey);
addInsertion(licenseMutator, keyLicense, cfLicense, NAME.toString(), license.getName());
addInsertion(licenseMutator, keyLicense, cfLicense, URL.toString(), license.getUrl());
}
licenseMutator.execute();
}
use of org.apache.archiva.metadata.model.License in project archiva by apache.
the class AbstractMetadataRepositoryTest method testUpdateProjectVersionMetadataWithAllElements.
@Test
public void testUpdateProjectVersionMetadataWithAllElements() throws Exception {
ProjectVersionMetadata metadata = new ProjectVersionMetadata();
metadata.setId(TEST_PROJECT_VERSION);
metadata.setName("project name");
metadata.setDescription("project description");
metadata.setUrl("the url");
MailingList mailingList = new MailingList();
mailingList.setName("Foo List");
mailingList.setUnsubscribeAddress("UnsubscribeAddress");
mailingList.setSubscribeAddress("SubscribeAddress");
mailingList.setPostAddress("PostAddress");
mailingList.setMainArchiveUrl("MainArchiveUrl");
mailingList.setOtherArchives(Arrays.asList("other archive"));
metadata.setMailingLists(Arrays.asList(mailingList));
Scm scm = new Scm();
scm.setConnection("connection");
scm.setDeveloperConnection("dev conn");
scm.setUrl("url");
metadata.setScm(scm);
CiManagement ci = new CiManagement();
ci.setSystem("system");
ci.setUrl("ci url");
metadata.setCiManagement(ci);
IssueManagement tracker = new IssueManagement();
tracker.setSystem("system");
tracker.setUrl("issue tracker url");
metadata.setIssueManagement(tracker);
metadata.setOrganization(TEST_ORGANIZATION);
License l = new License();
l.setName("license name");
l.setUrl("license url");
metadata.addLicense(l);
Dependency d = new Dependency();
d.setArtifactId("artifactId");
d.setClassifier("classifier");
d.setGroupId("groupId");
d.setScope("scope");
d.setSystemPath("system path");
d.setType("type");
d.setVersion("version");
d.setOptional(true);
metadata.addDependency(d);
repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
metadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
assertEquals(TEST_PROJECT_VERSION, metadata.getId());
assertEquals(TEST_PROJECT_VERSION, metadata.getVersion());
assertEquals("project name", metadata.getName());
assertEquals("project description", metadata.getDescription());
assertEquals("the url", metadata.getUrl());
assertEquals("connection", metadata.getScm().getConnection());
assertEquals("dev conn", metadata.getScm().getDeveloperConnection());
assertEquals("url", metadata.getScm().getUrl());
assertEquals("system", metadata.getCiManagement().getSystem());
assertEquals("ci url", metadata.getCiManagement().getUrl());
assertEquals("system", metadata.getIssueManagement().getSystem());
assertEquals("issue tracker url", metadata.getIssueManagement().getUrl());
assertEquals(TEST_ORGANIZATION.getName(), metadata.getOrganization().getName());
assertEquals(TEST_ORGANIZATION.getUrl(), metadata.getOrganization().getUrl());
assertEquals(1, metadata.getMailingLists().size());
MailingList retrievedMailingList = metadata.getMailingLists().get(0);
assertEquals(mailingList.getName(), retrievedMailingList.getName());
assertEquals(mailingList.getMainArchiveUrl(), retrievedMailingList.getMainArchiveUrl());
assertEquals(mailingList.getPostAddress(), retrievedMailingList.getPostAddress());
assertEquals(mailingList.getSubscribeAddress(), retrievedMailingList.getSubscribeAddress());
assertEquals(mailingList.getUnsubscribeAddress(), retrievedMailingList.getUnsubscribeAddress());
//
assertThat(retrievedMailingList.getOtherArchives()).isNotNull().isNotEmpty().hasSize(//
1).contains("other archive");
assertEquals(1, metadata.getLicenses().size());
l = metadata.getLicenses().get(0);
assertEquals("license name", l.getName());
assertEquals("license url", l.getUrl());
assertEquals(1, metadata.getDependencies().size());
d = metadata.getDependencies().get(0);
assertEquals("artifactId", d.getArtifactId());
assertEquals("classifier", d.getClassifier());
assertEquals("groupId", d.getGroupId());
assertEquals("scope", d.getScope());
assertEquals("system path", d.getSystemPath());
assertEquals("type", d.getType());
assertEquals("version", d.getVersion());
assertTrue(d.isOptional());
}
use of org.apache.archiva.metadata.model.License in project archiva by apache.
the class CassandraMetadataRepository method getLicenses.
protected List<License> getLicenses(String projectVersionMetadataKey) {
List<License> licenses = new ArrayList<>();
QueryResult<OrderedRows<String, String, String>> result = //
HFactory.createRangeSlicesQuery(cassandraArchivaManager.getKeyspace(), ss, ss, ss).setColumnFamily(//
cassandraArchivaManager.getLicenseFamilyName()).setColumnNames(//
"projectVersionMetadataModel.key").setRowCount(//
Integer.MAX_VALUE).addEqualsExpression("projectVersionMetadataModel.key", //
projectVersionMetadataKey).execute();
for (Row<String, String, String> row : result.get()) {
ColumnFamilyResult<String, String> columnFamilyResult = this.licenseTemplate.queryColumns(row.getKey());
licenses.add(new License(columnFamilyResult.getString(NAME.toString()), columnFamilyResult.getString(URL.toString())));
}
return licenses;
}
use of org.apache.archiva.metadata.model.License 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);
}
}
Aggregations