You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2016/12/11 12:42:03 UTC
[4/4] maven-surefire git commit: [SUREFIRE-1313] Unify console report
result in SurefirePlugin and VerifyMojo
[SUREFIRE-1313] Unify console report result in SurefirePlugin and VerifyMojo
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/f841a16e
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/f841a16e
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/f841a16e
Branch: refs/heads/master
Commit: f841a16e4f85ffc28a39baa3f01454c08092f79d
Parents: 9478990
Author: Tibor17 <ti...@lycos.com>
Authored: Sun Dec 11 13:38:42 2016 +0100
Committer: Tibor17 <ti...@lycos.com>
Committed: Sun Dec 11 13:38:42 2016 +0100
----------------------------------------------------------------------
.../maven/plugin/failsafe/VerifyMojo.java | 2 +-
.../maven/plugin/surefire/SurefireHelper.java | 94 +++++++++++++-------
.../maven/plugin/surefire/SurefirePlugin.java | 13 +--
.../apache/maven/surefire/suite/RunResult.java | 3 +-
4 files changed, 65 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f841a16e/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java
----------------------------------------------------------------------
diff --git a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java
index 37199a3..5d0b035 100644
--- a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java
+++ b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java
@@ -209,7 +209,7 @@ public class VerifyMojo
throw new MojoExecutionException( e.getMessage(), e );
}
- reportExecution( this, summary, getConsoleLogger() );
+ reportExecution( this, summary, getConsoleLogger(), null );
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f841a16e/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java
index 3f87c3c..e4b340a 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java
@@ -26,6 +26,7 @@ import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.surefire.log.PluginConsoleLogger;
import org.apache.maven.surefire.cli.CommandLineOption;
import org.apache.maven.surefire.suite.RunResult;
+import org.apache.maven.surefire.testset.TestSetFailedException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -34,10 +35,10 @@ import java.util.Collection;
import java.util.List;
import static java.util.Collections.unmodifiableList;
+import static org.apache.maven.surefire.cli.CommandLineOption.LOGGING_LEVEL_DEBUG;
import static org.apache.maven.surefire.cli.CommandLineOption.LOGGING_LEVEL_ERROR;
-import static org.apache.maven.surefire.cli.CommandLineOption.LOGGING_LEVEL_WARN;
import static org.apache.maven.surefire.cli.CommandLineOption.LOGGING_LEVEL_INFO;
-import static org.apache.maven.surefire.cli.CommandLineOption.LOGGING_LEVEL_DEBUG;
+import static org.apache.maven.surefire.cli.CommandLineOption.LOGGING_LEVEL_WARN;
import static org.apache.maven.surefire.cli.CommandLineOption.SHOW_ERRORS;
/**
@@ -55,48 +56,26 @@ public final class SurefireHelper
}
public static void reportExecution( SurefireReportParameters reportParameters, RunResult result,
- PluginConsoleLogger log )
+ PluginConsoleLogger log, Exception firstForkException )
throws MojoFailureException, MojoExecutionException
{
- boolean timeoutOrOtherFailure = result.isFailureOrTimeout();
-
- if ( !timeoutOrOtherFailure )
+ if ( firstForkException == null && !result.isTimeout() && result.isErrorFree() )
{
- if ( result.getCompletedCount() == 0 )
+ if ( result.getCompletedCount() == 0 && failIfNoTests( reportParameters ) )
{
- if ( reportParameters.getFailIfNoTests() == null || !reportParameters.getFailIfNoTests() )
- {
- return;
- }
- throw new MojoFailureException(
- "No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)" );
- }
-
- if ( result.isErrorFree() )
- {
- return;
+ throw new MojoFailureException( "No tests were executed! "
+ + "(Set -DfailIfNoTests=false to ignore this error.)" );
}
+ return;
}
- String msg = timeoutOrOtherFailure
- ? "There was a timeout or other error in the fork"
- : "There are test failures.\n\nPlease refer to " + reportParameters.getReportsDirectory()
- + " for the individual test results.";
-
if ( reportParameters.isTestFailureIgnore() )
{
- log.error( msg );
+ log.error( createErrorMessage( reportParameters, result, firstForkException ) );
}
else
{
- if ( result.isFailure() )
- {
- throw new MojoExecutionException( msg );
- }
- else
- {
- throw new MojoFailureException( msg );
- }
+ throwException( reportParameters, result, firstForkException );
}
}
@@ -181,4 +160,55 @@ public final class SurefireHelper
}
}
+ private static boolean failIfNoTests( SurefireReportParameters reportParameters )
+ {
+ return reportParameters.getFailIfNoTests() != null && reportParameters.getFailIfNoTests();
+ }
+
+ private static boolean isNotFatal( Exception firstForkException )
+ {
+ return firstForkException == null || firstForkException instanceof TestSetFailedException;
+ }
+
+ private static void throwException( SurefireReportParameters reportParameters, RunResult result,
+ Exception firstForkException )
+ throws MojoFailureException, MojoExecutionException
+ {
+ if ( isNotFatal( firstForkException ) )
+ {
+ throw new MojoFailureException( createErrorMessage( reportParameters, result, firstForkException ),
+ firstForkException );
+ }
+ else
+ {
+ throw new MojoExecutionException( createErrorMessage( reportParameters, result, firstForkException ),
+ firstForkException );
+ }
+ }
+
+ private static String createErrorMessage( SurefireReportParameters reportParameters, RunResult result,
+ Exception firstForkException )
+ {
+ StringBuilder msg = new StringBuilder( 128 );
+
+ if ( result.isTimeout() )
+ {
+ msg.append( "There was a timeout or other error in the fork" );
+ }
+ else
+ {
+ msg.append( "There are test failures.\n\nPlease refer to " )
+ .append( reportParameters.getReportsDirectory() )
+ .append( " for the individual test results." );
+ }
+
+ if ( firstForkException != null && firstForkException.getLocalizedMessage() != null )
+ {
+ msg.append( '\n' )
+ .append( firstForkException.getLocalizedMessage() );
+ }
+
+ return msg.toString();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f841a16e/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
----------------------------------------------------------------------
diff --git a/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java b/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
index 97f1a79..943ed69 100644
--- a/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
+++ b/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
@@ -331,18 +331,7 @@ public class SurefirePlugin
protected void handleSummary( RunResult summary, Exception firstForkException )
throws MojoExecutionException, MojoFailureException
{
- assertNoException( firstForkException );
-
- reportExecution( this, summary, getConsoleLogger() );
- }
-
- private void assertNoException( Exception firstForkException )
- throws MojoFailureException
- {
- if ( firstForkException != null )
- {
- throw new MojoFailureException( firstForkException.getMessage(), firstForkException );
- }
+ reportExecution( this, summary, getConsoleLogger(), firstForkException );
}
protected boolean isSkipExecution()
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f841a16e/surefire-api/src/main/java/org/apache/maven/surefire/suite/RunResult.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/suite/RunResult.java b/surefire-api/src/main/java/org/apache/maven/surefire/suite/RunResult.java
index 50102e0..a8466b2 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/suite/RunResult.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/suite/RunResult.java
@@ -177,7 +177,7 @@ public class RunResult
/* Indicates test timeout or technical failure */
public boolean isFailureOrTimeout()
{
- return this.timeout || isFailure();
+ return isTimeout() || isFailure();
}
public boolean isFailure()
@@ -195,7 +195,6 @@ public class RunResult
return timeout;
}
-
public RunResult aggregate( RunResult other )
{
String failureMessage = getFailure() != null ? getFailure() : other.getFailure();