3 Commits

Author SHA1 Message Date
9874ed9543 v1.3.3 pom 2023-08-20 15:03:10 -04:00
eeb7a84698 Merge branch 'develop' into stable 2023-08-20 15:02:58 -04:00
ca8913e558 don't delete pom metadata 2023-08-20 15:02:50 -04:00
2 changed files with 33 additions and 13 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.3.2</version> <version>1.3.3</version>
<packaging>maven-plugin</packaging> <packaging>maven-plugin</packaging>
<name>Ban Dependencies Maven Plugin</name> <name>Ban Dependencies Maven Plugin</name>

View File

@@ -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 certain paths from local Maven cache: " + repoPath);
this.getLog().info("DRYRUN: Would have deleted these paths: " + includePaths); this.getLog().info("DRYRUN: Would have deleted these paths: " + includePaths);
} else { } else {
for (Path path : includePaths) { for (Path versionPath : includePaths) {
Path fullpath = repoPath.resolve(path); Path fullVersionPath = repoPath.resolve(versionPath);
if (Files.exists(fullpath)) { if (Files.exists(fullVersionPath)) {
this.getLog().info("Deleting version from Maven cache: " + path); this.getLog().info("Deleting version from Maven cache: " + versionPath);
Files.walkFileTree(fullpath, new DeleteDirectoryVisitor()); Files.walkFileTree(fullVersionPath, new DeleteNonMetadataVisitor());
} else { } else {
// this will probably never happen // this will probably never happen
this.getLog().debug("Maven cache does not exist: " + path); this.getLog().debug("Maven cache does not exist: " + versionPath);
} }
} }
} }
@@ -279,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 @Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
@@ -288,12 +290,30 @@ public class PurgeRepoMojo extends AbstractMojo {
@Override @Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
try { if (attrs.isDirectory()) {
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 {
Files.delete(file); Files.delete(file);
} catch (IOException ie) { } catch (IOException ie) {
getLog().debug(ie); getLog().debug(ie);
getLog().warn("The file failed to delete: " + file); getLog().warn("The file failed to delete: " + file);
return FileVisitResult.SKIP_SIBLINGS;
}
} }
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;