use of org.apache.archiva.repository.LayoutException in project archiva by apache.
the class ManagedDefaultRepositoryContent method getRelatedArtifacts.
@Override
public Set<ArtifactReference> getRelatedArtifacts(ArtifactReference reference) throws ContentNotFoundException {
Path artifactFile = toFile(reference);
Path repoBase = PathUtil.getPathFromUri(repository.getLocation()).toAbsolutePath();
Path repoDir = artifactFile.getParent().toAbsolutePath();
if (!Files.exists(repoDir)) {
throw new ContentNotFoundException("Unable to get related artifacts using a non-existant directory: " + repoDir.toAbsolutePath());
}
if (!Files.isDirectory(repoDir)) {
throw new ContentNotFoundException("Unable to get related artifacts using a non-directory: " + repoDir.toAbsolutePath());
}
Set<ArtifactReference> foundArtifacts;
try (Stream<Path> stream = Files.list(repoDir)) {
foundArtifacts = stream.filter(Files::isRegularFile).map(path -> {
try {
ArtifactReference artifact = toArtifactReference(repoBase.relativize(path).toString());
if (artifact.getGroupId().equals(reference.getGroupId()) && artifact.getArtifactId().equals(reference.getArtifactId()) && artifact.getVersion().equals(reference.getVersion())) {
return artifact;
} else {
return null;
}
} catch (LayoutException e) {
log.debug("Not processing file that is not an artifact: {}", e.getMessage());
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toSet());
} catch (IOException e) {
log.error("Could not read directory {}: {}", repoDir, e.getMessage(), e);
return Collections.emptySet();
}
return foundArtifacts;
}
Aggregations