Skip to content

Commit 114bdf3

Browse files
[SUREFIRE-2264] Limit usage of commons-io from surefire-shared-utils
1 parent 6cfb5b8 commit 114bdf3

File tree

8 files changed

+45
-61
lines changed

8 files changed

+45
-61
lines changed

maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/util/FailsafeSummaryXmlUtils.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323

2424
import java.io.File;
2525
import java.io.FileInputStream;
26-
import java.io.FileOutputStream;
2726
import java.io.IOException;
2827
import java.io.InputStreamReader;
2928
import java.io.Reader;
29+
import java.nio.file.Files;
30+
import java.nio.file.StandardOpenOption;
3031
import java.util.Locale;
3132

3233
import org.apache.maven.surefire.api.suite.RunResult;
33-
import org.apache.maven.surefire.shared.io.IOUtils;
3434
import org.w3c.dom.Node;
3535
import org.xml.sax.InputSource;
3636

@@ -102,16 +102,19 @@ public static void fromRunResultToFile(RunResult fromRunResult, File toFailsafeS
102102
Locale.ROOT,
103103
FAILSAFE_SUMMARY_XML_TEMPLATE,
104104
fromRunResult.getFailsafeCode(),
105-
String.valueOf(fromRunResult.isTimeout()),
105+
fromRunResult.isTimeout(),
106106
fromRunResult.getCompletedCount(),
107107
fromRunResult.getErrors(),
108108
fromRunResult.getFailures(),
109109
fromRunResult.getSkipped(),
110110
msg);
111111

112-
try (FileOutputStream os = new FileOutputStream(toFailsafeSummaryXml)) {
113-
IOUtils.write(xml, os, UTF_8);
114-
}
112+
Files.write(
113+
toFailsafeSummaryXml.toPath(),
114+
xml.getBytes(UTF_8),
115+
StandardOpenOption.CREATE,
116+
StandardOpenOption.TRUNCATE_EXISTING,
117+
StandardOpenOption.WRITE);
115118
}
116119

117120
public static void writeSummary(RunResult mergedSummary, File mergedSummaryFile, boolean inProgress)

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoToolchainsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import java.util.List;
2626
import java.util.Map;
2727

28+
import org.apache.commons.io.FilenameUtils;
2829
import org.apache.maven.execution.MavenSession;
2930
import org.apache.maven.plugin.MojoFailureException;
30-
import org.apache.maven.surefire.shared.io.FilenameUtils;
3131
import org.apache.maven.toolchain.Toolchain;
3232
import org.apache.maven.toolchain.ToolchainManager;
3333
import org.apache.maven.toolchain.java.DefaultJavaToolChain;

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import junit.framework.Assert;
3131
import junit.framework.TestCase;
32+
import org.apache.commons.io.FileUtils;
3233
import org.apache.maven.surefire.api.booter.Shutdown;
3334
import org.apache.maven.surefire.api.cli.CommandLineOption;
3435
import org.apache.maven.surefire.api.report.ReporterConfiguration;
@@ -46,7 +47,6 @@
4647
import org.apache.maven.surefire.booter.ProviderConfiguration;
4748
import org.apache.maven.surefire.booter.StartupConfiguration;
4849
import org.apache.maven.surefire.booter.TypeEncodedValue;
49-
import org.apache.maven.surefire.shared.io.FileUtils;
5050
import org.junit.After;
5151
import org.junit.Before;
5252

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.List;
2929

3030
import junit.framework.TestCase;
31+
import org.apache.commons.io.FileUtils;
3132
import org.apache.maven.surefire.api.booter.Shutdown;
3233
import org.apache.maven.surefire.api.cli.CommandLineOption;
3334
import org.apache.maven.surefire.api.report.ReporterConfiguration;
@@ -45,7 +46,6 @@
4546
import org.apache.maven.surefire.booter.PropertiesWrapper;
4647
import org.apache.maven.surefire.booter.ProviderConfiguration;
4748
import org.apache.maven.surefire.booter.StartupConfiguration;
48-
import org.apache.maven.surefire.shared.io.FileUtils;
4949
import org.junit.After;
5050
import org.junit.Before;
5151

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Map;
3232
import java.util.Properties;
3333

