use of org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet in project archiva by apache.
the class DefaultBrowseService method getProjectVersionMetadata.
@Override
public ProjectVersionMetadata getProjectVersionMetadata(String groupId, String artifactId, String repositoryId) throws ArchivaRestServiceException {
List<String> selectedRepos = getSelectedRepos(repositoryId);
RepositorySession repositorySession = null;
try {
Collection<String> projectVersions = getVersions(selectedRepos, groupId, artifactId);
repositorySession = repositorySessionFactory.createSession();
MetadataResolver metadataResolver = repositorySession.getResolver();
ProjectVersionMetadata sharedModel = new ProjectVersionMetadata();
MavenProjectFacet mavenFacet = new MavenProjectFacet();
mavenFacet.setGroupId(groupId);
mavenFacet.setArtifactId(artifactId);
sharedModel.addFacet(mavenFacet);
boolean isFirstVersion = true;
for (String version : projectVersions) {
ProjectVersionMetadata versionMetadata = null;
for (String repoId : selectedRepos) {
if (versionMetadata == null || versionMetadata.isIncomplete()) {
try {
ProjectVersionMetadata projectVersionMetadataResolved = null;
boolean useCache = !StringUtils.endsWith(version, VersionUtil.SNAPSHOT);
String cacheKey = null;
boolean cacheToUpdate = false;
// not a snapshot so get it from cache
if (useCache) {
cacheKey = repoId + groupId + artifactId + version;
projectVersionMetadataResolved = versionMetadataCache.get(cacheKey);
}
if (useCache && projectVersionMetadataResolved != null) {
versionMetadata = projectVersionMetadataResolved;
} else {
projectVersionMetadataResolved = metadataResolver.resolveProjectVersion(repositorySession, repoId, groupId, artifactId, version);
versionMetadata = projectVersionMetadataResolved;
cacheToUpdate = true;
}
if (useCache && cacheToUpdate) {
versionMetadataCache.put(cacheKey, projectVersionMetadataResolved);
}
} catch (MetadataResolutionException e) {
log.error("Skipping invalid metadata while compiling shared model for " + groupId + ":" + artifactId + " in repo " + repoId + ": " + e.getMessage());
}
}
}
if (versionMetadata == null) {
continue;
}
if (isFirstVersion) {
sharedModel = versionMetadata;
sharedModel.setId(null);
} else {
MavenProjectFacet versionMetadataMavenFacet = (MavenProjectFacet) versionMetadata.getFacet(MavenProjectFacet.FACET_ID);
if (versionMetadataMavenFacet != null) {
if (//
mavenFacet.getPackaging() != null && !StringUtils.equalsIgnoreCase(mavenFacet.getPackaging(), versionMetadataMavenFacet.getPackaging())) {
mavenFacet.setPackaging(null);
}
}
if (//
StringUtils.isEmpty(sharedModel.getName()) && !StringUtils.isEmpty(versionMetadata.getName())) {
sharedModel.setName(versionMetadata.getName());
}
if (//
sharedModel.getDescription() != null && !StringUtils.equalsIgnoreCase(sharedModel.getDescription(), versionMetadata.getDescription())) {
sharedModel.setDescription(StringUtils.isNotEmpty(versionMetadata.getDescription()) ? versionMetadata.getDescription() : "");
}
if (//
sharedModel.getIssueManagement() != null && //
versionMetadata.getIssueManagement() != null && !StringUtils.equalsIgnoreCase(sharedModel.getIssueManagement().getUrl(), versionMetadata.getIssueManagement().getUrl())) {
sharedModel.setIssueManagement(versionMetadata.getIssueManagement());
}
if (//
sharedModel.getCiManagement() != null && //
versionMetadata.getCiManagement() != null && !StringUtils.equalsIgnoreCase(sharedModel.getCiManagement().getUrl(), versionMetadata.getCiManagement().getUrl())) {
sharedModel.setCiManagement(versionMetadata.getCiManagement());
}
if (//
sharedModel.getOrganization() != null && //
versionMetadata.getOrganization() != null && !StringUtils.equalsIgnoreCase(sharedModel.getOrganization().getName(), versionMetadata.getOrganization().getName())) {
sharedModel.setOrganization(versionMetadata.getOrganization());
}
if (//
sharedModel.getUrl() != null && !StringUtils.equalsIgnoreCase(sharedModel.getUrl(), versionMetadata.getUrl())) {
sharedModel.setUrl(versionMetadata.getUrl());
}
}
isFirstVersion = false;
}
return sharedModel;
} catch (MetadataResolutionException e) {
throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
} finally {
if (repositorySession != null) {
repositorySession.close();
}
}
}
Aggregations