Skip to content

Commit b89278e

Browse files
committed
Migrate Verifier and AbstractMavenIntegrationTestCase to NIO2
This commit migrates the Maven integration test infrastructure from java.io.File to NIO2 Path API while maintaining full backward compatibility. Changes in Verifier class: - Added Path-based overloads for loadProperties(), loadFile(), filterFile() - Migrated file operations to use Files.* methods instead of FileUtils - Replaced FileUtils.deleteDirectory() with custom NIO2 implementation - Updated file verification methods to use Path and DirectoryStream - Removed dependency on org.codehaus.plexus.util.FileUtils Changes in AbstractMavenIntegrationTestCase class: - Added extractResourcesAsPath() method returning Path instead of File - Updated settings file handling to use Path operations Benefits: - Better performance with NIO2 operations - Improved error handling and cross-platform compatibility - Modern API usage while maintaining backward compatibility - Comprehensive test coverage for new functionality All existing integration tests continue to work without modification. New @SInCE 4.0.0 methods provide Path-based alternatives for modern usage.
1 parent 58bbee6 commit b89278e

File tree

4 files changed

+378
-77
lines changed

4 files changed

+378
-77
lines changed

its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.io.IOException;
2424
import java.io.InputStream;
2525
import java.io.PrintStream;
26+
import java.nio.file.Path;
27+
import java.nio.file.Paths;
2628
import java.util.Arrays;
2729
import org.junit.jupiter.api.BeforeAll;
2830
import org.junit.jupiter.api.BeforeEach;
@@ -72,10 +74,21 @@ public void close() throws IOException {}
7274

7375

7476
protected File extractResources(String resourcePath) throws IOException {
75-
return new File(
76-
new File(System.getProperty("maven.test.tmpdir", System.getProperty("java.io.tmpdir"))),
77-
resourcePath)
78-
.getAbsoluteFile();
77+
return extractResourcesAsPath(resourcePath).toFile();
78+
}
79+
80+
/**
81+
* Extracts test resources to a temporary directory.
82+
*
83+
* @param resourcePath The path to the resource directory, must not be <code>null</code>.
84+
* @return The path to the extracted resources, never <code>null</code>.
85+
* @throws IOException If the resources could not be extracted.
86+
* @since 4.0.0
87+
*/
88+
protected Path extractResourcesAsPath(String resourcePath) throws IOException {
89+
return Paths.get(System.getProperty("maven.test.tmpdir", System.getProperty("java.io.tmpdir")))
90+
.resolve(resourcePath)
91+
.toAbsolutePath();
7992
}
8093

8194
protected Verifier newVerifier(String basedir) throws VerificationException {
@@ -107,27 +120,27 @@ protected Verifier newVerifier(String basedir, String settings, boolean createDo
107120
verifier.setAutoclean(false);
108121

109122
if (settings != null) {
110-
File settingsFile;
123+
Path settingsPath;
111124
if (!settings.isEmpty()) {
112-
settingsFile = new File("settings-" + settings + ".xml");
125+
settingsPath = Paths.get("settings-" + settings + ".xml");
113126
} else {
114-
settingsFile = new File("settings.xml");
127+
settingsPath = Paths.get("settings.xml");
115128
}
116129

117-
if (!settingsFile.isAbsolute()) {
130+
if (!settingsPath.isAbsolute()) {
118131
String settingsDir = System.getProperty("maven.it.global-settings.dir", "");
119132
if (!settingsDir.isEmpty()) {
120-
settingsFile = new File(settingsDir, settingsFile.getPath());
133+
settingsPath = Paths.get(settingsDir).resolve(settingsPath);
121134
} else {
122135
//
123136
// Make is easier to run ITs from m2e in Maven IT mode without having to set any additional
124137
// properties.
125138
//
126-
settingsFile = new File("target/test-classes", settingsFile.getPath());
139+
settingsPath = Paths.get("target/test-classes").resolve(settingsPath);
127140
}
128141
}
129142

130-
String path = settingsFile.getAbsolutePath();
143+
String path = settingsPath.toAbsolutePath().toString();
131144
verifier.addCliArgument("--install-settings");
132145
if (path.indexOf(' ') < 0) {
133146
verifier.addCliArgument(path);

0 commit comments

Comments
 (0)