mirror of https://github.com/apache/maven.git
[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.
git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@685027 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ddb5dae3b5
commit
0911fda7d2
|
@ -76,6 +76,7 @@ MavenITmng3415JunkRepositoryMetadataTest
|
||||||
MavenITmng3645POMSyntaxErrorTest
|
MavenITmng3645POMSyntaxErrorTest
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
suite.addTestSuite( MavenITmng3703ExecutionProjectWithRelativePathsTest.class );
|
||||||
suite.addTestSuite( MavenITmng3694ReactorProjectsDynamismTest.class );
|
suite.addTestSuite( MavenITmng3694ReactorProjectsDynamismTest.class );
|
||||||
suite.addTestSuite( MavenITmng3693PomFileBasedirChangeTest.class );
|
suite.addTestSuite( MavenITmng3693PomFileBasedirChangeTest.class );
|
||||||
suite.addTestSuite( MavenITmng3599useHttpProxyForWebDAV.class );
|
suite.addTestSuite( MavenITmng3599useHttpProxyForWebDAV.class );
|
||||||
|
|
|
@ -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:brianf@apache.org">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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>
|
|
@ -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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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";
|
||||||
|
}
|
||||||
|
}
|
|
@ -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";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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>
|
|
@ -0,0 +1,13 @@
|
||||||
|
package jar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hello world!
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class App
|
||||||
|
{
|
||||||
|
public static void main( String[] args )
|
||||||
|
{
|
||||||
|
System.out.println( "Hello World!" );
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 );
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.
|
Loading…
Reference in New Issue