use of org.apache.archiva.metadata.model.ProjectVersionReference in project archiva by apache.
the class AbstractMetadataRepositoryTest method testgetProjectReferences.
@Test
public void testgetProjectReferences() throws Exception {
ProjectVersionMetadata metadata = new ProjectVersionMetadata();
metadata.setId(TEST_PROJECT_VERSION);
metadata.setName("project name");
metadata.setDescription("project description");
metadata.setUrl("the url");
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);
d = new Dependency();
d.setArtifactId("artifactId1");
d.setClassifier("classifier");
d.setGroupId("groupId");
d.setScope("scope");
d.setSystemPath("system path");
d.setType("type");
d.setVersion("version1");
d.setOptional(true);
metadata.addDependency(d);
repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
repository.save();
metadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
Collection<ProjectVersionReference> references = repository.getProjectReferences(TEST_REPO_ID, d.getGroupId(), d.getArtifactId(), d.getVersion());
log.info("references: {}", references);
assertThat(references).isNotNull().hasSize(1).contains(new ProjectVersionReference(ProjectVersionReference.ReferenceType.DEPENDENCY, TEST_PROJECT, TEST_NAMESPACE, TEST_PROJECT_VERSION));
}
use of org.apache.archiva.metadata.model.ProjectVersionReference 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.ProjectVersionReference in project archiva by apache.
the class FileMetadataRepository method getProjectReferences.
@Override
public Collection<ProjectVersionReference> getProjectReferences(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);
int numberOfRefs = Integer.parseInt(properties.getProperty("ref:lastReferenceNum", "-1")) + 1;
List<ProjectVersionReference> references = new ArrayList<>();
for (int i = 0; i < numberOfRefs; i++) {
ProjectVersionReference reference = new ProjectVersionReference();
reference.setProjectId(properties.getProperty("ref:reference." + i + ".projectId"));
reference.setNamespace(properties.getProperty("ref:reference." + i + ".namespace"));
reference.setProjectVersion(properties.getProperty("ref:reference." + i + ".projectVersion"));
reference.setReferenceType(ProjectVersionReference.ReferenceType.valueOf(properties.getProperty("ref:reference." + i + ".referenceType")));
references.add(reference);
}
return references;
} catch (IOException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.model.ProjectVersionReference in project archiva by apache.
the class DefaultBrowseService method getDependees.
@Override
public List<Artifact> getDependees(String groupId, String artifactId, String version, String repositoryId) throws ArchivaRestServiceException {
List<ProjectVersionReference> references = new ArrayList<>();
// TODO: what if we get duplicates across repositories?
RepositorySession repositorySession = repositorySessionFactory.createSession();
try {
MetadataResolver metadataResolver = repositorySession.getResolver();
for (String repoId : getObservableRepos()) {
// TODO: what about if we want to see this irrespective of version?
references.addAll(metadataResolver.resolveProjectReferences(repositorySession, repoId, groupId, artifactId, version));
}
} catch (MetadataResolutionException e) {
throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
} finally {
repositorySession.close();
}
List<Artifact> artifacts = new ArrayList<>(references.size());
for (ProjectVersionReference projectVersionReference : references) {
artifacts.add(new Artifact(projectVersionReference.getNamespace(), projectVersionReference.getProjectId(), projectVersionReference.getProjectVersion()));
}
return artifacts;
}
use of org.apache.archiva.metadata.model.ProjectVersionReference in project archiva by apache.
the class DefaultMetadataResolver method resolveProjectVersion.
@Override
public ProjectVersionMetadata resolveProjectVersion(RepositorySession session, String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
MetadataRepository metadataRepository = session.getRepository();
ProjectVersionMetadata metadata = metadataRepository.getProjectVersion(repoId, namespace, projectId, projectVersion);
// may then work here and be more efficient than always trying again)
if (metadata == null || metadata.isIncomplete()) {
try {
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(namespace).projectId(projectId).projectVersion(projectVersion).browsingRequest(true);
metadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
log.debug("Resolved project version metadata from storage: {}", metadata);
// eg. maven projects should be able to process parent here
if (!metadata.getDependencies().isEmpty()) {
ProjectVersionReference ref = new ProjectVersionReference();
ref.setNamespace(namespace);
ref.setProjectId(projectId);
ref.setProjectVersion(projectVersion);
ref.setReferenceType(ProjectVersionReference.ReferenceType.DEPENDENCY);
}
try {
for (RepositoryListener listener : listeners) {
listener.addArtifact(session, repoId, namespace, projectId, metadata);
}
metadataRepository.updateProjectVersion(repoId, namespace, projectId, metadata);
} catch (MetadataRepositoryException e) {
log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
}
session.markDirty();
} catch (RepositoryStorageMetadataInvalidException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
throw new MetadataResolutionException(e.getMessage(), e);
} catch (RepositoryStorageMetadataNotFoundException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
// no need to rethrow - return null
} catch (RepositoryStorageRuntimeException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
throw new MetadataResolutionException(e.getMessage(), e);
}
}
return metadata;
}
Aggregations