Skip to content

Commit

Permalink
fix: make SpotBugsTask configuration-cache safe
Browse files Browse the repository at this point in the history
Signed-off-by: Kengo TODA <skypencil@gmail.com>
  • Loading branch information
KengoTODA committed Aug 11, 2023
1 parent 0091772 commit 566912e
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory
import java.io.File
import java.io.IOException
import java.lang.Boolean
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.StandardOpenOption
import java.util.*
Expand Down Expand Up @@ -104,7 +103,7 @@ abstract class SpotBugsRunner {
args.add("-release")
args.add(task.release.get())
val file = task.analyseClassFile.asFile.get()
generateFile(task.classes ?: task.project.layout.files(), task.analyseClassFile.asFile.get())
task.classes?.let { generateFile(it, file) }
args.add("-analyzeFromFile")
args.add(file.absolutePath)
args.addAll(task.extraArgs.getOrElse(emptyList()))
Expand Down Expand Up @@ -143,13 +142,13 @@ abstract class SpotBugsRunner {

private fun generateFile(files: FileCollection, file: File) {
try {
val lines =
Iterable {
files.filter { obj: File -> obj.exists() }
.files.stream().map { obj: File -> obj.absolutePath }
.iterator()
}
Files.write(file.toPath(), lines, StandardCharsets.UTF_8, StandardOpenOption.CREATE)
file.bufferedWriter().use { writer ->
files.filter(File::exists)
.forEach {
writer.write(it.absolutePath)
writer.newLine()
}
}
} catch (e: IOException) {
throw GradleException("Fail to generate the text file to list target .class files", e)
}
Expand Down

0 comments on commit 566912e

Please sign in to comment.