Skip to content

Commit

Permalink
fix: temp files should be cleaned up after the build
Browse files Browse the repository at this point in the history
close #249
  • Loading branch information
KengoTODA committed Sep 16, 2021
1 parent 774708b commit 9a1fd02
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Set;
import java.util.stream.Collectors;
import org.gradle.api.GradleException;
import org.gradle.api.Task;
import org.gradle.api.file.FileCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -114,7 +115,7 @@ protected List<String> buildArguments(SpotBugsTask task) {
args.add("-release");
args.add(task.getRelease().get());
args.add("-analyzeFromFile");
args.add(generateFile(task.getClasses()).getAbsolutePath());
args.add(generateFile(task.getClasses(), task).getAbsolutePath());

args.addAll(task.getExtraArgs().getOrElse(Collections.emptyList()));
log.debug("Arguments for SpotBugs are generated: {}", args);
Expand Down Expand Up @@ -152,9 +153,9 @@ private String createFileForAuxClasspath(SpotBugsTask task) {
}
}

private File generateFile(FileCollection files) {
private File generateFile(FileCollection files, Task task) {
try {
File file = File.createTempFile("spotbugs-gradle-plugin", ".txt");
File file = File.createTempFile("spotbugs-gradle-plugin", ".txt", task.getTemporaryDir());
Iterable<String> lines =
files.filter(File::exists).getFiles().stream().map(File::getAbsolutePath)::iterator;
Files.write(file.toPath(), lines, StandardCharsets.UTF_8, StandardOpenOption.WRITE);
Expand Down

0 comments on commit 9a1fd02

Please sign in to comment.