Skip to content

Commit

Permalink
feature: Add Code Coverage Report
Browse files Browse the repository at this point in the history
  • Loading branch information
wba2hi committed Feb 29, 2024
1 parent 4a04367 commit 1a3e8fe
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ class DataBrokerConnectorFactory {
createInsecureManagedChannel(connectionInfo)
}

val jsonWebToken = loadJsonWebToken(context, connectionInfo)
var jsonWebToken: JsonWebToken? = null
if (connectionInfo.isAuthenticationEnabled) {
jsonWebToken = loadJsonWebToken(context, connectionInfo.jwtUriPath)
}

return DataBrokerConnector(managedChannel, jsonWebToken).apply {
timeoutConfig = this@DataBrokerConnectorFactory.timeoutConfig
Expand Down Expand Up @@ -86,10 +89,8 @@ class DataBrokerConnectorFactory {
}

@Throws(IOException::class)
private fun loadJsonWebToken(context: Context, connectionInfo: ConnectionInfo): JsonWebToken? {
val isAuthenticationDisabled = !connectionInfo.isAuthenticationEnabled
val jwtUriPath = connectionInfo.jwtUriPath
if (isAuthenticationDisabled || jwtUriPath.isNullOrEmpty()) {
private fun loadJsonWebToken(context: Context, jwtUriPath: String?): JsonWebToken? {
if (jwtUriPath.isNullOrEmpty()) {
return null
}

Expand Down
80 changes: 80 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*
*/

import com.android.build.api.dsl.LibraryExtension
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import org.eclipse.kuksa.version.VERSION_FILE_DEFAULT_NAME
import org.eclipse.kuksa.version.VERSION_FILE_DEFAULT_PATH_KEY
import java.nio.file.FileVisitResult
Expand All @@ -38,6 +40,7 @@ plugins {
detekt
version
kotlin("jvm")
jacoco
}

subprojects {
Expand Down Expand Up @@ -102,3 +105,80 @@ tasks.register("mergeDashFiles") {
}
}
}

// region jacoco coverage report

subprojects {
apply {
plugin("jacoco")
}

if (plugins.hasPlugin("com.android.library")) {
configure<LibraryExtension> {
@Suppress("UnstableApiUsage")
testOptions {
buildTypes {
named("debug") {
enableUnitTestCoverage = true
enableAndroidTestCoverage = true
}
}
}
}
}

if (plugins.hasPlugin("com.android.application")) {
configure<BaseAppModuleExtension> {
@Suppress("UnstableApiUsage")
testOptions {
buildTypes {
named("debug") {
enableUnitTestCoverage = true
enableAndroidTestCoverage = true
}
}
}
}
}
}

tasks.create("jacocoRootReport", JacocoReport::class.java) {
group = "report"

reports {
html.required.set(true)
xml.required.set(true)
csv.required.set(false)
}

val excludes = listOf(
"**/buildSrc/**",
"**/app/**",
"**/samples/**",
"**/build/**/org/eclipse/kuksa/vss/**", // generated
"**/test*/**/*.*",
)

val sourcesKotlin = subprojects.map { it.layout.projectDirectory.dir("src/main/kotlin") }
val sourcesJava = subprojects.map { it.layout.projectDirectory.dir("src/main/java") }

val classes = fileTree(rootDir) {
include(
"**/build/classes/kotlin/**/*.class", // kotlin-jvm modules
"**/build/tmp/kotlin-classes/debug/**/*.class", // android modules (application, libraries)
)
exclude(excludes)
}.toSet()

val executionPaths = fileTree(rootDir) {
include("**/*.exec", "**/*.ec")
exclude(excludes)
}.toSet()

additionalSourceDirs.setFrom(sourcesKotlin, sourcesJava)
sourceDirectories.setFrom(sourcesKotlin, sourcesJava)
classDirectories.setFrom(classes)
executionData.setFrom(executionPaths)
}

// endregion jacoco
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class DataBrokerConnectionTest : BehaviorSpec({

// this test closes the connection, the connection can't be used afterward anymore
`when`("A DisconnectListener is registered successfully") {
val disconnectListener = mockk<DisconnectListener>()
val disconnectListener = mockk<DisconnectListener>(relaxed = true)
val disconnectListeners = dataBrokerConnection.disconnectListeners
disconnectListeners.register(disconnectListener)

Expand Down
1 change: 1 addition & 0 deletions vss-processor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ plugins {
kotlin("jvm")
publish
alias(libs.plugins.dokka)
jacoco
}

val versionPath = rootProject.ext[VERSION_FILE_DEFAULT_PATH_KEY] as String
Expand Down

0 comments on commit 1a3e8fe

Please sign in to comment.