This is an automated email from the ASF dual-hosted git repository. hboutemy pushed a commit to annotated tag maven-ant-plugin-2.1 in repository https://gitbox.apache.org/repos/asf/maven-ant-plugin.git
commit 732a9f938fa24e90bde7ccd57011c97cf7f857ef Author: Benjamin Bentmann <bentm...@apache.org> AuthorDate: Sat Mar 22 14:47:51 2008 +0000 [MANT-7] "test" target should support running a single test - just like mvn test does git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-ant-plugin@640004 13f79535-47bb-0310-9956-ffa450edef68 --- src/it/single-test-it/goals.txt | 2 + src/it/single-test-it/pom.xml | 66 ++++++++++++++++ .../single-test-it/src/test/java/it/BadTest.java | 37 +++++++++ .../single-test-it/src/test/java/it/GoodTest.java | 37 +++++++++ src/it/single-test-it/verify.bsh | 23 ++++++ .../apache/maven/plugin/ant/AntBuildWriter.java | 89 +++++++++++++++++----- src/site/apt/examples/{using.apt => customize.apt} | 6 +- .../{index.apt => examples/run-single-test.apt} | 36 ++++----- src/site/apt/index.apt | 8 +- src/site/apt/usage.apt | 6 +- src/site/fml/faq.fml | 4 +- src/site/site.xml | 3 +- 12 files changed, 264 insertions(+), 53 deletions(-) diff --git a/src/it/single-test-it/goals.txt b/src/it/single-test-it/goals.txt new file mode 100644 index 0000000..16cd63b --- /dev/null +++ b/src/it/single-test-it/goals.txt @@ -0,0 +1,2 @@ +ant:ant +initialize diff --git a/src/it/single-test-it/pom.xml b/src/it/single-test-it/pom.xml new file mode 100644 index 0000000..46eebd0 --- /dev/null +++ b/src/it/single-test-it/pom.xml @@ -0,0 +1,66 @@ +<?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/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.maven-ant-plugin.it</groupId> + <artifactId>single-test-it</artifactId> + <version>1.0-SNAPSHOT</version> + + <build> + <finalName>${project.artifactId}</finalName> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-ant-plugin</artifactId> + <version>@pom.version@</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + <version>1.1</version> + <executions> + <execution> + <phase>initialize</phase> + <configuration> + <tasks> + <property name="test" value="GoodTest" /> + <ant dir="${basedir}" antfile="${basedir}/build.xml" target="package" /> + </tasks> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>ant</groupId> + <artifactId>ant-junit</artifactId> + <version>1.6.5</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.2</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.2</version> + <scope>test</scope> + </dependency> + </dependencies> + + <properties> + <build.compiler>extJavac</build.compiler> + </properties> + +</project> diff --git a/src/it/single-test-it/src/test/java/it/BadTest.java b/src/it/single-test-it/src/test/java/it/BadTest.java new file mode 100644 index 0000000..447024f --- /dev/null +++ b/src/it/single-test-it/src/test/java/it/BadTest.java @@ -0,0 +1,37 @@ +package 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 junit.framework.TestCase; + +/** + * @version $Id$ + */ +public class BadTest + extends TestCase +{ + + public void testFail() + throws Exception + { + fail( "This test should have been excluded." ); + } + +} diff --git a/src/it/single-test-it/src/test/java/it/GoodTest.java b/src/it/single-test-it/src/test/java/it/GoodTest.java new file mode 100644 index 0000000..c6f6032 --- /dev/null +++ b/src/it/single-test-it/src/test/java/it/GoodTest.java @@ -0,0 +1,37 @@ +package 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 junit.framework.TestCase; + +/** + * @version $Id$ + */ +public class GoodTest + extends TestCase +{ + + public void testPass() + throws Exception + { + assertTrue( true ); + } + +} diff --git a/src/it/single-test-it/verify.bsh b/src/it/single-test-it/verify.bsh new file mode 100644 index 0000000..c993878 --- /dev/null +++ b/src/it/single-test-it/verify.bsh @@ -0,0 +1,23 @@ +import java.io.*; +import java.util.*; + +try +{ + File reportDir = new File( basedir, "target/test-reports" ); + + { + File file = new File( reportDir, "TEST-it.GoodTest.xml" ); + if ( !file.isFile() ) + { + System.err.println( "Report file does not exist: " + file ); + return false; + } + } +} +catch( Throwable t ) +{ + t.printStackTrace(); + return false; +} + +return true; diff --git a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java index ac9cab6..17bba3b 100644 --- a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java +++ b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java @@ -43,6 +43,8 @@ import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; +import sun.security.action.GetIntegerAction; + /** * Write Ant build files from <code>Maven Project</code> for <a href="http://ant.apache.org">Ant</a> 1.6.2 or above: * <ul> @@ -814,30 +816,23 @@ public class AntBuildWriter writer.startElement( "batchtest" ); writer.addAttribute( "todir", "${maven.test.reports}" ); + writer.addAttribute( "unless", "test" ); - List includes = - getSelectorList( AntBuildWriterUtil.getMavenSurefirePluginOptions( project, "includes", null ) ); - if ( includes == null || includes.isEmpty() ) - { - includes = Arrays.asList( new String[] { "**/Test*.java", "**/*Test.java", "**/*TestCase.java" } ); - } + List includes = getTestIncludes(); + List excludes = getTestExcludes(); - List excludes = - getSelectorList( AntBuildWriterUtil.getMavenSurefirePluginOptions( project, "excludes", null ) ); - if ( excludes == null || excludes.isEmpty() ) - { - excludes = Arrays.asList( new String[] { "**/*Abstract*Test.java" } ); - } + writeTestFilesets( writer, testCompileSourceRoots, includes, excludes ); + + writer.endElement(); // batchtest + + writer.startElement( "batchtest" ); + writer.addAttribute( "todir", "${maven.test.reports}" ); + writer.addAttribute( "if", "test" ); + + includes = Arrays.asList( new String[] { "**/${test}.java" } ); + + writeTestFilesets( writer, testCompileSourceRoots, includes, excludes ); - String[] compileSourceRoots = (String[]) testCompileSourceRoots.toArray( new String[0] ); - for ( int i = 0; i < compileSourceRoots.length; i++ ) - { - writer.startElement( "fileset" ); - writer.addAttribute( "dir", "${maven.build.testDir." + i + "}" ); - // TODO: m1 allows additional test exclusions via maven.ant.excludeTests - AntBuildWriterUtil.writeIncludesExcludes( writer, includes, excludes ); - writer.endElement(); // fileset - } writer.endElement(); // batchtest writer.endElement(); // junit @@ -882,6 +877,58 @@ public class AntBuildWriter } /** + * Gets the include patterns for the unit tests. + * + * @return A list of strings with include patterns, might be empty but never <code>null</code>. + */ + private List getTestIncludes() + throws IOException + { + List includes = getSelectorList( AntBuildWriterUtil.getMavenSurefirePluginOptions( project, "includes", null ) ); + if ( includes == null || includes.isEmpty() ) + { + includes = Arrays.asList( new String[] { "**/Test*.java", "**/*Test.java", "**/*TestCase.java" } ); + } + return includes; + } + + /** + * Gets the exclude patterns for the unit tests. + * + * @return A list of strings with exclude patterns, might be empty but never <code>null</code>. + */ + private List getTestExcludes() + throws IOException + { + List excludes = getSelectorList( AntBuildWriterUtil.getMavenSurefirePluginOptions( project, "excludes", null ) ); + if ( excludes == null || excludes.isEmpty() ) + { + excludes = Arrays.asList( new String[] { "**/*Abstract*Test.java" } ); + } + return excludes; + } + + /** + * Write the <code><fileset></code> elements for the test compile source roots. + * + * @param writer + * @param testCompileSourceRoots + * @param includes + * @param excludes + */ + private void writeTestFilesets( XMLWriter writer, List testCompileSourceRoots, List includes, List excludes ) + { + for ( int i = 0; i < testCompileSourceRoots.size(); i++ ) + { + writer.startElement( "fileset" ); + writer.addAttribute( "dir", "${maven.build.testDir." + i + "}" ); + // TODO: m1 allows additional test exclusions via maven.ant.excludeTests + AntBuildWriterUtil.writeIncludesExcludes( writer, includes, excludes ); + writer.endElement(); // fileset + } + } + + /** * Write javadoc target in the writer depending the packaging of the project. * * @param writer diff --git a/src/site/apt/examples/using.apt b/src/site/apt/examples/customize.apt similarity index 91% rename from src/site/apt/examples/using.apt rename to src/site/apt/examples/customize.apt index d2af823..0c72265 100644 --- a/src/site/apt/examples/using.apt +++ b/src/site/apt/examples/customize.apt @@ -1,5 +1,5 @@ ------ - Grammar Inheritance + Customizing Generated Ant Build Files ------ Vincent Siveton ------ @@ -24,9 +24,9 @@ ~~ http://maven.apache.org/guides/mini/guide-apt-format.html -Using generated Ant build files +Customizing Generated Ant Build Files - <<Note>>: If you want to add your own Ant targets, you should add them to <<<build.xml>>> and <<NOT>> <<<maven-build.xml>>>. + <<Warning>>: If you want to add your own Ant targets, you should add them to <<<build.xml>>> and <not> to <<<maven-build.xml>>>. The <<<build.xml>>> file uses the {{{http://ant.apache.org/manual/CoreTasks/import.html}import task}} of Ant. So, you can override the generated targets in the <<<build.xml>>> file. For instance: diff --git a/src/site/apt/index.apt b/src/site/apt/examples/run-single-test.apt similarity index 53% copy from src/site/apt/index.apt copy to src/site/apt/examples/run-single-test.apt index 865bb77..d55da8c 100644 --- a/src/site/apt/index.apt +++ b/src/site/apt/examples/run-single-test.apt @@ -1,9 +1,9 @@ ------ - Introduction + Running Individual Unit Tests ------ - Vincent Siveton + Benjamin Bentmann ------ - September 2006 + March 2008 ------ ~~ Copyright 2006 The Apache Software Foundation. @@ -24,24 +24,20 @@ ~~ http://maven.apache.org/guides/mini/guide-apt-format.html -Maven 2 Ant Plugin +Running Individual Unit Tests - The Ant Plugin generates {{{http://ant.apache.org/}Ant}} build files for Ant 1.6.2 or above. + Since version 2.1 of the Ant Plugin, the generated Ant build files allow to run individual unit tests. You merely need + to specify the simple name of the desired test class via the system property <<<test>>> as illustrated below: -* Goals Overview ++-----+ +ant test -Dtest=MyFavoriteTest ++-----+ - The Ant Plugin has two goals: + This will run a test matching the pattern <<<**/MyFavoriteTest.java>>>. You can also employ a simple pattern to select + multiple tests: + ++-----+ +ant test -Dtest=*FavoriteTest ++-----+ - * {{{ant-mojo.html}ant:ant}} Generate Ant build files. - - * {{{clean-mojo.html}ant:clean}} Clean all Ant build files. - -* Usage - - Instructions on how to use the Ant Plugin can be found {{{usage.html}here}}. - -* Examples - - The following examples show how to use the Ant Plugin in more advanced usecases: - - * {{{examples/using.html}Using generated Ant build files}} + <<Note>>: Unlike the Surefire Plugin, the Ant scripts do not support a comma-separated value for the <<<test>>> property. diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt index 865bb77..014bd2d 100644 --- a/src/site/apt/index.apt +++ b/src/site/apt/index.apt @@ -26,7 +26,7 @@ Maven 2 Ant Plugin - The Ant Plugin generates {{{http://ant.apache.org/}Ant}} build files for Ant 1.6.2 or above. + The Ant Plugin generates build files for {{{http://ant.apache.org/}Ant}} 1.6.2 or above from the POM. * Goals Overview @@ -38,10 +38,12 @@ Maven 2 Ant Plugin * Usage - Instructions on how to use the Ant Plugin can be found {{{usage.html}here}}. + Instructions on how to use the Ant Plugin can be found on the {{{usage.html}usage page}}. * Examples The following examples show how to use the Ant Plugin in more advanced usecases: - * {{{examples/using.html}Using generated Ant build files}} + * {{{examples/customize.html}Customizing Generated Ant Build Files}} + + * {{{examples/run-single-test.html}Running Individual Unit Tests}} diff --git a/src/site/apt/usage.apt b/src/site/apt/usage.apt index 6459292..af8ac75 100644 --- a/src/site/apt/usage.apt +++ b/src/site/apt/usage.apt @@ -26,7 +26,7 @@ Usage - The Ant Plugin generates Ant build files. The following example describe the basic + The Ant Plugin generates Ant build files from POMs. The following example describe the basic usage of the Plugin. * Generate Ant build files @@ -93,10 +93,10 @@ mvn ant:ant -Doverwrite=true ant -projecthelp +-----+ - <<Note>>: <<DO NOT EDIT maven-build.xml!>> It will be overwritten when calling <<<mvn ant:ant>>>. + <<Warning>>: Do not edit <<<maven-build.xml>>>! It will be overwritten when calling <<<mvn ant:ant>>>. ** maven-build.properties The <<<maven-build.properties>>> file contains several properties used by the <<<maven-build.xml>>> build file. - <<Note>>: <<DO NOT EDIT maven-build.properties!>> It will be overwritten when calling <<<mvn ant:ant>>>. + <<Warning>>: Do not edit <<<maven-build.properties>>>! It will be overwritten when calling <<<mvn ant:ant>>>. diff --git a/src/site/fml/faq.fml b/src/site/fml/faq.fml index a46b9de..de6d2e0 100644 --- a/src/site/fml/faq.fml +++ b/src/site/fml/faq.fml @@ -1,4 +1,4 @@ -<?xml version="1.0"?> +<?xml version="1.0" encoding="UTF-8"?> <!-- ~ Copyright 2006 The Apache Software Foundation. @@ -35,4 +35,4 @@ </answer> </faq> </part> -</faqs> \ No newline at end of file +</faqs> diff --git a/src/site/site.xml b/src/site/site.xml index dd3d94c..a5cd266 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -32,7 +32,8 @@ under the License. <item name="FAQ" href="faq.html"/> </menu> <menu name="Examples"> - <item name="Using Ant build files" href="/examples/using.html"/> + <item name="Customizing Ant Build Files" href="/examples/customize.html"/> + <item name="Running Individual Unit Tests" href="/examples/run-single-test.html"/> </menu> </body> </project> -- To stop receiving notification emails like this one, please contact "commits@maven.apache.org" <commits@maven.apache.org>.