34+
import org.apache.commons.io.FileUtils;
3435
import org.apache.maven.plugin.surefire.JdkAttributes;
3536
import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.Commandline;
3637
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
@@ -43,7 +44,6 @@
4344
import org.apache.maven.surefire.booter.StartupConfiguration;
4445
import org.apache.maven.surefire.booter.SurefireBooterForkException;
4546
import org.apache.maven.surefire.extensions.ForkNodeFactory;
46-
import org.apache.maven.surefire.shared.io.FileUtils;
4747
import org.junit.After;
4848
import org.junit.Before;
4949
import org.junit.Test;

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMapTest.java

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.io.ByteArrayInputStream;
2222
import java.io.File;
23-
import java.io.FileInputStream;
2423
import java.io.IOException;
2524
import java.io.InputStream;
2625
import java.nio.file.Files;
@@ -39,7 +38,6 @@
3938
import static java.nio.charset.StandardCharsets.UTF_8;
4039
import static org.apache.maven.surefire.api.report.RunMode.NORMAL_RUN;
4140
import static org.apache.maven.surefire.api.util.internal.StringUtils.NL;
42-
import static org.apache.maven.surefire.shared.io.IOUtils.readLines;
4341
import static org.assertj.core.api.Assertions.assertThat;
4442
import static org.powermock.reflect.Whitebox.getInternalState;
4543

@@ -82,13 +80,10 @@ public void testSerializeClass() throws Exception {
8280
ReportEntry reportEntry = new SimpleReportEntry(NORMAL_RUN, 0L, "abc", null, null, null, 42);
8381
newResults.add(newResults.createNextGeneration(reportEntry));
8482
newResults.serialize(data);
85-
try (InputStream io = new FileInputStream(data)) {
86-
List<String> lines = readLines(io, UTF_8);
8783

88-
assertThat(lines).hasSize(1);
89-
90-
assertThat(lines).containsSequence("1,42,abc,");
91-
}
84+
List<String> lines = Files.readAllLines(data.toPath(), UTF_8);
85+
assertThat(lines).hasSize(1);
86+
assertThat(lines).containsSequence("1,42,abc,");
9287
}
9388

9489
@SuppressWarnings("checkstyle:magicnumber")
@@ -122,13 +117,9 @@ public void testSerialize() throws Exception {
122117
newResults.add(existingEntries.createNextGeneration(reportEntry3));
123118

124119
newResults.serialize(data);
125-
try (InputStream io = new FileInputStream(data)) {
126-
List<String> lines = readLines(io, UTF_8);
127-
128-
assertThat(lines).hasSize(3);
129-
130-
assertThat(lines).containsSequence("1,17,abc,willFail", "1,42,abc,method1", "1,100,abc,method3");
131-
}
120+
List<String> lines = Files.readAllLines(data.toPath(), UTF_8);
121+
assertThat(lines).hasSize(3);
122+
assertThat(lines).containsSequence("1,17,abc,willFail", "1,42,abc,method1", "1,100,abc,method3");
132123

133124
RunEntryStatisticsMap nextRun = RunEntryStatisticsMap.fromFile(data);
134125
newResults = new RunEntryStatisticsMap();
@@ -142,13 +133,9 @@ public void testSerialize() throws Exception {
142133
newResults.add(nextRun.createNextGeneration(newRunReportEntry3));
143134

144135
newResults.serialize(data);
145-
try (InputStream io = new FileInputStream(data)) {
146-
List<String> lines = readLines(io, UTF_8);
147-
148-
assertThat(lines).hasSize(3);
149-
150-
assertThat(lines).containsSequence("0,27,abc,willFail", "2,52,abc,method1", "2,110,abc,method3");
151-
}
136+
lines = Files.readAllLines(data.toPath(), UTF_8);
137+
assertThat(lines).hasSize(3);
138+
assertThat(lines).containsSequence("0,27,abc,willFail", "2,52,abc,method1", "2,110,abc,method3");
152139
}
153140

154141
@SuppressWarnings("checkstyle:magicnumber")
@@ -160,24 +147,17 @@ public void testMultiLineTestMethodName() throws IOException {
160147
reportEntries.add(reportEntries.createNextGeneration(reportEntry));
161148

162149
reportEntries.serialize(data);
163-
try (InputStream io = new FileInputStream(data)) {
164-
List<String> lines = readLines(io, UTF_8);
165-
166-
assertThat(lines).hasSize(3);
167-
168-
assertThat(lines).containsSequence("1,42,abc,line1", " line2", " line3");
169-
}
150+
List<String> lines = Files.readAllLines(data.toPath(), UTF_8);
151+
assertThat(lines).hasSize(3);
152+
assertThat(lines).containsSequence("1,42,abc,line1", " line2", " line3");
170153

171154
RunEntryStatisticsMap nextRun = RunEntryStatisticsMap.fromFile(data);
172155
assertThat(data.delete()).isTrue();
173156
nextRun.serialize(data);
174-
try (InputStream io = new FileInputStream(data)) {
175-
List<String> lines = readLines(io, UTF_8);
176-
177-
assertThat(lines).hasSize(3);
178157

179-
assertThat(lines).containsSequence("1,42,abc,line1", " line2", " line3");
180-
}
158+
lines = Files.readAllLines(data.toPath(), UTF_8);
159+
assertThat(lines).hasSize(3);
160+
assertThat(lines).containsSequence("1,42,abc,line1", " line2", " line3");
181161
}
182162

183163
@SuppressWarnings("checkstyle:magicnumber")
@@ -190,24 +170,16 @@ public void testCombinedMethodNames() throws IOException {
190170
new SimpleReportEntry(NORMAL_RUN, 0L, "abc", null, "test", null, 10)));
191171

