Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -31,7 +31,7 @@ tasks.named<Test>("test") {
jvmArgs("-Xss1g", "-XX:+UseParallelGC")
}

task("copyDependencies", Copy::class) {
tasks.register<Copy>("copyDependencies") {
from(configurations.runtimeClasspath).into("${project.layout.buildDirectory.get()}/dependencies")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import kotlinx.fuzz.log.warn
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.FileCollection
import org.gradle.api.logging.Logging
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
Expand All @@ -28,7 +31,7 @@

@Suppress("unused")
abstract class KFuzzPlugin : Plugin<Project> {
val log = Logging.getLogger(KFuzzPlugin::class.java)!!
private val log = Logging.getLogger(KFuzzPlugin::class.java)!!

override fun apply(project: Project) {
val pluginVersion = "0.2.2"
Expand Down Expand Up @@ -71,6 +74,10 @@
testClassesDirs = defaultTCD
outputs.upToDateWhen { false } // so the task will run on every invocation

fuzzConfig = this@registerFuzzTask.fuzzConfig
mainSourceSet = this@registerFuzzTask.extensions.getByType<SourceSetContainer>()["main"]
runtimeClasspathConfiguration = this@registerFuzzTask.configurations["runtimeClasspath"]

doFirst {
systemProperties(fuzzConfig.toPropertiesMap())
systemProperties[INTELLIJ_DEBUGGER_DISPATCH_PORT_VAR_NAME] = System.getProperty(INTELLIJ_DEBUGGER_DISPATCH_PORT_VAR_NAME)
Expand Down Expand Up @@ -157,6 +164,13 @@
@get:Input
var reportWithAllClasspath: Boolean = false

@get:Internal
lateinit var fuzzConfig: KFuzzConfig
@get:Internal
lateinit var mainSourceSet: SourceSet
@get:Internal
var runtimeClasspathConfiguration: Configuration? = null

init {
description = "Runs fuzzing"
group = "verification"
Expand All @@ -165,8 +179,8 @@
@TaskAction
fun action() {
overallStats()
if (project.fuzzConfig.target.dumpCoverage) {
val workDir = project.fuzzConfig.global.workDir
if (fuzzConfig.target.dumpCoverage) {
val workDir = fuzzConfig.global.workDir

val coverageMerged = workDir.resolve("merged-coverage.exec")
jacocoMerge(workDir.resolve("coverage"), coverageMerged)
Expand All @@ -176,14 +190,13 @@
}

private fun overallStats() {
val workDir = project.fuzzConfig.global.workDir
val workDir = fuzzConfig.global.workDir
overallStats(workDir.resolve("stats"), workDir.resolve("overall-stats.csv"))
}

private fun jacocoReport(execFile: Path, workDir: Path) {
val extraDeps = getDependencies(project.fuzzConfig.coverage.includeDependencies)
val mainSourceSet = project.extensions.getByType<SourceSetContainer>()["main"]
val runtimeClasspath = project.configurations["runtimeClasspath"].files
val extraDeps = getDependencies(fuzzConfig.coverage.includeDependencies)
val runtimeClasspath = runtimeClasspathConfiguration?.files ?: emptySet()

val projectClasspath = mainSourceSet.output.files
val sourceDirectories = mainSourceSet.allSource.sourceDirectories.files
Expand All @@ -196,12 +209,12 @@
classPath = jacocoClassPath,
sourceDirectories = sourceDirectories,
reportDir = workDir.resolve("jacoco-report").createDirectories(),
reports = project.fuzzConfig.coverage.reportTypes,
reports = fuzzConfig.coverage.reportTypes,
)
}

private fun getDependencies(dependencies: Set<String>): Set<File> {
val configuration = project.configurations.findByName("runtimeClasspath") ?: run {
val configuration = runtimeClasspathConfiguration ?: run {
log.warn { "No 'runtimeClasspath' configuration found, skipping jacoco report generation" }
return emptySet()
}
Expand Down
Loading