use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.
the class FileMetadataRepository method getArtifactVersions.
@Override
public Collection<String> getArtifactVersions(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);
Set<String> versions = new HashSet<>();
for (Map.Entry entry : properties.entrySet()) {
String name = (String) entry.getKey();
if (name.startsWith("artifact:version:")) {
versions.add((String) entry.getValue());
}
}
return versions;
} catch (IOException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.
the class FileMetadataRepository method getNamespaces.
@Override
public Collection<String> getNamespaces(String repoId, String baseNamespace) throws MetadataResolutionException {
try {
List<String> allNamespaces;
Path directory = getDirectory(repoId);
if (!(Files.exists(directory) && Files.isDirectory(directory))) {
return Collections.emptyList();
}
final String searchFile = NAMESPACE_METADATA_KEY + ".properties";
try (Stream<Path> fs = Files.list(directory)) {
allNamespaces = fs.filter(Files::isDirectory).filter(path -> Files.exists(path.resolve(searchFile))).map(path -> path.getFileName().toString()).collect(Collectors.toList());
}
Set<String> namespaces = new LinkedHashSet<>();
int fromIndex = baseNamespace != null ? baseNamespace.length() + 1 : 0;
for (String namespace : allNamespaces) {
if (baseNamespace == null || namespace.startsWith(baseNamespace + ".")) {
int i = namespace.indexOf('.', fromIndex);
if (i >= 0) {
namespaces.add(namespace.substring(fromIndex, i));
} else {
namespaces.add(namespace.substring(fromIndex));
}
}
}
return new ArrayList<>(namespaces);
} catch (IOException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataResolutionException 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.repository.MetadataResolutionException in project archiva by apache.
the class FileMetadataRepository method getProjectVersions.
@Override
public Collection<String> getProjectVersions(String repoId, String namespace, String projectId) throws MetadataResolutionException {
try {
List<String> projectVersions;
Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId);
if (!(Files.exists(directory) && Files.isDirectory(directory))) {
return Collections.emptyList();
}
final String searchFile = PROJECT_VERSION_METADATA_KEY + ".properties";
try (Stream<Path> fs = Files.list(directory)) {
projectVersions = fs.filter(Files::isDirectory).filter(path -> Files.exists(path.resolve(searchFile))).map(path -> path.getFileName().toString()).collect(Collectors.toList());
}
return projectVersions;
} catch (IOException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.
the class JcrMetadataRepository method getProjectReferences.
@Override
public Collection<ProjectVersionReference> getProjectReferences(String repositoryId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
List<ProjectVersionReference> references = new ArrayList<>();
// TODO: bind variables instead
String q = "SELECT * FROM [archiva:dependency] WHERE ISDESCENDANTNODE([/repositories/" + repositoryId + "/content]) AND [groupId]='" + namespace + "' AND [artifactId]='" + projectId + "'";
if (projectVersion != null) {
q += " AND [version]='" + projectVersion + "'";
}
try {
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2);
QueryResult result = query.execute();
for (Node n : JcrUtils.getNodes(result)) {
// dependencies grouping element
n = n.getParent();
// project version
n = n.getParent();
String usedByProjectVersion = n.getName();
// project
n = n.getParent();
String usedByProject = n.getName();
// namespace
n = n.getParent();
String usedByNamespace = n.getProperty("namespace").getString();
ProjectVersionReference ref = new ProjectVersionReference();
ref.setNamespace(usedByNamespace);
ref.setProjectId(usedByProject);
ref.setProjectVersion(usedByProjectVersion);
ref.setReferenceType(ProjectVersionReference.ReferenceType.DEPENDENCY);
references.add(ref);
}
} catch (RepositoryException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
return references;
}
Aggregations