-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disabled writing of FreeMarker logs to stdout when generating an HTML…
… report Due to an untraceable error of FreeMarker templates, repeated attempts to generate a report are triggered in some cases. In case of unsuccessful attempts, FreeMarker writes to its logger, which is sent to stdout by default. If the error repeats frequently, an exception will be thrown with an error message - so we can ignore FreeMarker's own logging when generating an HTML report. - upgraded IntelliJ Coverage Library to version `1.0.738` - changed IntelliJ stdout logging level to error - refactored code that works with Gradle Worker API - small refactoring IntelliJ integration Fixes #446 PR #469
- Loading branch information
Showing
12 changed files
with
173 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tools/kover/Actions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.kover.gradle.plugin.tools.kover | ||
|
||
import com.intellij.rt.coverage.util.ErrorReporter | ||
import kotlinx.kover.gradle.plugin.commons.ArtifactContent | ||
import kotlinx.kover.gradle.plugin.commons.ReportContext | ||
import kotlinx.kover.gradle.plugin.commons.ReportFilters | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.workers.WorkAction | ||
import org.gradle.workers.WorkParameters | ||
import org.gradle.workers.WorkQueue | ||
|
||
private const val FREE_MARKER_LOGGER_PROPERTY_NAME = "org.freemarker.loggerLibrary" | ||
|
||
internal interface ReportParameters: WorkParameters { | ||
val filters: Property<ReportFilters> | ||
|
||
val files: Property<ArtifactContent> | ||
val tempDir: DirectoryProperty | ||
val projectPath: Property<String> | ||
val charset: Property<String> | ||
} | ||
|
||
internal abstract class AbstractReportAction<T : ReportParameters> : WorkAction<T> { | ||
protected abstract fun generate() | ||
|
||
final override fun execute() { | ||
// print to stdout only critical errors | ||
ErrorReporter.setLogLevel(ErrorReporter.ERROR) | ||
|
||
// disable freemarker logging to stdout for the time of report generation | ||
val oldFreemarkerLogger = System.setProperty(FREE_MARKER_LOGGER_PROPERTY_NAME, "none") | ||
try { | ||
generate() | ||
} finally { | ||
if (oldFreemarkerLogger == null) { | ||
System.clearProperty(FREE_MARKER_LOGGER_PROPERTY_NAME) | ||
} else { | ||
System.setProperty(FREE_MARKER_LOGGER_PROPERTY_NAME, oldFreemarkerLogger) | ||
} | ||
} | ||
} | ||
} | ||
|
||
internal inline fun <reified A : AbstractReportAction<P>, P : ReportParameters> ReportContext.submitAction(noinline parametersConfig: P.() -> Unit) { | ||
val workQueue: WorkQueue = services.workerExecutor.classLoaderIsolation { | ||
classpath.from(this@submitAction.classpath) | ||
} | ||
workQueue.submit(A::class.java) { parametersConfig(this) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tools/kover/IntellijApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package kotlinx.kover.gradle.plugin.tools.kover | ||
|
||
import com.intellij.rt.coverage.report.api.Filters | ||
import com.intellij.rt.coverage.verify.api.Counter | ||
import com.intellij.rt.coverage.verify.api.Target | ||
import com.intellij.rt.coverage.verify.api.ValueType | ||
import kotlinx.kover.gradle.plugin.commons.ReportFilters | ||
import kotlinx.kover.gradle.plugin.commons.VerificationBound | ||
import kotlinx.kover.gradle.plugin.commons.VerificationRule | ||
import kotlinx.kover.gradle.plugin.dsl.AggregationType | ||
import kotlinx.kover.gradle.plugin.dsl.GroupingEntityType | ||
import kotlinx.kover.gradle.plugin.dsl.MetricType | ||
import kotlinx.kover.gradle.plugin.util.ONE_HUNDRED | ||
import kotlinx.kover.gradle.plugin.util.asPatterns | ||
import java.math.BigDecimal | ||
import java.math.RoundingMode | ||
|
||
internal fun ReportFilters.toIntellij() = Filters( | ||
includesClasses.asPatterns(), | ||
excludesClasses.asPatterns(), | ||
excludesAnnotations.asPatterns() | ||
) | ||
|
||
internal fun VerificationRule.targetToIntellij(): Target { | ||
return when (entityType) { | ||
GroupingEntityType.APPLICATION -> Target.ALL | ||
GroupingEntityType.CLASS -> Target.CLASS | ||
GroupingEntityType.PACKAGE -> Target.PACKAGE | ||
} | ||
} | ||
|
||
internal fun VerificationBound.counterToIntellij(): Counter { | ||
return when (metric) { | ||
MetricType.LINE -> Counter.LINE | ||
MetricType.INSTRUCTION -> Counter.INSTRUCTION | ||
MetricType.BRANCH -> Counter.BRANCH | ||
} | ||
} | ||
|
||
internal fun VerificationBound.valueTypeToIntellij(): ValueType { | ||
return when (aggregation) { | ||
AggregationType.COVERED_COUNT -> ValueType.COVERED | ||
AggregationType.MISSED_COUNT -> ValueType.MISSED | ||
AggregationType.COVERED_PERCENTAGE -> ValueType.COVERED_RATE | ||
AggregationType.MISSED_PERCENTAGE -> ValueType.MISSED_RATE | ||
} | ||
} | ||
|
||
internal fun VerificationBound.valueToIntellij(value: BigDecimal?): BigDecimal? { | ||
value ?: return null | ||
return if (aggregation.isPercentage) { | ||
value.divide(ONE_HUNDRED, 6, RoundingMode.HALF_UP) | ||
} else { | ||
value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
...e-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tools/kover/KoverReportAggregator.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.