From fe10e53fb4652ec69fa0d06e66b07bf9881c2f07 Mon Sep 17 00:00:00 2001 From: "Brian M. Long" Date: Sun, 20 Aug 2023 11:26:07 -0400 Subject: [PATCH 1/3] added goal prefix config: "ban" --- pom.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pom.xml b/pom.xml index 9b4dd42..855902d 100644 --- a/pom.xml +++ b/pom.xml @@ -106,6 +106,9 @@ descriptor + + ban + help-descriptor From 24d69c3715a62ef993d6bdac1c34d2e4de5f9278 Mon Sep 17 00:00:00 2001 From: "Brian M. Long" Date: Sun, 20 Aug 2023 11:26:24 -0400 Subject: [PATCH 2/3] forcing extension to "xml" --- .../java/com/inteligr8/maven/ban/AbstractBanConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/inteligr8/maven/ban/AbstractBanConfiguration.java b/src/main/java/com/inteligr8/maven/ban/AbstractBanConfiguration.java index 418d354..14d7753 100644 --- a/src/main/java/com/inteligr8/maven/ban/AbstractBanConfiguration.java +++ b/src/main/java/com/inteligr8/maven/ban/AbstractBanConfiguration.java @@ -73,7 +73,7 @@ public abstract class AbstractBanConfiguration implements BanConfiguration { downloader = new BanConfigurationDownloader(this.session, this.artifactResolver, url); } else if (child.getName().equals("artifact")) { Artifact artifact = new DefaultArtifact(child.getValue()); - if (artifact.getExtension() == null) + if (!"xml".equals(artifact.getExtension())) artifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), "xml", artifact.getVersion()); ArtifactRequest request = new ArtifactRequest(artifact, this.session.getCurrentProject().getRemoteProjectRepositories(), null); From 51f5d6d0a3c20b75da7c27852f5ec6b0326d7538 Mon Sep 17 00:00:00 2001 From: "Brian M. Long" Date: Sun, 20 Aug 2023 11:35:12 -0400 Subject: [PATCH 3/3] fixed missing group/artifact paths on purge --- .../inteligr8/maven/ban/PurgeRepoMojo.java | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/inteligr8/maven/ban/PurgeRepoMojo.java b/src/main/java/com/inteligr8/maven/ban/PurgeRepoMojo.java index d544675..2ba8e9e 100644 --- a/src/main/java/com/inteligr8/maven/ban/PurgeRepoMojo.java +++ b/src/main/java/com/inteligr8/maven/ban/PurgeRepoMojo.java @@ -23,6 +23,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -90,10 +91,13 @@ public class PurgeRepoMojo extends AbstractMojo { continue; } - Path groupPath = this.getGroupPath(afilter); - List artifactPaths = this.getArtifactPaths(groupPath, afilter); + Path groupPath = this.resolveGroupPath(afilter); + if (groupPath == null) + continue; + + List artifactPaths = this.resolveArtifactPaths(groupPath, afilter); 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"); @@ -105,7 +109,7 @@ public class PurgeRepoMojo extends AbstractMojo { StringBuilder regex = new StringBuilder(); if (afilter.getGroupId() != null) { - regex.append('^').append(this.getGroupPath(afilter)); + regex.append('^').append(this.resolveGroupPath(afilter)); } else if (afilter.getGroupIdRegex() != null) { regex.append(afilter.getGroupIdRegex().replace("\\.", regexDirectorySeparator)); if (regex.charAt(0) != '^') @@ -171,20 +175,39 @@ public class PurgeRepoMojo extends AbstractMojo { 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("\\."); Path groupPath = Paths.get(""); for (String pathElement : pathElements) 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; } - private List getArtifactPaths(Path groupPath, ArtifactFilter afilter) throws IOException { - if (afilter.getArtifactId() != null) - return Arrays.asList(groupPath.resolve(afilter.getArtifactId())); + private List resolveArtifactPaths(Path groupPath, ArtifactFilter afilter) throws IOException { + Path repoPath = this.getRepositoryPath(); + + 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()); - Path repoPath = this.getRepositoryPath(); List paths = new LinkedList<>(); if (artifactPattern == null) @@ -208,7 +231,7 @@ public class PurgeRepoMojo extends AbstractMojo { return paths; } - private List getVersionPaths(Path artifactPath, VersionRange versionRange) throws IOException { + private List resolveVersionPaths(Path artifactPath, VersionRange versionRange) throws IOException { Path repoPath = this.getRepositoryPath(); List paths = new LinkedList<>();