You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2015/01/16 02:46:22 UTC

maven-integration-testing git commit: IT for MNG-5753: Allow plugin implementors to choose how they want the configuration created for a particular MojoExecution

Repository: maven-integration-testing
Updated Branches:
  refs/heads/master b182c5b1f -> 18bd438d1


IT for MNG-5753: Allow plugin implementors to choose how they want the configuration created for a particular MojoExecution


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/18bd438d
Tree: http://git-wip-us.apache.org/repos/asf/maven-integration-testing/tree/18bd438d
Diff: http://git-wip-us.apache.org/repos/asf/maven-integration-testing/diff/18bd438d

Branch: refs/heads/master
Commit: 18bd438d10f907758c826c1134d78893f4ad349f
Parents: b182c5b
Author: Jason van Zyl <ja...@tesla.io>
Authored: Thu Jan 15 15:11:42 2015 -0500
Committer: Jason van Zyl <ja...@tesla.io>
Committed: Thu Jan 15 15:11:42 2015 -0500

----------------------------------------------------------------------
 .../apache/maven/it/IntegrationTestSuite.java   |  5 +-
 ...5753CustomMojoExecutionConfiguratorTest.java | 66 +++++++++++++++++++
 .../plugin/pom.xml                              | 55 ++++++++++++++++
 .../maven/its/mng5753/plugin/TestMojo.java      | 68 ++++++++++++++++++++
 .../plugin/TestMojoExecutionConfigurator.java   | 42 ++++++++++++
 .../resources/META-INF/plexus/components.xml    | 15 +++++
 .../project/pom.xml                             | 52 +++++++++++++++
 7 files changed, 301 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/18bd438d/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 5cc7054..a69f937 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
@@ -24,12 +24,12 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.PrintStream;
 
-import org.codehaus.plexus.util.IOUtil;
-
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.codehaus.plexus.util.IOUtil;
+
 /**
  * The Core IT suite.
  */
@@ -106,6 +106,7 @@ public class IntegrationTestSuite
         // -------------------------------------------------------------------------------------------------------------
         // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
 
