Author: jdcasey Date: Mon Aug 11 20:19:23 2008 New Revision: 685027 URL: http://svn.apache.org/viewvc?rev=685027&view=rev Log: [MNG-3703] Calculate the concrete state of execution projects after a forked lifecycle completes, so paths, etc. are available to processing in the forking mojo. Including an integration test to verify this.
Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3703ExecutionProjectWithRelativePathsTest.java maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/pom.xml maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/AbstractCheckMojo.java maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/CheckMojo.java maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/RunMojo.java maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/pom.xml maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/main/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/main/java/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/main/java/jar/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/main/java/jar/App.java maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/test/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/test/java/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/test/java/jar/ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/test/java/jar/AppTest.java maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/readme.txt Modified: maven/components/branches/maven-2.0.10-RC/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.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/lifecycle/DefaultLifecycleExecutor.java URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.10-RC/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=685027&r1=685026&r2=685027&view=diff ============================================================================== --- maven/components/branches/maven-2.0.10-RC/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java (original) +++ maven/components/branches/maven-2.0.10-RC/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java Mon Aug 11 20:19:23 2008 @@ -575,6 +575,8 @@ forkLifecycle( mojoDescriptor, forkEntryPoints, session, project ); forkEntryPoints.pop(); + + calculateConcreteState( project.getExecutionProject(), session ); } if ( mojoDescriptor.isRequiresReports() ) 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=685027&r1=685026&r2=685027&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 Mon Aug 11 20:19:23 2008 @@ -76,6 +76,7 @@ MavenITmng3645POMSyntaxErrorTest */ + suite.addTestSuite( MavenITmng3703ExecutionProjectWithRelativePathsTest.class ); suite.addTestSuite( MavenITmng3694ReactorProjectsDynamismTest.class ); suite.addTestSuite( MavenITmng3693PomFileBasedirChangeTest.class ); suite.addTestSuite( MavenITmng3599useHttpProxyForWebDAV.class ); Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3703ExecutionProjectWithRelativePathsTest.java URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3703ExecutionProjectWithRelativePathsTest.java?rev=685027&view=auto ============================================================================== --- maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3703ExecutionProjectWithRelativePathsTest.java (added) +++ maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3703ExecutionProjectWithRelativePathsTest.java Mon Aug 11 20:19:23 2008 @@ -0,0 +1,72 @@ +/* + * 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. + */ + +package org.apache.maven.integrationtests; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.integrationtests.AbstractMavenIntegrationTestCase; +import org.apache.maven.it.Verifier; +import org.apache.maven.it.util.ResourceExtractor; + +/** + * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3703">MNG-3703</a>. + * + * @todo Fill in a better description of what this test verifies! + * + * @author <a href="mailto:[EMAIL PROTECTED]">Brian Fox</a> + * @author jdcasey + * + */ +public class MavenITmng3703ExecutionProjectWithRelativePathsTest + extends AbstractMavenIntegrationTestCase +{ + public MavenITmng3703ExecutionProjectWithRelativePathsTest() + throws InvalidVersionSpecificationException + { + super( "(2.0.9,)" ); // only test in 2.0.9+ + } + + public void testitMNG3703 () + throws Exception + { + File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3703-executionProjectRelativePaths" ); + File pluginDir = new File( testDir, "maven-mng3703-plugin" ); + File projectDir = new File( testDir, "project" ); + + Verifier 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(); + } +} Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/pom.xml?rev=685027&view=auto ============================================================================== --- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/pom.xml (added) +++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/pom.xml Mon Aug 11 20:19:23 2008 @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.its.mng3703</groupId> + <artifactId>maven-mng3703-plugin</artifactId> + <packaging>maven-plugin</packaging> + <name>maven-mng3703-plugin Maven Mojo</name> + <version>1</version> + <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> + </dependencies> +</project> \ No newline at end of file Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/AbstractCheckMojo.java URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/AbstractCheckMojo.java?rev=685027&view=auto ============================================================================== --- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/AbstractCheckMojo.java (added) +++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/AbstractCheckMojo.java Mon Aug 11 20:19:23 2008 @@ -0,0 +1,116 @@ +package jar; + +/* + * 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.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; + +import com.sun.tools.jdi.LinkedHashMap; + +public abstract class AbstractCheckMojo + extends AbstractMojo +{ + + protected static boolean forkHasRun = false; + + /** + * @parameter default-value="${project}" + * @required + * @readonly + */ + private MavenProject project; + + /** + * @parameter default-value="${executedProject}" + * @required + * @readonly + */ + private MavenProject executionProject; + + public void execute() + throws MojoExecutionException + { + if ( getMainProject().getBasedir() == null ) + { + throw new MojoExecutionException( "Basedir is null on the main project instance." ); + } + + if ( getTestProject().getBasedir() == null ) + { + throw new MojoExecutionException( "Basedir is null on the " + getTestProjectLabel() + " instance." ); + } + + String executionBasedir = getTestProject().getBasedir().getAbsolutePath(); + + Map failedPaths = new LinkedHashMap(); + + checkListOfPaths( getTestProject().getCompileSourceRoots(), executionBasedir, "compileSourceRoots", failedPaths ); + checkListOfPaths( getTestProject().getTestCompileSourceRoots(), executionBasedir, "testCompileSourceRoots", failedPaths ); + checkListOfPaths( getTestProject().getScriptSourceRoots(), executionBasedir, "scriptSourceRoots", failedPaths ); + + + if ( !failedPaths.isEmpty() ) + { + StringBuffer buffer = new StringBuffer(); + buffer.append( "The following paths were relative (should have been absolute):" ); + for ( Iterator it = failedPaths.entrySet().iterator(); it.hasNext(); ) + { + Map.Entry entry = (Map.Entry) it.next(); + + buffer.append( "\n- " ).append( entry.getKey() ).append( ": '" ).append( entry.getValue() ).append( "'" ); + } + + throw new MojoExecutionException( buffer.toString() ); + } + + forkHasRun = true; + } + + protected MavenProject getMainProject() + { + return project; + } + + protected MavenProject getExecutionProject() + { + return executionProject; + } + + protected abstract MavenProject getTestProject(); + + protected abstract String getTestProjectLabel(); + + private void checkListOfPaths( List paths, String base, String label, Map failedPaths ) + { + if ( paths != null && !paths.isEmpty() ) + { + for ( int i = 0; i < paths.size(); i++ ) + { + String root = (String) paths.get( i ); + if ( !root.startsWith( base ) ) + { + failedPaths.put( label + "[" + i + "]", root ); + } + } + } + } +} Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/CheckMojo.java URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/CheckMojo.java?rev=685027&view=auto ============================================================================== --- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/CheckMojo.java (added) +++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/CheckMojo.java Mon Aug 11 20:19:23 2008 @@ -0,0 +1,39 @@ +package jar; + +/* + * 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 org.apache.maven.project.MavenProject; + +/** + * @goal check + * @phase validate + * @execute phase="validate" + */ +public class CheckMojo + extends AbstractCheckMojo +{ + + protected MavenProject getTestProject() + { + return getExecutionProject(); + } + + protected String getTestProjectLabel() + { + return "execution project"; + } +} Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/RunMojo.java URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/RunMojo.java?rev=685027&view=auto ============================================================================== --- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/RunMojo.java (added) +++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/maven-mng3703-plugin/src/main/java/jar/RunMojo.java Mon Aug 11 20:19:23 2008 @@ -0,0 +1,53 @@ +package jar; + +/* + * 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 org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; + +/** + * @goal run + * @phase validate + */ +public class RunMojo + extends AbstractCheckMojo +{ + + public void execute() + throws MojoExecutionException + { + if ( forkHasRun ) + { + getLog().info( "Not running inside a forked execution; skipping this mojo's execution." ); + return; + } + + super.execute(); + } + + protected MavenProject getTestProject() + { + return getMainProject(); + } + + protected String getTestProjectLabel() + { + return "main-project"; + } + + +} Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/pom.xml URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/pom.xml?rev=685027&view=auto ============================================================================== --- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/pom.xml (added) +++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/pom.xml Mon Aug 11 20:19:23 2008 @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?><project> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.its.mng3703</groupId> + <artifactId>project</artifactId> + <name>project</name> + <version>1</version> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.its.mng3703</groupId> + <artifactId>maven-mng3703-plugin</artifactId> + <version>1</version> + <executions> + <execution> + <id>check</id> + <phase>validate</phase> + <goals> + <goal>check</goal> + </goals> + </execution> + <execution> + <id>run</id> + <phase>validate</phase> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/main/java/jar/App.java URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/main/java/jar/App.java?rev=685027&view=auto ============================================================================== --- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/main/java/jar/App.java (added) +++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/main/java/jar/App.java Mon Aug 11 20:19:23 2008 @@ -0,0 +1,13 @@ +package jar; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/test/java/jar/AppTest.java URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/test/java/jar/AppTest.java?rev=685027&view=auto ============================================================================== --- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/test/java/jar/AppTest.java (added) +++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/project/src/test/java/jar/AppTest.java Mon Aug 11 20:19:23 2008 @@ -0,0 +1,38 @@ +package jar; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/readme.txt URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/readme.txt?rev=685027&view=auto ============================================================================== --- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/readme.txt (added) +++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3703-executionProjectRelativePaths/readme.txt Mon Aug 11 20:19:23 2008 @@ -0,0 +1 @@ +Fill this in with a description of the scenario this test attempts to check. Also include instructions for running the test manually from the command line. \ No newline at end of file