Skip to content

Commit

Permalink
Upgraded IntelliJ Agent version to 1.0.647
Browse files Browse the repository at this point in the history
  • Loading branch information
shanshin committed Jan 12, 2022
1 parent 6b3343a commit 14715ce
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class InstrumentationFilteringTests : BaseGradleScriptTest() {
.build()
.run("build") {
xml(defaultXmlReport()) {
assertCounterExcluded(classCounter("org.jetbrains.ExampleClass"), this@run.engine)
assertCounterNotCovered(classCounter("org.jetbrains.ExampleClass"))
assertCounterCovered(classCounter("org.jetbrains.SecondClass"))
}
}
Expand All @@ -46,8 +46,8 @@ internal class InstrumentationFilteringTests : BaseGradleScriptTest() {
.build()
.run("build") {
xml(defaultXmlReport()) {
assertCounterExcluded(classCounter("org.jetbrains.ExampleClass"), this@run.engine)
assertCounterExcluded(classCounter("org.jetbrains.Unused"), this@run.engine)
assertCounterNotCovered(classCounter("org.jetbrains.ExampleClass"))
assertCounterNotCovered(classCounter("org.jetbrains.Unused"))
assertCounterCovered(classCounter("org.jetbrains.SecondClass"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@ internal fun RunResult.checkDefaultBinaryReport(mustExist: Boolean = true) {
assertFalse { exists() }
}
}

if (engine == CoverageEngine.INTELLIJ) {
val smap = defaultSmapFile(projectType)

if (mustExist) {
file(smap) {
assertTrue { exists() }
assertTrue { length() > 0 }
}
} else {
file(smap) {
assertFalse { exists() }
}
}
}
}

internal fun RunResult.checkDefaultReports(mustExist: Boolean = true) {
Expand Down Expand Up @@ -78,13 +63,9 @@ internal fun assertCounterAbsent(counter: Counter?) {
assertNull(counter)
}

internal fun assertCounterExcluded(counter: Counter?, engine: CoverageEngine) {
if (engine == CoverageEngine.INTELLIJ) {
assertNull(counter)
} else {
assertNotNull(counter)
assertEquals(0, counter.covered)
}
internal fun assertCounterNotCovered(counter: Counter?) {
assertNotNull(counter)
assertEquals(0, counter.covered)
}

internal fun assertCounterCovered(counter: Counter?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ internal fun defaultBinaryReport(engine: CoverageEngine, projectType: ProjectTyp
}
}

internal fun defaultSmapFile(projectType: ProjectType): String {
return defaultBinaryReport(CoverageEngine.INTELLIJ, projectType) + ".smap"
}

internal fun defaultXmlReport() = "reports/kover/report.xml"
internal fun defaultHtmlReport() = "reports/kover/html"

Expand Down
9 changes: 0 additions & 9 deletions src/main/kotlin/kotlinx/kover/KoverPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ class KoverPlugin : Plugin<Project> {

providers.projects.forEach { (projectName, m) ->
task.binaryReportFiles.put(projectName, NestedFiles(task.project.objects, m.reports))
task.smapFiles.put(projectName, NestedFiles(task.project.objects, m.smap))
task.srcDirs.put(projectName, NestedFiles(task.project.objects, m.sources))
task.outputDirs.put(projectName, NestedFiles(task.project.objects, m.output))
}
Expand Down Expand Up @@ -226,7 +225,6 @@ class KoverPlugin : Plugin<Project> {

// it is necessary to read all binary reports because project's classes can be invoked in another project
task.binaryReportFiles.set(providers.aggregated.reports)
task.smapFiles.set(providers.aggregated.smap)
task.dependsOn(providers.aggregated.tests)

task.onlyIf { !projectProviders.disabled.get() }
Expand Down Expand Up @@ -258,13 +256,6 @@ class KoverPlugin : Plugin<Project> {
val suffix = if (koverExtension.coverageEngine.get() == CoverageEngine.INTELLIJ) ".ic" else ".exec"
project.layout.buildDirectory.get().file("kover/$name$suffix").asFile
})
taskExtension.smapFile.set(this.project.provider {
val koverExtension = providers.koverExtension.get()
if (koverExtension.coverageEngine.get() == CoverageEngine.INTELLIJ)
File(taskExtension.binaryReportFile.get().canonicalPath + ".smap")
else
null
})

val excludeAndroidPackages =
project.provider { project.androidPluginIsApplied && !providers.koverExtension.get().instrumentAndroidPackage }
Expand Down
27 changes: 0 additions & 27 deletions src/main/kotlin/kotlinx/kover/Providers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ internal fun Project.createProviders(agents: Map<CoverageEngine, CoverageAgent>)
allprojects {
projects[it.name] = ProjectProviders(
it.provider { it.files(it.binaryReports(this)) },
it.provider { it.files(it.smapFiles(this)) },
it.provider { it.testTasks(this) },
it.provider { it.collectDirs(this).first },
it.provider { it.collectDirs(this).second },
Expand All @@ -36,15 +35,13 @@ internal fun Project.createProviders(agents: Map<CoverageEngine, CoverageAgent>)


val allReportsProvider: Provider<FileCollection> = provider { files(allBinaryReports()) }
val allSmapProvider: Provider<FileCollection> = provider { files(allSmapFiles()) }
val allTestsProvider = provider { allTestTasks() }

// all sources and all outputs providers are unused, so NOW it can return empty file collection
val emptyProvider: Provider<FileCollection> = provider { files() }
val aggregatedProviders =
ProjectProviders(
allReportsProvider,
allSmapProvider,
allTestsProvider,
emptyProvider,
emptyProvider,
Expand All @@ -62,10 +59,6 @@ internal fun Project.allBinaryReports(): List<File> {
return allprojects.flatMap { it.binaryReports(this) }
}

internal fun Project.allSmapFiles(): List<File> {
return allprojects.flatMap { it.smapFiles(this) }
}


internal fun Project.testTasks(rootProject: Project): List<Test> {
if (isDisabled(rootProject)) {
Expand All @@ -91,25 +84,6 @@ internal fun Project.binaryReports(root: Project): List<File> {
.toList()
}

internal fun Project.smapFiles(root: Project): List<File> {
if (isDisabled(root)) {
return emptyList()
}

return tasks.withType(Test::class.java).asSequence()
.map { t -> t.extensions.getByType(KoverTaskExtension::class.java) }
.filterNot { e -> e.isDisabled }
.mapNotNull { e -> e.smapFile.orNull }
/*
Binary reports and SMAP files have same ordering for IntelliJ engine:
* SMAP file is null if coverage engine is a JaCoCo by default - in this case property is unused
* SMAP file not creates by JaCoCo - property is unused
* test task have no sources - in this case binary report and SMAP file not exists
*/
.filter { f -> f.exists() }
.toList()
}

private fun Project.collectDirs(root: Project): Pair<FileCollection, FileCollection> {
if (isDisabled(root)) {
return files() to files()
Expand Down Expand Up @@ -146,7 +120,6 @@ internal class AllProviders(

internal class ProjectProviders(
val reports: Provider<FileCollection>,
val smap: Provider<FileCollection>,
val tests: Provider<List<Test>>,
val sources: Provider<FileCollection>,
val output: Provider<FileCollection>,
Expand Down
8 changes: 0 additions & 8 deletions src/main/kotlin/kotlinx/kover/api/KoverTaskExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ open class KoverTaskExtension(objects: ObjectFactory) {
@get:OutputFile
public val binaryReportFile: Property<File> = objects.property(File::class.java)

/**
* Specifies file path of generated source map (SMAP) file generated by IntelliJ coverage agent.
*/
@get:OutputFile
@get:Optional
public val smapFile: Property<File> = objects.property(File::class.java)


/**
* Specifies class inclusion rules coverage engine. Exclusion rules have priority over inclusion ones.
*
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/kotlinx/kover/engines/commons/Reports.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ package kotlinx.kover.engines.commons

import java.io.*

internal class Report(val files: List<ReportFiles>, val projects: List<ProjectInfo>)
internal class ReportFiles(val binary: File, val smap: File? = null)
internal class Report(val files: List<File>, val projects: List<ProjectInfo>)
internal class ProjectInfo(val sources: Iterable<File>, val outputs: Iterable<File>)
10 changes: 1 addition & 9 deletions src/main/kotlin/kotlinx/kover/engines/intellij/IntellijAgent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ internal fun Project.createIntellijAgent(koverExtension: KoverExtension): Covera

private class IntellijAgent(private val config: Configuration): CoverageAgent {
private val trackingPerTest = false // a flag to enable tracking per test coverage
private val calculateForUnloadedClasses = true // a flag to calculate coverage for unloaded classes
private val calculateForUnloadedClasses = false // a flag to calculate coverage for unloaded classes
private val appendToDataFile = false // a flag to use data file as initial coverage
private val samplingMode = false //a flag to run coverage in sampling mode or in tracing mode otherwise
private val generateSmapFile = true

override val engine: CoverageEngine = CoverageEngine.INTELLIJ
override val classpath: FileCollection = config
Expand All @@ -33,7 +32,6 @@ private class IntellijAgent(private val config: Configuration): CoverageAgent {
val jarFile = config.fileCollection { it.name == "intellij-coverage-agent" }.singleFile
return mutableListOf(
"-javaagent:${jarFile.canonicalPath}=${argsFile.canonicalPath}",
"-Didea.coverage.check.inline.signatures=true",
"-Didea.new.sampling.coverage=true",
"-Didea.new.tracing.coverage=true",
"-Didea.coverage.log.level=error",
Expand All @@ -46,18 +44,12 @@ private class IntellijAgent(private val config: Configuration): CoverageAgent {
binary.parentFile.mkdirs()
val binaryPath = binary.canonicalPath

val smap = extension.smapFile.get()
smap.parentFile.mkdirs()
val smapPath = smap.canonicalPath

printWriter().use { pw ->
pw.appendLine(binaryPath)
pw.appendLine(trackingPerTest.toString())
pw.appendLine(calculateForUnloadedClasses.toString())
pw.appendLine(appendToDataFile.toString())
pw.appendLine(samplingMode.toString())
pw.appendLine(generateSmapFile.toString())
pw.appendLine(smapPath)
extension.includes.forEach { i ->
pw.appendLine(i.replaceWildcards())
}
Expand Down
46 changes: 23 additions & 23 deletions src/main/kotlin/kotlinx/kover/engines/intellij/IntellijReports.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package kotlinx.kover.engines.intellij
import kotlinx.kover.api.*
import kotlinx.kover.engines.commons.*
import kotlinx.kover.engines.commons.Report
import kotlinx.kover.engines.commons.ReportFiles
import org.gradle.api.*
import org.gradle.api.file.*
import java.io.*
Expand Down Expand Up @@ -58,28 +57,29 @@ internal fun Project.copyIntellijErrorLog(toFile: File, customDirectory: File? =
JSON format:
```
{
"modules": [
{ "reports": [
{"ic": "path to ic binary file", "smap": "path to source map file"}
] [OPTIONAL, absence means that all classes were not covered],
"output": ["outputRoot1", "outputRoot2"],
"sources": ["sourceRoot1", "sourceRoot2"]
}
],
"xml": "path to xml file" [OPTIONAL],
"html": "path to html directory" [OPTIONAL]
reports: [{ic: "path", smap: "path" [OPTIONAL]}, ...],
modules: [{output: ["path1", "path2"], sources: ["source1", …]}, {…}],
xml: "path" [OPTIONAL],
html: "directory" [OPTIONAL],
include: {
classes: ["regex1", "regex2"] [OPTIONAL]
} [OPTIONAL],
exclude: {
classes: ["regex1", "regex2"] [OPTIONAL]
} [OPTIONAL],
}
```
JSON example:
```
{
"reports": [
{"ic": "/path/to/binary/report/result.ic"}
],
"html": "/path/to/html",
"modules": [
{ "reports": [
{"ic": "/path/to/binary/report/result.ic", "smap": "/path/to/binary/report/result.ic.smap"}
],
{
"output": [
"/build/output"
],
Expand All @@ -99,6 +99,12 @@ private fun Writer.writeReportsJson(
) {
appendLine("{")

appendLine(""" "reports": [ """)
appendLine(report.files.joinToString(",\n ", " ") { f ->
"""{"ic": "${f.safePath()}"}"""
})
appendLine(""" ], """)

xmlFile?.also {
appendLine(""" "xml": "${it.safePath()}",""")
}
Expand All @@ -107,20 +113,14 @@ private fun Writer.writeReportsJson(
}
appendLine(""" "modules": [""")
report.projects.forEachIndexed { index, aProject ->
writeProjectReportJson(report.files, aProject, index == (report.projects.size - 1))
writeProjectReportJson(aProject, index == (report.projects.size - 1))
}
appendLine(""" ]""")
appendLine("}")
}

private fun Writer.writeProjectReportJson(reportFiles: Iterable<ReportFiles>, projectInfo: ProjectInfo, isLast: Boolean) {
appendLine(""" { "reports": [ """)

appendLine(reportFiles.joinToString(",\n ", " ") { f ->
"""{"ic": "${f.binary.safePath()}", "smap": "${f.smap!!.safePath()}"}"""
})

appendLine(""" ], """)
private fun Writer.writeProjectReportJson(projectInfo: ProjectInfo, isLast: Boolean) {
appendLine(""" {""")
appendLine(""" "output": [""")
appendLine(
projectInfo.outputs.joinToString(",\n ", " ") { f -> '"' + f.safePath() + '"' })
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/kotlinx/kover/engines/intellij/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

package kotlinx.kover.engines.intellij

val defaultIntellijVersion = IntellijEngineVersion(1, 0, 640)
val minimalIntellijVersion = IntellijEngineVersion(1, 0, 639)
val minimalIntellijVersion = IntellijEngineVersion(1, 0, 647)
val defaultIntellijVersion = minimalIntellijVersion

data class IntellijEngineVersion(val major: Int, val minor: Int, val build: Int): Comparable<IntellijEngineVersion> {
override fun compareTo(other: IntellijEngineVersion): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ private fun Task.callJacocoAntReportTask(
)
)

val binaries: List<File> = report.files.map(kotlinx.kover.engines.commons.ReportFiles::binary)

val sources: MutableList<File> = mutableListOf()
val outputs: MutableList<File> = mutableListOf()
report.projects.forEach { projectInfo ->
Expand All @@ -40,7 +38,7 @@ private fun Task.callJacocoAntReportTask(

builder.invokeWithBody("jacocoReport") {
invokeWithBody("executiondata") {
project.files(binaries).addToAntBuilder(this, "resources")
project.files(report.files).addToAntBuilder(this, "resources")
}
invokeWithBody("structure", mapOf("name" to project.name)) {
invokeWithBody("sourcefiles") {
Expand Down

0 comments on commit 14715ce

Please sign in to comment.