use of org.apache.archiva.repository.ContentNotFoundException 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;
}
use of org.apache.archiva.repository.ContentNotFoundException in project archiva by apache.
the class ManagedDefaultRepositoryContent method deleteProject.
@Override
public void deleteProject(String namespace, String projectId) throws RepositoryException {
ArtifactReference artifactReference = new ArtifactReference();
artifactReference.setGroupId(namespace);
artifactReference.setArtifactId(projectId);
String path = toPath(artifactReference);
Path directory = Paths.get(getRepoRoot(), path);
if (!Files.exists(directory)) {
throw new ContentNotFoundException("cannot found project " + namespace + ":" + projectId);
}
if (Files.isDirectory(directory)) {
try {
org.apache.archiva.common.utils.FileUtils.deleteDirectory(directory);
} catch (IOException e) {
throw new RepositoryException(e.getMessage(), e);
}
} else {
log.warn("project {}:{} is not a directory", namespace, projectId);
}
}
Aggregations