Skip to content

Commit e7693ab

Browse files
committed
Remove remaining File usages
1 parent 7bd76c1 commit e7693ab

File tree

578 files changed

+283
-961
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

578 files changed

+283
-961
lines changed

its/core-it-suite/src/test/java/org/apache/maven/it/HttpServer.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@
1818
*/
1919
package org.apache.maven.it;
2020

21-
import javax.servlet.ServletException;
22-
import javax.servlet.http.HttpServletRequest;
23-
import javax.servlet.http.HttpServletResponse;
24-
25-
import java.io.File;
26-
import java.io.FileInputStream;
2721
import java.io.IOException;
2822
import java.io.InputStream;
2923
import java.io.OutputStream;
3024
import java.net.URL;
25+
import java.nio.file.Files;
26+
import java.nio.file.Path;
3127
import java.util.Collections;
32-
28+
import javax.servlet.ServletException;
29+
import javax.servlet.http.HttpServletRequest;
30+
import javax.servlet.http.HttpServletResponse;
3331
import org.eclipse.jetty.security.ConstraintMapping;
3432
import org.eclipse.jetty.security.ConstraintSecurityHandler;
3533
import org.eclipse.jetty.security.HashLoginService;
@@ -182,11 +180,11 @@ public InputStream stream(String path) throws IOException {
182180
return this;
183181
}
184182

185-
public HttpServerBuilder source(final File source) {
183+
public HttpServerBuilder source(final Path source) {
186184
this.source = new StreamSource() {
187185
@Override
188186
public InputStream stream(String path) throws IOException {
189-
return new FileInputStream(new File(source, path));
187+
return Files.newInputStream(source.resolve(path));
190188
}
191189
};
192190
return this;
@@ -227,7 +225,7 @@ public static void main(String[] args) throws Exception {
227225
.port(0) //
228226
.username("maven") //
229227
.password("secret") //
230-
.source(new File("/tmp/repo")) //
228+
.source(Path.of("/tmp/repo")) //
231229
.build();
232230
server.start();
233231
}

its/core-it-suite/src/test/java/org/apache/maven/it/ItUtils.java

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
*/
1919
package org.apache.maven.it;
2020

21-
import java.io.File;
22-
import java.io.FileInputStream;
2321
import java.io.IOException;
22+
import java.io.InputStream;
2423
import java.nio.file.Files;
2524
import java.nio.file.Path;
2625
import java.nio.file.StandardOpenOption;
26+
import java.nio.file.attribute.FileTime;
2727
import java.security.DigestInputStream;
2828
import java.security.MessageDigest;
29+
import org.codehaus.plexus.util.FileUtils;
2930

3031
import static org.junit.jupiter.api.Assertions.assertEquals;
3132

@@ -35,71 +36,45 @@
3536
class ItUtils {
3637

3738
public static String calcHash(Path file, String algo) throws Exception {
38-
return ItUtils.calcHash(file.toFile(), algo);
39-
}
40-
41-
public static String calcHash(File file, String algo) throws Exception {
4239
MessageDigest digester = MessageDigest.getInstance(algo);
4340

44-
DigestInputStream dis;
45-
try (FileInputStream is = new FileInputStream(file)) {
46-
dis = new DigestInputStream(is, digester);
47-
48-
for (byte[] buffer = new byte[1024 * 4]; dis.read(buffer) >= 0; ) {
41+
try (InputStream is = new DigestInputStream(Files.newInputStream(file), digester)) {
42+
byte[] buffer = new byte[1024 * 4];
43+
while (is.read(buffer) >= 0) {
4944
// just read it
5045
}
5146
}
5247

5348
byte[] digest = digester.digest();
54-
5549
StringBuilder hash = new StringBuilder(digest.length * 2);
56-
5750
for (byte aDigest : digest) {
5851
int b = aDigest & 0xFF;
59-
6052
if (b < 0x10) {
6153
hash.append('0');
6254
}
63-
6455
hash.append(Integer.toHexString(b));
6556
}
6657

6758
return hash.toString();
6859
}
6960

70-
/**
71-
* @deprecated Use {@link Verifier#setUserHomeDirectory(Path)} instead.
72-
*/
73-
@Deprecated
74-
public static void setUserHome(Verifier verifier, File file) {
75-
setUserHome(verifier, file.toPath());
76-
}
77-
78-
/**
79-
* @deprecated Use {@link Verifier#setUserHomeDirectory(Path)} instead.
80-
*/
81-
@Deprecated
82-
public static void setUserHome(Verifier verifier, Path home) {
83-
verifier.setUserHomeDirectory(home);
84-
}
85-
86-
public static void assertCanonicalFileEquals(File expected, File actual) throws IOException {
87-
assertEquals(expected.getCanonicalFile(), actual.getCanonicalFile());
88-
}
89-
9061
public static void assertCanonicalFileEquals(Path expected, Path actual) throws IOException {
9162
assertEquals(expected.toFile().getCanonicalFile(), actual.toFile().getCanonicalFile());
9263
}
9364

94-
public static void assertCanonicalFileEquals(String expected, String actual, String message) throws IOException {
95-
assertEquals(new File(expected).getCanonicalFile(), new File(actual).getCanonicalFile(), message);
65+
public static void createFile(Path path) throws IOException {
66+
Files.newInputStream(path, StandardOpenOption.CREATE).close();
9667
}
9768

98-
public static void assertCanonicalFileEquals(String expected, String actual) throws IOException {
99-
assertEquals(new File(expected).getCanonicalFile(), new File(actual).getCanonicalFile());
69+
public static long lastModified(Path path) throws IOException {
70+
return Files.getLastModifiedTime(path).toMillis();
10071
}
10172

102-
public static void createFile(Path path) throws IOException {
103-
Files.newInputStream(path, StandardOpenOption.CREATE).close();
73+
public static void lastModified(Path path, long millis) throws IOException {
74+
Files.setLastModifiedTime(path, FileTime.fromMillis(millis));
75+
}
76+
77+
public static void deleteDirectory(Path path) throws IOException {
78+
FileUtils.deleteDirectory(path.toFile());
10479
}
10580
}

its/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0008SimplePluginTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.maven.it;
2020

21-
import java.io.File;
2221
import java.nio.file.Path;
2322

2423
import org.junit.jupiter.api.Test;

its/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0009GoalConfigurationTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.maven.it;
2020

21-
import java.io.File;
2221
import java.nio.file.Path;
2322

2423
import org.junit.jupiter.api.Test;

its/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0010DependencyClosureResolutionTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.maven.it;
2020

21-
import java.io.File;
2221
import java.nio.file.Path;
2322
import java.util.List;
2423

its/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0012PomInterpolationTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.maven.it;
2020

21-
import java.io.File;
2221
import java.nio.file.Path;
2322

2423
import org.junit.jupiter.api.Test;

its/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0018DependencyManagementTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.maven.it;
2020

21-
import java.io.File;
2221
import java.nio.file.Path;
2322

2423
import org.junit.jupiter.api.Test;

its/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0019PluginVersionMgmtBySuperPomTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.maven.it;
2020

21-
import java.io.File;
2221
import java.nio.file.Path;
2322

2423
import org.junit.jupiter.api.Test;

its/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0021PomProfileTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.maven.it;
2020

21-
import java.io.File;
2221
import java.nio.file.Path;
2322

2423
import org.junit.jupiter.api.Test;

its/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0023SettingsProfileTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.maven.it;
2020

21-
import java.io.File;
2221
import java.nio.file.Path;
2322

2423
import org.junit.jupiter.api.Test;

0 commit comments

Comments
 (0)