From b1e7a78f7611bd01d593a95eb63b9af377ff5b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20Diga=C5=88a?= Date: Tue, 18 Jan 2022 15:34:28 +0100 Subject: [PATCH] [SUREFIRE-1981] Upgrade Apache maven-shared-utils to Version 3.3.4 --- .../DefaultForkConfiguration.java | 52 ++++++++------ .../output/ThreadedStreamConsumer.java | 3 +- .../surefire/report/StatelessXmlReporter.java | 71 ++++++++----------- .../booterclient/ForkConfigurationTest.java | 12 ++-- pom.xml | 7 +- .../jiras/Surefire1367AssumptionLogsIT.java | 2 +- 6 files changed, 70 insertions(+), 77 deletions(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfiguration.java index a2c38b8604..138e7f342a 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfiguration.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfiguration.java @@ -28,6 +28,7 @@ import org.apache.maven.surefire.booter.SurefireBooterForkException; import org.apache.maven.surefire.extensions.ForkNodeFactory; import org.apache.maven.surefire.api.util.internal.ImmutableMap; +import org.apache.maven.surefire.shared.utils.cli.CommandLineException; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -133,35 +134,42 @@ public OutputStreamFlushableCommandline createCommandLine( @Nonnull StartupConfi @Nonnull File dumpLogDirectory ) throws SurefireBooterForkException { - OutputStreamFlushableCommandline cli = - new OutputStreamFlushableCommandline( getExcludedEnvironmentVariables() ); + try + { + OutputStreamFlushableCommandline cli = + new OutputStreamFlushableCommandline( getExcludedEnvironmentVariables() ); - cli.setWorkingDirectory( getWorkingDirectory( forkNumber ).getAbsolutePath() ); + cli.setWorkingDirectory( getWorkingDirectory( forkNumber ).getAbsolutePath() ); - for ( Entry entry : getEnvironmentVariables().entrySet() ) - { - String value = entry.getValue(); - cli.addEnvironment( entry.getKey(), value == null ? "" : value ); - } + for ( Entry entry : getEnvironmentVariables().entrySet() ) + { + String value = entry.getValue(); + cli.addEnvironment( entry.getKey(), value == null ? "" : value ); + } - cli.setExecutable( getJdkForTests().getJvmExecutable().getAbsolutePath() ); + cli.setExecutable( getJdkForTests().getJvmExecutable().getAbsolutePath() ); - String jvmArgLine = newJvmArgLine( forkNumber ); - if ( !jvmArgLine.isEmpty() ) - { - cli.createArg() - .setLine( jvmArgLine ); - } + String jvmArgLine = newJvmArgLine( forkNumber ); + if ( !jvmArgLine.isEmpty() ) + { + cli.createArg() + .setLine( jvmArgLine ); + } - if ( getDebugLine() != null && !getDebugLine().isEmpty() ) - { - cli.createArg() - .setLine( getDebugLine() ); - } + if ( getDebugLine() != null && !getDebugLine().isEmpty() ) + { + cli.createArg() + .setLine( getDebugLine() ); + } - resolveClasspath( cli, findStartClass( config ), config, dumpLogDirectory ); + resolveClasspath( cli, findStartClass( config ), config, dumpLogDirectory ); - return cli; + return cli; + } + catch ( CommandLineException e ) + { + throw new SurefireBooterForkException( e.getLocalizedMessage(), e ); + } } protected ConsoleLogger getLogger() 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 10920c5501..742aad26c4 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 @@ -21,7 +21,6 @@ import org.apache.maven.surefire.api.event.Event; import org.apache.maven.surefire.extensions.EventHandler; -import org.apache.maven.surefire.shared.utils.cli.StreamConsumer; import javax.annotation.Nonnull; import java.io.Closeable; @@ -69,7 +68,7 @@ final class Pumper /** * Calls {@link ForkClient#handleEvent(Event)} which may throw any {@link RuntimeException}.
* Even if {@link ForkClient} is not fault-tolerant, this method MUST be fault-tolerant and thus the - * try-catch block must be inside of the loop which prevents from loosing events from {@link StreamConsumer}. + * try-catch block must be inside of the loop which prevents from loosing events from {@link EventHandler}. *
* If {@link org.apache.maven.plugin.surefire.report.ConsoleOutputFileReporter#writeTestOutput} throws * {@link java.io.IOException} and then {@code target.consumeLine()} throws any RuntimeException, this method 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 7c24fe23d0..54310696fd 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 @@ -23,7 +23,6 @@ import org.apache.maven.surefire.shared.utils.xml.PrettyPrintXMLWriter; import org.apache.maven.surefire.shared.utils.xml.XMLWriter; import org.apache.maven.surefire.extensions.StatelessReportEventListener; -import org.apache.maven.surefire.api.report.ReporterException; import org.apache.maven.surefire.api.report.SafeThrowable; import java.io.BufferedOutputStream; @@ -135,8 +134,10 @@ public void testSetCompleted( WrappedReportEntry testSetReportEntry, TestSetStat Map>> classMethodStatistics = arrangeMethodStatistics( testSetReportEntry, testSetStats ); - OutputStream outputStream = getOutputStream( testSetReportEntry ); - try ( OutputStreamWriter fw = getWriter( outputStream ) ) + // The Java Language Spec: + // "Note that the close methods of resources are called in the opposite order of their creation." + try ( OutputStream outputStream = getOutputStream( testSetReportEntry ); + OutputStreamWriter fw = getWriter( outputStream ) ) { XMLWriter ppw = new PrettyPrintXMLWriter( fw ); ppw.setEncoding( UTF_8.name() ); @@ -155,7 +156,7 @@ public void testSetCompleted( WrappedReportEntry testSetReportEntry, TestSetStat ppw.endElement(); // TestSuite } - catch ( Exception e ) + catch ( IOException e ) { // It's not a test error. // This method must be sail-safe and errors are in a dump log. @@ -201,6 +202,7 @@ private Deque aggregateCacheFromMultipleReruns( WrappedRepor private void serializeTestClass( OutputStream outputStream, OutputStreamWriter fw, XMLWriter ppw, List methodEntries ) + throws IOException { if ( rerunFailingTestsCount > 0 ) { @@ -216,6 +218,7 @@ private void serializeTestClass( OutputStream outputStream, OutputStreamWriter f private void serializeTestClassWithoutRerun( OutputStream outputStream, OutputStreamWriter fw, XMLWriter ppw, List methodEntries ) + throws IOException { for ( WrappedReportEntry methodEntry : methodEntries ) { @@ -232,6 +235,7 @@ private void serializeTestClassWithoutRerun( OutputStream outputStream, OutputSt private void serializeTestClassWithRerun( OutputStream outputStream, OutputStreamWriter fw, XMLWriter ppw, List methodEntries ) + throws IOException { WrappedReportEntry firstMethodEntry = methodEntries.get( 0 ); switch ( getTestResultType( methodEntries ) ) @@ -339,6 +343,7 @@ private Deque getAddMethodRunHistoryMap( String testClassNam } private OutputStream getOutputStream( WrappedReportEntry testSetReportEntry ) + throws IOException { File reportFile = getReportFile( testSetReportEntry ); @@ -346,15 +351,7 @@ private OutputStream getOutputStream( WrappedReportEntry testSetReportEntry ) //noinspection ResultOfMethodCallIgnored reportDir.mkdirs(); - - try - { - return new BufferedOutputStream( new FileOutputStream( reportFile ), 64 * 1024 ); - } - catch ( Exception e ) - { - throw new ReporterException( "When writing report", e ); - } + return new BufferedOutputStream( new FileOutputStream( reportFile ), 64 * 1024 ); } private static OutputStreamWriter getWriter( OutputStream fos ) @@ -370,6 +367,7 @@ private File getReportFile( WrappedReportEntry report ) } private void startTestElement( XMLWriter ppw, WrappedReportEntry report ) + throws IOException { ppw.startElement( "testcase" ); String name = phrasedMethodName ? report.getReportName() : report.getName(); @@ -391,6 +389,7 @@ private void startTestElement( XMLWriter ppw, WrappedReportEntry report ) } private void createTestSuiteElement( XMLWriter ppw, WrappedReportEntry report, TestSetStats testSetStats ) + throws IOException { ppw.startElement( "testsuite" ); @@ -421,6 +420,7 @@ private void createTestSuiteElement( XMLWriter ppw, WrappedReportEntry report, T private static void getTestProblems( OutputStreamWriter outputStreamWriter, XMLWriter ppw, WrappedReportEntry report, boolean trimStackTrace, OutputStream fw, String testErrorType, boolean createOutErrElementsInside ) + throws IOException { ppw.startElement( testErrorType ); @@ -478,6 +478,7 @@ private static void getTestProblems( OutputStreamWriter outputStreamWriter, XMLW // Create system-out and system-err elements private static void createOutErrElements( OutputStreamWriter outputStreamWriter, XMLWriter ppw, WrappedReportEntry report, OutputStream fw ) + throws IOException { EncodingOutputStream eos = new EncodingOutputStream( fw ); addOutputStreamElement( outputStreamWriter, eos, ppw, report.getStdout(), "system-out" ); @@ -488,24 +489,17 @@ private static void addOutputStreamElement( OutputStreamWriter outputStreamWrite EncodingOutputStream eos, XMLWriter xmlWriter, Utf8RecodingDeferredFileOutputStream utf8RecodingDeferredFileOutputStream, String name ) + throws IOException { if ( utf8RecodingDeferredFileOutputStream != null && utf8RecodingDeferredFileOutputStream.getByteCount() > 0 ) { xmlWriter.startElement( name ); - - try - { - xmlWriter.writeText( "" ); // Cheat sax to emit element - outputStreamWriter.flush(); - eos.getUnderlying().write( ByteConstantsHolder.CDATA_START_BYTES ); // emit cdata - utf8RecodingDeferredFileOutputStream.writeTo( eos ); - eos.getUnderlying().write( ByteConstantsHolder.CDATA_END_BYTES ); - eos.flush(); - } - catch ( IOException e ) - { - throw new ReporterException( "When writing xml report stdout/stderr", e ); - } + xmlWriter.writeText( "" ); // Cheat sax to emit element + outputStreamWriter.flush(); + eos.getUnderlying().write( ByteConstantsHolder.CDATA_START_BYTES ); // emit cdata + utf8RecodingDeferredFileOutputStream.writeTo( eos ); + eos.getUnderlying().write( ByteConstantsHolder.CDATA_END_BYTES ); + eos.flush(); xmlWriter.endElement(); } } @@ -517,6 +511,7 @@ private static void addOutputStreamElement( OutputStreamWriter outputStreamWrite * @param xmlWriter The test suite to report to */ private static void showProperties( XMLWriter xmlWriter, Map systemProperties ) + throws IOException { xmlWriter.startElement( "properties" ); for ( final Entry entry : systemProperties.entrySet() ) @@ -559,6 +554,7 @@ private static String extraEscapeAttribute( String message ) */ private static void extraEscapeElementValue( String message, OutputStreamWriter outputStreamWriter, XMLWriter xmlWriter, OutputStream fw ) + throws IOException { // Someday convert to xml 1.1 which handles everything but 0 inside string if ( containsEscapesIllegalXml10( message ) ) @@ -567,20 +563,13 @@ private static void extraEscapeElementValue( String message, OutputStreamWriter } else { - try - { - EncodingOutputStream eos = new EncodingOutputStream( fw ); - xmlWriter.writeText( "" ); // Cheat sax to emit element - outputStreamWriter.flush(); - eos.getUnderlying().write( ByteConstantsHolder.CDATA_START_BYTES ); - eos.write( message.getBytes( UTF_8 ) ); - eos.getUnderlying().write( ByteConstantsHolder.CDATA_END_BYTES ); - eos.flush(); - } - catch ( IOException e ) - { - throw new ReporterException( "When writing xml element", e ); - } + EncodingOutputStream eos = new EncodingOutputStream( fw ); + xmlWriter.writeText( "" ); // Cheat sax to emit element + outputStreamWriter.flush(); + eos.getUnderlying().write( ByteConstantsHolder.CDATA_START_BYTES ); + eos.write( message.getBytes( UTF_8 ) ); + eos.getUnderlying().write( ByteConstantsHolder.CDATA_END_BYTES ); + eos.flush(); } } diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java index b1db277c9e..9c5e77df41 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java @@ -32,7 +32,6 @@ import org.apache.maven.surefire.booter.SurefireBooterForkException; import org.apache.maven.surefire.extensions.ForkNodeFactory; import org.apache.maven.surefire.shared.io.FileUtils; -import org.apache.maven.surefire.shared.lang3.SystemUtils; import org.apache.maven.surefire.shared.utils.StringUtils; import org.apache.maven.surefire.shared.utils.cli.Commandline; import org.junit.After; @@ -56,6 +55,7 @@ import static org.apache.maven.surefire.api.util.internal.StringUtils.NL; import static org.apache.maven.surefire.booter.Classpath.emptyClasspath; import static org.apache.maven.surefire.booter.ProcessCheckerType.ALL; +import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_WINDOWS; import static org.fest.assertions.Assertions.assertThat; import static org.fest.util.Files.temporaryFolder; import static org.junit.Assert.assertEquals; @@ -168,11 +168,7 @@ public void testCliArgs() throws Exception // "/path/to/java arg1 @/path/to/argfile" int beginOfFileArg = cliAsString.indexOf( '@', cliAsString.lastIndexOf( "arg1" ) ); assertThat( beginOfFileArg ).isPositive(); - int endOfFileArg = cliAsString.indexOf( '"', beginOfFileArg ); - if ( endOfFileArg == -1 ) - { - endOfFileArg = cliAsString.length(); - } + int endOfFileArg = cliAsString.indexOf( IS_OS_WINDOWS ? '"' : '\'', beginOfFileArg ); assertThat( endOfFileArg ).isPositive(); Path argFile = Paths.get( cliAsString.substring( beginOfFileArg + 1, endOfFileArg ) ); String argFileText = new String( readAllBytes( argFile ) ); @@ -283,7 +279,7 @@ public void testArglineWithNewline() new StartupConfiguration( "", cpConfig, clc, ALL, Collections.emptyList() ); Commandline commandLine = config.createCommandLine( startup, 1, temporaryFolder() ); - assertTrue( commandLine.toString().contains( "abc def" ) ); + assertThat( commandLine.toString() ).contains( IS_OS_WINDOWS ? "abc def" : "'abc' 'def'" ); } @Test @@ -357,7 +353,7 @@ public void testExceptionWhenCurrentDirectoryCannotBeCreated() FileUtils.deleteDirectory( cwd ); } - if ( SystemUtils.IS_OS_WINDOWS || isJavaVersionAtLeast7u60() ) + if ( IS_OS_WINDOWS || isJavaVersionAtLeast7u60() ) { fail(); } diff --git a/pom.xml b/pom.xml index d6f4b300e1..15d933cb49 100644 --- a/pom.xml +++ b/pom.xml @@ -95,8 +95,8 @@ 1.11.1 1.11.1 1.1.0 - - 3.1.0 + + 3.3.4 2.0.9 3.6.2 0.8.7 @@ -257,9 +257,10 @@ 2.33 + org.fusesource.jansi jansi - 1.13 + 2.2.0 org.apache.maven.shared diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1367AssumptionLogsIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1367AssumptionLogsIT.java index 5d05c125cf..ddcf8c81c2 100644 --- a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1367AssumptionLogsIT.java +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1367AssumptionLogsIT.java @@ -87,7 +87,7 @@ private void verifyReportA( OutputValidator outputValidator ) { String xmlReport = outputValidator.getSurefireReportsXmlFile( "TEST-ATest.xml" ).readFileToString(); - String outputCData = "" + NL + " " + String outputCData = "\n " + ""; assertThat( xmlReport ).contains( outputCData );