Author: gboue Date: Thu Feb 9 21:30:04 2017 New Revision: 1782394 URL: http://svn.apache.org/viewvc?rev=1782394&view=rev Log: [MSHARED-616] Dependencies inside pluginManagement are not taken into account in reporting
Following the fix introduced in MSITE-507, we also need to take into account the case where the reporting plugin is only present in the build/pluginManagement section. Otherwise, its dependencies are ignored. Added: maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/ maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/invoker.properties (with props) maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/pom.xml (with props) maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/verify.groovy (with props) Modified: maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java maven/shared/trunk/maven-reporting-exec/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java Added: maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/invoker.properties URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/invoker.properties?rev=1782394&view=auto ============================================================================== --- maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/invoker.properties (added) +++ maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/invoker.properties Thu Feb 9 21:30:04 2017 @@ -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=clean site \ No newline at end of file Propchange: maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/invoker.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/invoker.properties ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/pom.xml URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/pom.xml?rev=1782394&view=auto ============================================================================== --- maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/pom.xml (added) +++ maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/pom.xml Thu Feb 9 21:30:04 2017 @@ -0,0 +1,72 @@ +<?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.shared.maren-reporting-exec.its</groupId> + <artifactId>pluginmanagement-dependencies</artifactId> + <version>1.0-SNAPSHOT</version> + <description>Tests that dependencies of build.pluginManagement are taken into account during reporting</description> + <url>https://issues.apache.org/jira/browse/MSHARED-616</url> + <build> + <pluginManagement> + <plugins> + <plugin> + <artifactId>maven-checkstyle-plugin</artifactId> + <version>2.17</version> + <dependencies> + <dependency> + <groupId>com.puppycrawl.tools</groupId> + <artifactId>checkstyle</artifactId> + <version>7.5</version> + </dependency> + </dependencies> + </plugin> + <plugin> + <artifactId>maven-site-plugin</artifactId> + <version>3.3</version> + <dependencies> + <dependency> + <groupId>@project.groupId@</groupId> + <artifactId>@project.artifactId@</artifactId> + <version>@project.version@</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </pluginManagement> + </build> + <reporting> + <plugins> + <plugin> + <artifactId>maven-checkstyle-plugin</artifactId> + <reportSets> + <reportSet> + <reports> + <report>checkstyle</report> + </reports> + </reportSet> + </reportSets> + </plugin> + </plugins> + </reporting> +</project> Propchange: maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/verify.groovy URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/verify.groovy?rev=1782394&view=auto ============================================================================== --- maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/verify.groovy (added) +++ maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/verify.groovy Thu Feb 9 21:30:04 2017 @@ -0,0 +1,26 @@ + +/* + * 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. + */ + +content = new File( basedir, 'build.log' ).text; + +assert !content.contains( 'com.puppycrawl.tools:checkstyle:jar:6.11.2' ); +assert content.contains( 'com.puppycrawl.tools:checkstyle:jar:7.5' ); + +return true; \ No newline at end of file Propchange: maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/verify.groovy ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/shared/trunk/maven-reporting-exec/src/it/pluginManagement_dependencies/verify.groovy ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java?rev=1782394&r1=1782393&r2=1782394&view=diff ============================================================================== --- maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java (original) +++ maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java Thu Feb 9 21:30:04 2017 @@ -27,6 +27,7 @@ import java.util.List; import java.util.Set; import org.apache.maven.lifecycle.LifecycleExecutor; +import org.apache.maven.model.Build; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MavenPluginManager; import org.apache.maven.plugin.Mojo; @@ -648,6 +649,7 @@ public class DefaultMavenReportExecutor * <li>dependencies</li> * </ul> * </p> + * The plugin could only be present in the dependency management section. * * @param mavenReportExecutorRequest * @param buildPlugin @@ -656,7 +658,12 @@ public class DefaultMavenReportExecutor private void mergePluginToReportPlugin( MavenReportExecutorRequest mavenReportExecutorRequest, Plugin buildPlugin, ReportPlugin reportPlugin ) { - Plugin configuredPlugin = find( reportPlugin, mavenReportExecutorRequest.getProject().getBuild().getPlugins() ); + Build build = mavenReportExecutorRequest.getProject().getBuild(); + Plugin configuredPlugin = find( reportPlugin, build.getPlugins() ); + if ( configuredPlugin == null && build.getPluginManagement() != null ) + { + configuredPlugin = find( reportPlugin, build.getPluginManagement().getPlugins() ); + } if ( configuredPlugin != null ) { if ( !configuredPlugin.getDependencies().isEmpty() ) Modified: maven/shared/trunk/maven-reporting-exec/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-exec/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java?rev=1782394&r1=1782393&r2=1782394&view=diff ============================================================================== --- maven/shared/trunk/maven-reporting-exec/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java (original) +++ maven/shared/trunk/maven-reporting-exec/src/test/java/org/apache/maven/reporting/exec/TestDefaultMavenReportExecutor.java Thu Feb 9 21:30:04 2017 @@ -32,6 +32,9 @@ import org.apache.maven.execution.MavenE import org.apache.maven.execution.MavenExecutionResult; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Build; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; @@ -79,7 +82,8 @@ public class TestDefaultMavenReportExecu reportSet.getReports().add( "test-javadoc" ); reportSet.getReports().add( "javadoc" ); - List<MavenReportExecution> mavenReportExecutions = buildReports( reportSet ); + MavenProject mavenProject = getMavenProject(); + List<MavenReportExecution> mavenReportExecutions = buildReports( mavenProject, reportSet ); assertNotNull( mavenReportExecutions ); assertEquals( 2, mavenReportExecutions.size() ); @@ -96,7 +100,8 @@ public class TestDefaultMavenReportExecu reportSet2.getReports().add( "test-javadoc" ); reportSet2.getReports().add( "javadoc" ); - List<MavenReportExecution> mavenReportExecutions = buildReports( reportSet, reportSet2 ); + MavenProject mavenProject = getMavenProject(); + List<MavenReportExecution> mavenReportExecutions = buildReports( mavenProject, reportSet, reportSet2 ); assertNotNull( mavenReportExecutions ); assertEquals( 3, mavenReportExecutions.size() ); @@ -105,7 +110,35 @@ public class TestDefaultMavenReportExecu assertEquals( "apidocs/index", mavenReportExecutions.get( 2 ).getMavenReport().getOutputName() ); } - private List<MavenReportExecution> buildReports( ReportSet... javadocReportSets ) + public void testReportingPluginWithDependenciesInPluginManagement() + throws Exception + { + ReportSet reportSet = new ReportSet(); + reportSet.getReports().add( "javadoc" ); + + MavenProject mavenProject = getMavenProject(); + Plugin plugin = new Plugin(); + plugin.setGroupId( "org.apache.maven.plugins" ); + plugin.setArtifactId( "maven-javadoc-plugin" ); + plugin.setVersion( "2.7" ); + Dependency dependency = new Dependency(); + dependency.setGroupId( "commons-lang" ); + dependency.setArtifactId( "commons-lang" ); + dependency.setVersion( "2.6" ); + plugin.getDependencies().add( dependency ); + mavenProject.getBuild().setPluginManagement( new PluginManagement() ); + mavenProject.getBuild().getPluginManagement().addPlugin( plugin ); + List<MavenReportExecution> mavenReportExecutions = buildReports( mavenProject, reportSet ); + + assertNotNull( mavenReportExecutions ); + assertEquals( 1, mavenReportExecutions.size() ); + List<Dependency> dependencies = mavenReportExecutions.get( 0 ).getPlugin().getDependencies(); + assertEquals( 1, dependencies.size() ); + assertEquals( "commons-lang", dependencies.get( 0 ).getGroupId() ); + assertEquals( "2.6", dependencies.get( 0 ).getVersion() ); + } + + private List<MavenReportExecution> buildReports( MavenProject mavenProject, ReportSet... javadocReportSets ) throws Exception { ClassLoader orig = Thread.currentThread().getContextClassLoader(); @@ -118,8 +151,6 @@ public class TestDefaultMavenReportExecu mavenReportExecutorRequest.setLocalRepository( getLocalArtifactRepository() ); - MavenProject mavenProject = getMavenProject(); - mavenReportExecutorRequest.setProject( mavenProject ); MavenSession mavenSession = getMavenSession( getLocalArtifactRepository(), mavenProject );