You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by if...@apache.org on 2014/02/10 04:11:10 UTC

git commit: MNG-5581 lifecycle mapping delegate test

Updated Branches:
  refs/heads/master 0714fe233 -> c2806e6c3


MNG-5581 lifecycle mapping delegate test

Signed-off-by: Igor Fedorenko <ig...@ifedorenko.com>


Project: http://git-wip-us.apache.org/repos/asf/maven-integration-testing/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-integration-testing/commit/c2806e6c
Tree: http://git-wip-us.apache.org/repos/asf/maven-integration-testing/tree/c2806e6c
Diff: http://git-wip-us.apache.org/repos/asf/maven-integration-testing/diff/c2806e6c

Branch: refs/heads/master
Commit: c2806e6c3bde4fc95789475bef0c7b72f23639dc
Parents: 0714fe2
Author: Igor Fedorenko <ig...@ifedorenko.com>
Authored: Wed Jan 15 10:41:23 2014 -0500
Committer: Igor Fedorenko <ig...@ifedorenko.com>
Committed: Sun Feb 9 22:07:54 2014 -0500

----------------------------------------------------------------------
 .../apache/maven/it/IntegrationTestSuite.java   |  1 +
 .../MavenITmng5581LifecycleMappingDelegate.java | 96 ++++++++++++++++++++
 .../basic/BasicClass.java                       | 24 +++++
 .../basic/pom.xml                               | 47 ++++++++++
 .../basic/test/BasicTest.java                   | 33 +++++++
 .../extension/pom.xml                           | 65 +++++++++++++
 .../TestLifecycleMappingDelegate.java           | 71 +++++++++++++++
 .../resources/META-INF/plexus/components.xml    | 16 ++++
 8 files changed, 353 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/c2806e6c/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
index 4b8ff07..7914c45 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
@@ -105,6 +105,7 @@ public class IntegrationTestSuite
         // Tests that don't run stable and need to be fixed
         // -------------------------------------------------------------------------------------------------------------
         // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137        
