You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2018/02/25 16:24:05 UTC

svn commit: r1825308 - in /maven/archetypes/trunk/maven-archetype-plugin/src: main/resources-filtered/archetype-resources/ main/resources/META-INF/maven/ main/resources/archetype-resources/src/test/ main/resources/archetype-resources/src/test/java/ mai...

Author: hboutemy
Date: Sun Feb 25 16:24:05 2018
New Revision: 1825308

URL: http://svn.apache.org/viewvc?rev=1825308&view=rev
Log:
[MARCHETYPES-51] added plugin testing harness
Submitted by: Nick Lombard

Added:
    maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/
    maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/java/
    maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/java/MyMojoTest.java
    maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/resources/
    maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/resources/project-to-test/
    maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/resources/project-to-test/pom.xml
Modified:
    maven/archetypes/trunk/maven-archetype-plugin/src/main/resources-filtered/archetype-resources/pom.xml
    maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/META-INF/maven/archetype-metadata.xml
    maven/archetypes/trunk/maven-archetype-plugin/src/site/apt/index.apt.vm
    maven/archetypes/trunk/maven-archetype-plugin/src/test/resources/projects/it-basic/verify.groovy

Modified: maven/archetypes/trunk/maven-archetype-plugin/src/main/resources-filtered/archetype-resources/pom.xml
URL: http://svn.apache.org/viewvc/maven/archetypes/trunk/maven-archetype-plugin/src/main/resources-filtered/archetype-resources/pom.xml?rev=1825308&r1=1825307&r2=1825308&view=diff
==============================================================================
--- maven/archetypes/trunk/maven-archetype-plugin/src/main/resources-filtered/archetype-resources/pom.xml (original)
+++ maven/archetypes/trunk/maven-archetype-plugin/src/main/resources-filtered/archetype-resources/pom.xml Sun Feb 25 16:24:05 2018
@@ -34,20 +34,52 @@
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.compiler.source>1.7</project.compiler.source>
     <project.compiler.target>1.7</project.compiler.target>
+    <maven.version>3.5.2</maven.version>
   </properties>
 
   <dependencies>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
-      <version>2.0</version>
+      <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>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>${maven.version}</version>
+      <scope>provided</scope>
     </dependency>
     <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-compat</artifactId>
+      <version>${maven.version}</version>
+      <scope>provided</scope>
+    </dependency> 
+    <dependency>
       <groupId>org.apache.maven.plugin-tools</groupId>
       <artifactId>maven-plugin-annotations</artifactId>
       <version>${plugin}</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.12</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugin-testing</groupId>
+      <artifactId>maven-plugin-testing-harness</artifactId>
+      <version>3.3.0</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
@@ -96,8 +128,9 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-plugin-plugin</artifactId>
-        <version>3.2</version>
+        <version>3.5</version>
         <configuration>
+          <!-- <goalPrefix>${artifactId}</goalPrefix> -->
           <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
         </configuration>
         <executions>
@@ -154,7 +187,6 @@
             </executions>
           </plugin>
         </plugins>
-
       </build>
     </profile>
   </profiles>

Modified: maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/META-INF/maven/archetype-metadata.xml
URL: http://svn.apache.org/viewvc/maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/META-INF/maven/archetype-metadata.xml?rev=1825308&r1=1825307&r2=1825308&view=diff
==============================================================================
--- maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/META-INF/maven/archetype-metadata.xml (original)
+++ maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/META-INF/maven/archetype-metadata.xml Sun Feb 25 16:24:05 2018
@@ -25,6 +25,12 @@ under the License.
     <fileSet filtered="true" packaged="true">
       <directory>src/main/java</directory>
     </fileSet>
+    <fileSet filtered="true" packaged="true">
+      <directory>src/test/java</directory>
+    </fileSet>
+    <fileSet filtered="true" packaged="false">
+      <directory>src/test/resources</directory>
+    </fileSet>
     <fileSet filtered="true" packaged="false">
       <directory>src/it</directory>
     </fileSet>

