You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2008/07/25 22:20:27 UTC
svn commit: r679892 - in /maven:
components/branches/maven-2.0.10-RC/maven-core/src/main/java/org/apache/maven/plugin/
core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/
core-integration-testing/trunk...
Author: jdcasey
Date: Fri Jul 25 13:20:26 2008
New Revision: 679892
URL: http://svn.apache.org/viewvc?rev=679892&view=rev
Log:
[MNG-3684] Adding integration test to verify fix, and surrounding report configuration/instantiation with calls to make the project build section concrete, then restore it to dynamic mode after the report is ready to go. The execution of a plugin that uses these reports will trigger the calculation of the project's concrete state again, but we don't want to leave the project in this state in the meantime.
Added:
maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3684BuildPluginParameterTest.java
maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/
maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/
maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/pom.xml
maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/
maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/main/
maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/main/java/
maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/main/java/plugin/
maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/main/java/plugin/MyMojo.java
maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/main/java/plugin/MyReport.java
maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/project/
maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/project/pom.xml
Modified:
maven/components/branches/maven-2.0.10-RC/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/IntegrationTestSuite.java
Modified: maven/components/branches/maven-2.0.10-RC/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.10-RC/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=679892&r1=679891&r2=679892&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.10-RC/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java (original)
+++ maven/components/branches/maven-2.0.10-RC/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java Fri Jul 25 13:20:26 2008
@@ -556,14 +556,39 @@
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
PluginDescriptor descriptor = mojoDescriptor.getPluginDescriptor();
+
+ if ( !project.isConcrete() )
+ {
+ try
+ {
+ mavenProjectBuilder.calculateConcreteState( project, session.getProjectBuilderConfiguration() );
+ }
+ catch ( ModelInterpolationException e )
+ {
+ throw new PluginManagerException( "Failed to calculate concrete state for project: " + project, e );
+ }
+ }
+
Xpp3Dom dom = project.getReportConfiguration( descriptor.getGroupId(), descriptor.getArtifactId(),
mojoExecution.getExecutionId() );
+
if ( mojoExecution.getConfiguration() != null )
{
dom = Xpp3Dom.mergeXpp3Dom( dom, mojoExecution.getConfiguration() );
}
- return (MavenReport) getConfiguredMojo( session, dom, project, true, mojoExecution );
+ MavenReport report = (MavenReport) getConfiguredMojo( session, dom, project, true, mojoExecution );
+
+ try
+ {
+ mavenProjectBuilder.restoreDynamicState( project, session.getProjectBuilderConfiguration() );
+ }
+ catch ( ModelInterpolationException e )
+ {
+ throw new PluginManagerException( "Failed to restore dynamic state for project: " + project, e );
+ }
+
+ return report;
}
public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin,
Modified: maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/IntegrationTestSuite.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/IntegrationTestSuite.java?rev=679892&r1=679891&r2=679892&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/IntegrationTestSuite.java (original)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/IntegrationTestSuite.java Fri Jul 25 13:20:26 2008
@@ -65,6 +65,7 @@
* a fail fast technique as well.
*/
+ suite.addTestSuite( MavenITmng3684BuildPluginParameterTest.class );
suite.addTestSuite( MavenITmng3680InvalidDependencyPOMTest.class );
suite.addTestSuite( MavenITmng3679PluginExecIdInterpolationTest.class );
suite.addTestSuite( MavenITmng3671PluginLevelDepInterpolationTest.class );
Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3684BuildPluginParameterTest.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3684BuildPluginParameterTest.java?rev=679892&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3684BuildPluginParameterTest.java (added)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3684BuildPluginParameterTest.java Fri Jul 25 13:20:26 2008
@@ -0,0 +1,54 @@
+package org.apache.maven.integrationtests;
+
+import java.io.File;
+
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+/**
+ * Verify that the Build instance injected as a plugin parameter contains
+ * interpolated values for things like the various build paths, etc.
+ *
+ * @author jdcasey
+ */
+public class MavenITmng3684BuildPluginParameterTest
+ extends AbstractMavenIntegrationTestCase
+{
+ public MavenITmng3684BuildPluginParameterTest()
+ throws InvalidVersionSpecificationException
+ {
+ super( "(2.0.9,)" );
+ }
+
+ public void testitMNG3684 ()
+ throws Exception
+ {
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3684-buildPluginParameter" );
+ File pluginDir = new File( testDir, "maven-mng3684-plugin" );
+ File projectDir = new File( testDir, "project" );
+
+ Verifier verifier = new Verifier( pluginDir.getAbsolutePath() );
+ verifier.executeGoal( "install" );
+
+ verifier.verifyErrorFreeLog();
+ verifier.resetStreams();
+
+ verifier = new Verifier( projectDir.getAbsolutePath() );
+ verifier.executeGoal( "validate" );
+
+ verifier.verifyErrorFreeLog();
+ verifier.resetStreams();
+
+ File logFile = new File( projectDir, "log.txt" );
+ logFile.renameTo( new File( projectDir, "log-validate.txt" ) );
+
+ verifier.executeGoal( "site" );
+
+ verifier.verifyErrorFreeLog();
+ verifier.resetStreams();
+
+ logFile.renameTo( new File( projectDir, "log-site.txt" ) );
+
+ }
+}
Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/pom.xml?rev=679892&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/pom.xml (added)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/pom.xml Fri Jul 25 13:20:26 2008
@@ -0,0 +1,38 @@
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.its.mng3684</groupId>
+ <artifactId>maven-mng3684-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <version>1</version>
+ <name>maven-mng3684-plugin Maven Mojo</name>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.0.9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-api</artifactId>
+ <version>2.0.9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-impl</artifactId>
+ <version>2.0.4.1</version>
+ </dependency>
+ </dependencies>
+</project>
Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/main/java/plugin/MyMojo.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/main/java/plugin/MyMojo.java?rev=679892&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/main/java/plugin/MyMojo.java (added)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/main/java/plugin/MyMojo.java Fri Jul 25 13:20:26 2008
@@ -0,0 +1,122 @@
+package plugin;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * @goal check
+ */
+public class MyMojo
+ extends AbstractMojo
+{
+ /**
+ * @parameter default-value="${project.build}"
+ * @required
+ * @readonly
+ */
+ private Build build;
+
+ /**
+ * @parameter default-value="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
+ public void execute()
+ throws MojoExecutionException
+ {
+ Build projectBuild = project.getBuild();
+
+ Map failedComparisons = new HashMap();
+
+ check( "project.build.directory", projectBuild.getDirectory(), build.getDirectory(), failedComparisons );
+
+ check( "project.build.outputDirectory", projectBuild.getOutputDirectory(), build.getOutputDirectory(),
+ failedComparisons );
+
+ check( "project.build.sourceDirectory", projectBuild.getSourceDirectory(), build.getSourceDirectory(),
+ failedComparisons );
+
+ check( "project.build.testSourceDirectory", projectBuild.getTestSourceDirectory(),
+ build.getTestSourceDirectory(), failedComparisons );
+
+ check( "project.build.scriptSourceDirectory", projectBuild.getScriptSourceDirectory(),
+ build.getScriptSourceDirectory(), failedComparisons );
+
+ List projectResources = projectBuild.getResources();
+ List buildResources = build.getResources();
+
+ if ( projectResources != null )
+ {
+ for ( int i = 0; i < projectResources.size(); i++ )
+ {
+ Resource projectRes = (Resource) projectResources.get( i );
+ Resource buildRes = (Resource) buildResources.get( i );
+
+ check( "project.build.resources[" + i + "].directory", projectRes.getDirectory(),
+ buildRes.getDirectory(), failedComparisons );
+
+ check( "project.build.resources[" + i + "].targetPath", projectRes.getTargetPath(),
+ buildRes.getTargetPath(), failedComparisons );
+ }
+ }
+
+ if ( !failedComparisons.isEmpty() )
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append( "One or more build-section values were not interpolated correctly"
+ + "\nbefore the build instance was injected as a plugin parameter:\n" );
+
+ for ( Iterator it = failedComparisons.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ String key = (String) entry.getKey();
+ String[] value = (String[]) entry.getValue();
+
+ buffer.append( "\n- " ).append( key );
+ buffer.append( "\n\tShould be: \'" ).append( value[0] );
+ buffer.append( "\'\n\t Was: \'" ).append( value[1] ).append( "\'\n" );
+ }
+
+ throw new MojoExecutionException( buffer.toString() );
+ }
+ }
+
+ private void check( String description, String projectValue, String buildValue, Map failedComparisons )
+ {
+ if ( projectValue == null && buildValue != null )
+ {
+ failedComparisons.put( description, new String[] { projectValue, buildValue } );
+ }
+ else if ( projectValue != null && !projectValue.equals( buildValue ) )
+ {
+ failedComparisons.put( description, new String[] { projectValue, buildValue } );
+ }
+ }
+}
Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/main/java/plugin/MyReport.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/main/java/plugin/MyReport.java?rev=679892&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/main/java/plugin/MyReport.java (added)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/maven-mng3684-plugin/src/main/java/plugin/MyReport.java Fri Jul 25 13:20:26 2008
@@ -0,0 +1,160 @@
+package plugin;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.maven.doxia.siterenderer.Renderer;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Resource;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.reporting.AbstractMavenReport;
+import org.apache.maven.reporting.MavenReportException;
+
+/**
+ * @goal check-report
+ */
+public class MyReport
+ extends AbstractMavenReport
+{
+ /**
+ * @parameter default-value="${project.build}"
+ * @required
+ * @readonly
+ */
+ private Build build;
+
+ /**
+ * @parameter default-value="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
+ private void runChecks()
+ throws MavenReportException
+ {
+ Build projectBuild = project.getBuild();
+
+ Map failedComparisons = new HashMap();
+
+ check( "project.build.directory", projectBuild.getDirectory(), build.getDirectory(), failedComparisons );
+
+ check( "project.build.outputDirectory", projectBuild.getOutputDirectory(), build.getOutputDirectory(),
+ failedComparisons );
+
+ check( "project.build.sourceDirectory", projectBuild.getSourceDirectory(), build.getSourceDirectory(),
+ failedComparisons );
+
+ check( "project.build.testSourceDirectory", projectBuild.getTestSourceDirectory(),
+ build.getTestSourceDirectory(), failedComparisons );
+
+ check( "project.build.scriptSourceDirectory", projectBuild.getScriptSourceDirectory(),
+ build.getScriptSourceDirectory(), failedComparisons );
+
+ List projectResources = projectBuild.getResources();
+ List buildResources = build.getResources();
+
+ if ( projectResources != null )
+ {
+ for ( int i = 0; i < projectResources.size(); i++ )
+ {
+ Resource projectRes = (Resource) projectResources.get( i );
+ Resource buildRes = (Resource) buildResources.get( i );
+
+ check( "project.build.resources[" + i + "].directory", projectRes.getDirectory(),
+ buildRes.getDirectory(), failedComparisons );
+
+ check( "project.build.resources[" + i + "].targetPath", projectRes.getTargetPath(),
+ buildRes.getTargetPath(), failedComparisons );
+ }
+ }
+
+ if ( !failedComparisons.isEmpty() )
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append( "One or more build-section values were not interpolated correctly"
+ + "\nbefore the build instance was injected as a plugin parameter:\n" );
+
+ for ( Iterator it = failedComparisons.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ String key = (String) entry.getKey();
+ String[] value = (String[]) entry.getValue();
+
+ buffer.append( "\n- " ).append( key );
+ buffer.append( "\n\tShould be: \'" ).append( value[0] );
+ buffer.append( "\'\n\t Was: \'" ).append( value[1] ).append( "\'\n" );
+ }
+
+ throw new MavenReportException( buffer.toString() );
+ }
+ }
+
+ private void check( String description, String projectValue, String buildValue, Map failedComparisons )
+ {
+ if ( projectValue == null && buildValue != null )
+ {
+ failedComparisons.put( description, new String[] { projectValue, buildValue } );
+ }
+ else if ( projectValue != null && !projectValue.equals( buildValue ) )
+ {
+ failedComparisons.put( description, new String[] { projectValue, buildValue } );
+ }
+ }
+
+ protected void executeReport( Locale locale )
+ throws MavenReportException
+ {
+ runChecks();
+ }
+
+ protected String getOutputDirectory()
+ {
+ return project.getReporting().getOutputDirectory();
+ }
+
+ protected MavenProject getProject()
+ {
+ return project;
+ }
+
+ protected Renderer getSiteRenderer()
+ {
+ return null;
+ }
+
+ public String getDescription( Locale locale )
+ {
+ return "test";
+ }
+
+ public String getName( Locale locale )
+ {
+ return "test";
+ }
+
+ public String getOutputName()
+ {
+ return "test";
+ }
+}
Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/project/pom.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/project/pom.xml?rev=679892&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/project/pom.xml (added)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3684-buildPluginParameter/project/pom.xml Fri Jul 25 13:20:26 2008
@@ -0,0 +1,37 @@
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.its.mng3684</groupId>
+ <artifactId>mng3684-project</artifactId>
+ <packaging>jar</packaging>
+ <version>1</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.its.mng3684</groupId>
+ <artifactId>maven-mng3684-plugin</artifactId>
+ <version>1</version>
+ <executions>
+ <execution>
+ <id>check</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.its.mng3684</groupId>
+ <artifactId>maven-mng3684-plugin</artifactId>
+ <version>1</version>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>