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/04 18:14:17 UTC

[1/3] git commit: changed version to 3.1.0-SNAPSHOT

Updated Branches:
  refs/heads/master 3b02e6986 -> 603b53d80


changed version to 3.1.0-SNAPSHOT

Signed-off-by: Igor Fedorenko <if...@apache.org>


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

Branch: refs/heads/master
Commit: 30dba957099520450815d873e746f020803f25a3
Parents: 3b02e69
Author: Igor Fedorenko <if...@apache.org>
Authored: Sat Feb 1 14:34:13 2014 -0500
Committer: Igor Fedorenko <if...@apache.org>
Committed: Sat Feb 1 14:34:13 2014 -0500

----------------------------------------------------------------------
 maven-plugin-testing-harness/pom.xml | 2 +-
 maven-plugin-testing-tools/pom.xml   | 2 +-
 maven-test-tools/pom.xml             | 2 +-
 pom.xml                              | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-plugin-testing/blob/30dba957/maven-plugin-testing-harness/pom.xml
----------------------------------------------------------------------
diff --git a/maven-plugin-testing-harness/pom.xml b/maven-plugin-testing-harness/pom.xml
index 94d72b8..7aa51af 100644
--- a/maven-plugin-testing-harness/pom.xml
+++ b/maven-plugin-testing-harness/pom.xml
@@ -25,7 +25,7 @@ under the License.
   <parent>
     <groupId>org.apache.maven.plugin-testing</groupId>
     <artifactId>maven-plugin-testing</artifactId>
-    <version>3.0.1-SNAPSHOT</version>
+    <version>3.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>maven-plugin-testing-harness</artifactId>

http://git-wip-us.apache.org/repos/asf/maven-plugin-testing/blob/30dba957/maven-plugin-testing-tools/pom.xml
----------------------------------------------------------------------
diff --git a/maven-plugin-testing-tools/pom.xml b/maven-plugin-testing-tools/pom.xml
index 4b94401..a6fde2c 100644
--- a/maven-plugin-testing-tools/pom.xml
+++ b/maven-plugin-testing-tools/pom.xml
@@ -25,7 +25,7 @@ under the License.
   <parent>
     <groupId>org.apache.maven.plugin-testing</groupId>
     <artifactId>maven-plugin-testing</artifactId>
-    <version>3.0.1-SNAPSHOT</version>
+    <version>3.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>maven-plugin-testing-tools</artifactId>

http://git-wip-us.apache.org/repos/asf/maven-plugin-testing/blob/30dba957/maven-test-tools/pom.xml
----------------------------------------------------------------------
diff --git a/maven-test-tools/pom.xml b/maven-test-tools/pom.xml
index 569150e..20a63e9 100644
--- a/maven-test-tools/pom.xml
+++ b/maven-test-tools/pom.xml
@@ -25,7 +25,7 @@ under the License.
   <parent>
     <groupId>org.apache.maven.plugin-testing</groupId>
     <artifactId>maven-plugin-testing</artifactId>
-    <version>3.0.1-SNAPSHOT</version>
+    <version>3.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>maven-test-tools</artifactId>

http://git-wip-us.apache.org/repos/asf/maven-plugin-testing/blob/30dba957/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 704e691..3779c3a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@ under the License.
 
   <groupId>org.apache.maven.plugin-testing</groupId>
   <artifactId>maven-plugin-testing</artifactId>
-  <version>3.0.1-SNAPSHOT</version>
+  <version>3.1.0-SNAPSHOT</version>
   <packaging>pom</packaging>
 
   <name>Maven Plugin Testing</name>


[2/3] git commit: MPLUGINTESTING-37 introduced MojoRule #executeMojo and related methods

Posted by if...@apache.org.
MPLUGINTESTING-37 introduced MojoRule #executeMojo and related methods

Signed-off-by: Igor Fedorenko <if...@apache.org>


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

