Repository: maven-surefire Updated Branches: refs/heads/master 201a31346 -> 4d3673c42
[SUREFIRE-1317] - Refactoring Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/b50ea3ac Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/b50ea3ac Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/b50ea3ac Branch: refs/heads/master Commit: b50ea3acf0701e4a66ad8f55930cb41dd2bfc999 Parents: 201a313 Author: Tibor17 <tibo...@lycos.com> Authored: Sun Jan 8 00:21:34 2017 +0100 Committer: Tibor17 <tibo...@lycos.com> Committed: Sun Jan 8 00:21:34 2017 +0100 ---------------------------------------------------------------------- maven-surefire-common/pom.xml | 1 + .../plugin/surefire/AbstractSurefireMojo.java | 1 + .../surefire/StartupReportConfiguration.java | 7 ++- .../surefire/booterclient/ForkStarter.java | 4 +- .../output/DeserializedStacktraceWriter.java | 2 +- .../booterclient/output/ForkClient.java | 13 +++++- .../output/LostCommandsDumpSingleton.java | 7 +++ .../output/ThreadedStreamConsumer.java | 49 ++++++++------------ .../surefire/report/DefaultReporterFactory.java | 13 +++--- .../report/NullStatelessXmlReporter.java | 2 +- .../surefire/report/StatelessXmlReporter.java | 10 ++-- .../surefire/report/TestSetRunListener.java | 2 +- .../surefire/runorder/StatisticsReporter.java | 4 +- .../report/DefaultReporterFactoryTest.java | 18 +++---- .../report/StatelessXmlReporterTest.java | 6 +-- .../maven/plugins/surefire/report/Utils.java | 1 + .../surefire/booter/MasterProcessCommand.java | 8 ++-- .../surefire/report/CategorizedReportEntry.java | 17 +++---- .../maven/surefire/report/SafeThrowable.java | 5 ++ .../surefire/util/internal/StringUtils.java | 28 +---------- 20 files changed, 93 insertions(+), 105 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/pom.xml ---------------------------------------------------------------------- diff --git a/maven-surefire-common/pom.xml b/maven-surefire-common/pom.xml index 54825b7..ae71f0d 100644 --- a/maven-surefire-common/pom.xml +++ b/maven-surefire-common/pom.xml @@ -141,6 +141,7 @@ </executions> </plugin> <plugin> + <!-- Remove in 3.0 --> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/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 4f7744f..99eca2c 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 @@ -234,6 +234,7 @@ public abstract class AbstractSurefireMojo * unless overridden. */ @Parameter + // TODO use regex for fully qualified class names in 3.0 and change the filtering abilities private List<String> excludes; /** http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java index 482ce00..bf6e5ef 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java @@ -171,11 +171,16 @@ public final class StartupReportConfiguration return rerunFailingTestsCount; } + public boolean hasRerunFailingTestsCount() + { + return getRerunFailingTestsCount() > 0; + } + public StatelessXmlReporter instantiateStatelessXmlReporter() { return isDisableXmlReport() ? null - : new StatelessXmlReporter( reportsDirectory, reportNameSuffix, trimStackTrace, rerunFailingTestsCount, + : new StatelessXmlReporter( reportsDirectory, reportNameSuffix, trimStackTrace, hasRerunFailingTestsCount(), testClassMethodRunHistory, xsdSchemaLocation ); } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java index 05c4cc2..b864076 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java @@ -189,9 +189,9 @@ public class ForkStarter { closeable.close(); } - catch ( IOException e ) + catch ( Throwable e ) { - // ignore + e.printStackTrace(); } } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/DeserializedStacktraceWriter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/DeserializedStacktraceWriter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/DeserializedStacktraceWriter.java index 8832a36..952feb8 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/DeserializedStacktraceWriter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/DeserializedStacktraceWriter.java @@ -64,6 +64,6 @@ public class DeserializedStacktraceWriter public SafeThrowable getThrowable() { - return new SafeThrowable( new Throwable( message ) ); + return new SafeThrowable( message ); } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java index 68ce40d..e37e82f 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java @@ -25,7 +25,6 @@ import org.apache.maven.plugin.surefire.report.DefaultReporterFactory; import org.apache.maven.shared.utils.cli.StreamConsumer; import org.apache.maven.surefire.report.ConsoleOutputReceiver; import org.apache.maven.surefire.report.ReportEntry; -import org.apache.maven.surefire.report.ReporterException; import org.apache.maven.surefire.report.RunListener; import org.apache.maven.surefire.report.StackTraceWriter; @@ -68,6 +67,7 @@ import static org.apache.maven.surefire.util.internal.StringUtils.isNotBlank; import static org.apache.maven.surefire.util.internal.StringUtils.unescapeBytes; import static org.apache.maven.surefire.util.internal.StringUtils.unescapeString; +// todo move to the same package with ForkStarter /** * Knows how to reconstruct *all* the state transmitted over stdout by the forked process. * @@ -284,16 +284,25 @@ public class ForkClient } catch ( NumberFormatException e ) { + // native stream sent a text e.g. GC verbose // SUREFIRE-859 LostCommandsDumpSingleton.getSingleton().dumpException( e, s, defaultReporterFactory ); } catch ( NoSuchElementException e ) { + // native stream sent a text e.g. GC verbose // SUREFIRE-859 LostCommandsDumpSingleton.getSingleton().dumpException( e, s, defaultReporterFactory ); } - catch ( ReporterException e ) + catch ( IndexOutOfBoundsException e ) { + // native stream sent a text e.g. GC verbose + // SUREFIRE-859 + LostCommandsDumpSingleton.getSingleton().dumpException( e, s, defaultReporterFactory ); + } + catch ( RuntimeException e ) + { + // e.g. ReporterException LostCommandsDumpSingleton.getSingleton().dumpException( e, s, defaultReporterFactory ); throw e; } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/LostCommandsDumpSingleton.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/LostCommandsDumpSingleton.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/LostCommandsDumpSingleton.java index fa38c05..a8f11e4 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/LostCommandsDumpSingleton.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/LostCommandsDumpSingleton.java @@ -21,8 +21,15 @@ package org.apache.maven.plugin.surefire.booterclient.output; import org.apache.maven.plugin.surefire.report.DefaultReporterFactory; import org.apache.maven.surefire.util.internal.DumpFileUtils; + import java.io.File; +/** + * Dumps lost commands and caused exceptions in {@link ForkClient}. + * + * @author <a href="mailto:tibordig...@apache.org">Tibor Digana (tibor17)</a> + * @since 2.19.2 + */ final class LostCommandsDumpSingleton { private static final LostCommandsDumpSingleton SINGLETON = new LostCommandsDumpSingleton(); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java index ebf3edb..c095199 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java @@ -20,12 +20,15 @@ package org.apache.maven.plugin.surefire.booterclient.output; */ import org.apache.maven.shared.utils.cli.StreamConsumer; -import org.apache.maven.surefire.util.internal.DaemonThreadFactory; -import java.util.concurrent.BlockingQueue; import java.io.Closeable; +import java.io.IOException; +import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.apache.maven.surefire.util.internal.DaemonThreadFactory.newDaemonThread; + /** * Knows how to reconstruct *all* the state transmitted over stdout by the forked process. * @@ -36,27 +39,21 @@ public final class ThreadedStreamConsumer { private static final String POISON = "Pioson"; - private static final int ITEM_LIMIT_BEFORE_SLEEP = 10000; - private final BlockingQueue<String> items = new LinkedBlockingQueue<String>(); private final Thread thread; private final Pumper pumper; - static class Pumper + final class Pumper implements Runnable { - private final BlockingQueue<String> queue; - private final StreamConsumer target; private volatile Throwable throwable; - - Pumper( BlockingQueue<String> queue, StreamConsumer target ) + Pumper( StreamConsumer target ) { - this.queue = queue; this.target = target; } @@ -77,7 +74,7 @@ public final class ThreadedStreamConsumer { try { - item = queue.take(); + item = items.take(); target.consumeLine( item ); } catch ( InterruptedException e ) @@ -99,8 +96,8 @@ public final class ThreadedStreamConsumer public ThreadedStreamConsumer( StreamConsumer target ) { - pumper = new Pumper( items, target ); - thread = DaemonThreadFactory.newDaemonThread( pumper, "ThreadedStreamConsumer" ); + pumper = new Pumper( target ); + thread = newDaemonThread( pumper, ThreadedStreamConsumer.class.getSimpleName() ); thread.start(); } @@ -108,35 +105,29 @@ public final class ThreadedStreamConsumer public void consumeLine( String s ) { items.add( s ); - if ( items.size() > ITEM_LIMIT_BEFORE_SLEEP ) - { - try - { - Thread.sleep( 100 ); - } - catch ( InterruptedException ignore ) - { - } - } } - - public void close() + public void close() throws IOException { try { items.add( POISON ); - thread.join(); + if ( thread.isAlive() ) + { + thread.join( SECONDS.toMillis( 10L ) ); + thread.interrupt(); + } } catch ( InterruptedException e ) { - throw new RuntimeException( e ); + throw new IOException( e ); } //noinspection ThrowableResultOfMethodCallIgnored - if ( pumper.getThrowable() != null ) + Throwable e = pumper.getThrowable(); + if ( e != null ) { - throw new RuntimeException( pumper.getThrowable() ); + throw new IOException( e ); } } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java index b4a6f30..1c2c68c 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java @@ -37,6 +37,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.TreeMap; import java.util.concurrent.ConcurrentLinkedQueue; @@ -218,11 +219,11 @@ public class DefaultReporterFactory * if it only has errors or failures, then count its result based on its first run * * @param reportEntries the list of test run report type for a given test - * @param rerunFailingTestsCount configured rerun count for failing tests + * @param hasRerunFailingTestsCount <tt>true</tt> if rerun count for failing tests is greater than zero * @return the type of test result */ // Use default visibility for testing - static TestResultType getTestResultType( List<ReportEntryType> reportEntries, int rerunFailingTestsCount ) + static TestResultType getTestResultType( List<ReportEntryType> reportEntries, boolean hasRerunFailingTestsCount ) { if ( reportEntries == null || reportEntries.isEmpty() ) { @@ -248,7 +249,7 @@ public class DefaultReporterFactory if ( seenFailure || seenError ) { - if ( seenSuccess && rerunFailingTestsCount > 0 ) + if ( seenSuccess & hasRerunFailingTestsCount ) { return flake; } @@ -310,7 +311,7 @@ public class DefaultReporterFactory // Update globalStatistics by iterating through mergedTestHistoryResult int completedCount = 0, skipped = 0; - for ( Map.Entry<String, List<TestMethodStats>> entry : mergedTestHistoryResult.entrySet() ) + for ( Entry<String, List<TestMethodStats>> entry : mergedTestHistoryResult.entrySet() ) { List<TestMethodStats> testMethodStats = entry.getValue(); String testClassMethodName = entry.getKey(); @@ -322,7 +323,7 @@ public class DefaultReporterFactory resultTypes.add( methodStats.getResultType() ); } - switch ( getTestResultType( resultTypes, reportConfiguration.getRerunFailingTestsCount() ) ) + switch ( getTestResultType( resultTypes, reportConfiguration.hasRerunFailingTestsCount() ) ) { case success: // If there are multiple successful runs of the same test, count all of them @@ -393,7 +394,7 @@ public class DefaultReporterFactory printed = true; } - for ( Map.Entry<String, List<TestMethodStats>> entry : testStats.entrySet() ) + for ( Entry<String, List<TestMethodStats>> entry : testStats.entrySet() ) { printed = true; List<TestMethodStats> testMethodStats = entry.getValue(); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/NullStatelessXmlReporter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/NullStatelessXmlReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/NullStatelessXmlReporter.java index 5895c8a..e72adc7 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/NullStatelessXmlReporter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/NullStatelessXmlReporter.java @@ -33,7 +33,7 @@ class NullStatelessXmlReporter private NullStatelessXmlReporter() { - super( null, null, false, 0, null, null ); + super( null, null, false, false, null, null ); } @Override http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java index 8ebeb96..271d3f0 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java @@ -92,7 +92,7 @@ public class StatelessXmlReporter private final boolean trimStackTrace; - private final int rerunFailingTestsCount; + private final boolean hasRerunFailingTestsCount; private final String xsdSchemaLocation; @@ -101,14 +101,14 @@ public class StatelessXmlReporter private final Map<String, Map<String, List<WrappedReportEntry>>> testClassMethodRunHistoryMap; public StatelessXmlReporter( File reportsDirectory, String reportNameSuffix, boolean trimStackTrace, - int rerunFailingTestsCount, + boolean hasRerunFailingTestsCount, Map<String, Map<String, List<WrappedReportEntry>>> testClassMethodRunHistoryMap, String xsdSchemaLocation ) { this.reportsDirectory = reportsDirectory; this.reportNameSuffix = reportNameSuffix; this.trimStackTrace = trimStackTrace; - this.rerunFailingTestsCount = rerunFailingTestsCount; + this.hasRerunFailingTestsCount = hasRerunFailingTestsCount; this.testClassMethodRunHistoryMap = testClassMethodRunHistoryMap; this.xsdSchemaLocation = xsdSchemaLocation; } @@ -147,7 +147,7 @@ public class StatelessXmlReporter if ( !methodEntryList.isEmpty() ) { - if ( rerunFailingTestsCount > 0 ) + if ( hasRerunFailingTestsCount ) { TestResultType resultType = getTestResultType( methodEntryList ); switch ( resultType ) @@ -268,7 +268,7 @@ public class StatelessXmlReporter testResultTypeList.add( singleRunEntry.getReportEntryType() ); } - return DefaultReporterFactory.getTestResultType( testResultTypeList, rerunFailingTestsCount ); + return DefaultReporterFactory.getTestResultType( testResultTypeList, hasRerunFailingTestsCount ); } private Map<String, List<WrappedReportEntry>> getAddMethodRunHistoryMap( String testClassName ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java index f0f996d..c5a17d3 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java @@ -269,7 +269,7 @@ public class TestSetRunListener } } - public List<TestMethodStats> getTestMethodStats() + List<TestMethodStats> getTestMethodStats() { return testMethodStats; } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java index 5776cc9..3f78939 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java @@ -42,11 +42,11 @@ public class StatisticsReporter this( dataFile, fromFile( dataFile ), new RunEntryStatisticsMap() ); } - protected StatisticsReporter( File dataFile, RunEntryStatisticsMap existing, RunEntryStatisticsMap newRestuls ) + protected StatisticsReporter( File dataFile, RunEntryStatisticsMap existing, RunEntryStatisticsMap newResults ) { this.dataFile = dataFile; this.existing = existing; - this.newResults = newRestuls; + this.newResults = newResults; } public synchronized void testSetCompleted() http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java index fbe875d..c4c2556 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java @@ -185,41 +185,41 @@ public class DefaultReporterFactoryTest public void testGetTestResultType() { List<ReportEntryType> emptyList = new ArrayList<ReportEntryType>(); - assertEquals( unknown, getTestResultType( emptyList, 1 ) ); + assertEquals( unknown, getTestResultType( emptyList, true ) ); List<ReportEntryType> successList = new ArrayList<ReportEntryType>(); successList.add( ReportEntryType.SUCCESS ); successList.add( ReportEntryType.SUCCESS ); - assertEquals( success, getTestResultType( successList, 1 ) ); + assertEquals( success, getTestResultType( successList, true ) ); List<ReportEntryType> failureErrorList = new ArrayList<ReportEntryType>(); failureErrorList.add( ReportEntryType.FAILURE ); failureErrorList.add( ReportEntryType.ERROR ); - assertEquals( error, getTestResultType( failureErrorList, 1 ) ); + assertEquals( error, getTestResultType( failureErrorList, true ) ); List<ReportEntryType> errorFailureList = new ArrayList<ReportEntryType>(); errorFailureList.add( ReportEntryType.ERROR ); errorFailureList.add( ReportEntryType.FAILURE ); - assertEquals( error, getTestResultType( errorFailureList, 1 ) ); + assertEquals( error, getTestResultType( errorFailureList, true ) ); List<ReportEntryType> flakeList = new ArrayList<ReportEntryType>(); flakeList.add( ReportEntryType.SUCCESS ); flakeList.add( ReportEntryType.FAILURE ); - assertEquals( flake, getTestResultType( flakeList, 1 ) ); + assertEquals( flake, getTestResultType( flakeList, true ) ); - assertEquals( failure, getTestResultType( flakeList, 0 ) ); + assertEquals( failure, getTestResultType( flakeList, false ) ); flakeList = new ArrayList<ReportEntryType>(); flakeList.add( ReportEntryType.ERROR ); flakeList.add( ReportEntryType.SUCCESS ); flakeList.add( ReportEntryType.FAILURE ); - assertEquals( flake, getTestResultType( flakeList, 1 ) ); + assertEquals( flake, getTestResultType( flakeList, true ) ); - assertEquals( error, getTestResultType( flakeList, 0 ) ); + assertEquals( error, getTestResultType( flakeList, false ) ); List<ReportEntryType> skippedList = new ArrayList<ReportEntryType>(); skippedList.add( ReportEntryType.SKIPPED ); - assertEquals( skipped, getTestResultType( skippedList, 1 ) ); + assertEquals( skipped, getTestResultType( skippedList, true ) ); } static class DummyStackTraceWriter http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporterTest.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporterTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporterTest.java index 5b649e3..553ee40 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporterTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporterTest.java @@ -83,7 +83,7 @@ public class StatelessXmlReporterTest public void testFileNameWithoutSuffix() { StatelessXmlReporter reporter = - new StatelessXmlReporter( reportDir, null, false, 0, + new StatelessXmlReporter( reportDir, null, false, false, new ConcurrentHashMap<String, Map<String, List<WrappedReportEntry>>>(), XSD ); reporter.cleanTestHistoryMap(); @@ -136,7 +136,7 @@ public class StatelessXmlReporterTest ReportEntryType.ERROR, 13, stdOut, stdErr ); stats.testSucceeded( t2 ); - StatelessXmlReporter reporter = new StatelessXmlReporter( reportDir, null, false, 0, + StatelessXmlReporter reporter = new StatelessXmlReporter( reportDir, null, false, false, new ConcurrentHashMap<String, Map<String, List<WrappedReportEntry>>>(), XSD ); reporter.testSetCompleted( testSetReportEntry, stats ); @@ -216,7 +216,7 @@ public class StatelessXmlReporterTest rerunStats.testSucceeded( testThreeSecondRun ); StatelessXmlReporter reporter = - new StatelessXmlReporter( reportDir, null, false, 1, + new StatelessXmlReporter( reportDir, null, false, true, new HashMap<String, Map<String, List<WrappedReportEntry>>>(), XSD ); reporter.testSetCompleted( testSetReportEntry, stats ); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/Utils.java ---------------------------------------------------------------------- diff --git a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/Utils.java b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/Utils.java index 8fd91bf..d2cb04e 100644 --- a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/Utils.java +++ b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/Utils.java @@ -23,6 +23,7 @@ public final class Utils { private Utils() { + throw new IllegalStateException( "no instantiable constructor" ); } public static String toSystemNewLine( String s ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java index a75aa83..0bd7b89 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java @@ -19,8 +19,6 @@ package org.apache.maven.surefire.booter; * under the License. */ -import org.apache.maven.surefire.util.internal.StringUtils; - import java.io.DataInputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -48,7 +46,7 @@ public enum MasterProcessCommand /** To tell a forked process that the master process is still alive. Repeated after 10 seconds. */ NOOP( 4, Void.class ); - private static final Charset ASCII = Charset.forName( "ASCII" ); + private static final Charset ASCII = Charset.forName( "US-ASCII" ); private final int id; @@ -152,7 +150,7 @@ public enum MasterProcessCommand case RUN_CLASS: return new String( data, FORK_STREAM_CHARSET_NAME ); case SHUTDOWN: - return StringUtils.decode( data, ASCII ); + return new String( data, ASCII ); default: return null; } @@ -170,7 +168,7 @@ public enum MasterProcessCommand case RUN_CLASS: return encodeStringForForkCommunication( data ); case SHUTDOWN: - return StringUtils.encode( data, ASCII ); + return data.getBytes( ASCII ); default: return new byte[0]; } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/surefire-api/src/main/java/org/apache/maven/surefire/report/CategorizedReportEntry.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/report/CategorizedReportEntry.java b/surefire-api/src/main/java/org/apache/maven/surefire/report/CategorizedReportEntry.java index 77cfaf3..0cccd6e 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/report/CategorizedReportEntry.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/report/CategorizedReportEntry.java @@ -67,17 +67,7 @@ public class CategorizedReportEntry @Override public String getNameWithGroup() { - StringBuilder result = new StringBuilder(); - result.append( getName() ); - - if ( getGroup() != null && !getName().equals( getGroup() ) ) - { - result.append( GROUP_PREFIX ); - result.append( getGroup() ); - result.append( GROUP_SUFIX ); - } - - return result.toString(); + return isNameWithGroup() ? getName() + GROUP_PREFIX + getGroup() + GROUP_SUFIX : getName(); } public boolean equals( Object o ) @@ -107,4 +97,9 @@ public class CategorizedReportEntry result = 31 * result + ( group != null ? group.hashCode() : 0 ); return result; } + + private boolean isNameWithGroup() + { + return getGroup() != null && !getGroup().equals( getName() ); + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/surefire-api/src/main/java/org/apache/maven/surefire/report/SafeThrowable.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/report/SafeThrowable.java b/surefire-api/src/main/java/org/apache/maven/surefire/report/SafeThrowable.java index 60c7897..b3b86f2 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/report/SafeThrowable.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/report/SafeThrowable.java @@ -31,6 +31,11 @@ public class SafeThrowable this.target = target; } + public SafeThrowable( String message ) + { + this( new Throwable( message ) ); + } + public String getLocalizedMessage() { try http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b50ea3ac/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java b/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java index 830cace..352b5fd 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java @@ -57,7 +57,7 @@ import java.util.StringTokenizer; */ public final class StringUtils { - public static final String NL = System.getProperty( "line.separator" ); + public static final String NL = System.getProperty( "line.separator", "\n" ); private static final byte[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; @@ -345,32 +345,6 @@ public final class StringUtils return ByteBuffer.wrap( out, 0, outPos ); } - public static String decode( byte[] toDecode, Charset charset ) - { - try - { - // @todo use new JDK 1.6 constructor String(byte bytes[], Charset charset) - return new String( toDecode, charset.name() ); - } - catch ( UnsupportedEncodingException e ) - { - throw new RuntimeException( "The JVM must support Charset " + charset, e ); - } - } - - public static byte[] encode( String toEncode, Charset charset ) - { - try - { - // @todo use new JDK 1.6 method getBytes(Charset charset) - return toEncode.getBytes( charset.name() ); - } - catch ( UnsupportedEncodingException e ) - { - throw new RuntimeException( "The JVM must support Charset " + charset, e ); - } - } - public static byte[] encodeStringForForkCommunication( String string ) { try