in repository/service/src/main/java/org/apache/karaf/cave/repository/service/RepositoryServiceImpl.java [513:547]
public void deleteArtifact(String artifactUrl, String name) throws Exception {
if (repositories.get(name) == null) {
throw new IllegalArgumentException("Repository " + name + " doesn't exist");
}
if (repositories.get(name).getLocation() == null || repositories.get(name).getLocation().isEmpty()) {
throw new IllegalStateException("Repository " + name + " location is not defined");
}
Path path;
// if the URL is a mvn URL
if (artifactUrl.startsWith("mvn:")) {
path = Paths.get(repositories.get(name).getLocation()).resolve(Paths.get(convertMvnUrlToPath(artifactUrl)));
} else {
// the artifact location is relative to the repository storage
path = Paths.get(repositories.get(name).getLocation() + "/" + artifactUrl);
}
if (Files.exists(path)) {
if (Files.isDirectory(path)) {
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
} else {
Files.delete(path);
}
}
}