+        suite.addTestSuite( MavenITmng5581LifecycleMappingDelegate.class );
         suite.addTestSuite( MavenITmng5572ReactorPluginExtensionsTest.class  );
         suite.addTestSuite( MavenITmng5576CdFriendlyVersions.class );
         suite.addTestSuite( MavenITmng5530MojoExecutionScopeTest.class );

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/c2806e6c/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5581LifecycleMappingDelegate.java
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5581LifecycleMappingDelegate.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5581LifecycleMappingDelegate.java
new file mode 100644
index 0000000..590927a
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5581LifecycleMappingDelegate.java
@@ -0,0 +1,96 @@
+package org.apache.maven.it;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.maven.it.util.ResourceExtractor;
+
+public class MavenITmng5581LifecycleMappingDelegate
+    extends AbstractMavenIntegrationTestCase
+{
+    public MavenITmng5581LifecycleMappingDelegate()
+    {
+        super( "[3.2.0,)" );
+    }
+
+    /**
+     * This test uses API introduced in Maven 3.2.0-SNAPSHOT. Until 3.2.0 is released, latest maven core must be
+     * installed in local repository before running this test.
+     */
+    public void testCustomLifecycle()
+        throws Exception
+    {
+        /*
+         * This test comes in two parts, a build extension project that defines custom lifecycle with corresponding
+         * lifecycle mapping delegate, and a test project used to validate the custom lifecycle. The custom lifecycle id
+         * is "test-only", it has single build phase "test-only" and lifecycle mapping delegate that picks default
+         * surefire-plugin execution out of all mojos configured in project pom.xml. The test asserts it is possible to
+         * run "test-only" build phase and that it does not run maven-compiler-plugin.
+         */
+
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5581-lifecycle-mapping-delegate" );
+        File extensionDir = new File( testDir, "extension" );
+        File projectDir = new File( testDir, "basic" );
+
+        Verifier verifier;
+
+        // install the test extension
+        verifier = newVerifier( extensionDir.getAbsolutePath(), "remote" );
+        verifier.executeGoal( "install" );
+        verifier.resetStreams();
+        verifier.verifyErrorFreeLog();
+
+        // compile the test project
+        verifier = newVerifier( projectDir.getAbsolutePath(), "remote" );
+        verifier.executeGoal( "compile" );
+        verifier.resetStreams();
+        verifier.verifyErrorFreeLog();
+
+        // run custom "test-only" build phase
+        verifier.executeGoal( "test-only" );
+        verifier.resetStreams();
+        verifier.verifyErrorFreeLog();
+        verifier.verifyTextInLog( "maven-surefire-plugin" );
+        verifyTextNotInLog( verifier, "maven-compiler-plugin" );
+    }
+
+    private void verifyTextNotInLog( Verifier verifier, String text )
+        throws VerificationException
+    {
+        List<String> lines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
+
+        boolean result = true;
+        for ( String line : lines )
+        {
+            if ( line.contains( text ) )
+            {
+                result = false;
+                break;
+            }
+        }
+        if ( !result )
+        {
+            throw new VerificationException( "Text not found in log: " + text );
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/c2806e6c/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/basic/main/java/org/apache/maven/its/mng5581/lifecyclemappingdelegate/basic/BasicClass.java
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/basic/main/java/org/apache/maven/its/mng5581/lifecyclemappingdelegate/basic/BasicClass.java b/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/basic/main/java/org/apache/maven/its/mng5581/lifecyclemappingdelegate/basic/BasicClass.java
new file mode 100644
index 0000000..1bbb6e5
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/basic/main/java/org/apache/maven/its/mng5581/lifecyclemappingdelegate/basic/BasicClass.java
@@ -0,0 +1,24 @@
+package org.apache.maven.its.mng5581.lifecyclemappingdelegate.basic;
+
+/*
+ * 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.
+ */
+
+public class BasicClass {
+
+}

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/c2806e6c/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/basic/pom.xml
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/basic/pom.xml b/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/basic/pom.xml
new file mode 100644
index 0000000..eb79026
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/basic/pom.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>mng-5581-lifecycle-mapping-delegate</groupId>
+  <artifactId>mng-5581-lifecycle-mapping-delegate-basic</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.11</version>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <extensions>
+      <extension>
+        <groupId>mng-5581-lifecycle-mapping-delegate</groupId>
+        <artifactId>mng-5581-lifecycle-mapping-delegate-extension</artifactId>
+        <version>0.1</version>
+      </extension>
+    </extensions>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/c2806e6c/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/basic/test/java/org/apache/maven/its/mng5581/lifecyclemappingdelegate/basic/test/BasicTest.java
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/basic/test/java/org/apache/maven/its/mng5581/lifecyclemappingdelegate/basic/test/BasicTest.java b/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/basic/test/java/org/apache/maven/its/mng5581/lifecyclemappingdelegate/basic/test/BasicTest.java
new file mode 100644
index 0000000..03eb201
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/basic/test/java/org/apache/maven/its/mng5581/lifecyclemappingdelegate/basic/test/BasicTest.java
@@ -0,0 +1,33 @@
+package org.apache.maven.its.mng5581.lifecyclemappingdelegate.basic.test;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.its.mng5581.lifecyclemappingdelegate.basic.BasicClass;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ModuleBTest {
+
+	@Test
+	public void testBasic() {
+		Assert.assertNotNull(new BasicClass().toString());
+	}
+}

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/c2806e6c/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/extension/pom.xml
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/extension/pom.xml b/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/extension/pom.xml
new file mode 100644
index 0000000..64fb903
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/extension/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>mng-5581-lifecycle-mapping-delegate</groupId>
+  <artifactId>mng-5581-lifecycle-mapping-delegate-extension</artifactId>
+  <version>0.1</version>
+
+  <properties>
+    <!--
+      This extension uses new API introduced in Maven 3.2.0-SNAPSHOT.
+      TODO Change to 3.2.0 when it is released.
+     -->
+    <maven.version>3.2.0-SNAPSHOT</maven.version>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+      <version>${maven.version}</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.sonatype.plugins</groupId>
+        <artifactId>sisu-maven-plugin</artifactId>
+        <version>1.1</version>
+        <executions>
+          <execution>
+            <id>generate-index</id>
+            <goals>
+              <goal>main-index</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/c2806e6c/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/extension/src/main/java/org/apache/maven/its/mng5581/lifecyclemappingdelegate/TestLifecycleMappingDelegate.java
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/extension/src/main/java/org/apache/maven/its/mng5581/lifecyclemappingdelegate/TestLifecycleMappingDelegate.java b/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/extension/src/main/java/org/apache/maven/its/mng5581/lifecyclemappingdelegate/TestLifecycleMappingDelegate.java
new file mode 100644
index 0000000..9c5c5e4
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/extension/src/main/java/org/apache/maven/its/mng5581/lifecyclemappingdelegate/TestLifecycleMappingDelegate.java
@@ -0,0 +1,71 @@
+package org.apache.maven.its.mng5581.lifecyclemappingdelegate;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Named;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.Lifecycle;
+import org.apache.maven.lifecycle.LifecycleMappingDelegate;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginExecution;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginNotFoundException;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.project.MavenProject;
+
+@Named("test-only")
+public class TestLifecycleMappingDelegate implements LifecycleMappingDelegate {
+
+    public Map<String, List<MojoExecution>> calculateLifecycleMappings(MavenSession session, MavenProject project,
+            Lifecycle lifecycle, String lifecyclePhase) throws PluginNotFoundException, PluginResolutionException,
+            PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException {
+
+        Map<String, List<MojoExecution>> pluginExecutions = new LinkedHashMap<String, List<MojoExecution>>();
+
+        for (Plugin plugin : project.getBuild().getPlugins()) {
+            for (PluginExecution execution : plugin.getExecutions()) {
+                List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
+                for (String goal : execution.getGoals()) {
+                    MojoExecution mojoExecution = new MojoExecution(plugin, goal, execution.getId());
+                    mojoExecution.setLifecyclePhase(execution.getPhase());
+                    mojoExecutions.add(mojoExecution);
+                }
+                if (!mojoExecutions.isEmpty()) {
+                    pluginExecutions.put(getExecutionKey(plugin, execution), mojoExecutions);
+                }
+            }
+        }
+
+        List<MojoExecution> result = new ArrayList<MojoExecution>();
+
+        List<MojoExecution> mojoExecutions = pluginExecutions
+                .get("org.apache.maven.plugins:maven-surefire-plugin:default-test");
+        if (mojoExecutions != null) {
+            result.addAll(mojoExecutions);
+        }
+
+        return Collections.singletonMap("test-only", result);
+    }
+
+    private String getExecutionKey(Plugin plugin, PluginExecution execution) {
+        return plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + execution.getId();
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/c2806e6c/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/extension/src/main/resources/META-INF/plexus/components.xml
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/extension/src/main/resources/META-INF/plexus/components.xml b/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/extension/src/main/resources/META-INF/plexus/components.xml
new file mode 100644
index 0000000..718d2c0
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5581-lifecycle-mapping-delegate/extension/src/main/resources/META-INF/plexus/components.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<component-set>
+  <components>
+    <component>
+      <role>org.apache.maven.lifecycle.Lifecycle</role>
+      <implementation>org.apache.maven.lifecycle.Lifecycle</implementation>
+      <role-hint>post</role-hint>
+      <configuration>
+        <id>test-only</id>
+        <phases>
+          <phase>test-only</phase>
+        </phases>
+      </configuration>
+    </component>
+  </components>
+</component-set>