v1.5.x; added parent/module support
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
# Artifact Ban Maven Plugin
|
||||
|
||||
This is a maven plugin that allows for developers and organizations to ban Maven artifacts. We are keenly aware of the capability in the `maven-enforcer-plugin`. Instead of simply generating an error when a banned artifact is referenced, this plugin prevents the artifact from being downloaded as well. This is crucial within certain organizations with strict security scans that crawl the Maven cache.
|
||||
This is a maven plugin that allows developers and organizations to ban Maven artifacts. We are keenly aware of the capability in the `maven-enforcer-plugin`. Instead of simply generating an error when a banned artifact is referenced, this plugin prevents the artifact from being downloaded as well. This is crucial within certain organizations with strict security scans that crawl the Maven cache.
|
||||
|
||||
## Extension
|
||||
|
||||
@@ -33,6 +33,8 @@ When using as an extension, it will enforce a ban on the configured dependencies
|
||||
|
||||
The `extensions` elements is critical. Without it, the plugin does nothing as far as banning artifacts/dependencies. With it, the plugin is able to not only detect banned artifacts, but do it before they are downloaded. This keeps libraries from even reaching your local Maven repository cache.
|
||||
|
||||
A module project will inherit the `extensions` setting from its parent project. A project with the extension (whether declared or inherited) will inherit the plugin configurations of its ancestral projects.
|
||||
|
||||
### Configuration
|
||||
|
||||
| Element | Description |
|
||||
@@ -45,7 +47,7 @@ The `extensions` elements is critical. Without it, the plugin does nothing as f
|
||||
|
||||
When specifying `artifact`, you can use any of the following formats. The example is of this library; just replace the values to match the artifacts you want to ban.
|
||||
|
||||
- Exact artifact/version: `com.inteligr8:ban-maven-plugin:1.0.0`
|
||||
- Exact artifact/version: `com.inteligr8:ban-maven-plugin:[1.0.0]`
|
||||
- Exact artifact; all versions: `com.inteligr8:ban-maven-plugin`
|
||||
- Exact artifact; version range: `com.inteligr8:ban-maven-plugin:[,1.4.0)`
|
||||
- All artifacts/versions in group: `org.springframework:`
|
||||
@@ -72,15 +74,15 @@ It supports the use of regular expressions with `groupIdRegex` and `artifactIdRe
|
||||
</artifact>
|
||||
```
|
||||
|
||||
If no `includes` are provided, then no artifacts will be banned. An *included* artifact is a banned artifact. An *excluded* artifact is not banned. It is the opposite of what you may think. If no `excludes` are provided, then no banned artifacts are granted an exception.
|
||||
If no `includes` are provided, then no artifacts will be banned. An *included* artifact is a banned artifact. An *excluded* artifact is not banned. It may be the opposite of what you think. If no `excludes` are provided, then no banned artifacts are granted an exception.
|
||||
|
||||
The `artifact` element supports the descriptive `groupId`/`artifactId`/`version` elements or the abbreviated colon-based notation. When using the colon-based notation, the group ID and artifact ID may be treated as `groupIdRegex` and `artifactIdRegex` (see below). If you only use acceptable `groupId` and `artifactId` characters (letters/numbers/dashes/underscores/dots), it will not. But if you include any other characters, like `\.` or `*`, then it will be treated as regex. How it is treated will impact the functionality of `purge-repo` goal, if you are using it.
|
||||
|
||||
If `groupId` or `artifactId` or `version` are not provided, they are ignored in the matching process. So it will match all applicable artifacts and the constraint will be only for what was specified. This means that `<includes><artifact>:</artifact></includes>` will ban every artifact and all their versions.
|
||||
|
||||
If `groupId` and `groupIdRegex` are both provided, only `groupId` is used. The same is true for `artifactId` and `artifactIdRegex`. The `*Regex` element values use standard Java regular expression parsing. If using regular expressions, remember to escape the dots (`\.`) in group IDs. If you do use `groupIdRegex` or use regular expressions in the colon-notation, the matching artifacts will not be purged using the `purge-repo` goal. So if you intend to use that goal, group ID regular expression matching needs be avoided.
|
||||
If `groupId` and `groupIdRegex` are both provided, only `groupId` is used. The same is true for `artifactId` and `artifactIdRegex`. The `*Regex` element values use standard Java regular expression parsing. If using regular expressions, remember to escape the dots (`\.`) in group IDs. If you do use `groupIdRegex` or use regular expressions in the group part of the colon-notation, the matching artifacts will not be purged using the `purge-repo` goal. So if you intend to use that goal, group ID regular expression matching needs be avoided.
|
||||
|
||||
The `version` element supports the standard Maven specification. You can match a specific version like `1.0.0`. Or you can match all versions before `1.2.17` like `[,1.2.17)`. You can match all future versions after `1.2.17` (inclusive) with `[1.2.17,)`.
|
||||
The `version` element supports the standard [Maven version specification](https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html). You can match a specific version like `[1.0.0]`. Or you can match all versions before `1.2.17` like `[,1.2.17)`. You can match all future versions after `1.2.17` (inclusive) with `[1.2.17,)`. The bracket-less `1.0.0` is not the same as `[1.0.0]`.
|
||||
|
||||
There is nothing stopping you from specifying two `artifact` elements with the exact same values. So you can ban multiple version ranges of the same artifact by using multiple `artifact` elements.
|
||||
|
||||
@@ -142,7 +144,7 @@ This goal will purge the local Maven repository of banned artifacts. The most c
|
||||
mvn -Dban.file=ban-config.xml com.inteligr8:ban-maven-plugin:1.4.1:purge-repo clean
|
||||
```
|
||||
|
||||
This goal does **NOT support** `groupIdRegex` or blank `groupId` specifications. So any of those will be ignored not be purged/removed (if in `includes`).
|
||||
This goal does **NOT support** `groupIdRegex` or blank `groupId` specifications. So any of those will be ignored and not be purged/removed (if in `includes`).
|
||||
|
||||
#### Configuration
|
||||
|
||||
@@ -160,7 +162,7 @@ The following additional elements/properties are supported:
|
||||
| -------- | ------------------- | ------- | ----------- |
|
||||
| `skip` | `ban.skip` | `false` | `true` to skip the purge. |
|
||||
| `dryRun` | `ban.dryRun` | `false` | `true` to not actually delete any files or directories. |
|
||||
| `eager` | `ban.eager | `false` | `true` to delete non-artifact (e.g. `pom` and `_remote.repositories`) files. |
|
||||
| `eager` | `ban.eager` | `false` | `true` to delete non-artifact (e.g. `pom` and `_remote.repositories`) files. |
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<groupId>com.inteligr8</groupId>
|
||||
<artifactId>ban-maven-plugin</artifactId>
|
||||
<version>1.4-SNAPSHOT</version>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
||||
<name>Ban Artifacts Maven Plugin</name>
|
||||
@@ -46,23 +46,25 @@
|
||||
<maven.version>3.9.11</maven.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.19.0</version>
|
||||
</dependency>
|
||||
<!-- v2.11 included by file-management v3.1 -->
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.20.0</version>
|
||||
<version>2.21.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.shared</groupId>
|
||||
<artifactId>file-management</artifactId>
|
||||
<!-- v3.2+ appears to require maven v4+ -->
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
@@ -178,28 +180,18 @@
|
||||
<projectsDirectory>${basedir}/src/it</projectsDirectory>
|
||||
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
|
||||
<mavenHome>${env.MAVEN_HOME}</mavenHome>
|
||||
<debug>true</debug>
|
||||
<ignoreFailures>true</ignoreFailures>
|
||||
<parallelThreads>4</parallelThreads>
|
||||
<properties>
|
||||
<project.main.basedir>${basedir}</project.main.basedir>
|
||||
</properties>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>run-its</id>
|
||||
<goals>
|
||||
<goal>install</goal>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>run-it-1</id>
|
||||
<id>run-it</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>run-it</name>
|
||||
@@ -227,6 +219,30 @@
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>run-its</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>!run-it</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-invoker-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>run-its</id>
|
||||
<goals>
|
||||
<goal>install</goal>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>central-publish</id>
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
invoker.buildResult=failure
|
||||
@@ -5,12 +5,12 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.inteligr8</groupId>
|
||||
<artifactId>ban-maven-plugin-log4j-all</artifactId>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@-log4j-all</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Log4j Ban Plugin Tests</name>
|
||||
<name>Ban Plugin Test: All Log4J</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -23,12 +23,8 @@
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>ban-maven-plugin</artifactId>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.inteligr8</groupId>
|
||||
<artifactId>ban-maven-plugin-log4j-old</artifactId>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@-log4j-old</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Log4j Ban Plugin Tests</name>
|
||||
<name>Ban Plugin Test: Old Log4J</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -23,8 +23,8 @@
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>ban-maven-plugin</artifactId>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.inteligr8</groupId>
|
||||
<artifactId>ban-maven-plugin-log4j-old</artifactId>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@-log4j-purge</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Log4j Ban Plugin Tests</name>
|
||||
<name>Ban Plugin Test: Purge Old Log4J</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -23,12 +23,8 @@
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>ban-maven-plugin</artifactId>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
@@ -41,6 +37,7 @@
|
||||
<excludes>
|
||||
<artifact>log4j:log.+:[1.2.17,)</artifact>
|
||||
</excludes>
|
||||
<eager>true</eager>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
invoker.buildResult=failure
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@-parent</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>@pom.artifactId@-module</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Ban Plugin Test: Module</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<extensions>true</extensions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@-parent</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Ban Plugin Test: Parent</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<configuration>
|
||||
<includes>
|
||||
<artifact>log4j:log.*</artifact>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<modules>
|
||||
<module>module</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@-noext</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Ban Plugin Test: Not Extension</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -5,22 +5,18 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.inteligr8</groupId>
|
||||
<artifactId>ban-maven-plugin-unsued</artifactId>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@-none</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Log4j Ban Plugin Tests</name>
|
||||
<name>Ban Plugin Test: Nothing</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>ban-maven-plugin</artifactId>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<extensions>true</extensions>
|
||||
</plugin>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
invoker.buildResult=failure
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@-parent</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>@pom.artifactId@-module</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Ban Plugin Test: Module</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@-parent</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Ban Plugin Test: Parent</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<includes>
|
||||
<artifact>log4j:log.*</artifact>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<modules>
|
||||
<module>module</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
@@ -5,19 +5,15 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.inteligr8</groupId>
|
||||
<artifactId>ban-maven-plugin-unsued</artifactId>
|
||||
<groupId>@pom.groupId@</groupId>
|
||||
<artifactId>@pom.artifactId@-unsued</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Log4j Ban Plugin Tests</name>
|
||||
<name>Ban Plugin Test: Unused</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>ban-maven-plugin</artifactId>
|
||||
|
||||
@@ -22,11 +22,11 @@ import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.artifact.versioning.VersionRange;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.eclipse.aether.artifact.Artifact;
|
||||
import org.eclipse.aether.artifact.DefaultArtifact;
|
||||
@@ -94,34 +94,28 @@ public abstract class AbstractBanConfiguration implements BanConfiguration {
|
||||
this.versionRangeResolver = versionRangeResolver;
|
||||
}
|
||||
|
||||
public void init(Xpp3Dom rootDom) throws IOException, MojoFailureException {
|
||||
this.init(rootDom, null);
|
||||
}
|
||||
|
||||
public void init(Xpp3Dom rootDom, Properties userProperties) throws IOException, MojoFailureException {
|
||||
if (userProperties != null) {
|
||||
public void amendProperties(Properties userProperties) throws IOException, MojoFailureException {
|
||||
if (userProperties.containsKey("ban.file"))
|
||||
this.processFileImport(StringUtils.trimToNull(userProperties.getProperty("ban.file")));
|
||||
this.processFileImport(this.trimToNull(userProperties.getProperty("ban.file")));
|
||||
if (userProperties.containsKey("ban.url"))
|
||||
this.processUrlImport(StringUtils.trimToNull(userProperties.getProperty("ban.url")));
|
||||
this.processUrlImport(this.trimToNull(userProperties.getProperty("ban.url")));
|
||||
if (userProperties.containsKey("ban.artifact"))
|
||||
this.processArtifactImport(StringUtils.trimToNull(userProperties.getProperty("ban.artifact")));
|
||||
this.processArtifactImport(this.trimToNull(userProperties.getProperty("ban.artifact")));
|
||||
}
|
||||
|
||||
if (rootDom != null) {
|
||||
public void amendConfigurationElement(Xpp3Dom rootDom) throws IOException, MojoFailureException {
|
||||
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()) {
|
||||
if (child.getName().equals("file")) {
|
||||
this.processFileImport(StringUtils.trimToNull(child.getValue()));
|
||||
this.processFileImport(this.trimToNull(child.getValue()));
|
||||
} else if (child.getName().equals("url")) {
|
||||
this.processUrlImport(StringUtils.trimToNull(child.getValue()));
|
||||
this.processUrlImport(this.trimToNull(child.getValue()));
|
||||
} else if (child.getName().equals("artifact")) {
|
||||
this.processArtifactImport(child.getValue());
|
||||
} else {
|
||||
@@ -136,7 +130,7 @@ public abstract class AbstractBanConfiguration implements BanConfiguration {
|
||||
}
|
||||
|
||||
private BanConfigurationDownloader getUrlDownloader(String url) throws IOException, MojoFailureException {
|
||||
url = StringUtils.trimToNull(url);
|
||||
url = this.trimToNull(url);
|
||||
return new BanConfigurationDownloader(this.session, this.artifactResolver, this.versionRangeResolver, url);
|
||||
}
|
||||
|
||||
@@ -221,9 +215,6 @@ public abstract class AbstractBanConfiguration implements BanConfiguration {
|
||||
Xpp3Dom excludesDom = rootDom.getChild("excludes");
|
||||
if (excludesDom != null)
|
||||
this.excludeArtifacts.addAll(this.parseArtifacts(excludesDom));
|
||||
|
||||
this.logger.debug("Include artifacts: {}", this.includeArtifacts);
|
||||
this.logger.debug("Exclude artifacts: {}", this.excludeArtifacts);
|
||||
}
|
||||
|
||||
public List<ArtifactFilter> getIncludeArtifacts() {
|
||||
@@ -248,18 +239,18 @@ public abstract class AbstractBanConfiguration implements BanConfiguration {
|
||||
}
|
||||
|
||||
if (this.notRegexPattern.matcher(matcher.group(1)).matches()) {
|
||||
filter.setGroupId(StringUtils.trimToNull(matcher.group(1)));
|
||||
filter.setGroupId(this.trimToNull(matcher.group(1)));
|
||||
} else {
|
||||
filter.setGroupIdRegex(StringUtils.trimToNull(matcher.group(1)));
|
||||
filter.setGroupIdRegex(this.trimToNull(matcher.group(1)));
|
||||
}
|
||||
|
||||
if (this.notRegexPattern.matcher(matcher.group(2)).matches()) {
|
||||
filter.setArtifactId(StringUtils.trimToNull(matcher.group(2)));
|
||||
filter.setArtifactId(this.trimToNull(matcher.group(2)));
|
||||
} else {
|
||||
filter.setArtifactIdRegex(StringUtils.trimToNull(matcher.group(2)));
|
||||
filter.setArtifactIdRegex(this.trimToNull(matcher.group(2)));
|
||||
}
|
||||
|
||||
versionSpec = StringUtils.trimToNull(matcher.group(4));
|
||||
versionSpec = this.trimToNull(matcher.group(4));
|
||||
} else {
|
||||
filter.setGroupId(this.getChildValue(artifactDom, "groupId"));
|
||||
filter.setGroupIdRegex(this.getChildValue(artifactDom, "groupIdRegex"));
|
||||
@@ -287,7 +278,21 @@ public abstract class AbstractBanConfiguration implements BanConfiguration {
|
||||
|
||||
private String getChildValue(Xpp3Dom dom, String child) {
|
||||
Xpp3Dom childDom = dom.getChild(child);
|
||||
return childDom == null ? null : StringUtils.trimToNull(childDom.getValue());
|
||||
return childDom == null ? null : this.trimToNull(childDom.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-implemented here just to avoid unnecessary dependencies, since this
|
||||
* plugin is about banning dependencies.
|
||||
*
|
||||
* @param value A string value; may be null
|
||||
* @return A trim, but if empty, return `null`; `null` returns `null`.
|
||||
*/
|
||||
protected String trimToNull(String value) {
|
||||
if (value == null)
|
||||
return null;
|
||||
value = StringUtils.trim(value);
|
||||
return value.isEmpty() ? null : value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,10 +54,13 @@ public class BanConfigurationDownloader extends AbstractBanConfiguration {
|
||||
|
||||
try {
|
||||
Xpp3Dom rootDom = this.load(new URL(url));
|
||||
this.init(rootDom);
|
||||
this.amendConfigurationElement(rootDom);
|
||||
} catch (XmlPullParserException xppe) {
|
||||
throw new MojoFailureException(xppe.getMessage(), xppe);
|
||||
}
|
||||
|
||||
this.logger.debug("Include artifacts: {}", this.includeArtifacts);
|
||||
this.logger.debug("Exclude artifacts: {}", this.excludeArtifacts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,10 +78,13 @@ public class BanConfigurationDownloader extends AbstractBanConfiguration {
|
||||
|
||||
try {
|
||||
Xpp3Dom rootDom = this.load(file);
|
||||
this.init(rootDom);
|
||||
this.amendConfigurationElement(rootDom);
|
||||
} catch (XmlPullParserException xppe) {
|
||||
throw new MojoFailureException(xppe.getMessage(), xppe);
|
||||
}
|
||||
|
||||
this.logger.debug("Include artifacts: {}", this.includeArtifacts);
|
||||
this.logger.debug("Exclude artifacts: {}", this.excludeArtifacts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.VersionRange;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.eclipse.aether.artifact.Artifact;
|
||||
import org.eclipse.aether.graph.DependencyFilter;
|
||||
import org.eclipse.aether.graph.DependencyNode;
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.inteligr8.maven.ban;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
@@ -81,11 +82,36 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
|
||||
@Parameter(name = "excludes")
|
||||
private List<String> excludes;
|
||||
|
||||
/**
|
||||
* This does not execute unless the plugin is declared an extension at some
|
||||
* layer in the reactor. That could be the current project, an ancestor,
|
||||
* or a module. It will only execute once and in the context where
|
||||
* `session.getCurrentProject()` is the POM `mvn` was executed on.
|
||||
*/
|
||||
@Override
|
||||
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
|
||||
BanConfiguration config = this.getConfiguration(session);
|
||||
if (config == null)
|
||||
return;
|
||||
List<MavenProject> extensionProjects = new LinkedList<>();
|
||||
|
||||
MavenProject project = session.getCurrentProject();
|
||||
Plugin plugin = this.getExtensionPlugin(project);
|
||||
if (plugin != null)
|
||||
extensionProjects.add(project);
|
||||
|
||||
for (MavenProject childProject : session.getProjectDependencyGraph().getDownstreamProjects(project, true)) {
|
||||
plugin = this.getExtensionPlugin(childProject);
|
||||
if (plugin != null)
|
||||
extensionProjects.add(childProject);
|
||||
}
|
||||
|
||||
this.logger.debug("Discovered {} projects with the '{}' plugin as an extension: {}", extensionProjects.size(), THIS_PLUGIN_KEY, extensionProjects);
|
||||
|
||||
for (MavenProject extensionProject : extensionProjects) {
|
||||
this.handleProject(session, extensionProject);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleProject(MavenSession session, MavenProject project) throws MavenExecutionException {
|
||||
BanConfiguration config = this.getConfiguration(session, project);
|
||||
|
||||
BanDependencyFilter depFilter = new BanDependencyFilter(
|
||||
config.getIncludeArtifacts(),
|
||||
@@ -93,11 +119,9 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
|
||||
//depFilter.setFailFast(true);
|
||||
boolean fail = false;
|
||||
|
||||
MavenProject project = session.getCurrentProject();
|
||||
|
||||
try {
|
||||
for (Plugin plugin : project.getBuildPlugins()) {
|
||||
this.logger.debug("Evaluating plugin dependencies: {}", plugin);
|
||||
this.logger.debug("Evaluating plugin dependencies: {}: {}", project, plugin);
|
||||
|
||||
Artifact artifact = new DefaultArtifact(plugin.getId());
|
||||
DependencyNode depNodeRoot = this.pluginDepResolver.resolve(plugin, artifact, depFilter, project.getRemotePluginRepositories(), session.getRepositorySession());
|
||||
@@ -132,23 +156,41 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
|
||||
throw new MavenExecutionException("Banned dependencies were detected; see warnings: ", project.getFile());
|
||||
}
|
||||
|
||||
private BanConfiguration getConfiguration(MavenSession session) throws MavenExecutionException {
|
||||
MavenProject project = session.getCurrentProject();
|
||||
private Plugin getExtensionPlugin(MavenProject project) {
|
||||
Plugin plugin = project.getPlugin(THIS_PLUGIN_KEY);
|
||||
if (plugin == null)
|
||||
throw new MavenExecutionException("The plugin is executing but it cannot be found", project.getFile());
|
||||
|
||||
if (!plugin.isExtensions()) {
|
||||
this.logger.warn("The '{}' plugin must be defined with '<extensions>true</extensions>'; ignoring plugin", plugin.getId());
|
||||
if (plugin == null) {
|
||||
this.logger.debug("Although a module declares the '{}' plugin, the ancestral project '{}' does not", THIS_PLUGIN_KEY, project.getId());
|
||||
return null;
|
||||
} else if (!plugin.isExtensions()) {
|
||||
this.logger.debug("Although an ancester or module declares the '{}' plugin as an extension, this project '{}' does not", plugin.getId(), project.getId());
|
||||
return null;
|
||||
} else {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
|
||||
private BanConfiguration getConfiguration(MavenSession session, MavenProject project) throws MavenExecutionException {
|
||||
Plugin plugin = project.getPlugin(THIS_PLUGIN_KEY);
|
||||
this.logger.debug("Found plugin definition in project: {}", project.getId());
|
||||
Stack<Plugin> pluginDefinitions = new Stack<>();
|
||||
pluginDefinitions.push(plugin);
|
||||
|
||||
MavenProject parent = project.getParent();
|
||||
while (parent != null) {
|
||||
plugin = parent.getPlugin(THIS_PLUGIN_KEY);
|
||||
if (plugin != null) {
|
||||
this.logger.debug("Found plugin definition in project: {}", parent.getId());
|
||||
pluginDefinitions.push(plugin);
|
||||
}
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
try {
|
||||
return new BanPluginConfigurationParser(session, this.artifactResolver, this.versionRangeResolver, plugin);
|
||||
return new BanPluginConfigurationParser(session, this.artifactResolver, this.versionRangeResolver, pluginDefinitions);
|
||||
} catch (IOException | MojoFailureException e) {
|
||||
throw new MavenExecutionException(e.getMessage(), project.getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<Dependency> crawlDependencyTree(DependencyNode depNode, DependencyFilter depFilter) {
|
||||
return this.crawlDependencyTree(depNode, new LinkedList<>(), depFilter);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.inteligr8.maven.ban;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.Plugin;
|
||||
@@ -22,6 +23,8 @@ import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.eclipse.aether.impl.ArtifactResolver;
|
||||
import org.eclipse.aether.impl.VersionRangeResolver;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* This class parses the POM plugin configuration block for this plugin. The
|
||||
@@ -30,11 +33,34 @@ import org.eclipse.aether.impl.VersionRangeResolver;
|
||||
*/
|
||||
public class BanPluginConfigurationParser extends AbstractBanConfiguration {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public BanPluginConfigurationParser(MavenSession session, ArtifactResolver artifactResolver, VersionRangeResolver versionRangeResolver, Plugin plugin) throws IOException, MojoFailureException {
|
||||
super(session, artifactResolver, versionRangeResolver);
|
||||
|
||||
Xpp3Dom rootDom = plugin == null ? null : (Xpp3Dom) plugin.getConfiguration();
|
||||
this.init(rootDom, session.getUserProperties());
|
||||
if (session.getUserProperties() != null)
|
||||
this.amendProperties(session.getUserProperties());
|
||||
if (plugin != null) {
|
||||
Xpp3Dom rootDom = (Xpp3Dom) plugin.getConfiguration();
|
||||
if (rootDom != null)
|
||||
this.amendConfigurationElement(rootDom);
|
||||
}
|
||||
}
|
||||
|
||||
public BanPluginConfigurationParser(MavenSession session, ArtifactResolver artifactResolver, VersionRangeResolver versionRangeResolver, Stack<Plugin> plugins) throws IOException, MojoFailureException {
|
||||
super(session, artifactResolver, versionRangeResolver);
|
||||
|
||||
if (session.getUserProperties() != null)
|
||||
this.amendProperties(session.getUserProperties());
|
||||
while (!plugins.isEmpty()) {
|
||||
Plugin plugin = plugins.pop();
|
||||
Xpp3Dom rootDom = (Xpp3Dom) plugin.getConfiguration();
|
||||
if (rootDom != null)
|
||||
this.amendConfigurationElement(rootDom);
|
||||
}
|
||||
|
||||
this.logger.debug("Include artifacts: {}", this.includeArtifacts);
|
||||
this.logger.debug("Exclude artifacts: {}", this.excludeArtifacts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class PurgeRepoMojo extends AbstractMojo {
|
||||
if (this.skip) {
|
||||
this.getLog().debug("Skipping purge of banned artifacts");
|
||||
} else {
|
||||
this.getLog().info("Purging banned artifacts from local repository: " + this.session.getLocalRepository().getBasedir());
|
||||
this.getLog().info("Purging banned artifacts from local repository: " + this.session.getRepositorySession().getLocalRepository().getBasedir());
|
||||
|
||||
try {
|
||||
this.purge();
|
||||
@@ -282,7 +282,7 @@ public class PurgeRepoMojo extends AbstractMojo {
|
||||
}
|
||||
|
||||
private Path getRepositoryPath() {
|
||||
return new File(this.session.getLocalRepository().getBasedir()).toPath();
|
||||
return this.session.getRepositorySession().getLocalRepository().getBasedir().toPath();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user