docs and tidy up
This commit is contained in:
31
pom.xml
31
pom.xml
@@ -88,9 +88,9 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
<version>4.13.2</version>
|
<version>5.12.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -106,6 +106,16 @@
|
|||||||
<artifactId>maven-invoker-plugin</artifactId>
|
<artifactId>maven-invoker-plugin</artifactId>
|
||||||
<version>3.9.0</version>
|
<version>3.9.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.eclipse.sisu</groupId>
|
||||||
|
<artifactId>sisu-maven-plugin</artifactId>
|
||||||
|
<version>0.9.0.M2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-component-metadata</artifactId>
|
||||||
|
<version>2.2.0</version>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
<plugins>
|
<plugins>
|
||||||
@@ -132,7 +142,6 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.eclipse.sisu</groupId>
|
<groupId>org.eclipse.sisu</groupId>
|
||||||
<artifactId>sisu-maven-plugin</artifactId>
|
<artifactId>sisu-maven-plugin</artifactId>
|
||||||
<version>0.3.5</version>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>generate-index</id>
|
<id>generate-index</id>
|
||||||
@@ -145,7 +154,6 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.plexus</groupId>
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
<artifactId>plexus-component-metadata</artifactId>
|
<artifactId>plexus-component-metadata</artifactId>
|
||||||
<version>2.2.0</version>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
@@ -210,7 +218,7 @@
|
|||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
<profile>
|
<profile>
|
||||||
<id>ossrh-release</id>
|
<id>central-publish</id>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -247,14 +255,13 @@
|
|||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.sonatype.plugins</groupId>
|
<groupId>org.sonatype.central</groupId>
|
||||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||||
<version>1.7.0</version>
|
<version>0.8.0</version>
|
||||||
<extensions>true</extensions>
|
<extensions>true</extensions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<serverId>ossrh</serverId>
|
<publishingServerId>central</publishingServerId>
|
||||||
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
|
<autoPublish>true</autoPublish>
|
||||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
@@ -43,6 +43,37 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import com.inteligr8.maven.model.ArtifactFilter;
|
import com.inteligr8.maven.model.ArtifactFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class handles the parsing of the configuration specification supported
|
||||||
|
* by this plugin. It does not implement the banning execution; just the
|
||||||
|
* collection of configurations to decide what artifacts should be banned.
|
||||||
|
*
|
||||||
|
* The specification is as follows:
|
||||||
|
*
|
||||||
|
* ```xml
|
||||||
|
* <configuration>
|
||||||
|
* <import>
|
||||||
|
* <file>relative/path/file.xml</file>
|
||||||
|
* <url>https://host.domain/path/file.xml</url>
|
||||||
|
* <artifact>domain.host:artifact-id:[1.0,)</artifact>
|
||||||
|
* </import>
|
||||||
|
* <includes>
|
||||||
|
* <artifact>log4j:log4j</artifact>
|
||||||
|
* <artifact>org.apache.logging:log4j-impl:[,2.16.1)</artifact>
|
||||||
|
* </includes>
|
||||||
|
* <excludes>
|
||||||
|
* <artifact>...</artifact>
|
||||||
|
* </excludes>
|
||||||
|
* </configuration>
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* The imports are recursively processed under the same specification. The
|
||||||
|
* included artifacts are the ones that are banned. Any artifact matching both
|
||||||
|
* includes and excludes will be excluded and therefore NOT banned.
|
||||||
|
*
|
||||||
|
* The `groupId` and `artifactId` of the standard shorthand Maven `artifact`
|
||||||
|
* nomenclature may use regular expressions.
|
||||||
|
*/
|
||||||
public abstract 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());
|
||||||
|
@@ -31,10 +31,24 @@ import org.eclipse.aether.impl.VersionRangeResolver;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class parses the a configuration file that conforms with the
|
||||||
|
* specification defined by this plugin.
|
||||||
|
*/
|
||||||
public class BanConfigurationDownloader extends AbstractBanConfiguration {
|
public class BanConfigurationDownloader extends AbstractBanConfiguration {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructs the downloader based on an accessible URL.
|
||||||
|
*
|
||||||
|
* @param session A Maven session object.
|
||||||
|
* @param artifactResolver A Maven Aether artifact resolver service.
|
||||||
|
* @param versionRangeResolver A Maven Aether version range resolver service.
|
||||||
|
* @param url The URL of a ban configuration file.
|
||||||
|
* @throws IOException The file could not be downloaded for any number of reasons.
|
||||||
|
* @throws MojoFailureException The file could not be parsed due to bad formatting or unexpected response.
|
||||||
|
*/
|
||||||
public BanConfigurationDownloader(MavenSession session, ArtifactResolver artifactResolver, VersionRangeResolver versionRangeResolver, String url) throws IOException, MojoFailureException {
|
public BanConfigurationDownloader(MavenSession session, ArtifactResolver artifactResolver, VersionRangeResolver versionRangeResolver, String url) throws IOException, MojoFailureException {
|
||||||
super(session, artifactResolver, versionRangeResolver);
|
super(session, artifactResolver, versionRangeResolver);
|
||||||
|
|
||||||
@@ -45,7 +59,17 @@ public class BanConfigurationDownloader extends AbstractBanConfiguration {
|
|||||||
throw new MojoFailureException(xppe.getMessage(), xppe);
|
throw new MojoFailureException(xppe.getMessage(), xppe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructs the downloader based on a file object.
|
||||||
|
*
|
||||||
|
* @param session A Maven session object.
|
||||||
|
* @param artifactResolver A Maven Aether artifact resolver service.
|
||||||
|
* @param versionRangeResolver A Maven Aether version range resolver service.
|
||||||
|
* @param file A file, typically local, though technically may be remote.
|
||||||
|
* @throws IOException The file could not be read for any number of reasons.
|
||||||
|
* @throws MojoFailureException The file could not be parsed due to bad formatting.
|
||||||
|
*/
|
||||||
public BanConfigurationDownloader(MavenSession session, ArtifactResolver artifactResolver, VersionRangeResolver versionRangeResolver, File file) throws IOException, MojoFailureException {
|
public BanConfigurationDownloader(MavenSession session, ArtifactResolver artifactResolver, VersionRangeResolver versionRangeResolver, File file) throws IOException, MojoFailureException {
|
||||||
super(session, artifactResolver, versionRangeResolver);
|
super(session, artifactResolver, versionRangeResolver);
|
||||||
|
|
||||||
@@ -57,6 +81,14 @@ public class BanConfigurationDownloader extends AbstractBanConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method loads the configuration from the specified URL.
|
||||||
|
*
|
||||||
|
* @param url A URL of a ban configuration file.
|
||||||
|
* @return A Maven Plexus XML DOM object.
|
||||||
|
* @throws IOException The file could not be downloaded for any number of reasons.
|
||||||
|
* @throws MojoFailureException The file could not be parsed due to bad formatting or unexpected response.
|
||||||
|
*/
|
||||||
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);
|
||||||
@@ -67,7 +99,15 @@ public class BanConfigurationDownloader extends AbstractBanConfiguration {
|
|||||||
bistream.close();
|
bistream.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method loads the configuration from the specified file.
|
||||||
|
*
|
||||||
|
* @param file A file, typically local, though technically may be remote.
|
||||||
|
* @return A Maven Plexus XML DOM object.
|
||||||
|
* @throws IOException The file could not be read for any number of reasons.
|
||||||
|
* @throws MojoFailureException The file could not be parsed due to bad formatting.
|
||||||
|
*/
|
||||||
private Xpp3Dom load(File file) throws IOException, XmlPullParserException {
|
private Xpp3Dom load(File file) throws IOException, XmlPullParserException {
|
||||||
FileInputStream fistream = new FileInputStream(file);
|
FileInputStream fistream = new FileInputStream(file);
|
||||||
BufferedInputStream bistream = new BufferedInputStream(fistream, 16384);
|
BufferedInputStream bistream = new BufferedInputStream(fistream, 16384);
|
||||||
|
@@ -28,6 +28,18 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import com.inteligr8.maven.model.ArtifactFilter;
|
import com.inteligr8.maven.model.ArtifactFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class implements the banned artifact detection logic.
|
||||||
|
*
|
||||||
|
* It will recursively scan every dependency and plugin dependency to find any
|
||||||
|
* artifacts that reference a banned artifact and its banned versions. If one
|
||||||
|
* is found, the filter will fail and stop the build immediately. It will
|
||||||
|
* prevent the banned artifact from being downloaded.
|
||||||
|
*
|
||||||
|
* The complicated part is that when multiple versions of the same artifact
|
||||||
|
* show up in the dependency tree, only one may be selected. So this filter
|
||||||
|
* will ignore the versions that are not selected.
|
||||||
|
*/
|
||||||
public class BanDependencyFilter implements DependencyFilter {
|
public class BanDependencyFilter implements DependencyFilter {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
@@ -87,7 +87,9 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
|
|||||||
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();
|
MavenProject project = session.getCurrentProject();
|
||||||
@@ -132,7 +134,7 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
|
|||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
return new BanConfigurationParser(session, this.artifactResolver, this.versionRangeResolver, plugin);
|
return new BanPluginConfigurationParser(session, this.artifactResolver, this.versionRangeResolver, plugin);
|
||||||
} catch (IOException | MojoFailureException e) {
|
} catch (IOException | MojoFailureException e) {
|
||||||
throw new MavenExecutionException(e.getMessage(), project.getFile());
|
throw new MavenExecutionException(e.getMessage(), project.getFile());
|
||||||
}
|
}
|
||||||
|
@@ -23,9 +23,14 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
|
|||||||
import org.eclipse.aether.impl.ArtifactResolver;
|
import org.eclipse.aether.impl.ArtifactResolver;
|
||||||
import org.eclipse.aether.impl.VersionRangeResolver;
|
import org.eclipse.aether.impl.VersionRangeResolver;
|
||||||
|
|
||||||
public class BanConfigurationParser extends AbstractBanConfiguration {
|
/**
|
||||||
|
* This class parses the POM plugin configuration block for this plugin. The
|
||||||
|
* specification for that configuration block is shared with the one found in
|
||||||
|
* the ban configuration file.
|
||||||
|
*/
|
||||||
|
public class BanPluginConfigurationParser extends AbstractBanConfiguration {
|
||||||
|
|
||||||
public BanConfigurationParser(MavenSession session, ArtifactResolver artifactResolver, VersionRangeResolver versionRangeResolver, Plugin plugin) throws IOException, MojoFailureException {
|
public BanPluginConfigurationParser(MavenSession session, ArtifactResolver artifactResolver, VersionRangeResolver versionRangeResolver, Plugin plugin) throws IOException, MojoFailureException {
|
||||||
super(session, artifactResolver, versionRangeResolver);
|
super(session, artifactResolver, versionRangeResolver);
|
||||||
|
|
||||||
Xpp3Dom rootDom = (Xpp3Dom) plugin.getConfiguration();
|
Xpp3Dom rootDom = (Xpp3Dom) plugin.getConfiguration();
|
@@ -88,7 +88,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();
|
BanPluginConfigurationParser config = this.getConfiguration();
|
||||||
|
|
||||||
for (ArtifactFilter afilter : config.getIncludeArtifacts()) {
|
for (ArtifactFilter afilter : config.getIncludeArtifacts()) {
|
||||||
if (afilter.getGroupId() == null) {
|
if (afilter.getGroupId() == null) {
|
||||||
@@ -172,12 +172,12 @@ public class PurgeRepoMojo extends AbstractMojo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BanConfigurationParser getConfiguration() throws MojoFailureException, IOException {
|
private BanPluginConfigurationParser getConfiguration() throws MojoFailureException, IOException {
|
||||||
MavenProject project = this.session.getCurrentProject();
|
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(this.session, this.artifactResolver, this.versionRangeResolver, plugin);
|
return new BanPluginConfigurationParser(this.session, this.artifactResolver, this.versionRangeResolver, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path resolveGroupPath(ArtifactFilter afilter) {
|
private Path resolveGroupPath(ArtifactFilter afilter) {
|
||||||
|
Reference in New Issue
Block a user