You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/01/11 11:31:58 UTC
[maven-project-info-reports-plugin] 01/01: add plugin excludes
feature for plugin-management report Added pluginManagementExcludes list
parameter.
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MPIR-375
in repository https://gitbox.apache.org/repos/asf/maven-project-info-reports-plugin.git
commit 82f4bf23b79fe87d2e414c70ab2058e8f1b4146b
Author: Gabriel Belingueres <be...@gmail.com>
AuthorDate: Sun Nov 25 16:36:12 2018 -0300
add plugin excludes feature for plugin-management report Added pluginManagementExcludes list parameter.
---
pom.xml | 1 +
src/it/MPIR-375/invoker.properties | 18 +++
src/it/MPIR-375/pom.xml | 125 +++++++++++++++++++++
src/it/MPIR-375/verify.groovy | 29 +++++
.../report/projectinfo/PluginManagementReport.java | 78 +++++++++++--
.../projectinfo/PluginManagementReportTest.java | 47 +++++++-
.../stubs/PluginManagementMPIR375Stub.java | 35 ++++++
.../plugin-management-plugin-config-MPIR-375.xml | 89 +++++++++++++++
8 files changed, 414 insertions(+), 8 deletions(-)
diff --git a/pom.xml b/pom.xml
index 883b729..20007a1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -81,6 +81,7 @@ under the License.
</contributor>
<contributor>
<name>Gabriel Belingueres</name>
+ <email>belingueres@gmail.com</email>
</contributor>
<contributor>
<name>Simon Wang</name>
diff --git a/src/it/MPIR-375/invoker.properties b/src/it/MPIR-375/invoker.properties
new file mode 100644
index 0000000..1c5ce88
--- /dev/null
+++ b/src/it/MPIR-375/invoker.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:plugin-management
diff --git a/src/it/MPIR-375/pom.xml b/src/it/MPIR-375/pom.xml
new file mode 100644
index 0000000..16afb89
--- /dev/null
+++ b/src/it/MPIR-375/pom.xml
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+-->
+
+<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.project-info-reports.its</groupId>
+ <artifactId>MPIR-375</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <url>http://maven.apache.org/plugins/it/${project.artifactId}</url>
+
+ <properties>
+ <maven.compiler.source>1.7</maven.compiler.source>
+ <maven.compiler.target>1.7</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ </properties>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. -->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>keytool-maven-plugin</artifactId>
+ <versionRange>[1.5,)</versionRange>
+ <goals>
+ <goal>clean</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore></ignore>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>3.0.1</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>@sitePluginVersion@</version>
+ </plugin>
+ <!--
+ Example plugin generating the Eclipse's "Plugin execution not covered by lifecycle configuration" error message
+ -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>keytool-maven-plugin</artifactId>
+ <version>1.5</version>
+ <executions>
+ <execution>
+ <id>init</id>
+ <phase>initialize</phase>
+ <goals>
+ <goal>clean</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>@pom.version@</version>
+ <configuration>
+ <pluginManagementExcludes>
+ <pluginManagementExclude>org.eclipse.m2e:lifecycle-mapping</pluginManagementExclude>
+ </pluginManagementExcludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>@pom.version@</version>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>plugin-management</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
diff --git a/src/it/MPIR-375/verify.groovy b/src/it/MPIR-375/verify.groovy
new file mode 100644
index 0000000..3bf172b
--- /dev/null
+++ b/src/it/MPIR-375/verify.groovy
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+File log = new File( basedir, 'build.log' );
+assert !( log.text.contains("org.eclipse.aether.transfer.ArtifactNotFoundException: Failure to find org.eclipse.m2e:lifecycle-mapping:pom") );
+
+plugins = new File( basedir, 'target/site/plugin-management.html' ).text;
+
+// maven-javadoc-plugin is defined in pluginManagement and not excluded
+assert plugins.contains( 'maven-javadoc-plugin' );
+
+// org.eclipse.m2e:lifecycle-mapping plugin is excluded
+assert !( plugins.contains( 'org.eclipse.m2e' ) );
+assert !( plugins.contains( 'lifecycle-mapping' ) );
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/report/projectinfo/PluginManagementReport.java b/src/main/java/org/apache/maven/report/projectinfo/PluginManagementReport.java
index b14d511..a9f088b 100644
--- a/src/main/java/org/apache/maven/report/projectinfo/PluginManagementReport.java
+++ b/src/main/java/org/apache/maven/report/projectinfo/PluginManagementReport.java
@@ -26,6 +26,7 @@ import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
@@ -51,6 +52,17 @@ import java.util.Locale;
public class PluginManagementReport
extends AbstractProjectInfoReport
{
+
+ /**
+ * Specify the excluded plugins. This can be a list of artifacts in the format
+ * groupId[:artifactId[:type[:version]]]. <br>
+ * Plugins matching any exclude will not be present in the report.
+ *
+ * @since 3.0.1
+ */
+ @Parameter
+ private List<String> pluginManagementExcludes = null;
+
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
@@ -61,7 +73,8 @@ public class PluginManagementReport
PluginManagementRenderer r =
new PluginManagementRenderer( getLog(), getSink(), locale, getI18N( locale ),
project.getPluginManagement().getPlugins(), project, projectBuilder,
- repositorySystem, getSession().getProjectBuildingRequest() );
+ repositorySystem, getSession().getProjectBuildingRequest(),
+ pluginManagementExcludes );
r.render();
}
@@ -102,6 +115,7 @@ public class PluginManagementReport
protected static class PluginManagementRenderer
extends AbstractProjectInfoRenderer
{
+
private final Log log;
private final List<Plugin> pluginManagement;
@@ -113,6 +127,8 @@ public class PluginManagementReport
private final RepositorySystem repositorySystem;
private final ProjectBuildingRequest buildingRequest;
+
+ private final List<String> excludes;
/**
* @param log {@link #log}
@@ -124,10 +140,12 @@ public class PluginManagementReport
* @param projectBuilder {@link ProjectBuilder}
* @param repositorySystem {@link RepositorySystem}
* @param buildingRequest {@link ProjectBuildingRequest}
+ * @param excludes the list of plugins to be excluded from the report
*/
public PluginManagementRenderer( Log log, Sink sink, Locale locale, I18N i18n, List<Plugin> plugins,
MavenProject project, ProjectBuilder projectBuilder,
- RepositorySystem repositorySystem, ProjectBuildingRequest buildingRequest )
+ RepositorySystem repositorySystem, ProjectBuildingRequest buildingRequest,
+ List<String> excludes )
{
super( sink, i18n, locale );
@@ -142,6 +160,8 @@ public class PluginManagementReport
this.repositorySystem = repositorySystem;
this.buildingRequest = buildingRequest;
+
+ this.excludes = excludes;
}
@Override
@@ -200,13 +220,21 @@ public class PluginManagementReport
Artifact pluginArtifact = repositorySystem.createProjectArtifact( plugin.getGroupId(), plugin
.getArtifactId(), versionRange.toString() );
-
+
try
{
- MavenProject pluginProject = projectBuilder.build( pluginArtifact, buildingRequest ).getProject();
-
- tableRow( getPluginRow( pluginProject.getGroupId(), pluginProject.getArtifactId(), pluginProject
- .getVersion(), pluginProject.getUrl() ) );
+ if ( isExcluded( pluginArtifact ) )
+ {
+ log.debug( "Excluding plugin " + pluginArtifact.getId() + " from report" );
+ }
+ else
+ {
+ MavenProject pluginProject =
+ projectBuilder.build( pluginArtifact, buildingRequest ).getProject();
+
+ tableRow( getPluginRow( pluginProject.getGroupId(), pluginProject.getArtifactId(),
+ pluginProject.getVersion(), pluginProject.getUrl() ) );
+ }
}
catch ( ProjectBuildingException e )
{
@@ -255,5 +283,41 @@ public class PluginManagementReport
}
};
}
+
+ private boolean isExcluded( Artifact pluginArtifact )
+ {
+ if ( excludes == null )
+ {
+ return false;
+ }
+
+ for ( String pattern : excludes )
+ {
+ String[] subStrings = pattern.split( ":" );
+ subStrings = StringUtils.stripAll( subStrings );
+ String resultPattern = StringUtils.join( subStrings, ":" );
+
+ if ( compareDependency( resultPattern, pluginArtifact ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Compares the given pattern against the given artifact. The pattern should follow the format
+ * <code>groupId:artifactId:type:classifier:version</code>.
+ *
+ * @param pattern The pattern to compare the artifact with.
+ * @param artifact the artifact
+ * @return <code>true</code> if the artifact matches the pattern
+ */
+ protected boolean compareDependency( String pattern, Artifact artifact )
+ {
+ // TODO: compare with a better pattern matcher, like class ArtifactMatcher from Enforcer rules plugin
+ return artifact.getId().startsWith( pattern );
+ }
}
}
diff --git a/src/test/java/org/apache/maven/report/projectinfo/PluginManagementReportTest.java b/src/test/java/org/apache/maven/report/projectinfo/PluginManagementReportTest.java
index 59f3bf0..9f9281e 100644
--- a/src/test/java/org/apache/maven/report/projectinfo/PluginManagementReportTest.java
+++ b/src/test/java/org/apache/maven/report/projectinfo/PluginManagementReportTest.java
@@ -118,7 +118,52 @@ public class PluginManagementReportTest
TextBlock[] textBlocks = response.getTextBlocks();
assertEquals( getString( "report.plugin-management.title" ), textBlocks[0].getText() );
}
-
+
+ /**
+ * Test report with excludes (to solve MPIR-375)
+ *
+ * @throws Exception if any
+ */
+ public void testReportEclipseM2EPluginLifecycleMapping()
+ throws Exception
+ {
+ generateReport( "plugin-management", "plugin-management-plugin-config-MPIR-375.xml" );
+ assertTrue( "Test html generated", getGeneratedReport( "plugin-management.html" ).exists() );
+
+ URL reportURL = getGeneratedReport( "plugin-management.html" ).toURI().toURL();
+ assertNotNull( reportURL );
+
+ // HTTPUnit
+ WebRequest request = new GetMethodWebRequest( reportURL.toString() );
+ WebResponse response = WEB_CONVERSATION.getResponse( request );
+
+ // Basic HTML tests
+ assertTrue( response.isHTML() );
+ assertTrue( response.getContentLength() > 0 );
+
+ // Test the Page title
+ String expectedTitle = prepareTitle( getString( "report.plugin-management.name" ),
+ getString( "report.plugin-management.title" ) );
+ assertEquals( expectedTitle, response.getTitle() );
+
+ // Test the tables
+ WebTable[] webTables = response.getTables();
+ assertEquals( 1, webTables.length );
+
+ // generated table for the plugin management
+ assertEquals( 3, webTables[0].getColumnCount() );
+ assertEquals( 2, webTables[0].getRowCount() );
+ // row 0 are the table titles
+ // row 1 is the m-javadoc-plugin
+ assertEquals( "org.apache.maven.plugins", webTables[0].getCellAsText( 1, 0 ) );
+ assertEquals( "maven-javadoc-plugin", webTables[0].getCellAsText( 1, 1 ) );
+ assertEquals( "3.0.1", webTables[0].getCellAsText( 1, 2 ) );
+
+ // Test the texts
+ TextBlock[] textBlocks = response.getTextBlocks();
+ assertEquals( getString( "report.plugin-management.title" ), textBlocks[0].getText() );
+ }
+
private static ProjectBuildingResult createProjectBuildingResult( Artifact artifact, String url )
{
ProjectBuildingResult result = mock( ProjectBuildingResult.class );
diff --git a/src/test/java/org/apache/maven/report/projectinfo/stubs/PluginManagementMPIR375Stub.java b/src/test/java/org/apache/maven/report/projectinfo/stubs/PluginManagementMPIR375Stub.java
new file mode 100644
index 0000000..d6bf548
--- /dev/null
+++ b/src/test/java/org/apache/maven/report/projectinfo/stubs/PluginManagementMPIR375Stub.java
@@ -0,0 +1,35 @@
+package org.apache.maven.report.projectinfo.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * @author Gabriel Belingueres
+ * @version $Id$
+ * @since 3.0.1
+ */
+public class PluginManagementMPIR375Stub
+ extends ProjectInfoProjectStub
+{
+ @Override
+ protected String getPOM()
+ {
+ return "plugin-management-plugin-config-MPIR-375.xml";
+ }
+}
diff --git a/src/test/resources/plugin-configs/plugin-management-plugin-config-MPIR-375.xml b/src/test/resources/plugin-configs/plugin-management-plugin-config-MPIR-375.xml
new file mode 100644
index 0000000..6a94350
--- /dev/null
+++ b/src/test/resources/plugin-configs/plugin-management-plugin-config-MPIR-375.xml
@@ -0,0 +1,89 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.plugin.projectinfo.tests</groupId>
+ <artifactId>plugin-management</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>plugin management project info</name>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <!--This plugin's configuration is used to store Eclipse m2e settings only.
+ It has no influence on the Maven build itself. -->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>
+ clirr-maven-plugin
+ </artifactId>
+ <versionRange>[2.8,)</versionRange>
+ <goals>
+ <goal>clirr</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore></ignore>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>3.0.1</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <configuration>
+ <outputDirectory>target/test-harness/plugin-management</outputDirectory>
+ <localRepository>${localRepository}</localRepository>
+ <project implementation="org.apache.maven.report.projectinfo.stubs.PluginManagementMPIR375Stub"/>
+
+ <pluginManagementExcludes>
+ <pluginManagementExclude>org.eclipse.m2e:lifecycle-mapping</pluginManagementExclude>
+ </pluginManagementExcludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>