Branch: refs/heads/master
Commit: 6ac53b29a3557907607374c9fa81649d96a7f218
Parents: 30dba95
Author: Igor Fedorenko <if...@apache.org>
Authored: Sat Feb 1 14:35:16 2014 -0500
Committer: Igor Fedorenko <if...@apache.org>
Committed: Tue Feb 4 11:56:07 2014 -0500

----------------------------------------------------------------------
 .../apache/maven/plugin/testing/MojoRule.java   | 52 ++++++++++++++++++++
 1 file changed, 52 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-plugin-testing/blob/6ac53b29/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java
----------------------------------------------------------------------
diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java
index 6abfee8..858cfe1 100644
--- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java
+++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java
@@ -23,15 +23,21 @@ import java.io.File;
 import java.io.InputStream;
 import java.util.Map;
 
+import org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.Mojo;
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuilder;
+import org.apache.maven.project.ProjectBuildingRequest;
 import org.codehaus.plexus.ContainerConfiguration;
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.junit.Assert;
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
@@ -303,4 +309,50 @@ public class MojoRule
             }            
         };       
     }
+
+    /**
+     * @since 3.1.0
+     */
+    public MavenProject readMavenProject( File basedir )
+        throws Exception
+    {
+        File pom = new File( basedir, "pom.xml" );
+        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
+        request.setBaseDirectory( basedir );
+        ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
+        MavenProject project = lookup( ProjectBuilder.class ).build( pom, configuration ).getProject();
+        Assert.assertNotNull( project );
+        return project;
+    }
+
+    /**
+     * @since 3.1.0
+     */
+    public void executeMojo( File basedir, String goal )
+        throws Exception
+    {
+        lookupConfiguredMojo( basedir, goal ).execute();
+    }
+
+    /**
+     * @since 3.1.0
+     */
+    public Mojo lookupConfiguredMojo( File basedir, String goal )
+        throws Exception, ComponentConfigurationException
+    {
+        MavenProject project = readMavenProject( basedir );
+        MavenSession session = newMavenSession( project );
+        MojoExecution execution = newMojoExecution( goal );
+        return lookupConfiguredMojo( session, execution );
+    }
+
+    /**
+     * @since 3.1.0
+     */
+    public final <T> T lookup( final Class<T> role )
+        throws ComponentLookupException
+    {
+        return getContainer().lookup( role );
+    }
+
 }


[3/3] git commit: MPLUGINTESTING-36 introduced TestResources junit4 test Rule

Posted by if...@apache.org.
MPLUGINTESTING-36 introduced TestResources junit4 test Rule

Signed-off-by: Igor Fedorenko <if...@apache.org>


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

Branch: refs/heads/master
Commit: 603b53d807819aeb6e0e2157459963a442b8cadb
Parents: 6ac53b2
Author: Igor Fedorenko <if...@apache.org>
Authored: Sat Feb 1 14:38:05 2014 -0500
Committer: Igor Fedorenko <if...@apache.org>
Committed: Tue Feb 4 12:07:12 2014 -0500

----------------------------------------------------------------------
 .../plugin/testing/resources/TestResources.java | 174 +++++++++++++++++++
 1 file changed, 174 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-plugin-testing/blob/603b53d8/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/resources/TestResources.java
