8 Commits

3 changed files with 40 additions and 12 deletions

View File

@@ -7,7 +7,7 @@
<groupId>com.inteligr8</groupId> <groupId>com.inteligr8</groupId>
<artifactId>ban-maven-plugin</artifactId> <artifactId>ban-maven-plugin</artifactId>
<version>1.2.2</version> <version>1.2.4</version>
<packaging>maven-plugin</packaging> <packaging>maven-plugin</packaging>
<name>Ban Dependencies Maven Plugin</name> <name>Ban Dependencies Maven Plugin</name>
@@ -106,6 +106,9 @@
<goals> <goals>
<goal>descriptor</goal> <goal>descriptor</goal>
</goals> </goals>
<configuration>
<goalPrefix>ban</goalPrefix>
</configuration>
</execution> </execution>
<execution> <execution>
<id>help-descriptor</id> <id>help-descriptor</id>

View File

@@ -69,10 +69,12 @@ public abstract class AbstractBanConfiguration implements BanConfiguration {
for (Xpp3Dom child : importDom.getChildren()) { for (Xpp3Dom child : importDom.getChildren()) {
BanConfigurationDownloader downloader = null; BanConfigurationDownloader downloader = null;
if (child.getName().equals("url")) { if (child.getName().equals("url")) {
String url = StringUtils.trimToNull(importDom.getValue()); String url = StringUtils.trimToNull(child.getValue());
downloader = new BanConfigurationDownloader(this.session, this.artifactResolver, url); downloader = new BanConfigurationDownloader(this.session, this.artifactResolver, url);
} else if (child.getName().equals("artifact")) { } else if (child.getName().equals("artifact")) {
Artifact artifact = new DefaultArtifact(child.getValue()); Artifact artifact = new DefaultArtifact(child.getValue());
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); ArtifactRequest request = new ArtifactRequest(artifact, this.session.getCurrentProject().getRemoteProjectRepositories(), null);
try { try {

View File

@@ -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<>();