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 2024/09/17 21:18:31 UTC

(maven-surefire) 01/01: [SUREFIRE-2264] Drop commons-io from surefire-shared-utils

This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch SUREFIRE-2264
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit a242de14731f94d69793fb05b15112f85c12f132
Author: Slawomir Jaranowski <sl...@payu.com>
AuthorDate: Tue Sep 17 23:18:11 2024 +0200

    [SUREFIRE-2264] Drop commons-io from surefire-shared-utils
---
 .../failsafe/util/FailsafeSummaryXmlUtils.java     | 15 +++--
 .../AbstractSurefireMojoToolchainsTest.java        |  2 +-
 ...ooterDeserializerProviderConfigurationTest.java |  2 +-
 ...BooterDeserializerStartupConfigurationTest.java |  2 +-
 .../booterclient/ForkConfigurationTest.java        |  2 +-
 .../runorder/RunEntryStatisticsMapTest.java        | 70 +++++++---------------
 .../apache/maven/surefire/booter/PpidChecker.java  | 11 +++-
 .../maven/surefire/booter/ForkedBooterTest.java    |  2 +-
 surefire-shared-utils/pom.xml                      |  9 ---
 9 files changed, 45 insertions(+), 70 deletions(-)

diff --git a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/util/FailsafeSummaryXmlUtils.java b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/util/FailsafeSummaryXmlUtils.java
index ccd826c20..ed39cc90a 100644
--- a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/util/FailsafeSummaryXmlUtils.java
+++ b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/util/FailsafeSummaryXmlUtils.java
@@ -23,14 +23,14 @@ import javax.xml.xpath.XPathFactory;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.nio.file.Files;
+import java.nio.file.StandardOpenOption;
 import java.util.Locale;
 
 import org.apache.maven.surefire.api.suite.RunResult;
-import org.apache.maven.surefire.shared.io.IOUtils;
 import org.w3c.dom.Node;
 import org.xml.sax.InputSource;
 
@@ -102,16 +102,19 @@ public final class FailsafeSummaryXmlUtils {
                 Locale.ROOT,
                 FAILSAFE_SUMMARY_XML_TEMPLATE,
                 fromRunResult.getFailsafeCode(),
-                String.valueOf(fromRunResult.isTimeout()),
+                fromRunResult.isTimeout(),
                 fromRunResult.getCompletedCount(),
                 fromRunResult.getErrors(),
                 fromRunResult.getFailures(),
                 fromRunResult.getSkipped(),
                 msg);
 
-        try (FileOutputStream os = new FileOutputStream(toFailsafeSummaryXml)) {
-            IOUtils.write(xml, os, UTF_8);
-        }
+        Files.write(
+                toFailsafeSummaryXml.toPath(),
+                xml.getBytes(UTF_8),
+                StandardOpenOption.CREATE,
+                StandardOpenOption.TRUNCATE_EXISTING,
+                StandardOpenOption.WRITE);
     }
 
     public static void writeSummary(RunResult mergedSummary, File mergedSummaryFile, boolean inProgress)
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoToolchainsTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoToolchainsTest.java
index 954bf5872..d4908ae80 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoToolchainsTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoToolchainsTest.java
@@ -25,9 +25,9 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.io.FilenameUtils;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.surefire.shared.io.FilenameUtils;
 import org.apache.maven.toolchain.Toolchain;
 import org.apache.maven.toolchain.ToolchainManager;
 import org.apache.maven.toolchain.java.DefaultJavaToolChain;
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java
index 9f3a37e21..0069e00d5 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java
@@ -29,6 +29,7 @@ import java.util.List;
 
 import junit.framework.Assert;
 import junit.framework.TestCase;
+import org.apache.commons.io.FileUtils;
 import org.apache.maven.surefire.api.booter.Shutdown;
 import org.apache.maven.surefire.api.cli.CommandLineOption;
 import org.apache.maven.surefire.api.report.ReporterConfiguration;
@@ -46,7 +47,6 @@ import org.apache.maven.surefire.booter.PropertiesWrapper;
 import org.apache.maven.surefire.booter.ProviderConfiguration;
 import org.apache.maven.surefire.booter.StartupConfiguration;
 import org.apache.maven.surefire.booter.TypeEncodedValue;
-import org.apache.maven.surefire.shared.io.FileUtils;
 import org.junit.After;
 import org.junit.Before;
 
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
index 68f97be62..78183944f 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
@@ -28,6 +28,7 @@ import java.util.HashMap;
 import java.util.List;
 
 import junit.framework.TestCase;
+import org.apache.commons.io.FileUtils;
 import org.apache.maven.surefire.api.booter.Shutdown;
 import org.apache.maven.surefire.api.cli.CommandLineOption;
 import org.apache.maven.surefire.api.report.ReporterConfiguration;
