[MNG-3704] Accommodate external implementations that extend DefaultLifecycleExecutor, but which may not be up-to-date on the latest component requirements for that class...specifically the project builder and the model interpolator. Also includes an integration test.

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@685293 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2008-08-12 20:20:56 +00:00
parent 0911fda7d2
commit 6b9daf3171
10 changed files with 451 additions and 0 deletions

View File

@ -76,6 +76,7 @@ MavenITmng3415JunkRepositoryMetadataTest
MavenITmng3645POMSyntaxErrorTest
*/
suite.addTestSuite( MavenITmng3704LifecycleExecutorWrapperTest.class );
suite.addTestSuite( MavenITmng3703ExecutionProjectWithRelativePathsTest.class );
suite.addTestSuite( MavenITmng3694ReactorProjectsDynamismTest.class );
suite.addTestSuite( MavenITmng3693PomFileBasedirChangeTest.class );

View File

@ -0,0 +1,68 @@
/*
* 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 org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
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-3704">MNG-3704</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 MavenITmng3704LifecycleExecutorWrapperTest
extends AbstractMavenIntegrationTestCase
{
public MavenITmng3704LifecycleExecutorWrapperTest()
throws InvalidVersionSpecificationException
{
super( "(2.0.9,)" ); // only test in 2.0.9+
}
public void testitMNG3704 ()
throws Exception
{
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3704-lifecycleExecutorWrapper" );
File pluginDir = new File( testDir, "maven-mng3704-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( "package" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
}
}

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?><project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng3704</groupId>
<artifactId>maven-mng3704-plugin</artifactId>
<packaging>maven-plugin</packaging>
<name>maven-mng3704-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-core</artifactId>
<version>2.0.9</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,133 @@
package org.apache.maven.lifecycle;
/*
* 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.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.maven.BuildFailureException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.monitor.event.DefaultEventDispatcher;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
import org.apache.maven.project.DuplicateProjectException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.plexus.util.dag.CycleDetectedException;
/**
* Tests that the lifecycle executor with the out-of-date component configuration (missing some new component
* requirements) will still work...
*
* @goal run
* @phase validate
*/
public class MyMojo
extends AbstractMojo
{
/**
* @component role-hint="test"
*/
private LifecycleExecutor lifecycleExecutor;
/**
* @parameter default-value="${session}"
* @required
* @readonly
*/
private MavenSession session;
/**
* @component
*/
private MavenProjectBuilder projectBuilder;
/**
* @parameter default-value="${project}"
* @required
* @readonly
*/
private MavenProject project;
public void execute()
throws MojoExecutionException
{
if ( !( lifecycleExecutor instanceof TestLifecycleExecutor ) )
{
throw new MojoExecutionException( "Wrong LifecycleExecutor was injected into the mojo." );
}
MavenProject testProject;
try
{
testProject = projectBuilder.build( new File( project.getBasedir(), "test-project/pom.xml" ),
new DefaultProjectBuilderConfiguration() );
}
catch ( ProjectBuildingException e )
{
throw new MojoExecutionException( "Failed to build test project instance prior to lifecycle execution.", e );
}
List tasks = new ArrayList();
tasks.add( "compile" );
ReactorManager rm;
try
{
rm = new ReactorManager( Collections.singletonList( testProject ) );
}
catch ( CycleDetectedException e )
{
throw new MojoExecutionException( "Failed to construct ReactorManager instance prior to lifecycle execution.", e );
}
catch ( DuplicateProjectException e )
{
throw new MojoExecutionException( "Failed to construct ReactorManager instance prior to lifecycle execution.", e );
}
MavenSession s =
new MavenSession( session.getContainer(), session.getSettings(), session.getLocalRepository(),
new DefaultEventDispatcher(), rm, tasks, session.getExecutionRootDirectory(),
session.getExecutionProperties(), session.getStartTime() );
try
{
lifecycleExecutor.execute( s, rm, s.getEventDispatcher() );
}
catch ( LifecycleExecutionException e )
{
throw new MojoExecutionException( "Unexpected error: " + e.getMessage(), e );
}
catch ( BuildFailureException e )
{
throw new MojoExecutionException( "Unexpected error: " + e.getMessage(), e );
}
catch ( NullPointerException e )
{
throw new MojoExecutionException(
"Encountered a NullPointerException. Check that all component requirements have been met or managed through the initialization phase.",
e );
}
}
}

