Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle's GFileUtils will be removed in Gradle 9 #308

Merged
merged 4 commits into from
Sep 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import groovy.util.logging.Slf4j
import org.aim42.htmlsanitycheck.collect.PerRunResults
import org.aim42.htmlsanitycheck.collect.SingleCheckResults
import org.aim42.htmlsanitycheck.collect.SinglePageResults
import org.gradle.util.GFileUtils

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

/**
* write the findings report to HTML
Expand Down Expand Up @@ -63,9 +69,22 @@ public class HtmlReporter extends Reporter {
*/
private void copyResourceFromJarToDirectory(String resourceName, File outputDirectory) {
URL resource = getClass().getClassLoader().getResource(resourceName);
// String dir = StringUtils.substringAfterLast(resourceName, ".");
//GFileUtils.copyURLToFile(resource, new File(outputDirectory, dir + "/" + resourceName));
GFileUtils.copyURLToFile(resource, new File(outputDirectory, resourceName));

// https://github.com/aim42/htmlSanityCheck/issues/305
// unfortunately we currently are not able to use try-with-ressources yet.
InputStream stream = null;
try {
stream = resource.openStream()
Files.copy(stream, new File(outputDirectory, resourceName).toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (final IOException e) {
throw new UncheckedIOException(e);
} finally {
try {
stream.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}


Expand Down