----------------------------------------------------------------------
diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/resources/TestResources.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/resources/TestResources.java
new file mode 100644
index 0000000..378c03e
--- /dev/null
+++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/resources/TestResources.java
@@ -0,0 +1,174 @@
+package org.apache.maven.plugin.testing.resources;
+
+/*
+ * 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.IOException;
+import java.util.Collection;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.FileUtils;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+
+/**
+ * Junit4 test {@link Rule} to extract and assert test resources.
+ * 
+ * @since 3.1.0
+ */
+public class TestResources
+    extends TestWatcher
+{
+
+    private final String projectsDir;
+
+    private final String workDir;
+
+    public TestResources()
+    {
+        this( "src/test/projects", "target/ut/" );
+    }
+
+    public TestResources( String projectsDir, String workDir )
+    {
+        this.projectsDir = projectsDir;
+        this.workDir = workDir;
+    }
+
+    private String name;
+
+    @Override
+    protected void starting( Description d )
+    {
+        name = d.getTestClass().getSimpleName() + "_" + d.getMethodName();
+    }
+
+    /**
+     * Creates new clean copy of test project directory structure. The copy is named after both the test being executed
+     * and test project name, which allows the same test project can be used by multiple tests and by different
+     * instances of the same parametrized tests.<br/>
+     * TODO Provide alternative working directory naming for Windows, which still limits path names to ~250 charecters
+     */
+    public File getBasedir( String project )
+        throws IOException
+    {
+        File src = new File( projectsDir, project ).getCanonicalFile();
+        Assert.assertTrue( "Test project directory does not exist: " + src.getPath(), src.isDirectory() );
+        File basedir = new File( workDir, name + "_" + project ).getCanonicalFile();
+        FileUtils.deleteDirectory( basedir );
+        Assert.assertTrue( "Test project working directory created", basedir.mkdirs() );
+        FileUtils.copyDirectoryStructure( src, basedir );
+        return basedir;
+    }
+
+    // static helpers
+
+    public static void cp( File basedir, String from, String to )
+        throws IOException
+    {
+        // TODO ensure destination lastModified timestamp changes
+        FileUtils.copyFile( new File( basedir, from ), new File( basedir, to ) );
+    }
+
+    public static void assertFileContents( File basedir, String expectedPath, String actualPath )
+        throws IOException
+    {
+        String expected = FileUtils.fileRead( new File( basedir, expectedPath ) );
+        String actual = FileUtils.fileRead( new File( basedir, actualPath ) );
+        Assert.assertEquals( expected, actual );
+    }
+
+    public static void assertDirectoryContents( File dir, String... expectedPaths )
+    {
+        DirectoryScanner scanner = new DirectoryScanner();
+        scanner.setBasedir( dir );
+        scanner.addDefaultExcludes();
+        scanner.scan();
+
+        Set<String> actual = new TreeSet<String>();
+        for ( String path : scanner.getIncludedFiles() )
+        {
+            actual.add( path );
+        }
+        for ( String path : scanner.getIncludedDirectories() )
+        {
+            if ( path.length() > 0 )
+            {
+                actual.add( path + "/" );
+            }
+        }
+
+        Set<String> expected = new TreeSet<String>();
+        if ( expectedPaths != null )
+        {
+            for ( String path : expectedPaths )
+            {
+                expected.add( path );
+            }
+        }
+
+        // compare textual representation to make diff easier to understand
+        Assert.assertEquals( toString( expected ), toString( actual ) );
+    }
+
+    private static String toString( Collection<String> strings )
+    {
+        StringBuilder sb = new StringBuilder();
+        for ( String string : strings )
+        {
+            sb.append( string ).append( '\n' );
+        }
+        return sb.toString();
+    }
+
+    public static void touch( File basedir, String path )
+        throws InterruptedException
+    {
+        touch( new File( basedir, path ) );
+    }
+
+    public static void touch( File file )
+        throws InterruptedException
+    {
+        if ( !file.isFile() )
+        {
+            throw new IllegalArgumentException( "Not a file " + file );
+        }
+        long lastModified = file.lastModified();
+        file.setLastModified( System.currentTimeMillis() );
+
+        // TODO do modern filesystems still have this silly lastModified resolution?
+        if ( lastModified == file.lastModified() )
+        {
+            Thread.sleep( 1000L );
+            file.setLastModified( System.currentTimeMillis() );
+        }
+    }
+
+    public static void rm( File basedir, String path )
+    {
+        Assert.assertTrue( "delete " + path, new File( basedir, path ).delete() );
+    }
+
+}