diff --git a/README.md b/README.md index 68c9fe5..e0c4779 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,18 @@ The plugin supports non-root packages in line with the recommended [Kotlin direc which was missing in many other plugins for the Kotlin ecosystem. ## Usage -Apply the plugin with the ID: `com.github.nbaztec.coveralls-jacoco-kotlin` +[Gradle Plugin page](https://plugins.gradle.org/plugin/com.github.nbaztec.coveralls-jacoco-kotlin) + +Apply the plugin with the ID: `com.github.nbaztec.coveralls-jacoco-kotlin` This will add a gradle task `coverallsJacoco` that can be used to publish coverage report via `./gradlew test coverallsJacoco` ## Options ```kotlin coverallsJacoco { - rootPackage = 'com.github.nbaztec.foo' // optional, leave out if project has java directory structure reportPath = 'build/reports/jacoco/test/jacocoTestReport.xml' + rootPackage = 'com.github.nbaztec.foo' // optional, leave out if project has java directory structure + additionalSourceSets = [ sourceSets.foo, sourceSets.bar ] // optional, sourceSet.main is always included + apiEndpoint = "https://coveralls.io/api/v1/jobs" // optional } ``` \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 8f141da..62d0e98 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ group = "com.github.nbaztec" -version = "1.0.2" +version = "1.0.3" repositories { mavenCentral() diff --git a/src/main/kotlin/CoverallsJacocoPlugin.kt b/src/main/kotlin/CoverallsJacocoPlugin.kt index 7a45077..f43c947 100644 --- a/src/main/kotlin/CoverallsJacocoPlugin.kt +++ b/src/main/kotlin/CoverallsJacocoPlugin.kt @@ -2,11 +2,13 @@ package org.gradle.plugin.coveralls.jacoco import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.tasks.SourceSet open class CoverallsJacocoPluginExtension { var rootPackage: String? = null var reportPath = "build/reports/jacoco/test/jacocoTestReport.xml" var apiEndpoint = "https://coveralls.io/api/v1/jobs" + var additionalSourceSets = emptyList() } class CoverallsJacocoPlugin : Plugin { diff --git a/src/main/kotlin/SourceReportParser.kt b/src/main/kotlin/SourceReportParser.kt index d4420fa..99c12b9 100644 --- a/src/main/kotlin/SourceReportParser.kt +++ b/src/main/kotlin/SourceReportParser.kt @@ -62,16 +62,15 @@ class SourceReportParser { val pluginExtension = project.extensions.getByName("coverallsJacoco") as CoverallsJacocoPluginExtension val kotlinExtension = project.extensions.getByName("kotlin") as KotlinProjectExtension - val sourceDirs = kotlinExtension.sourceSets.getByName("main").kotlin.srcDirs.filterNotNull() + val sourceSets = listOf(kotlinExtension.sourceSets.getByName("main").kotlin) + + pluginExtension.additionalSourceSets.map { it.allJava } + val sourceDirs = sourceSets.flatMap { it.srcDirs }.filterNotNull() + logger.debug("using source directories: $sourceDirs") return read(pluginExtension.reportPath, pluginExtension.rootPackage) .mapNotNull { (filename, cov) -> sourceDirs.find { - File(it, filename).let { f -> - f.exists().also { exists -> - if (!exists) logger.debug("${f.absolutePath} does not exist, skipping") - } - } + File(it, filename).exists() }?.let { dir -> val f = File(dir, filename) val lines = f.readLines() @@ -81,6 +80,8 @@ class SourceReportParser { val relPath = File(project.projectDir.absolutePath).toURI().relativize(f.toURI()).toString() SourceReport(relPath, f.md5(), lineHits.toList()) + }.also { + it ?: logger.info("$filename could not be found in any of the source directories, skipping") } } }