From 6b9daf3171c4b445f588a975f67c7e9f97bce113 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Tue, 12 Aug 2008 20:20:56 +0000 Subject: [PATCH] [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 --- .../IntegrationTestSuite.java | 1 + ...ITmng3704LifecycleExecutorWrapperTest.java | 68 +++++++++ .../maven-mng3704-plugin/pom.xml | 27 ++++ .../org/apache/maven/lifecycle/MyMojo.java | 133 ++++++++++++++++++ .../lifecycle/TestLifecycleExecutor.java | 9 ++ .../resources/META-INF/plexus/components.xml | 119 ++++++++++++++++ .../project/pom.xml | 27 ++++ .../project/test-project/pom.xml | 16 +++ .../test-project/src/main/java/jar/App.java | 13 ++ .../src/test/java/jar/AppTest.java | 38 +++++ 10 files changed, 451 insertions(+) create mode 100644 its/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3704LifecycleExecutorWrapperTest.java create mode 100644 its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/pom.xml create mode 100644 its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/src/main/java/org/apache/maven/lifecycle/MyMojo.java create mode 100644 its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/src/main/java/org/apache/maven/lifecycle/TestLifecycleExecutor.java create mode 100644 its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/src/main/resources/META-INF/plexus/components.xml create mode 100644 its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/pom.xml create mode 100644 its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/test-project/pom.xml create mode 100644 its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/test-project/src/main/java/jar/App.java create mode 100644 its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/test-project/src/test/java/jar/AppTest.java diff --git a/its/core-integration-tests/src/test/java/org/apache/maven/integrationtests/IntegrationTestSuite.java b/its/core-integration-tests/src/test/java/org/apache/maven/integrationtests/IntegrationTestSuite.java index 35a877b1ad..9118a0ed75 100644 --- a/its/core-integration-tests/src/test/java/org/apache/maven/integrationtests/IntegrationTestSuite.java +++ b/its/core-integration-tests/src/test/java/org/apache/maven/integrationtests/IntegrationTestSuite.java @@ -76,6 +76,7 @@ MavenITmng3415JunkRepositoryMetadataTest MavenITmng3645POMSyntaxErrorTest */ + suite.addTestSuite( MavenITmng3704LifecycleExecutorWrapperTest.class ); suite.addTestSuite( MavenITmng3703ExecutionProjectWithRelativePathsTest.class ); suite.addTestSuite( MavenITmng3694ReactorProjectsDynamismTest.class ); suite.addTestSuite( MavenITmng3693PomFileBasedirChangeTest.class ); diff --git a/its/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3704LifecycleExecutorWrapperTest.java b/its/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3704LifecycleExecutorWrapperTest.java new file mode 100644 index 0000000000..a140069582 --- /dev/null +++ b/its/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3704LifecycleExecutorWrapperTest.java @@ -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 MNG-3704. + * + * @todo Fill in a better description of what this test verifies! + * + * @author Brian Fox + * @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(); + } +} diff --git a/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/pom.xml b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/pom.xml new file mode 100644 index 0000000000..2e753cc833 --- /dev/null +++ b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/pom.xml @@ -0,0 +1,27 @@ + + 4.0.0 + org.apache.maven.its.mng3704 + maven-mng3704-plugin + maven-plugin + maven-mng3704-plugin Maven Mojo + 1 + http://maven.apache.org + + + org.apache.maven + maven-plugin-api + 2.0 + + + junit + junit + 3.8.1 + test + + + org.apache.maven + maven-core + 2.0.9 + + + \ No newline at end of file diff --git a/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/src/main/java/org/apache/maven/lifecycle/MyMojo.java b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/src/main/java/org/apache/maven/lifecycle/MyMojo.java new file mode 100644 index 0000000000..93e49ffd43 --- /dev/null +++ b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/src/main/java/org/apache/maven/lifecycle/MyMojo.java @@ -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 ); + } + } +} diff --git a/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/src/main/java/org/apache/maven/lifecycle/TestLifecycleExecutor.java b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/src/main/java/org/apache/maven/lifecycle/TestLifecycleExecutor.java new file mode 100644 index 0000000000..87247cacef --- /dev/null +++ b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/src/main/java/org/apache/maven/lifecycle/TestLifecycleExecutor.java @@ -0,0 +1,9 @@ +package org.apache.maven.lifecycle; + +import org.apache.maven.lifecycle.DefaultLifecycleExecutor; + +public class TestLifecycleExecutor + extends DefaultLifecycleExecutor +{ + +} diff --git a/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/src/main/resources/META-INF/plexus/components.xml b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/src/main/resources/META-INF/plexus/components.xml new file mode 100644 index 0000000000..ef24167965 --- /dev/null +++ b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/maven-mng3704-plugin/src/main/resources/META-INF/plexus/components.xml @@ -0,0 +1,119 @@ + + + + org.apache.maven.lifecycle.LifecycleExecutor + test + org.apache.maven.lifecycle.TestLifecycleExecutor + + + org.apache.maven.plugin.PluginManager + + + org.apache.maven.extension.ExtensionManager + + + org.apache.maven.artifact.handler.manager.ArtifactHandlerManager + + + + + + + default + + + validate + initialize + generate-sources + process-sources + generate-resources + process-resources + compile + process-classes + generate-test-sources + process-test-sources + generate-test-resources + process-test-resources + test-compile + process-test-classes + test + package + pre-integration-test + integration-test + post-integration-test + verify + install + deploy + + + + + clean + + pre-clean + clean + post-clean + + + org.apache.maven.plugins:maven-clean-plugin:clean + + + + site + + pre-site + site + post-site + site-deploy + + + org.apache.maven.plugins:maven-site-plugin:site + org.apache.maven.plugins:maven-site-plugin:deploy + + + + + + org.apache.maven.plugins:maven-project-info-reports-plugin + + + + + + + + + + \ No newline at end of file diff --git a/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/pom.xml b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/pom.xml new file mode 100644 index 0000000000..149af3cf6a --- /dev/null +++ b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/pom.xml @@ -0,0 +1,27 @@ + + 4.0.0 + org.apache.maven.its.mng3704 + project + Test Launcher Project + 1 + pom + http://maven.apache.org + + + + org.apache.maven.its.mng3704 + maven-mng3704-plugin + 1 + + + test + package + + run + + + + + + + \ No newline at end of file diff --git a/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/test-project/pom.xml b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/test-project/pom.xml new file mode 100644 index 0000000000..98dffce028 --- /dev/null +++ b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/test-project/pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + org.apache.maven.its.mng3704 + test-project + Test Project + 1 + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + \ No newline at end of file diff --git a/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/test-project/src/main/java/jar/App.java b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/test-project/src/main/java/jar/App.java new file mode 100644 index 0000000000..9772ca4786 --- /dev/null +++ b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/test-project/src/main/java/jar/App.java @@ -0,0 +1,13 @@ +package jar; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/test-project/src/test/java/jar/AppTest.java b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/test-project/src/test/java/jar/AppTest.java new file mode 100644 index 0000000000..4f2fe94988 --- /dev/null +++ b/its/core-integration-tests/src/test/resources/mng-3704-lifecycleExecutorWrapper/project/test-project/src/test/java/jar/AppTest.java @@ -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 ); + } +}