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 3d291cde3729698edcc7862b9d132154e80abc8f Author: Benjamin Bentmann <bentm...@apache.org> AuthorDate: Sat Mar 22 17:22:21 2008 +0000 [MANT-6] "test" targets should fail if junit.jar not present o Added example to show how to realize this by target overriding git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-ant-plugin@640016 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/plugin/ant/AntBuildWriter.java | 5 +- src/site/apt/examples/customize.apt | 2 +- src/site/apt/examples/fail-missing-junit.apt | 61 ++++++++++++++++++++++ src/site/apt/index.apt | 2 + src/site/site.xml | 1 + 5 files changed, 66 insertions(+), 5 deletions(-) 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 17bba3b..c3618d9 100644 --- a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java +++ b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -43,8 +42,6 @@ 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> @@ -863,7 +860,7 @@ public class AntBuildWriter writer.endElement(); // echo writer.startElement( "echo" ); - writer.writeText( " Junit isn't present in your $ANT_HOME/lib directory. Tests not executed. " ); + writer.writeText( " JUnit is not present in your $ANT_HOME/lib directory. Tests not executed." ); writer.endElement(); // echo writer.startElement( "echo" ); diff --git a/src/site/apt/examples/customize.apt b/src/site/apt/examples/customize.apt index 0c72265..c1ddca3 100644 --- a/src/site/apt/examples/customize.apt +++ b/src/site/apt/examples/customize.apt @@ -38,7 +38,7 @@ Customizing Generated Ant Build Files <!-- Ant build file (http://ant.apache.org/) for Ant 1.6.2 or above. --> <!-- ====================================================================== --> -<project name="%PROJECT_ARTIFACTID%" default="jar" basedir="."> +<project name="%PROJECT_ARTIFACT_ID%" default="package" basedir="."> <!-- ====================================================================== --> <!-- Import maven-build.xml into the current project --> diff --git a/src/site/apt/examples/fail-missing-junit.apt b/src/site/apt/examples/fail-missing-junit.apt new file mode 100644 index 0000000..7db0299 --- /dev/null +++ b/src/site/apt/examples/fail-missing-junit.apt @@ -0,0 +1,61 @@ + ------ + Failing the Build if JUnit is Missing + ------ + Benjamin Bentmann + ------ + March 2008 + ------ + + ~~ Copyright 2006 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. + + ~~ NOTE: For help with the syntax of this file, see: + ~~ http://maven.apache.org/guides/mini/guide-apt-format.html + + +Failing the Build if JUnit is Missing + + The build scripts generated by the Ant Plugin require JUnit to run the unit tests. By default, the <<<build.xml>>> will + only output a warning if JUnit was not found on the class path, i.e. the build simply continues without running the + unit tests. If you rather want the build to fail in this case, you can easily customize the <<<build.xml>>> by + overriding the target <<<junit-present>>>: + ++-----+ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- ====================================================================== --> +<!-- Ant build file (http://ant.apache.org/) for Ant 1.6.2 or above. --> +<!-- ====================================================================== --> + +<project name="%PROJECT_ARTIFACT_ID%" default="package" basedir="."> + ... + + <!-- ====================================================================== --> + <!-- Unit testing, overridden to fail upon missing JUnit --> + <!-- ====================================================================== --> + + <target name="junit-present" + depends="test-junit-present" + unless="junit.present"> + <property name="ant.libdir" location="${ant.home}/lib" /> + <echo level="error">==================================== ERROR ====================================</echo> + <echo level="error"> JUnit is not present in your $ANT_HOME/lib directory, aborting build. </echo> + <echo level="error"> Please copy "junit.jar" to "${ant.libdir}". </echo> + <echo level="error">===============================================================================</echo> + <fail>JUnit not found on class path, cannot run unit tests.</fail> + </target> + + ... +</project> ++-----+ diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt index 014bd2d..2d39c20 100644 --- a/src/site/apt/index.apt +++ b/src/site/apt/index.apt @@ -47,3 +47,5 @@ Maven 2 Ant Plugin * {{{examples/customize.html}Customizing Generated Ant Build Files}} * {{{examples/run-single-test.html}Running Individual Unit Tests}} + + * {{{examples/fail-missing-junit.html}Failing the Build if JUnit is Missing}} diff --git a/src/site/site.xml b/src/site/site.xml index a5cd266..0b1cf9d 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -34,6 +34,7 @@ under the License. <menu name="Examples"> <item name="Customizing Ant Build Files" href="/examples/customize.html"/> <item name="Running Individual Unit Tests" href="/examples/run-single-test.html"/> + <item name="Failing if JUnit is Missing" href="/examples/fail-missing-junit.html"/> </menu> </body> </project> -- To stop receiving notification emails like this one, please contact "commits@maven.apache.org" <commits@maven.apache.org>.