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

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");
* 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.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.stream.Collectors;
@ -68,8 +67,7 @@ public abstract class PackageTangleCheck extends DefaultTask {
File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile();
outputFile.getParentFile().mkdirs();
if (result.hasViolation()) {
Files.write(outputFile.toPath(), result.getFailureReport().toString().getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE);
Files.writeString(outputFile.toPath(), result.getFailureReport().toString(), StandardOpenOption.CREATE);
FileWriter writer = new FileWriter(outputFile);
FileCopyUtils.copy(result.getFailureReport().toString(), writer);
throw new GradleException("Package tangle check failed. See '" + outputFile + "' for details.");