use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.
the class FileMetadataRepository method getProjects.
@Override
public Collection<String> getProjects(String repoId, String namespace) throws MetadataResolutionException {
try {
List<String> projects;
Path directory = getDirectory(repoId).resolve(namespace);
if (!(Files.exists(directory) && Files.isDirectory(directory))) {
return Collections.emptyList();
}
final String searchFile = PROJECT_METADATA_KEY + ".properties";
try (Stream<Path> fs = Files.list(directory)) {
projects = fs.filter(Files::isDirectory).filter(path -> Files.exists(path.resolve(searchFile))).map(path -> path.getFileName().toString()).collect(Collectors.toList());
}
return projects;
} 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 getProject.
@Override
public ProjectMetadata getProject(String repoId, String namespace, String projectId) throws MetadataResolutionException {
try {
Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId);
Properties properties = readOrCreateProperties(directory, PROJECT_METADATA_KEY);
ProjectMetadata project = null;
String id = properties.getProperty("id");
if (id != null) {
project = new ProjectMetadata();
project.setNamespace(properties.getProperty("namespace"));
project.setId(id);
}
return project;
} 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 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.repository.MetadataResolutionException in project archiva by apache.
the class FileMetadataRepository method getArtifacts.
@Override
public Collection<ArtifactMetadata> getArtifacts(String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
try {
Map<String, ArtifactMetadata> artifacts = new HashMap<>();
Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + projectVersion);
Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
for (Map.Entry entry : properties.entrySet()) {
String name = (String) entry.getKey();
StringTokenizer tok = new StringTokenizer(name, ":");
if (tok.hasMoreTokens() && "artifact".equals(tok.nextToken())) {
String field = tok.nextToken();
String id = tok.nextToken();
ArtifactMetadata artifact = artifacts.get(id);
if (artifact == null) {
artifact = new ArtifactMetadata();
artifact.setRepositoryId(repoId);
artifact.setNamespace(namespace);
artifact.setProject(projectId);
artifact.setProjectVersion(projectVersion);
artifact.setVersion(projectVersion);
artifact.setId(id);
artifacts.put(id, artifact);
}
String value = (String) entry.getValue();
if ("updated".equals(field)) {
artifact.setFileLastModified(Long.parseLong(value));
} else if ("size".equals(field)) {
artifact.setSize(Long.valueOf(value));
} else if ("whenGathered".equals(field)) {
artifact.setWhenGathered(new Date(Long.parseLong(value)));
} else if ("version".equals(field)) {
artifact.setVersion(value);
} else if ("md5".equals(field)) {
artifact.setMd5(value);
} else if ("sha1".equals(field)) {
artifact.setSha1(value);
} else if ("facetIds".equals(field)) {
if (value.length() > 0) {
String propertyPrefix = "artifact:facet:" + id + ":";
for (String facetId : value.split(",")) {
MetadataFacetFactory factory = metadataFacetFactories.get(facetId);
if (factory == null) {
log.error("Attempted to load unknown artifact metadata facet: {}", facetId);
} else {
MetadataFacet facet = factory.createMetadataFacet();
String prefix = propertyPrefix + facet.getFacetId();
Map<String, String> map = new HashMap<>();
for (Object key : new ArrayList<>(properties.keySet())) {
String property = (String) key;
if (property.startsWith(prefix)) {
map.put(property.substring(prefix.length() + 1), properties.getProperty(property));
}
}
facet.fromProperties(map);
artifact.addFacet(facet);
}
}
}
updateArtifactFacets(artifact, properties);
}
}
}
return artifacts.values();
} 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 getArtifactsByDateRange.
@Override
public List<ArtifactMetadata> getArtifactsByDateRange(String repoId, Date startTime, Date endTime) throws MetadataRepositoryException {
try {
// TODO: this is quite slow - if we are to persist with this repository implementation we should build an index
// of this information (eg. in Lucene, as before)
List<ArtifactMetadata> artifacts = new ArrayList<>();
for (String ns : getRootNamespaces(repoId)) {
getArtifactsByDateRange(artifacts, repoId, ns, startTime, endTime);
}
artifacts.sort(new ArtifactComparator());
return artifacts;
} catch (MetadataResolutionException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
Aggregations