@@ -45,7 +46,6 @@ import org.apache.maven.surefire.booter.ClasspathConfiguration;
 import org.apache.maven.surefire.booter.PropertiesWrapper;
 import org.apache.maven.surefire.booter.ProviderConfiguration;
 import org.apache.maven.surefire.booter.StartupConfiguration;
-import org.apache.maven.surefire.shared.io.FileUtils;
 import org.junit.After;
 import org.junit.Before;
 
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 2209a808d..c6d7330ca 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
@@ -31,6 +31,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.maven.plugin.surefire.JdkAttributes;
 import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.Commandline;
 import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
@@ -43,7 +44,6 @@ import org.apache.maven.surefire.booter.ModularClasspathConfiguration;
 import org.apache.maven.surefire.booter.StartupConfiguration;
 import org.apache.maven.surefire.booter.SurefireBooterForkException;
 import org.apache.maven.surefire.extensions.ForkNodeFactory;
-import org.apache.maven.surefire.shared.io.FileUtils;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMapTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMapTest.java
index 324d51584..f4f52395b 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMapTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMapTest.java
@@ -20,7 +20,6 @@ package org.apache.maven.plugin.surefire.runorder;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Files;
@@ -39,7 +38,6 @@ import org.apache.maven.surefire.api.util.internal.ClassMethod;
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.apache.maven.surefire.api.report.RunMode.NORMAL_RUN;
 import static org.apache.maven.surefire.api.util.internal.StringUtils.NL;
-import static org.apache.maven.surefire.shared.io.IOUtils.readLines;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.powermock.reflect.Whitebox.getInternalState;
 
@@ -82,13 +80,10 @@ public class RunEntryStatisticsMapTest extends TestCase {
         ReportEntry reportEntry = new SimpleReportEntry(NORMAL_RUN, 0L, "abc", null, null, null, 42);
         newResults.add(newResults.createNextGeneration(reportEntry));
         newResults.serialize(data);
-        try (InputStream io = new FileInputStream(data)) {
-            List<String> lines = readLines(io, UTF_8);
 
-            assertThat(lines).hasSize(1);
-
-            assertThat(lines).containsSequence("1,42,abc,");
-        }
+        List<String> lines = Files.readAllLines(data.toPath(), UTF_8);
+        assertThat(lines).hasSize(1);
+        assertThat(lines).containsSequence("1,42,abc,");
     }
 
     @SuppressWarnings("checkstyle:magicnumber")
@@ -122,13 +117,9 @@ public class RunEntryStatisticsMapTest extends TestCase {
         newResults.add(existingEntries.createNextGeneration(reportEntry3));
 
         newResults.serialize(data);
-        try (InputStream io = new FileInputStream(data)) {
-            List<String> lines = readLines(io, UTF_8);
-
-            assertThat(lines).hasSize(3);
-
-            assertThat(lines).containsSequence("1,17,abc,willFail", "1,42,abc,method1", "1,100,abc,method3");
-        }
+        List<String> lines = Files.readAllLines(data.toPath(), UTF_8);
+        assertThat(lines).hasSize(3);
+        assertThat(lines).containsSequence("1,17,abc,willFail", "1,42,abc,method1", "1,100,abc,method3");
 
         RunEntryStatisticsMap nextRun = RunEntryStatisticsMap.fromFile(data);
         newResults = new RunEntryStatisticsMap();
@@ -142,13 +133,9 @@ public class RunEntryStatisticsMapTest extends TestCase {
         newResults.add(nextRun.createNextGeneration(newRunReportEntry3));
 
         newResults.serialize(data);
-        try (InputStream io = new FileInputStream(data)) {
-            List<String> lines = readLines(io, UTF_8);
-
-            assertThat(lines).hasSize(3);
-
-            assertThat(lines).containsSequence("0,27,abc,willFail", "2,52,abc,method1", "2,110,abc,method3");
-        }
+        lines = Files.readAllLines(data.toPath(), UTF_8);
+        assertThat(lines).hasSize(3);
+        assertThat(lines).containsSequence("0,27,abc,willFail", "2,52,abc,method1", "2,110,abc,method3");
     }
 
     @SuppressWarnings("checkstyle:magicnumber")
@@ -160,24 +147,17 @@ public class RunEntryStatisticsMapTest extends TestCase {
         reportEntries.add(reportEntries.createNextGeneration(reportEntry));
 
         reportEntries.serialize(data);
-        try (InputStream io = new FileInputStream(data)) {
-            List<String> lines = readLines(io, UTF_8);
-
-            assertThat(lines).hasSize(3);
-
-            assertThat(lines).containsSequence("1,42,abc,line1", " line2", "  line3");
-        }
+        List<String> lines = Files.readAllLines(data.toPath(), UTF_8);
+        assertThat(lines).hasSize(3);
+        assertThat(lines).containsSequence("1,42,abc,line1", " line2", "  line3");
 
         RunEntryStatisticsMap nextRun = RunEntryStatisticsMap.fromFile(data);
         assertThat(data.delete()).isTrue();
         nextRun.serialize(data);
-        try (InputStream io = new FileInputStream(data)) {
-            List<String> lines = readLines(io, UTF_8);
-
-            assertThat(lines).hasSize(3);
 
-            assertThat(lines).containsSequence("1,42,abc,line1", " line2", "  line3");
-        }
+        lines = Files.readAllLines(data.toPath(), UTF_8);
+        assertThat(lines).hasSize(3);
+        assertThat(lines).containsSequence("1,42,abc,line1", " line2", "  line3");
     }
 
     @SuppressWarnings("checkstyle:magicnumber")
@@ -190,24 +170,16 @@ public class RunEntryStatisticsMapTest extends TestCase {
                 new SimpleReportEntry(NORMAL_RUN, 0L, "abc", null, "test", null, 10)));
 
         reportEntries.serialize(data);
