You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/11/11 12:31:54 UTC
[maven-integration-testing] 01/01: Allow basedir system property to be null for build info.txt
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch empty-basedir
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git
commit 4bcae776426b21a6acabc0caec6697d7e11c903b
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Fri Nov 11 13:28:30 2022 +0100
Allow basedir system property to be null for build info.txt
- basedir can be null when test is executed by IDE, use default value
- use try-with-resources
---
.../org/apache/maven/it/TestSuiteOrdering.java | 42 +++++++++-------------
1 file changed, 16 insertions(+), 26 deletions(-)
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
index 62d1ec8e8..6ce234c38 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
@@ -19,7 +19,10 @@ package org.apache.maven.it;
* under the License.
*/
+import java.io.BufferedWriter;
+import java.io.IOException;
import java.io.PrintStream;
+import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Comparator;
@@ -27,7 +30,6 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.maven.shared.verifier.Verifier;
-import org.codehaus.plexus.util.IOUtil;
import org.junit.jupiter.api.ClassDescriptor;
import org.junit.jupiter.api.ClassOrderer;
import org.junit.jupiter.api.ClassOrdererContext;
@@ -42,46 +44,34 @@ public class TestSuiteOrdering implements ClassOrderer
final Map<Class<?>, Integer> tests = new HashMap<>();
- private static void infoProperty( PrintStream info, String property )
+ private static void infoProperty( Writer info, String property ) throws IOException
{
- info.println( property + ": " + System.getProperty( property ) );
+ info.append( property ).append( ": " ).append( System.getProperty( property ) );
}
static
{
try
{
- PrintStream info = null;
- Verifier verifier = null;
- try
- {
- verifier = new Verifier( "" );
- String mavenVersion = verifier.getMavenVersion();
-
- String executable = verifier.getExecutable();
-
- out.println( "Running integration tests for Maven " + mavenVersion + System.lineSeparator()
- + "\tusing Maven executable: " + executable + System.lineSeparator()
- + "\twith verifier.forkMode: " + System.getProperty( "verifier.forkMode", "not defined == fork" ) );
+ Verifier verifier = new Verifier( "" );
+ String mavenVersion = verifier.getMavenVersion();
+ String executable = verifier.getExecutable();
- System.setProperty( "maven.version", mavenVersion );
+ out.println( "Running integration tests for Maven " + mavenVersion + System.lineSeparator()
+ + "\tusing Maven executable: " + executable + System.lineSeparator()
+ + "\twith verifier.forkMode: " + System.getProperty( "verifier.forkMode",
+ "not defined == fork" ) );
- String basedir = System.getProperty( "basedir" );
- info = new PrintStream( Files.newOutputStream( Paths.get( basedir, "target/info.txt" ) ) );
+ System.setProperty( "maven.version", mavenVersion );
+ String basedir = System.getProperty( "basedir", "." );
+ try ( BufferedWriter info = Files.newBufferedWriter( Paths.get( basedir, "target/info.txt" ) ) )
+ {
infoProperty( info, "maven.version" );
infoProperty( info, "java.version" );
infoProperty( info, "os.name" );
infoProperty( info, "os.version" );
}
- finally
- {
- if ( verifier != null )
- {
- verifier.resetStreams();
- }
- IOUtil.close( info );
- }
}
catch ( Exception e )
{