192172
reportEntries.serialize(data);
193-
try (InputStream io = new FileInputStream(data)) {
194-
List<String> lines = readLines(io, UTF_8);
195-
196-
assertThat(lines).hasSize(3);
197-
198-
assertThat(lines).containsSequence("1,10,abc,test", "1,42,abc,line1", " line2");
199-
}
173+
List<String> lines = Files.readAllLines(data.toPath(), UTF_8);
174+
assertThat(lines).hasSize(3);
175+
assertThat(lines).containsSequence("1,10,abc,test", "1,42,abc,line1", " line2");
200176

201177
RunEntryStatisticsMap nextRun = RunEntryStatisticsMap.fromFile(data);
202178
assertThat(data.delete()).isTrue();
203179
nextRun.serialize(data);
204-
try (InputStream io = new FileInputStream(data)) {
205-
List<String> lines = readLines(io, UTF_8);
206-
207-
assertThat(lines).hasSize(3);
208-
209-
assertThat(lines).containsSequence("1,10,abc,test", "1,42,abc,line1", " line2");
210-
}
180+
lines = Files.readAllLines(data.toPath(), UTF_8);
181+
assertThat(lines).hasSize(3);
182+
assertThat(lines).containsSequence("1,10,abc,test", "1,42,abc,line1", " line2");
211183
}
212184

213185
class A {}

surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import static org.apache.maven.surefire.booter.ProcessInfo.INVALID_PROCESS_INFO;
5050
import static org.apache.maven.surefire.booter.ProcessInfo.unixProcessInfo;
5151
import static org.apache.maven.surefire.booter.ProcessInfo.windowsProcessInfo;
52-
import static org.apache.maven.surefire.shared.io.IOUtils.closeQuietly;
5352
import static org.apache.maven.surefire.shared.lang3.StringUtils.isNotBlank;
5453
import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_HP_UX;
5554
import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_LINUX;
@@ -412,6 +411,16 @@ ProcessInfo execute(String... command) {
412411
}
413412
}
414413
}
414+
415+
private void closeQuietly(AutoCloseable autoCloseable) {
416+
if (autoCloseable != null) {
417+
try {
418+
autoCloseable.close();
419+
} catch (Exception e) {
420+
// ignore
421+
}
422+
}
423+
}
415424
}
416425

417426
@Override

surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
import java.util.concurrent.ScheduledThreadPoolExecutor;
3333
import java.util.concurrent.Semaphore;
3434

35+
import org.apache.commons.io.FileUtils;
3536
import org.apache.maven.surefire.api.util.SureFireFileManager;
36-
import org.apache.maven.surefire.shared.io.FileUtils;
3737
import org.junit.Test;
3838

3939
import static java.nio.charset.StandardCharsets.UTF_8;

0 commit comments

Comments
 (0)