Skip to content

Commit

Permalink
Merge pull request #308 from oliva123456/gradle
Browse files Browse the repository at this point in the history
Gradle's GFileUtils will be removed in Gradle 9
  • Loading branch information
gernotstarke committed Sep 30, 2023
2 parents cc299e0 + 6d1579f commit 619caf4
Showing 1 changed file with 23 additions and 4 deletions.
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

0 comments on commit 619caf4

Please sign in to comment.