Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
9874ed9543 | |||
eeb7a84698 | |||
ca8913e558 | |||
4c1c4d412d | |||
fc5e0c6bd1 | |||
2a1523012b | |||
d41d73fa1c | |||
a9aa47d412 | |||
47fd07247d |
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
||||
|
||||
<groupId>com.inteligr8</groupId>
|
||||
<artifactId>ban-maven-plugin</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<version>1.3.3</version>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
||||
<name>Ban Dependencies Maven Plugin</name>
|
||||
|
@@ -90,7 +90,7 @@ public abstract class AbstractBanConfiguration implements BanConfiguration {
|
||||
this.logger.error("The artifact version range could not be resolved; skipping: {}", child.getValue());
|
||||
} else {
|
||||
Version version = vrresult.getHighestVersion();
|
||||
artifact.setVersion(version.toString());
|
||||
artifact = artifact.setVersion(version.toString());
|
||||
|
||||
ArtifactRequest arequest = new ArtifactRequest(artifact, this.session.getCurrentProject().getRemoteProjectRepositories(), null);
|
||||
try {
|
||||
@@ -98,7 +98,7 @@ public abstract class AbstractBanConfiguration implements BanConfiguration {
|
||||
File file = aresult.getArtifact().getFile();
|
||||
downloader = new BanConfigurationDownloader(this.session, this.artifactResolver, this.versionRangeResolver, file);
|
||||
} catch (ArtifactResolutionException are) {
|
||||
this.logger.warn("The artifact version could not be resolved; skipping: {} | {}", child.getValue(), version);
|
||||
this.logger.warn("The artifact version could not be resolved; skipping: {}", artifact, version);
|
||||
}
|
||||
}
|
||||
} catch (VersionRangeResolutionException vrre) {
|
||||
|
@@ -158,14 +158,14 @@ public class PurgeRepoMojo extends AbstractMojo {
|
||||
this.getLog().info("DRYRUN: Would have deleted certain paths from local Maven cache: " + repoPath);
|
||||
this.getLog().info("DRYRUN: Would have deleted these paths: " + includePaths);
|
||||
} else {
|
||||
for (Path path : includePaths) {
|
||||
Path fullpath = repoPath.resolve(path);
|
||||
if (Files.exists(fullpath)) {
|
||||
this.getLog().info("Deleting version from Maven cache: " + path);
|
||||
Files.walkFileTree(fullpath, new DeleteDirectoryVisitor());
|
||||
for (Path versionPath : includePaths) {
|
||||
Path fullVersionPath = repoPath.resolve(versionPath);
|
||||
if (Files.exists(fullVersionPath)) {
|
||||
this.getLog().info("Deleting version from Maven cache: " + versionPath);
|
||||
Files.walkFileTree(fullVersionPath, new DeleteNonMetadataVisitor());
|
||||
} else {
|
||||
// this will probably never happen
|
||||
this.getLog().debug("Maven cache does not exist: " + path);
|
||||
this.getLog().debug("Maven cache does not exist: " + versionPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,14 +219,27 @@ public class PurgeRepoMojo extends AbstractMojo {
|
||||
|
||||
Files.list(repoPath.resolve(groupPath)).forEach(new Consumer<Path>() {
|
||||
@Override
|
||||
public void accept(Path t) {
|
||||
public void accept(Path fullArtifactPath) {
|
||||
if (artifactPattern == null) {
|
||||
paths.add(repoPath.relativize(t));
|
||||
// these may include sub-groups and not just artifacts
|
||||
// which will lead to paths with artifacts as versions
|
||||
// so we are looping through versions to see if it is indeed an artifact
|
||||
try {
|
||||
Files.list(fullArtifactPath).findFirst().ifPresent(new Consumer<Path>() {
|
||||
@Override
|
||||
public void accept(Path fullVersionPath) {
|
||||
if (Files.exists(fullVersionPath.resolve("_remote.repositories")))
|
||||
paths.add(repoPath.relativize(fullArtifactPath));
|
||||
}
|
||||
});
|
||||
} catch (IOException ie) {
|
||||
getLog().error(ie.getMessage(), ie);
|
||||
}
|
||||
} else {
|
||||
Matcher matcher = artifactPattern.matcher(t.getFileName().toString());
|
||||
Matcher matcher = artifactPattern.matcher(fullArtifactPath.getFileName().toString());
|
||||
if (matcher.matches()) {
|
||||
getLog().debug("The artifact directory '" + t.getFileName() + "' qualifies as included");
|
||||
paths.add(repoPath.relativize(t));
|
||||
getLog().debug("The artifact directory '" + fullArtifactPath.getFileName() + "' qualifies as included");
|
||||
paths.add(repoPath.relativize(fullArtifactPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,7 +279,9 @@ public class PurgeRepoMojo extends AbstractMojo {
|
||||
|
||||
|
||||
|
||||
private class DeleteDirectoryVisitor implements FileVisitor<Path> {
|
||||
private class DeleteNonMetadataVisitor implements FileVisitor<Path> {
|
||||
|
||||
private final Pattern versionPathPattern = Pattern.compile("/([^/]+)/([^/]+)$");
|
||||
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
||||
@@ -275,12 +290,30 @@ public class PurgeRepoMojo extends AbstractMojo {
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
if (attrs.isDirectory()) {
|
||||
getLog().warn("An unexpected directory was found: " + file);
|
||||
return FileVisitResult.SKIP_SUBTREE;
|
||||
}
|
||||
|
||||
Matcher matcher = this.versionPathPattern.matcher(file.toString());
|
||||
if (!matcher.find()) {
|
||||
getLog().debug("Ignoring file from purge: " + file);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
String artifactId = matcher.group(1);
|
||||
String version = matcher.group(2);
|
||||
String includeName = artifactId + "-" + version;
|
||||
String excludeName = artifactId + "-" + version + ".pom";
|
||||
if (file.getFileName().toString().startsWith(includeName) &&
|
||||
!file.getFileName().toString().startsWith(excludeName)) {
|
||||
try {
|
||||
if (!attrs.isDirectory())
|
||||
Files.delete(file);
|
||||
} catch (IOException ie) {
|
||||
getLog().debug(ie);
|
||||
getLog().warn("The file failed to delete: " + file);
|
||||
return FileVisitResult.SKIP_SIBLINGS;
|
||||
}
|
||||
}
|
||||
|
||||
return FileVisitResult.CONTINUE;
|
||||
|
Reference in New Issue
Block a user