Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
034b319172 | |||
65009df10b | |||
8df2d5bd03 | |||
0edac4fc37 | |||
f837e5d1c0 | |||
78e34d85e9 | |||
6e2a701c0d | |||
08498d4224 | |||
1c7997d85c | |||
9116d4bfd9 | |||
9874ed9543 | |||
eeb7a84698 | |||
ca8913e558 |
2
pom.xml
2
pom.xml
@@ -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.6</version>
|
||||||
<packaging>maven-plugin</packaging>
|
<packaging>maven-plugin</packaging>
|
||||||
|
|
||||||
<name>Ban Dependencies Maven Plugin</name>
|
<name>Ban Dependencies Maven Plugin</name>
|
||||||
|
@@ -29,6 +29,7 @@ import org.apache.maven.model.Plugin;
|
|||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
import org.apache.maven.plugin.PluginResolutionException;
|
import org.apache.maven.plugin.PluginResolutionException;
|
||||||
import org.apache.maven.plugin.internal.PluginDependenciesResolver;
|
import org.apache.maven.plugin.internal.PluginDependenciesResolver;
|
||||||
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
import org.apache.maven.project.DefaultDependencyResolutionRequest;
|
import org.apache.maven.project.DefaultDependencyResolutionRequest;
|
||||||
import org.apache.maven.project.DependencyResolutionException;
|
import org.apache.maven.project.DependencyResolutionException;
|
||||||
import org.apache.maven.project.DependencyResolutionResult;
|
import org.apache.maven.project.DependencyResolutionResult;
|
||||||
@@ -44,6 +45,8 @@ import org.eclipse.aether.impl.VersionRangeResolver;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.inteligr8.maven.ban.model.ImportConfig;
|
||||||
|
|
||||||
@Named("ban")
|
@Named("ban")
|
||||||
@Singleton
|
@Singleton
|
||||||
public class BanExtension extends AbstractMavenLifecycleParticipant {
|
public class BanExtension extends AbstractMavenLifecycleParticipant {
|
||||||
@@ -65,6 +68,18 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PluginDependenciesResolver pluginDepResolver;
|
private PluginDependenciesResolver pluginDepResolver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The configuration is parsed manually. This is here to prevent warning messages with IDEs and builders.
|
||||||
|
*/
|
||||||
|
@Parameter(name = "import")
|
||||||
|
private ImportConfig importConfig;
|
||||||
|
|
||||||
|
@Parameter(name = "includes")
|
||||||
|
private List<String> includes;
|
||||||
|
|
||||||
|
@Parameter(name = "excludes")
|
||||||
|
private List<String> excludes;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
|
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
|
||||||
|
@@ -16,6 +16,7 @@ package com.inteligr8.maven.ban;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.DirectoryNotEmptyException;
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.FileVisitor;
|
import java.nio.file.FileVisitor;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -158,14 +159,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 +280,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 +291,33 @@ 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";
|
||||||
|
getLog().debug("artifact-version: " + includeName);
|
||||||
|
|
||||||
|
if (file.getFileName().toString().startsWith(includeName) &&
|
||||||
|
!file.getFileName().toString().startsWith(excludeName)) {
|
||||||
|
try {
|
||||||
|
getLog().info("Deleting artifact: " + file);
|
||||||
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;
|
||||||
@@ -308,6 +332,8 @@ public class PurgeRepoMojo extends AbstractMojo {
|
|||||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||||
try {
|
try {
|
||||||
Files.delete(dir);
|
Files.delete(dir);
|
||||||
|
} catch (DirectoryNotEmptyException dnee) {
|
||||||
|
getLog().debug("The folder will not be deleted as it is not empty: " + dir);
|
||||||
} catch (IOException ie) {
|
} catch (IOException ie) {
|
||||||
getLog().debug(ie);
|
getLog().debug(ie);
|
||||||
getLog().warn("The folder failed to delete: " + dir);
|
getLog().warn("The folder failed to delete: " + dir);
|
||||||
|
11
src/main/java/com/inteligr8/maven/ban/model/Config.java
Normal file
11
src/main/java/com/inteligr8/maven/ban/model/Config.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package com.inteligr8.maven.ban.model;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
|
||||||
|
public ImportConfig importConfigs;
|
||||||
|
public List<String> includes;
|
||||||
|
public List<String> excludes;
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,10 @@
|
|||||||
|
package com.inteligr8.maven.ban.model;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ImportConfig {
|
||||||
|
|
||||||
|
public List<String> url;
|
||||||
|
public List<String> artifact;
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user