Merge branch 'develop' into stable
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.inteligr8.maven.ban;
|
package com.inteligr8.maven.ban;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -23,14 +24,21 @@ import java.util.regex.Pattern;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
import org.apache.maven.artifact.versioning.VersionRange;
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
|
import org.eclipse.aether.artifact.Artifact;
|
||||||
|
import org.eclipse.aether.artifact.DefaultArtifact;
|
||||||
|
import org.eclipse.aether.impl.ArtifactResolver;
|
||||||
|
import org.eclipse.aether.resolution.ArtifactRequest;
|
||||||
|
import org.eclipse.aether.resolution.ArtifactResolutionException;
|
||||||
|
import org.eclipse.aether.resolution.ArtifactResult;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.inteligr8.maven.model.ArtifactFilter;
|
import com.inteligr8.maven.model.ArtifactFilter;
|
||||||
|
|
||||||
public class AbstractBanConfiguration implements BanConfiguration {
|
public abstract class AbstractBanConfiguration implements BanConfiguration {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
private final Pattern artifactPattern = Pattern.compile("^([^:]+):([^:]+)(:([^:]+))?$");
|
private final Pattern artifactPattern = Pattern.compile("^([^:]+):([^:]+)(:([^:]+))?$");
|
||||||
@@ -39,10 +47,51 @@ public class AbstractBanConfiguration implements BanConfiguration {
|
|||||||
protected final List<ArtifactFilter> includeArtifacts = new LinkedList<>();
|
protected final List<ArtifactFilter> includeArtifacts = new LinkedList<>();
|
||||||
protected final List<ArtifactFilter> excludeArtifacts = new LinkedList<>();
|
protected final List<ArtifactFilter> excludeArtifacts = new LinkedList<>();
|
||||||
|
|
||||||
|
private final ArtifactResolver artifactResolver;
|
||||||
|
private final MavenSession session;
|
||||||
|
|
||||||
|
public AbstractBanConfiguration(MavenSession session, ArtifactResolver artifactResolver) {
|
||||||
|
this.session = session;
|
||||||
|
this.artifactResolver = artifactResolver;
|
||||||
|
}
|
||||||
|
|
||||||
public void init(Xpp3Dom rootDom) throws IOException, MojoFailureException {
|
public void init(Xpp3Dom rootDom) throws IOException, MojoFailureException {
|
||||||
if (rootDom == null)
|
if (rootDom == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Xpp3Dom importDom = rootDom.getChild("import");
|
||||||
|
if (importDom != null)
|
||||||
|
this.processImports(importDom);
|
||||||
|
this.processIncludesExcludes(rootDom);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processImports(Xpp3Dom importDom) throws IOException, MojoFailureException {
|
||||||
|
for (Xpp3Dom child : importDom.getChildren()) {
|
||||||
|
BanConfigurationDownloader downloader = null;
|
||||||
|
if (child.getName().equals("url")) {
|
||||||
|
String url = StringUtils.trimToNull(importDom.getValue());
|
||||||
|
downloader = new BanConfigurationDownloader(this.session, this.artifactResolver, url);
|
||||||
|
} else if (child.getName().equals("artifact")) {
|
||||||
|
Artifact artifact = new DefaultArtifact(child.getValue());
|
||||||
|
ArtifactRequest request = new ArtifactRequest(artifact, this.session.getCurrentProject().getRemoteProjectRepositories(), null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ArtifactResult result = this.artifactResolver.resolveArtifact(this.session.getRepositorySession(), request);
|
||||||
|
File file = result.getArtifact().getFile();
|
||||||
|
downloader = new BanConfigurationDownloader(this.session, this.artifactResolver, file);
|
||||||
|
} catch (ArtifactResolutionException are) {
|
||||||
|
this.logger.warn("The artifact could not be resolved; skipping: {}", child.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (downloader != null) {
|
||||||
|
this.includeArtifacts.addAll(downloader.getIncludeArtifacts());
|
||||||
|
this.excludeArtifacts.addAll(downloader.getExcludeArtifacts());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processIncludesExcludes(Xpp3Dom rootDom) {
|
||||||
Xpp3Dom includesDom = rootDom.getChild("includes");
|
Xpp3Dom includesDom = rootDom.getChild("includes");
|
||||||
if (includesDom != null)
|
if (includesDom != null)
|
||||||
this.includeArtifacts.addAll(this.parseArtifacts(includesDom));
|
this.includeArtifacts.addAll(this.parseArtifacts(includesDom));
|
||||||
|
@@ -21,18 +21,12 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
|
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
|
||||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||||
import org.eclipse.aether.artifact.Artifact;
|
|
||||||
import org.eclipse.aether.artifact.DefaultArtifact;
|
|
||||||
import org.eclipse.aether.impl.ArtifactResolver;
|
import org.eclipse.aether.impl.ArtifactResolver;
|
||||||
import org.eclipse.aether.resolution.ArtifactRequest;
|
|
||||||
import org.eclipse.aether.resolution.ArtifactResolutionException;
|
|
||||||
import org.eclipse.aether.resolution.ArtifactResult;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -40,16 +34,8 @@ public class BanConfigurationDownloader extends AbstractBanConfiguration {
|
|||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
private final ArtifactResolver artifactResolver;
|
|
||||||
private final MavenSession session;
|
|
||||||
|
|
||||||
public BanConfigurationDownloader(MavenSession session, ArtifactResolver artifactResolver) {
|
|
||||||
this.session = session;
|
|
||||||
this.artifactResolver = artifactResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BanConfigurationDownloader(MavenSession session, ArtifactResolver artifactResolver, String url) throws IOException, MojoFailureException {
|
public BanConfigurationDownloader(MavenSession session, ArtifactResolver artifactResolver, String url) throws IOException, MojoFailureException {
|
||||||
this(session, artifactResolver);
|
super(session, artifactResolver);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Xpp3Dom rootDom = this.load(new URL(url));
|
Xpp3Dom rootDom = this.load(new URL(url));
|
||||||
@@ -60,7 +46,7 @@ public class BanConfigurationDownloader extends AbstractBanConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BanConfigurationDownloader(MavenSession session, ArtifactResolver artifactResolver, File file) throws IOException, MojoFailureException {
|
public BanConfigurationDownloader(MavenSession session, ArtifactResolver artifactResolver, File file) throws IOException, MojoFailureException {
|
||||||
this(session, artifactResolver);
|
super(session, artifactResolver);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Xpp3Dom rootDom = this.load(file);
|
Xpp3Dom rootDom = this.load(file);
|
||||||
@@ -70,36 +56,6 @@ public class BanConfigurationDownloader extends AbstractBanConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(Xpp3Dom rootDom) throws IOException, MojoFailureException {
|
|
||||||
Xpp3Dom importDom = rootDom.getChild("import");
|
|
||||||
if (importDom != null) {
|
|
||||||
for (Xpp3Dom child : importDom.getChildren()) {
|
|
||||||
BanConfigurationDownloader downloader = null;
|
|
||||||
if (child.getName().equals("url")) {
|
|
||||||
String url = StringUtils.trimToNull(importDom.getValue());
|
|
||||||
downloader = new BanConfigurationDownloader(this.session, this.artifactResolver, url);
|
|
||||||
} else if (child.getName().equals("artifact")) {
|
|
||||||
Artifact artifact = new DefaultArtifact(child.getValue());
|
|
||||||
ArtifactRequest request = new ArtifactRequest(artifact, this.session.getCurrentProject().getRemoteProjectRepositories(), null);
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArtifactResult result = this.artifactResolver.resolveArtifact(this.session.getRepositorySession(), request);
|
|
||||||
File file = result.getArtifact().getFile();
|
|
||||||
downloader = new BanConfigurationDownloader(this.session, this.artifactResolver, file);
|
|
||||||
} catch (ArtifactResolutionException are) {
|
|
||||||
this.logger.warn("The artifact could not be resolved; skipping: {}", child.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (downloader != null) {
|
|
||||||
this.includeArtifacts.addAll(downloader.getIncludeArtifacts());
|
|
||||||
this.excludeArtifacts.addAll(downloader.getExcludeArtifacts());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Xpp3Dom load(URL url) throws IOException, XmlPullParserException {
|
private Xpp3Dom load(URL url) throws IOException, XmlPullParserException {
|
||||||
InputStream istream = url.openStream();
|
InputStream istream = url.openStream();
|
||||||
BufferedInputStream bistream = new BufferedInputStream(istream, 16384);
|
BufferedInputStream bistream = new BufferedInputStream(istream, 16384);
|
||||||
|
@@ -16,13 +16,17 @@ package com.inteligr8.maven.ban;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
|
import org.eclipse.aether.impl.ArtifactResolver;
|
||||||
|
|
||||||
public class BanConfigurationParser extends AbstractBanConfiguration {
|
public class BanConfigurationParser extends AbstractBanConfiguration {
|
||||||
|
|
||||||
public BanConfigurationParser(Plugin plugin) throws IOException, MojoFailureException {
|
public BanConfigurationParser(MavenSession session, ArtifactResolver artifactResolver, Plugin plugin) throws IOException, MojoFailureException {
|
||||||
|
super(session, artifactResolver);
|
||||||
|
|
||||||
Xpp3Dom rootDom = (Xpp3Dom) plugin.getConfiguration();
|
Xpp3Dom rootDom = (Xpp3Dom) plugin.getConfiguration();
|
||||||
this.init(rootDom);
|
this.init(rootDom);
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,7 @@ import org.eclipse.aether.artifact.DefaultArtifact;
|
|||||||
import org.eclipse.aether.graph.Dependency;
|
import org.eclipse.aether.graph.Dependency;
|
||||||
import org.eclipse.aether.graph.DependencyFilter;
|
import org.eclipse.aether.graph.DependencyFilter;
|
||||||
import org.eclipse.aether.graph.DependencyNode;
|
import org.eclipse.aether.graph.DependencyNode;
|
||||||
|
import org.eclipse.aether.impl.ArtifactResolver;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -52,6 +53,9 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
|
|||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ArtifactResolver artifactResolver;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ProjectDependenciesResolver projDepResolver;
|
private ProjectDependenciesResolver projDepResolver;
|
||||||
|
|
||||||
@@ -60,13 +64,14 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
|
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
|
||||||
MavenProject project = session.getCurrentProject();
|
BanConfiguration config = this.getConfiguration(session);
|
||||||
BanConfiguration config = this.getConfiguration(project);
|
|
||||||
if (config == null)
|
if (config == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BanDependencyFilter depFilter = new BanDependencyFilter(config.getIncludeArtifacts(), config.getExcludeArtifacts());
|
BanDependencyFilter depFilter = new BanDependencyFilter(config.getIncludeArtifacts(), config.getExcludeArtifacts());
|
||||||
depFilter.setFailFast(true);
|
depFilter.setFailFast(true);
|
||||||
|
|
||||||
|
MavenProject project = session.getCurrentProject();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (Plugin plugin : project.getBuildPlugins()) {
|
for (Plugin plugin : project.getBuildPlugins()) {
|
||||||
@@ -97,7 +102,8 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BanConfigurationParser getConfiguration(MavenProject project) throws MavenExecutionException {
|
private BanConfiguration getConfiguration(MavenSession session) throws MavenExecutionException {
|
||||||
|
MavenProject project = session.getCurrentProject();
|
||||||
Plugin plugin = project.getPlugin(THIS_PLUGIN_KEY);
|
Plugin plugin = project.getPlugin(THIS_PLUGIN_KEY);
|
||||||
if (plugin == null)
|
if (plugin == null)
|
||||||
throw new MavenExecutionException("The plugin is executing but it cannot be found", project.getFile());
|
throw new MavenExecutionException("The plugin is executing but it cannot be found", project.getFile());
|
||||||
@@ -107,7 +113,7 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
|
|||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
return new BanConfigurationParser(plugin);
|
return new BanConfigurationParser(session, this.artifactResolver, plugin);
|
||||||
} catch (IOException | MojoFailureException e) {
|
} catch (IOException | MojoFailureException e) {
|
||||||
throw new MavenExecutionException(e.getMessage(), project.getFile());
|
throw new MavenExecutionException(e.getMessage(), project.getFile());
|
||||||
}
|
}
|
||||||
|
@@ -44,6 +44,7 @@ import org.apache.maven.plugins.annotations.Mojo;
|
|||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
import org.eclipse.aether.impl.ArtifactResolver;
|
||||||
|
|
||||||
import com.inteligr8.maven.model.ArtifactFilter;
|
import com.inteligr8.maven.model.ArtifactFilter;
|
||||||
|
|
||||||
@@ -54,6 +55,9 @@ public class PurgeRepoMojo extends AbstractMojo {
|
|||||||
@Inject
|
@Inject
|
||||||
private MavenSession session;
|
private MavenSession session;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ArtifactResolver artifactResolver;
|
||||||
|
|
||||||
@Parameter(name = "skip", defaultValue = "false")
|
@Parameter(name = "skip", defaultValue = "false")
|
||||||
private boolean skip = false;
|
private boolean skip = false;
|
||||||
|
|
||||||
@@ -78,7 +82,7 @@ public class PurgeRepoMojo extends AbstractMojo {
|
|||||||
private void purge() throws MojoFailureException, IOException {
|
private void purge() throws MojoFailureException, IOException {
|
||||||
List<Path> includePaths = new LinkedList<>();
|
List<Path> includePaths = new LinkedList<>();
|
||||||
|
|
||||||
BanConfigurationParser config = this.getConfiguration(this.session.getCurrentProject());
|
BanConfigurationParser config = this.getConfiguration();
|
||||||
|
|
||||||
for (ArtifactFilter afilter : config.getIncludeArtifacts()) {
|
for (ArtifactFilter afilter : config.getIncludeArtifacts()) {
|
||||||
if (afilter.getGroupId() == null) {
|
if (afilter.getGroupId() == null) {
|
||||||
@@ -159,11 +163,12 @@ public class PurgeRepoMojo extends AbstractMojo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BanConfigurationParser getConfiguration(MavenProject project) throws MojoFailureException, IOException {
|
private BanConfigurationParser getConfiguration() throws MojoFailureException, IOException {
|
||||||
|
MavenProject project = this.session.getCurrentProject();
|
||||||
Plugin plugin = project.getPlugin(BanExtension.THIS_PLUGIN_KEY);
|
Plugin plugin = project.getPlugin(BanExtension.THIS_PLUGIN_KEY);
|
||||||
if (plugin == null)
|
if (plugin == null)
|
||||||
throw new MojoFailureException("The plugin is executing but it cannot be found");
|
throw new MojoFailureException("The plugin is executing but it cannot be found");
|
||||||
return new BanConfigurationParser(plugin);
|
return new BanConfigurationParser(this.session, this.artifactResolver, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path getGroupPath(ArtifactFilter afilter) {
|
private Path getGroupPath(ArtifactFilter afilter) {
|
||||||
@@ -243,7 +248,14 @@ 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 {
|
||||||
Files.delete(file);
|
try {
|
||||||
|
if (!attrs.isDirectory())
|
||||||
|
Files.delete(file);
|
||||||
|
} catch (IOException ie) {
|
||||||
|
getLog().debug(ie);
|
||||||
|
getLog().warn("The file failed to delete: " + file);
|
||||||
|
}
|
||||||
|
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,7 +266,13 @@ public class PurgeRepoMojo extends AbstractMojo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||||
Files.delete(dir);
|
try {
|
||||||
|
Files.delete(dir);
|
||||||
|
} catch (IOException ie) {
|
||||||
|
getLog().debug(ie);
|
||||||
|
getLog().warn("The folder failed to delete: " + dir);
|
||||||
|
}
|
||||||
|
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user