Repository: maven-surefire
Updated Branches:
  refs/heads/master 5a079a277 -> f2ae49aa8


[SUREFIRE] improved sanity check and site


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/f2ae49aa
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/f2ae49aa
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/f2ae49aa

Branch: refs/heads/master
Commit: f2ae49aa8eed8b987e4dcd595d48c38f3ae9a555
Parents: 5a079a2
Author: Tibor17 <tibo...@lycos.com>
Authored: Mon Oct 5 22:59:16 2015 +0200
Committer: Tibor17 <tibo...@lycos.com>
Committed: Mon Oct 5 22:59:16 2015 +0200

----------------------------------------------------------------------
 .../plugin/surefire/AbstractSurefireMojo.java   | 63 +++++++++++++++++++-
 .../site/apt/examples/skip-after-failure.apt.vm | 15 ++++-
 2 files changed, 74 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f2ae49aa/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
----------------------------------------------------------------------
diff --git 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index a5bb43f..2a77415 100644
--- 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++ 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -829,6 +829,7 @@ public abstract class AbstractSurefireMojo
             warnIfDefunctGroupsCombinations();
             warnIfRerunClashes();
             warnIfWrongShutdownValue();
+            warnIfNotApplicableSkipAfterFailureCount();
         }
         return true;
     }
@@ -2362,15 +2363,21 @@ public abstract class AbstractSurefireMojo
     private void warnIfRerunClashes()
         throws MojoFailureException
     {
+        if ( getRerunFailingTestsCount() < 0 )
+        {
+            throw new MojoFailureException( "Parameter 
\"rerunFailingTestsCount\" should not be negative." );
+        }
+
         if ( getSkipAfterFailureCount() < 0 )
         {
-            throw new MojoFailureException( "Parameter rerunFailingTestsCount 
should not be negative." );
+            throw new MojoFailureException( "Parameter 
\"skipAfterFailureCount\" should not be negative." );
         }
+
         boolean isRerun = getRerunFailingTestsCount() > 0;
         boolean isFailFast = getSkipAfterFailureCount() > 0;
         if ( isRerun && isFailFast )
         {
-            throw new MojoFailureException( "Parameters 
[rerunFailingTestsCount, skipAfterFailureCount] "
+            throw new MojoFailureException( "Parameters 
[\"rerunFailingTestsCount\", \"skipAfterFailureCount\"] "
                                                 + "should not be enabled 
together." );
         }
     }
@@ -2384,6 +2391,58 @@ public abstract class AbstractSurefireMojo
         }
     }
 
+    private void warnIfNotApplicableSkipAfterFailureCount()
+        throws MojoFailureException
+    {
+        int skipAfterFailureCount = getSkipAfterFailureCount();
+
+        if ( skipAfterFailureCount < 0 )
+        {
+            throw new MojoFailureException( "Parameter 
\"skipAfterFailureCount\" should not be negative." );
+        }
+        else if ( skipAfterFailureCount > 0 )
+        {
+            try
+            {
+                Artifact testng = getTestNgArtifact();
+                if ( testng != null )
+                {
+                    VersionRange range = VersionRange.createFromVersionSpec( 
"[5.10,)" );
+                    if ( !range.containsVersion( new DefaultArtifactVersion( 
testng.getVersion() ) ) )
+                    {
+                        throw new MojoFailureException(
+                            "Parameter \"skipAfterFailureCount\" expects 
TestNG Version 5.10 or higher. "
+                                + "java.lang.NoClassDefFoundError: 
org/testng/IInvokedMethodListener" );
+                    }
+                }
+                else
+                {
+                    // TestNG is dependent on JUnit
+                    Artifact junit = getJunitArtifact();
+                    if ( junit != null )
+                    {
+                        VersionRange range = 
VersionRange.createFromVersionSpec( "[4.0,)" );
+                        if ( !range.containsVersion( new 
DefaultArtifactVersion( junit.getVersion() ) ) )
+                        {
+                            throw new MojoFailureException(
+                                "Parameter \"skipAfterFailureCount\" expects 
JUnit Version 4.0 or higher. "
+                                    + "java.lang.NoSuchMethodError: "
+                                    + 
"org.junit.runner.notification.RunNotifier.pleaseStop()V" );
+                        }
+                    }
+                }
+            }
+            catch ( MojoExecutionException e )
+            {
+                throw new MojoFailureException( e.getLocalizedMessage() );
+            }
+            catch ( InvalidVersionSpecificationException e )
+            {
+                throw new RuntimeException( e );
+            }
+        }
+    }
+
     final class TestNgProviderInfo
         implements ProviderInfo
     {

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f2ae49aa/maven-surefire-plugin/src/site/apt/examples/skip-after-failure.apt.vm
----------------------------------------------------------------------
diff --git 
a/maven-surefire-plugin/src/site/apt/examples/skip-after-failure.apt.vm 
b/maven-surefire-plugin/src/site/apt/examples/skip-after-failure.apt.vm
index 7fa2c8b..1ba41bd 100644
--- a/maven-surefire-plugin/src/site/apt/examples/skip-after-failure.apt.vm
+++ b/maven-surefire-plugin/src/site/apt/examples/skip-after-failure.apt.vm
@@ -46,8 +46,19 @@ Prerequisite
  
  If version of TestNG is lover than 5.10 while the parameter 
  <<<skipAfterFailureCount>>> is set, the plugin fails with error:
- <<<[ERROR] org.apache.maven.surefire.util.SurefireReflectionException: 
- java.lang.NoClassDefFoundError: org/testng/IInvokedMethodListener>>>
+ 
+ <<<[ERROR] Failed to execute goal ...: Parameter "skipAfterFailureCount"
+ expects TestNG Version 5.10 or higher. java.lang.NoClassDefFoundError:
+ org/testng/IInvokedMethodListener>>>
+
+ 
+ 
+ If version of JUnit is lover than 4.0 while the parameter 
+ <<<skipAfterFailureCount>>> is set, the plugin fails with error:
+ 
+ <<<[ERROR] Failed to execute goal ...: Parameter "skipAfterFailureCount"
+ expects JUnit Version 4.0 or higher. java.lang.NoSuchMethodError:
+ org.junit.runner.notification.RunNotifier.pleaseStop()V>>>
  
  
 Notices

Reply via email to