+        suite.addTestSuite( MavenITmng5753CustomMojoExecutionConfiguratorTest.class );
         suite.addTestSuite( MavenITmng5716ToolchainsTypeTest.class );
         suite.addTestSuite( MavenITmng5663NestedImportScopePomResolutionTest.class );
         suite.addTestSuite( MavenITmng2562Timestamp322Test.class );

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/18bd438d/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5753CustomMojoExecutionConfiguratorTest.java
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5753CustomMojoExecutionConfiguratorTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5753CustomMojoExecutionConfiguratorTest.java
new file mode 100644
index 0000000..cc73063
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5753CustomMojoExecutionConfiguratorTest.java
@@ -0,0 +1,66 @@
+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 org.apache.maven.it.util.ResourceExtractor;
+import org.apache.maven.shared.utils.io.FileUtils;
+
+public class MavenITmng5753CustomMojoExecutionConfiguratorTest
+    extends AbstractMavenIntegrationTestCase
+{
+
+    public MavenITmng5753CustomMojoExecutionConfiguratorTest()
+    {
+        super( "[3.2.6-SNAPSHOT,)" );
+    }
+
+    public void testCustomMojoExecutionConfigurator()
+        throws Exception
+    {        
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5753-custom-mojo-execution-configurator" );
+        File pluginDir = new File( testDir, "plugin" );
+        File projectDir = new File( testDir, "project" );
+
+        Verifier verifier;
+
+        // install the test plugin
+        verifier = newVerifier( pluginDir.getAbsolutePath(), "remote" );
+        verifier.executeGoal( "install" );
+        verifier.resetStreams();
+        verifier.verifyErrorFreeLog();
+
+        // build the test project
+        verifier = newVerifier( projectDir.getAbsolutePath(), "remote" );
+        verifier.executeGoal( "validate" );
+        verifier.resetStreams();
+        verifier.verifyErrorFreeLog();
+        
+        File configurationFile = new File(projectDir, "configuration.txt");
+        verifier.assertFilePresent( configurationFile.getCanonicalPath() );
+        //
+        // The <name/> element in the original configuration is "ORIGINAL". We want to assert that our
+        // custom MojoExecutionConfigurator made the transformation of the element from "ORIGINAL" to "TRANSFORMED"
+        //
+        String actual = FileUtils.fileRead( configurationFile );
+        assertEquals( "TRANSFORMED", actual );
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/18bd438d/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/pom.xml
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/pom.xml b/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/pom.xml
new file mode 100644
index 0000000..21e07a3
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/pom.xml
@@ -0,0 +1,55 @@
+<?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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>mng-5753-custom-mojo-execution-configurator</groupId>
+  <artifactId>mng-5753-custom-mojo-execution-configurator-plugin</artifactId>
+  <version>0.1</version>
+  <packaging>maven-plugin</packaging>
+
+  <properties>
+    <maven-version>3.2.6-SNAPSHOT</maven-version>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>${maven-version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-model</artifactId>
+      <version>${maven-version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+      <version>${maven-version}</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/18bd438d/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/src/main/java/org/apache/maven/its/mng5753/plugin/TestMojo.java
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/src/main/java/org/apache/maven/its/mng5753/plugin/TestMojo.java b/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/src/main/java/org/apache/maven/its/mng5753/plugin/TestMojo.java
new file mode 100644
index 0000000..29fb2d9
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/src/main/java/org/apache/maven/its/mng5753/plugin/TestMojo.java
@@ -0,0 +1,68 @@
+package org.apache.maven.its.mng5753.plugin;
+
+/*
+ * 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.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * @goal test
+ * @configurator test
+ */
+public class TestMojo
+    extends AbstractMojo
+{
+    /** @parameter expression="${project}" */
+    private MavenProject project;
+    
+    /** @parameter */
+    private String name;
+    
+    public void execute()
+        throws MojoExecutionException
+    {        
+        try
+        {
+            File file = new File( project.getBasedir(), "configuration.txt" );
+            file.getParentFile().mkdirs();
+            Writer w = new OutputStreamWriter( new FileOutputStream( file, true ), "UTF-8" );
+            try
+            {
+                w.write( name );
+            }
+            finally
+            {
+                w.close();
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( e.getMessage(), e );
+        }
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/18bd438d/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/src/main/java/org/apache/maven/its/mng5753/plugin/TestMojoExecutionConfigurator.java
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/src/main/java/org/apache/maven/its/mng5753/plugin/TestMojoExecutionConfigurator.java b/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/src/main/java/org/apache/maven/its/mng5753/plugin/TestMojoExecutionConfigurator.java
new file mode 100644
index 0000000..89076cf
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/src/main/java/org/apache/maven/its/mng5753/plugin/TestMojoExecutionConfigurator.java
@@ -0,0 +1,42 @@
+package org.apache.maven.its.mng5753.plugin;
+
+/*
+ * 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.lifecycle.internal.DefaultMojoExecutionConfigurator;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+public class TestMojoExecutionConfigurator
+    extends DefaultMojoExecutionConfigurator
+{
+    @Override
+    public void configure( MavenProject project, MojoExecution mojoExecution, boolean allowPluginLevelConfig )
+    {
+        // We do exactly what the default mojo execution configurator does
+        super.configure( project, mojoExecution, allowPluginLevelConfig );        
+        
+        // And now we'll insert some additional configuration that we can assert was placed
+        // in the configuration in our test
+        Xpp3Dom mojoConfiguration = mojoExecution.getConfiguration();
+        
+        mojoConfiguration.getChild( "name" ).setValue( "TRANSFORMED" );        
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/18bd438d/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/src/main/resources/META-INF/plexus/components.xml
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/src/main/resources/META-INF/plexus/components.xml b/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/src/main/resources/META-INF/plexus/components.xml
new file mode 100644
index 0000000..46fcf16
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/plugin/src/main/resources/META-INF/plexus/components.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<component-set>
+  <components>
+    <component>
+      <role>org.codehaus.plexus.component.configurator.ComponentConfigurator</role>
+      <role-hint>test</role-hint>
+      <implementation>org.codehaus.plexus.component.configurator.BasicComponentConfigurator</implementation>
+    </component>        
+    <component>
+      <role>org.apache.maven.lifecycle.MojoExecutionConfigurator</role>
+      <role-hint>test</role-hint>
+      <implementation>org.apache.maven.its.mng5753.plugin.TestMojoExecutionConfigurator</implementation>
+    </component>
+  </components>
+</component-set>

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/18bd438d/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/project/pom.xml
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/project/pom.xml b/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/project/pom.xml
new file mode 100644
index 0000000..c4fca0b
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5753-custom-mojo-execution-configurator/project/pom.xml
@@ -0,0 +1,52 @@
+<?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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>mng-5753-custom-mojo-execution-configurator</groupId>
+  <artifactId>mng-5753-custom-mojo-execution-configurator-project</artifactId>
+  <version>0.1</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>mng-5753-custom-mojo-execution-configurator</groupId>
+        <artifactId>mng-5753-custom-mojo-execution-configurator-plugin</artifactId>
+        <version>0.1</version>
+        <extensions>true</extensions>
+        <executions>
+          <execution>
+            <id>test</id>
+            <goals>
+              <goal>test</goal>
+            </goals>
+            <phase>validate</phase>
+            <configuration>
+              <name>ORIGINAL</name>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>