Use Files.writeString() and Files.readString() where possible

See gh-31459
This commit is contained in:
dreis2211
2022-06-20 07:03:59 +02:00
committed by Stephane Nicoll
parent d9d1bdf0f6
commit fb45fc4819
9 changed files with 38 additions and 57 deletions

View File

@@ -20,7 +20,6 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -140,12 +139,12 @@ class MavenBuild {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.toFile().getName().equals("pom.xml")) {
String pomXml = new String(Files.readAllBytes(file), StandardCharsets.UTF_8);
String pomXml = Files.readString(file);
for (Entry<String, String> replacement : MavenBuild.this.pomReplacements.entrySet()) {
pomXml = pomXml.replace("@" + replacement.getKey() + "@", replacement.getValue());
}
Files.write(destination.resolve(source.relativize(file)),
pomXml.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE_NEW);
Files.writeString(destination.resolve(source.relativize(file)), pomXml,
StandardOpenOption.CREATE_NEW);
}
else {
Files.copy(file, destination.resolve(source.relativize(file)),
@@ -155,14 +154,11 @@ class MavenBuild {
}
});
String settingsXml = new String(Files.readAllBytes(Paths.get("src", "intTest", "projects", "settings.xml")),
StandardCharsets.UTF_8)
.replace("@localCentralUrl@",
new File("build/int-test-maven-repository").toURI().toURL().toString())
.replace("@localRepositoryPath@",
new File("build/local-maven-repository").getAbsolutePath());
Files.write(destination.resolve("settings.xml"), settingsXml.getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE_NEW);
String settingsXml = Files.readString(Paths.get("src", "intTest", "projects", "settings.xml"))
.replace("@localCentralUrl@",
new File("build/int-test-maven-repository").toURI().toURL().toString())
.replace("@localRepositoryPath@", new File("build/local-maven-repository").getAbsolutePath());
Files.writeString(destination.resolve("settings.xml"), settingsXml, StandardOpenOption.CREATE_NEW);
request.setBaseDirectory(this.temp);
request.setJavaHome(new File(System.getProperty("java.home")));
request.setProperties(this.properties);