Skip to content

Commit

Permalink
add option for additional source sets
Browse files Browse the repository at this point in the history
  • Loading branch information
Nisheeth Barthwal committed Jul 30, 2020
1 parent 5db069e commit 4b3263e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = "com.github.nbaztec"
version = "1.0.2"
version = "1.0.3"

repositories {
mavenCentral()
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/CoverallsJacocoPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<SourceSet>()
}

class CoverallsJacocoPlugin : Plugin<Project> {
Expand Down
13 changes: 7 additions & 6 deletions src/main/kotlin/SourceReportParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
}
}
}
Expand Down

0 comments on commit 4b3263e

Please sign in to comment.