This is an automated email from the ASF dual-hosted git repository. hboutemy pushed a commit to annotated tag maven-invoker-plugin-1.1 in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
commit fa99c3df2c6b701b30016e78fa4774a84265f649 Author: Oliver Lamy <ol...@apache.org> AuthorDate: Fri Nov 30 22:31:36 2007 +0000 [MINVOKER-13] support a parameter "a la" -Dtest like in surefire git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-invoker-plugin@599989 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/plugin/invoker/InvokerMojo.java | 41 +++++++++++++++++-- src/site/apt/advance-usage.apt | 6 +++ .../maven/plugin/invoker/InvokerMojoTest.java | 46 ++++++++++++++++++++++ src/test/resources/unit/dummy/pom.xml | 29 ++++++++++++++ 4 files changed, 119 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java b/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java index 1fdfea5..845ecad 100644 --- a/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java +++ b/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java @@ -50,6 +50,7 @@ import org.apache.maven.shared.model.fileset.util.FileSetManager; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.InterpolationFilterReader; +import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.xml.XmlStreamReader; @@ -229,7 +230,17 @@ public class InvokerMojo * @readonly * @since 1.1 */ - private MavenProject project; + private MavenProject project; + + /** + * Specify this parameter to run individual tests by file name, overriding the <code>pomIncludes</code> + * and <code>pomExcludes</code> parameters. Each pattern you specify here will be used to create an + * include pattern formatted like <code>${projectsDirectory}/${invoker.test}</code>, + * so you can just type "-Dinvoker.test=MyTest" to run a single it in ${projectsDirectory}/${invoker.test}". + * @parameter expression="${invoker.test}" + * @since 1.1 + */ + private String invokerTest; // list to store interpolated pom for delete at the end private List/*File*/ interpolatedPomFiles = new ArrayList(); @@ -775,7 +786,7 @@ public class InvokerMojo return invocationGoals; } - private String[] getPoms() + protected String[] getPoms() throws IOException { String[] poms; @@ -784,6 +795,30 @@ public class InvokerMojo { poms = new String[]{ pom.getAbsolutePath() }; } + else if ( invokerTest != null ) + { + String[] testRegexes = StringUtils.split( invokerTest, "," ); + List /* String */includes = new ArrayList( testRegexes.length ); + + for ( int i = 0, size = testRegexes.length; i < size; i++ ) + { + // user just use -Dinvoker.test=MWAR191,MNG111 to use a directory thats the end is not pom.xml + includes.add( testRegexes[i].endsWith( "pom.xml" ) ? testRegexes[i] : testRegexes[i] + + File.separatorChar + "pom.xml" ); + } + + final FileSet fs = new FileSet(); + + fs.setIncludes( includes ); + //fs.setExcludes( pomExcludes ); + fs.setDirectory( projectsDirectory.getCanonicalPath() ); + fs.setFollowSymlinks( false ); + fs.setUseDefaultExcludes( false ); + + final FileSetManager fsm = new FileSetManager( getLog() ); + + poms = fsm.getIncludedFiles( fs ); + } else { final FileSet fs = new FileSet(); @@ -803,7 +838,7 @@ public class InvokerMojo return poms; } - + private String[] normalizePomPaths( String[] poms ) throws IOException { diff --git a/src/site/apt/advance-usage.apt b/src/site/apt/advance-usage.apt index 33e33c9..3748d1e 100755 --- a/src/site/apt/advance-usage.apt +++ b/src/site/apt/advance-usage.apt @@ -23,6 +23,12 @@ Advance Usage * values from the project pom (you must use @pom.groupId@ notation in your pom file) * In the plugin configuration you can add some properties in a interpolationsProperties element + +* Running only some tests + + The plugin support a parameter -Dinvoker.test to run only its in the directory match by the expressions + used in the parameter + command line is : mvn -Dinvoker.test=*MWAR*,simple* \ No newline at end of file diff --git a/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java b/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java index b676f2b..add82dc 100644 --- a/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java +++ b/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java @@ -21,6 +21,7 @@ package org.apache.maven.plugin.invoker; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.apache.maven.plugin.testing.AbstractMojoTestCase; @@ -75,4 +76,49 @@ public class InvokerMojoTest invokerMojo.execute(); } + public void testSingleInvokerTest() + throws Exception + { + InvokerMojo invokerMojo = new InvokerMojo(); + setVariableValueToObject( invokerMojo, "goalsFile", "validate-goal.txt" ); + String dirPath = getBasedir() + "/src/test/resources/unit"; + List goals = invokerMojo.getGoals( new File( dirPath ) ); + assertEquals( 1, goals.size() ); + setVariableValueToObject( invokerMojo, "projectsDirectory", new File( dirPath ) ); + setVariableValueToObject( invokerMojo, "invokerTest", "*dummy*" ); + String[] poms = invokerMojo.getPoms(); + System.out.println( Arrays.asList( poms ) ); + assertEquals( 1, poms.length ); + } + + public void testMultiInvokerTest() + throws Exception + { + InvokerMojo invokerMojo = new InvokerMojo(); + setVariableValueToObject( invokerMojo, "goalsFile", "validate-goal.txt" ); + String dirPath = getBasedir() + "/src/test/resources/unit"; + List goals = invokerMojo.getGoals( new File( dirPath ) ); + assertEquals( 1, goals.size() ); + setVariableValueToObject( invokerMojo, "projectsDirectory", new File( dirPath ) ); + setVariableValueToObject( invokerMojo, "invokerTest", "*dummy*,*terpolatio*" ); + String[] poms = invokerMojo.getPoms(); + System.out.println( Arrays.asList( poms ) ); + assertEquals( 2, poms.length ); + } + + public void testFullPatternInvokerTest() + throws Exception + { + InvokerMojo invokerMojo = new InvokerMojo(); + setVariableValueToObject( invokerMojo, "goalsFile", "validate-goal.txt" ); + String dirPath = getBasedir() + "/src/test/resources/unit"; + List goals = invokerMojo.getGoals( new File( dirPath ) ); + assertEquals( 1, goals.size() ); + setVariableValueToObject( invokerMojo, "projectsDirectory", new File( dirPath ) ); + setVariableValueToObject( invokerMojo, "invokerTest", "*" ); + String[] poms = invokerMojo.getPoms(); + System.out.println( Arrays.asList( poms ) ); + assertEquals( 3, poms.length ); + } + } diff --git a/src/test/resources/unit/dummy/pom.xml b/src/test/resources/unit/dummy/pom.xml new file mode 100755 index 0000000..ab2014a --- /dev/null +++ b/src/test/resources/unit/dummy/pom.xml @@ -0,0 +1,29 @@ +<?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>org.apache.maven.test</groupId> + <artifactId>unit</artifactId> + <packaging>pom</packaging> + <version>0.1-SNAPSHOT</version> + <properties> + <interpolateValue>@foo@</interpolateValue> + </properties> +</project> \ No newline at end of file -- To stop receiving notification emails like this one, please contact "commits@maven.apache.org" <commits@maven.apache.org>.