-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a maven plugin for the dash license tool
The maven plugin is fully configurable and has feature parity with the command line tool. Also allows maven-dependency-plugin style artifact filtering which allows users to ignore deps that are not interesting (e.g. test deps or deps from the Eclipse Foundation itself.) Fixes #7 Signed-off-by: Mat Booth <mat.booth@redhat.com>
- Loading branch information
Showing
11 changed files
with
594 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>dash-maven-plugin</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/main/java=UTF-8 | ||
encoding//src/main/resources=UTF-8 | ||
encoding//src/test/java=UTF-8 | ||
encoding//src/test/resources=UTF-8 | ||
encoding/<project>=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 | ||
org.eclipse.jdt.core.compiler.compliance=11 | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore | ||
org.eclipse.jdt.core.compiler.release=disabled | ||
org.eclipse.jdt.core.compiler.source=11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<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>org.eclipse.dash</groupId> | ||
<artifactId>dash-licenses-parent</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>dash-maven-plugin</artifactId> | ||
<packaging>maven-plugin</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-core</artifactId> | ||
<version>3.6.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-plugin-api</artifactId> | ||
<version>3.6.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.plugin-tools</groupId> | ||
<artifactId>maven-plugin-annotations</artifactId> | ||
<version>3.6.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.shared</groupId> | ||
<artifactId>maven-common-artifact-filters</artifactId> | ||
<version>3.1.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.dash</groupId> | ||
<artifactId>org.eclipse.dash.licenses</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-plugin-plugin</artifactId> | ||
<version>3.6.0</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
141 changes: 141 additions & 0 deletions
141
...n-plugin/src/main/java/org/eclipse/dash/licenses/maven/AbstractArtifactFilteringMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/************************************************************************* | ||
* Copyright (c) 2020, Red Hat Inc. | ||
* | ||
* This program and the accompanying materials are made available under | ||
* the terms of the Eclipse Public License 2.0 which accompanies this | ||
* distribution, and is available at https://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*************************************************************************/ | ||
package org.eclipse.dash.licenses.maven; | ||
|
||
import java.util.Set; | ||
|
||
import org.apache.maven.artifact.Artifact; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; | ||
import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter; | ||
import org.apache.maven.shared.artifact.filter.collection.ClassifierFilter; | ||
import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts; | ||
import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter; | ||
import org.apache.maven.shared.artifact.filter.collection.ScopeFilter; | ||
import org.apache.maven.shared.artifact.filter.collection.TypeFilter; | ||
|
||
/** | ||
* Abstract mojo containing artifact filtering capability. | ||
*/ | ||
public abstract class AbstractArtifactFilteringMojo extends AbstractMojo { | ||
|
||
/** | ||
* Scope of dependencies to include, as determined by Maven. If specified, it | ||
* must be one of the following values: | ||
* <ul> | ||
* <li><code>runtime</code> -- gives runtime and compile dependencies only.</li> | ||
* <li><code>compile</code> -- (default) gives compile, provided, and system | ||
* dependencies only.</li> | ||
* <li><code>test</code> -- gives all dependencies.</li> | ||
* <li><code>provided</code> -- gives provided dependencies only.</li> | ||
* <li><code>system</code> -- gives system dependencies only.</li> | ||
* </ul> | ||
* If no scope is specified, then the default value of <code>compile</code> is | ||
* used, including compile, provided, and system dependencies only. | ||
*/ | ||
@Parameter(defaultValue = "compile") | ||
protected String includeScope; | ||
|
||
/** | ||
* Scope to exclude. An empty string indicates no scopes (default). | ||
*/ | ||
@Parameter(defaultValue = "") | ||
protected String excludeScope; | ||
|
||
/** | ||
* Comma separated list of types to include. Empty string indicates include | ||
* everything (default). | ||
*/ | ||
@Parameter(defaultValue = "") | ||
protected String includeTypes; | ||
|
||
/** | ||
* Comma separated list of types to exclude. Empty string indicates don't | ||
* exclude anything (default). | ||
*/ | ||
@Parameter(defaultValue = "") | ||
protected String excludeTypes; | ||
|
||
/** | ||
* Comma separated list of classifiers to include. Empty string indicates | ||
* include everything (default). | ||
*/ | ||
@Parameter(defaultValue = "") | ||
protected String includeClassifiers; | ||
|
||
/** | ||
* Comma separated list of classifiers to exclude. Empty string indicates don't | ||
* exclude anything (default). | ||
*/ | ||
@Parameter(defaultValue = "") | ||
protected String excludeClassifiers; | ||
|
||
/** | ||
* Comma separated list of group IDs to include. Empty string indicates include | ||
* everything (default). | ||
*/ | ||
@Parameter(defaultValue = "") | ||
protected String includeGroupIds; | ||
|
||
/** | ||
* Comma separated list of group IDs to exclude. Empty string indicates don't | ||
* exclude anything (default). | ||
*/ | ||
@Parameter(defaultValue = "") | ||
protected String excludeGroupIds; | ||
|
||
/** | ||
* Comma separated list of artifact IDs to include. Empty string indicates | ||
* include everything (default). | ||
*/ | ||
@Parameter(defaultValue = "") | ||
protected String includeArtifactIds; | ||
|
||
/** | ||
* Comma separated list of artifact IDs to exclude. Empty string indicates don't | ||
* exclude anything (default). | ||
*/ | ||
@Parameter(defaultValue = "") | ||
protected String excludeArtifactIds; | ||
|
||
/** | ||
* Filter a set of artifacts based on the user-supplied filter parameters. | ||
* | ||
* @param artifacts a set of artifacts to filter | ||
* @return a new set containing only the artifacts that match the filter | ||
* @throws MojoExecutionException if there was a problem filtering the artifacts | ||
*/ | ||
protected Set<Artifact> filterArtifacts(Set<Artifact> artifacts) throws MojoExecutionException { | ||
FilterArtifacts filter = new FilterArtifacts(); | ||
filter.addFilter(new ScopeFilter(sanitise(includeScope), sanitise(excludeScope))); | ||
filter.addFilter(new TypeFilter(sanitise(includeTypes), sanitise(excludeTypes))); | ||
filter.addFilter(new ClassifierFilter(sanitise(includeClassifiers), sanitise(excludeClassifiers))); | ||
filter.addFilter(new GroupIdFilter(sanitise(includeGroupIds), sanitise(excludeGroupIds))); | ||
filter.addFilter(new ArtifactIdFilter(sanitise(includeArtifactIds), sanitise(excludeArtifactIds))); | ||
try { | ||
return filter.filter(artifacts); | ||
} catch (ArtifactFilterException e) { | ||
throw new MojoExecutionException(e.getMessage(), e); | ||
} | ||
} | ||
|
||
/** | ||
* Utility to strip extraneous spaces from user-supplied filter parameters. | ||
*/ | ||
private static String sanitise(String value) { | ||
String sanitised = ""; | ||
if (value != null && !value.isEmpty()) { | ||
sanitised = value.trim().replaceAll("[\\s]*,[\\s]*", ","); | ||
} | ||
return sanitised; | ||
} | ||
} |
Oops, something went wrong.