-        try (InputStream io = new FileInputStream(data)) {
-            List<String> lines = readLines(io, UTF_8);
-
-            assertThat(lines).hasSize(3);
-
-            assertThat(lines).containsSequence("1,10,abc,test", "1,42,abc,line1", " line2");
-        }
+        List<String> lines = Files.readAllLines(data.toPath(), UTF_8);
+        assertThat(lines).hasSize(3);
+        assertThat(lines).containsSequence("1,10,abc,test", "1,42,abc,line1", " line2");
 
         RunEntryStatisticsMap nextRun = RunEntryStatisticsMap.fromFile(data);
         assertThat(data.delete()).isTrue();
         nextRun.serialize(data);
-        try (InputStream io = new FileInputStream(data)) {
-            List<String> lines = readLines(io, UTF_8);
-
-            assertThat(lines).hasSize(3);
-
-            assertThat(lines).containsSequence("1,10,abc,test", "1,42,abc,line1", " line2");
-        }
+        lines = Files.readAllLines(data.toPath(), UTF_8);
+        assertThat(lines).hasSize(3);
+        assertThat(lines).containsSequence("1,10,abc,test", "1,42,abc,line1", " line2");
     }
 
     class A {}
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java
index fcdad391c..2c836ea21 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java
@@ -49,7 +49,6 @@ import static org.apache.maven.surefire.booter.ProcessInfo.ERR_PROCESS_INFO;
 import static org.apache.maven.surefire.booter.ProcessInfo.INVALID_PROCESS_INFO;
 import static org.apache.maven.surefire.booter.ProcessInfo.unixProcessInfo;
 import static org.apache.maven.surefire.booter.ProcessInfo.windowsProcessInfo;
-import static org.apache.maven.surefire.shared.io.IOUtils.closeQuietly;
 import static org.apache.maven.surefire.shared.lang3.StringUtils.isNotBlank;
 import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_HP_UX;
 import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_LINUX;
@@ -412,6 +411,16 @@ final class PpidChecker {
                 }
             }
         }
+
+        private void closeQuietly(AutoCloseable autoCloseable) {
+            if (autoCloseable != null) {
+                try {
+                    autoCloseable.close();
+                } catch (Exception e) {
+                    // ignore
+                }
+            }
+        }
     }
 
     @Override
diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterTest.java
index 2f047faf2..af99fe2cd 100644
--- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterTest.java
+++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterTest.java
@@ -32,8 +32,8 @@ import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.Semaphore;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.maven.surefire.api.util.SureFireFileManager;
-import org.apache.maven.surefire.shared.io.FileUtils;
 import org.junit.Test;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
diff --git a/surefire-shared-utils/pom.xml b/surefire-shared-utils/pom.xml
index 4de4b27e9..58bd03b73 100644
--- a/surefire-shared-utils/pom.xml
+++ b/surefire-shared-utils/pom.xml
@@ -44,11 +44,6 @@
       <artifactId>maven-shared-utils</artifactId>
       <scope>runtime</scope>
     </dependency>
-    <dependency>
-      <groupId>commons-io</groupId>
-      <artifactId>commons-io</artifactId>
-      <scope>runtime</scope>
-    </dependency>
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-lang3</artifactId>
@@ -76,10 +71,6 @@
                   <pattern>org.apache.maven.shared.utils</pattern>
                   <shadedPattern>org.apache.maven.surefire.shared.utils</shadedPattern>
                 </relocation>
-                <relocation>
-                  <pattern>org.apache.commons.io</pattern>
-                  <shadedPattern>org.apache.maven.surefire.shared.io</shadedPattern>
-                </relocation>
                 <relocation>
                   <pattern>org.apache.commons.lang3</pattern>
                   <shadedPattern>org.apache.maven.surefire.shared.lang3</shadedPattern>