fixed missing group/artifact paths on purge
This commit is contained in:
@@ -23,6 +23,7 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -90,10 +91,13 @@ public class PurgeRepoMojo extends AbstractMojo {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Path groupPath = this.getGroupPath(afilter);
|
Path groupPath = this.resolveGroupPath(afilter);
|
||||||
List<Path> artifactPaths = this.getArtifactPaths(groupPath, afilter);
|
if (groupPath == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
List<Path> artifactPaths = this.resolveArtifactPaths(groupPath, afilter);
|
||||||
for (Path artifactPath : artifactPaths)
|
for (Path artifactPath : artifactPaths)
|
||||||
includePaths.addAll(this.getVersionPaths(artifactPath, afilter.getVersionRange()));
|
includePaths.addAll(this.resolveVersionPaths(artifactPath, afilter.getVersionRange()));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getLog().debug("May be purging all files in " + includePaths.size() + " paths");
|
this.getLog().debug("May be purging all files in " + includePaths.size() + " paths");
|
||||||
@@ -105,7 +109,7 @@ public class PurgeRepoMojo extends AbstractMojo {
|
|||||||
StringBuilder regex = new StringBuilder();
|
StringBuilder regex = new StringBuilder();
|
||||||
|
|
||||||
if (afilter.getGroupId() != null) {
|
if (afilter.getGroupId() != null) {
|
||||||
regex.append('^').append(this.getGroupPath(afilter));
|
regex.append('^').append(this.resolveGroupPath(afilter));
|
||||||
} else if (afilter.getGroupIdRegex() != null) {
|
} else if (afilter.getGroupIdRegex() != null) {
|
||||||
regex.append(afilter.getGroupIdRegex().replace("\\.", regexDirectorySeparator));
|
regex.append(afilter.getGroupIdRegex().replace("\\.", regexDirectorySeparator));
|
||||||
if (regex.charAt(0) != '^')
|
if (regex.charAt(0) != '^')
|
||||||
@@ -171,20 +175,39 @@ public class PurgeRepoMojo extends AbstractMojo {
|
|||||||
return new BanConfigurationParser(this.session, this.artifactResolver, plugin);
|
return new BanConfigurationParser(this.session, this.artifactResolver, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path getGroupPath(ArtifactFilter afilter) {
|
private Path resolveGroupPath(ArtifactFilter afilter) {
|
||||||
|
if (afilter.getGroupId() == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
String[] pathElements = afilter.getGroupId().split("\\.");
|
String[] pathElements = afilter.getGroupId().split("\\.");
|
||||||
Path groupPath = Paths.get("");
|
Path groupPath = Paths.get("");
|
||||||
for (String pathElement : pathElements)
|
for (String pathElement : pathElements)
|
||||||
groupPath = groupPath.resolve(pathElement);
|
groupPath = groupPath.resolve(pathElement);
|
||||||
|
|
||||||
|
Path fullGroupPath = this.getRepositoryPath().resolve(groupPath);
|
||||||
|
if (!Files.exists(fullGroupPath)) {
|
||||||
|
this.getLog().debug("The group path does not exist, so nothing to purge: " + fullGroupPath);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return groupPath;
|
return groupPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Path> getArtifactPaths(Path groupPath, ArtifactFilter afilter) throws IOException {
|
private List<Path> resolveArtifactPaths(Path groupPath, ArtifactFilter afilter) throws IOException {
|
||||||
if (afilter.getArtifactId() != null)
|
Path repoPath = this.getRepositoryPath();
|
||||||
return Arrays.asList(groupPath.resolve(afilter.getArtifactId()));
|
|
||||||
|
if (afilter.getArtifactId() != null) {
|
||||||
|
Path artifactPath = groupPath.resolve(afilter.getArtifactId());
|
||||||
|
Path fullArtifactPath = repoPath.resolve(artifactPath);
|
||||||
|
if (Files.exists(fullArtifactPath)) {
|
||||||
|
return Arrays.asList(artifactPath);
|
||||||
|
} else {
|
||||||
|
this.getLog().debug("The artifact path does not exist, so nothing to purge: " + fullArtifactPath);
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Pattern artifactPattern = afilter.getArtifactIdRegex() == null ? null : Pattern.compile(afilter.getArtifactIdRegex());
|
Pattern artifactPattern = afilter.getArtifactIdRegex() == null ? null : Pattern.compile(afilter.getArtifactIdRegex());
|
||||||
Path repoPath = this.getRepositoryPath();
|
|
||||||
List<Path> paths = new LinkedList<>();
|
List<Path> paths = new LinkedList<>();
|
||||||
|
|
||||||
if (artifactPattern == null)
|
if (artifactPattern == null)
|
||||||
@@ -208,7 +231,7 @@ public class PurgeRepoMojo extends AbstractMojo {
|
|||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Path> getVersionPaths(Path artifactPath, VersionRange versionRange) throws IOException {
|
private List<Path> resolveVersionPaths(Path artifactPath, VersionRange versionRange) throws IOException {
|
||||||
Path repoPath = this.getRepositoryPath();
|
Path repoPath = this.getRepositoryPath();
|
||||||
List<Path> paths = new LinkedList<>();
|
List<Path> paths = new LinkedList<>();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user