Added: maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/java/MyMojoTest.java
URL: http://svn.apache.org/viewvc/maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/java/MyMojoTest.java?rev=1825308&view=auto
==============================================================================
--- maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/java/MyMojoTest.java (added)
+++ maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/java/MyMojoTest.java Sun Feb 25 16:24:05 2018
@@ -0,0 +1,76 @@
+package $package;
+
+##
+## 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.testing.MojoRule;
+import org.apache.maven.plugin.testing.WithoutMojo;
+
+import org.junit.Rule;
+import static org.junit.Assert.*;
+import org.junit.Test;
+import java.io.File;
+
+public class MyMojoTest
+{
+    @Rule
+    public MojoRule rule = new MojoRule()
+    {
+        @Override
+        protected void before() throws Throwable 
+        {
+        }
+
+        @Override
+        protected void after()
+        {
+        }
+    };
+
+    /**
+     * @throws Exception if any
+     */
+    @Test
+    public void testSomething()
+            throws Exception
+    {
+        File pom = new File( "target/test-classes/project-to-test/" );
+        assertNotNull( pom );
+        assertTrue( pom.exists() );
+
+        MyMojo myMojo = ( MyMojo ) rule.lookupConfiguredMojo( pom, "touch" );
+        assertNotNull( myMojo );
+        myMojo.execute();
+
+        File outputDirectory = ( File ) rule.getVariableValueFromObject( myMojo, "outputDirectory" );
+        assertNotNull( outputDirectory );
+        assertTrue( outputDirectory.exists() );
+
+        File touch = new File( outputDirectory, "touch.txt" );
+        assertTrue( touch.exists() );
+
+    }
+
+    /** Do not need the MojoRule. */
+    @WithoutMojo
+    @Test
+    public void testSomethingWhichDoesNotNeedTheMojoAndProbablyShouldBeExtractedIntoANewClassOfItsOwn()
+    {
+        assertTrue( true );
+    }
+
+}
+

Added: maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/resources/project-to-test/pom.xml
URL: http://svn.apache.org/viewvc/maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/resources/project-to-test/pom.xml?rev=1825308&view=auto
==============================================================================
--- maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/resources/project-to-test/pom.xml (added)
+++ maven/archetypes/trunk/maven-archetype-plugin/src/main/resources/archetype-resources/src/test/resources/project-to-test/pom.xml Sun Feb 25 16:24:05 2018
@@ -0,0 +1,39 @@
+##
+## 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.
+##
+<?xml version="1.0" encoding="UTF-8"?>
+<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>${groupId}</groupId>
+  <artifactId>${artifactId}</artifactId>
+  <version>${version}</version>
+  <packaging>jar</packaging>
+  <name>Test MyMojo</name>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-my-plugin</artifactId>
+        <configuration>
+          <!-- Specify the MyMojo parameter -->
+          <outputDirectory>target/test-harness/project-to-test</outputDirectory>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Modified: maven/archetypes/trunk/maven-archetype-plugin/src/site/apt/index.apt.vm
URL: http://svn.apache.org/viewvc/maven/archetypes/trunk/maven-archetype-plugin/src/site/apt/index.apt.vm?rev=1825308&r1=1825307&r2=1825308&view=diff
==============================================================================
--- maven/archetypes/trunk/maven-archetype-plugin/src/site/apt/index.apt.vm (original)
+++ maven/archetypes/trunk/maven-archetype-plugin/src/site/apt/index.apt.vm Sun Feb 25 16:24:05 2018
@@ -39,6 +39,13 @@ project
     |   `-- java
     |       `-- $package
     |           `-- MyMojo.java
+    |-- test
+    |   |-- java
+    |   |   `-- $package
+    |   │       `-- MyMojoTest.java
+    |   `-- resources
+    |       `-- project-to-test
+    |           `-- pom.xml
     `-- it
         |-- simple-it
         |   |-- pom.xml

Modified: maven/archetypes/trunk/maven-archetype-plugin/src/test/resources/projects/it-basic/verify.groovy
URL: http://svn.apache.org/viewvc/maven/archetypes/trunk/maven-archetype-plugin/src/test/resources/projects/it-basic/verify.groovy?rev=1825308&r1=1825307&r2=1825308&view=diff
==============================================================================
--- maven/archetypes/trunk/maven-archetype-plugin/src/test/resources/projects/it-basic/verify.groovy (original)
+++ maven/archetypes/trunk/maven-archetype-plugin/src/test/resources/projects/it-basic/verify.groovy Sun Feb 25 16:24:05 2018
@@ -22,7 +22,21 @@ assert parameter.type.text() == 'java.io
 assert parameter.required.text() == 'true'
 assert parameter.description.text() == 'Location of the file.'
 
+File testFile = new File( basedir, "project/basic-plugin/src/main/java/it/pkg/plugin/MyMojo.java" );
+assert testFile.exists()
 
+testFile = new File( basedir, "project/basic-plugin/src/test/java/it/pkg/plugin/MyMojoTest.java" );
+assert testFile.exists()
 
+testFile = new File( basedir, "project/basic-plugin/src/test/resources/project-to-test/pom.xml" );
+assert testFile.exists()
 
+testFile = new File( basedir, "project/basic-plugin/src/it/simple-it/verify.groovy" );
+assert testFile.exists()
+
+testFile = new File( basedir, "project/basic-plugin/src/it/simple-it/pom.xml" );
+assert testFile.exists()
+
+testFile = new File( basedir, "project/basic-plugin/src/it/settings.xml" );
+assert testFile.exists()