View File

@ -0,0 +1,9 @@
package org.apache.maven.lifecycle;
import org.apache.maven.lifecycle.DefaultLifecycleExecutor;
public class TestLifecycleExecutor
extends DefaultLifecycleExecutor
{
}

View File

@ -0,0 +1,119 @@
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
<role-hint>test</role-hint>
<implementation>org.apache.maven.lifecycle.TestLifecycleExecutor</implementation>
<requirements>
<requirement>
<role>org.apache.maven.plugin.PluginManager</role>
</requirement>
<requirement>
<role>org.apache.maven.extension.ExtensionManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
</requirement>
<!-- These are missing BY DESIGN. They are new requirements, which means
external implementations who extend the default will not have these
requirements. The executor should try to compensate, to remain as
compatible as possible.
<requirement>
<role>org.apache.maven.project.MavenProjectBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
</requirement>
-->
</requirements>
<configuration>
<lifecycles>
<lifecycle>
<id>default</id>
<!-- START SNIPPET: lifecycle -->
<phases>
<phase>validate</phase>
<phase>initialize</phase>
<phase>generate-sources</phase>
<phase>process-sources</phase>
<phase>generate-resources</phase>
<phase>process-resources</phase>
<phase>compile</phase>
<phase>process-classes</phase>
<phase>generate-test-sources</phase>
<phase>process-test-sources</phase>
<phase>generate-test-resources</phase>
<phase>process-test-resources</phase>
<phase>test-compile</phase>
<phase>process-test-classes</phase>
<phase>test</phase>
<phase>package</phase>
<phase>pre-integration-test</phase>
<phase>integration-test</phase>
<phase>post-integration-test</phase>
<phase>verify</phase>
<phase>install</phase>
<phase>deploy</phase>
</phases>
<!-- END SNIPPET: lifecycle -->
</lifecycle>
<lifecycle>
<id>clean</id>
<phases>
<phase>pre-clean</phase>
<phase>clean</phase>
<phase>post-clean</phase>
</phases>
<default-phases>
<clean>org.apache.maven.plugins:maven-clean-plugin:clean</clean>
</default-phases>
</lifecycle>
<lifecycle>
<id>site</id>
<phases>
<phase>pre-site</phase>
<phase>site</phase>
<phase>post-site</phase>
<phase>site-deploy</phase>
</phases>
<default-phases>
<site>org.apache.maven.plugins:maven-site-plugin:site</site>
<site-deploy>org.apache.maven.plugins:maven-site-plugin:deploy</site-deploy>
</default-phases>
</lifecycle>
</lifecycles>
<!-- START SNIPPET: default-reports -->
<defaultReports>
<report>org.apache.maven.plugins:maven-project-info-reports-plugin</report>
<!-- TODO: currently in mojo - should they be defaults any more?
<report>org.apache.maven.plugins:maven-checkstyle-plugin</report>
<report>org.apache.maven.plugins:maven-javadoc-plugin</report>
<report>org.apache.maven.plugins:maven-changelog-plugin</report>
<report>org.apache.maven.plugins:maven-surefire-report-plugin</report>
<report>org.apache.maven.plugins:maven-jdepend-plugin</report>
<report>org.apache.maven.plugins:maven-jxr-plugin</report>
<report>org.apache.maven.plugins:maven-taglist-plugin</report>
-->
</defaultReports>
<!-- END SNIPPET: default-reports -->
<!-- START SNIPPET: default-lifecycle -->
<!-- NOT USED, ACCORDING TO CODE.
<defaultPhases>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
<process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
<package>
org.apache.maven.plugins:maven-jar-plugin:jar,
org.apache.maven.plugins:maven-source-plugin:jar
</package>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</defaultPhases>
-->
<!-- END SNIPPET: default-lifecycle -->
</configuration>
</component>
</components>
</component-set>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?><project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng3704</groupId>
<artifactId>project</artifactId>
<name>Test Launcher Project</name>
<version>1</version>
<packaging>pom</packaging>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.mng3704</groupId>
<artifactId>maven-mng3704-plugin</artifactId>
<version>1</version>
<executions>
<execution>
<id>test</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?><project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng3704</groupId>
<artifactId>test-project</artifactId>
<name>Test Project</name>
<version>1</version>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,13 @@
package jar;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

View File

@ -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 );
}
}