Skip to content

Commit b8dfa7b

Browse files
authored
Run configuration (#6)
* Don't display all packages on code coverage view with checked * created run configuration * collect coverage stat from diff coverage core * set min coverage in run configuration * persist diff coverage configuration settings per IDE session
1 parent 7e30da3 commit b8dfa7b

39 files changed

Lines changed: 1194 additions & 519 deletions

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
# diff-coverage-idea-plugin Changelog
44

55
## [Unreleased]
6+
### Added
7+
- Keep diff coverage configuration settings per IDE session
8+
- Added option to set up min coverage in run configuration
9+
### Changed
10+
- Diff Coverage running replaced with run configuration instead of shortcut
11+
- Removed triggering `diffCoverage` Gradle task
12+
### Fixed
13+
- Displaying all packages on code coverage view with checked 'Flatten Packages'
14+
15+
## [0.0.4]
616
### Fixed
717
- Intellij 2021.1 compatibility
818
### Changed

README.md

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
11
# diff-coverage-idea-plugin
22

33
![Build](https://github.com/SurpSG/diff-coverage-idea-plugin/workflows/Build/badge.svg)
4-
[![Version](https://img.shields.io/jetbrains/plugin/v/16403-diff-coverage.svg)](https://plugins.jetbrains.com/plugin/PLUGIN_ID)
5-
[![Downloads](https://img.shields.io/jetbrains/plugin/d/16403-diff-coverage.svg)](https://plugins.jetbrains.com/plugin/PLUGIN_ID)
6-
7-
* Create or open gradle project
8-
* Apply and setup [diff coverage plugin](https://github.com/form-com/diff-coverage-gradle)
9-
* Make some changes to your code and run tests to collect coverage info
10-
* Run diff coverage idea plugin: `ctrl+shift+d`
11-
12-
Diff coverage IDEA plugin does:
13-
* detects a module to which DiffCoverage Gradle plugin is applied
14-
* Runs `diffCoverage` Gradle task
15-
* Displays coverage windows for modified code
16-
* Shows balloon with a link to diff coverage html report
17-
18-
## Template ToDo list
19-
- [x] Create a new [IntelliJ Platform Plugin Template][template] project.
20-
- [x] Verify the [pluginGroup](/gradle.properties), [plugin ID](/src/main/resources/META-INF/plugin.xml) and [sources package](/src/main/kotlin).
21-
- [x] Review the [Legal Agreements](https://plugins.jetbrains.com/docs/marketplace/legal-agreements.html).
22-
- [x] [Publish a plugin manually](https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/publishing_plugin.html) for the first time.
23-
- [x] Set the Plugin ID in the above README badges.
24-
- [x] Set the [Deployment Token](https://plugins.jetbrains.com/docs/marketplace/plugin-upload.html).
25-
- [x] Click the <kbd>Watch</kbd> button on the top of the [IntelliJ Platform Plugin Template][template] to be notified about releases containing new features and fixes.
26-
27-
<!-- Plugin description -->
28-
29-
<!-- Plugin description end -->
4+
[![Version](https://img.shields.io/jetbrains/plugin/v/16403-diff-coverage.svg)](https://plugins.jetbrains.com/plugin/16403-diff-coverage)
5+
[![Downloads](https://img.shields.io/jetbrains/plugin/d/16403-diff-coverage.svg)](https://plugins.jetbrains.com/plugin/16403-diff-coverage)
306

317
## Installation
328

339
- Using IDE built-in plugin system:
34-
10+
3511
<kbd>Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>Marketplace</kbd> > <kbd>Search for "diff-coverage-idea-plugin"</kbd> >
3612
<kbd>Install Plugin</kbd>
37-
13+
3814
- Manually:
3915

4016
Download the [latest release](https://github.com/SurpSG/diff-coverage-idea-plugin/releases/latest) and install it manually using
4117
<kbd>Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>⚙️</kbd> > <kbd>Install plugin from disk...</kbd>
18+
19+
## How to use
20+
* Create or open gradle project
21+
* Apply and setup [DiffCoverage Gradle plugin](https://github.com/form-com/diff-coverage-gradle)
22+
* Make some changes to your code and run tests to collect coverage info
23+
* Set up Diff Coverage run configuration
4224

25+
![Diff Coverage run configuration](imgs/diff-run-config.png)
26+
27+
<!-- Plugin description -->
28+
29+
<!-- Plugin description end -->
30+
31+
## How it works
32+
Diff coverage IDEA plugin:
33+
* detects a module to which [DiffCoverage Gradle plugin](https://github.com/form-com/diff-coverage-gradle) is applied and collects settings
34+
* Analyzes coverage of uncommited code
35+
* Displays coverage panel for uncommited code and shows a balloon with coverage stats
36+
* Displays coverage for uncommited code in the project view and in code editor
37+
38+
![Diff Coverage report view](imgs/coverage-view.png)
39+
![Diff Coverage project view](imgs/project-view.png)

build.gradle.kts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ repositories {
77
maven(url = "https://jitpack.io")
88
}
99

10+
fun properties(key: String) = project.findProperty(key).toString()
11+
1012
plugins {
1113
// Java support
1214
id("java")
1315
// Kotlin support
14-
id("org.jetbrains.kotlin.jvm") version "1.4.0"
16+
kotlin("jvm") version "1.5.0"
1517
// gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
16-
id("org.jetbrains.intellij") version "0.4.21"
18+
id("org.jetbrains.intellij") version "0.7.3"
1719
// gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
18-
id("org.jetbrains.changelog") version "0.4.0"
20+
id("org.jetbrains.changelog") version "1.1.2"
1921
// detekt linter - read more: https://detekt.github.io/detekt/kotlindsl.html
2022
id("io.gitlab.arturbosch.detekt") version "1.10.0"
2123
}
@@ -40,22 +42,22 @@ repositories {
4042
jcenter()
4143
}
4244
dependencies {
43-
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.0")
44-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.9")
45+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0")
46+
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.12.3")
47+
implementation("org.jetbrains.kotlin:kotlin-reflect:1.5.0")
4548

4649
implementation("org.jacoco:org.jacoco.core:0.8.5")
4750
implementation("com.github.form-com.diff-coverage-gradle:jacoco-filtering-extension:0.7.1")
48-
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.12.+")
4951
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.10.0")
5052
}
5153

5254
// Configure gradle-intellij-plugin plugin.
5355
// Read more: https://github.com/JetBrains/gradle-intellij-plugin
5456
intellij {
55-
pluginName = pluginName
56-
version = platformVersion
57-
type = platformType
58-
downloadSources = platformDownloadSources.toBoolean()
57+
pluginName = properties("pluginName")
58+
version = properties("platformVersion")
59+
type = properties("platformType")
60+
downloadSources = properties("platformDownloadSources").toBoolean()
5961
updateSinceUntilBuild = true
6062

6163
// Plugin Dependencies:

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
pluginGroup = com.github.surpsg.diffcoverage
55
pluginName = Diff Coverage
6-
pluginVersion = 0.0.4
6+
pluginVersion = 1.0.0
77
pluginSinceBuild = 203
88
pluginUntilBuild = 211.*
99
pluginVerifierIdeVersions = 2020.3.2, 2020.3.3, 2021.1

imgs/coverage-view.png

12.3 KB
Loading

imgs/diff-run-config.png

12.7 KB
Loading

imgs/project-view.png

51 KB
Loading

src/main/kotlin/com/github/surpsg/diffcoverage/actions/RunDiffCoverageAction.kt

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.github.surpsg.diffcoverage.domain
2+
3+
import org.jacoco.core.analysis.ICounter
4+
import org.jacoco.core.analysis.ICoverageNode
5+
import org.jacoco.core.internal.analysis.CounterImpl
6+
7+
class CoverageStat(
8+
counters: Map<ICoverageNode.CounterEntity, ICounter>
9+
) {
10+
private val counters: MutableMap<ICoverageNode.CounterEntity, ICounter> = HashMap(counters)
11+
12+
val linesCoverage: Double
13+
get() = getCoverage(ICoverageNode.CounterEntity.LINE).coveredRatio.toPercents()
14+
val branchesCoverage: Double
15+
get() = getCoverage(ICoverageNode.CounterEntity.BRANCH).coveredRatio.toPercents()
16+
val instructionsCoverage: Double
17+
get() = getCoverage(ICoverageNode.CounterEntity.INSTRUCTION).coveredRatio.toPercents()
18+
19+
fun getCoverage(coverageType: ICoverageNode.CounterEntity): ICounter {
20+
return counters[coverageType] ?: createEmptyCounter()
21+
}
22+
23+
fun merge(coverageStat: CoverageStat) {
24+
coverageStat.counters.forEach { (type, counter) ->
25+
mergeCounter(type, counter)
26+
}
27+
}
28+
29+
private fun mergeCounter(
30+
type: ICoverageNode.CounterEntity,
31+
counter: ICounter
32+
) {
33+
val currentCounter = counters.computeIfAbsent(type) {
34+
createEmptyCounter()
35+
}
36+
counters[type] = CounterImpl.getInstance(
37+
currentCounter.missedCount + counter.missedCount,
38+
currentCounter.coveredCount + counter.coveredCount
39+
)
40+
}
41+
42+
private fun createEmptyCounter() = CounterImpl.getInstance(0, 0)
43+
44+
private fun Double.toPercents(): Double = this * PERCENT_MULTIPLIER
45+
46+
private companion object {
47+
const val PERCENT_MULTIPLIER = 100
48+
}
49+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.github.surpsg.diffcoverage.domain
2+
3+
import com.intellij.coverage.CoverageSuite
4+
import com.intellij.coverage.CoverageSuitesBundle
5+
6+
class CoverageSuiteBundleWithStat(suite: CoverageSuite) : CoverageSuitesBundle(suite) {
7+
8+
override fun getCoverageData(): ProjectDataWithStat {
9+
return suites.asSequence()
10+
.map { it.getCoverageData(null) }
11+
.map { it as? ProjectDataWithStat }
12+
.filterNotNull()
13+
.first()
14+
.apply {
15+
super.getCoverageData()?.let {
16+
merge(it)
17+
}
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)