Use Files.writeString

See gh-33987
This commit is contained in:
Krzysztof Krason 2023-01-26 18:32:58 -08:00 committed by Phillip Webb
parent f4af93fb03
commit 1b5b1cd250
1 changed files with 2 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2022-2022 the original author or authors. * Copyright 2022-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,7 +19,6 @@ package org.springframework.boot.build.architecture;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -68,8 +67,7 @@ public abstract class PackageTangleCheck extends DefaultTask {
File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile(); File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile();
outputFile.getParentFile().mkdirs(); outputFile.getParentFile().mkdirs();
if (result.hasViolation()) { if (result.hasViolation()) {
Files.write(outputFile.toPath(), result.getFailureReport().toString().getBytes(StandardCharsets.UTF_8), Files.writeString(outputFile.toPath(), result.getFailureReport().toString(), StandardOpenOption.CREATE);
StandardOpenOption.CREATE);
FileWriter writer = new FileWriter(outputFile); FileWriter writer = new FileWriter(outputFile);
FileCopyUtils.copy(result.getFailureReport().toString(), writer); FileCopyUtils.copy(result.getFailureReport().toString(), writer);
throw new GradleException("Package tangle check failed. See '" + outputFile + "' for details."); throw new GradleException("Package tangle check failed. See '" + outputFile + "' for details.");