Skip to content

Commit

Permalink
Added Kover artifacts (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanshin committed Apr 12, 2023
1 parent 5bc1760 commit a2911be
Show file tree
Hide file tree
Showing 32 changed files with 1,357 additions and 11 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ allprojects {
mavenCentral()
}

if (name.startsWith("kover")) {
return
}

apply plugin: 'java'
sourceCompatibility = project.release ? 1.5 : 1.6
targetCompatibility = project.release ? 1.5 : 1.6
Expand Down
23 changes: 23 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
}
15 changes: 15 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
136 changes: 136 additions & 0 deletions buildSrc/src/main/kotlin/kover-publishing-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
`maven-publish`
signing
}

interface KoverPublicationExtension {
val description: Property<String>
}

val extension = extensions.create<KoverPublicationExtension>("koverPublication")

extension.description.convention("")

publishing {
repositories {
addSonatypeRepository()
}

val sources = sourceSets.main.map { it.allSource }

publications {
register<MavenPublication>("Kover") {
// add jar with module
from(components["java"])

addEmptyJavadocArtifact()
addSourcesArtifact(sources)
}
}

publications.withType<MavenPublication>().configureEach {
addMetadata()
signPublicationIfKeyPresent()
}
}


fun MavenPublication.addEmptyJavadocArtifact() {
val javadocJar by tasks.creating(org.gradle.jvm.tasks.Jar::class) {
archiveClassifier.set("javadoc")
// contents are deliberately left empty
}
artifact(javadocJar)
}

fun MavenPublication.addSourcesArtifact(sources: Provider<SourceDirectorySet>) {
val sourcesJar by tasks.creating(org.gradle.jvm.tasks.Jar::class) {
archiveClassifier.set("sources")
from(sources)
}
artifact(sourcesJar)
}


fun RepositoryHandler.addSonatypeRepository() {
maven {
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = acquireProperty("libs.sonatype.user")
password = acquireProperty("libs.sonatype.password")
}
}
}

fun MavenPublication.signPublicationIfKeyPresent() {
val keyId = acquireProperty("libs.sign.key.id")
val signingKey = acquireProperty("libs.sign.key.private")
val signingKeyPassphrase = acquireProperty("libs.sign.passphrase")
if (!signingKey.isNullOrBlank()) {
extensions.configure<SigningExtension>("signing") {
useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase)
sign(this@signPublicationIfKeyPresent)
}
}
}

fun MavenPublication.addMetadata() {
pom {
if (!name.isPresent) {
name.set(artifactId)
}
groupId = "org.jetbrains.kotlinx"

description.set(extension.description)

url.set("https://github.com/JetBrains/intellij-coverage")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("JetBrains")
name.set("JetBrains Team")
organization.set("JetBrains")
organizationUrl.set("https://www.jetbrains.com")
}
}
scm {
connection.set("scm:git:git@github.com:JetBrains/intellij-coverage.git")
developerConnection.set("scm:git:git@github.com:JetBrains/intellij-coverage.git")
url.set("https://github.com/JetBrains/intellij-coverage")
}
}
}


fun Project.acquireProperty(name: String): String? {
return project.findProperty(name) as? String ?: System.getenv(name)
}

val Project.sourceSets: SourceSetContainer get() =
(this as ExtensionAware).extensions.getByName("sourceSets") as SourceSetContainer

val SourceSetContainer.main: NamedDomainObjectProvider<SourceSet>
get() = named<SourceSet>("main")

46 changes: 46 additions & 0 deletions kover/kover-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Kover Command Line Interface

This is a single jar artifact that allows to use some of the functionality of Kover Toolset through command-line calls.

Java 1.6 or greater is required for execution.

## Commands

### Off-line instrumentation

`java -jar kover-cli.jar instrument [<class-file-path> ...] --dest <dir> [--exclude <class-name>] [--excludeAnnotation <annotation-name>] [--hits] [--include <class-name>]`

| Option | Description | Required | Multiple |
|---------------------------------------|------------------------------------------------------------------------------------------------|:--------:|:--------:|
| `<class-file-path>` | list of the compiled class-files roots | | + |
| --dest <dir> | path to write instrumented Java classes to | + | |
| --exclude <class-name> | filter to exclude classes from instrumentation, wildcards `*` and `?` are acceptable | | + |
| --excludeAnnotation <annotation-name> | filter to exclude annotated classes from instrumentation, wildcards `*` and `?` are acceptable | | + |
| --hits | a flag to enable line hits counting | | |
| --include <class-name> | instrument only specified classes, wildcards `*` and `?` are acceptable | | + |

### Generating reports
Allows you to generate HTML and XML reports.

`java -jar kover-cli.jar report [<binary-report-path> ...] --classfiles <class-file-path> [--exclude <class-name>] [--excludeAnnotation <annotation-name>] [--html <html-dir>] [--include <class-name>] --src <sources-path> [--title <html-title>] [--xml <xml-file-path>]`

| Option | Description | Required | Multiple |
|---------------------------------------|---------------------------------------------------------------------------------------------------------|:--------:|:--------:|
| `<binary-report-path>` | list of binary reports files | | + |
| --classfiles <class-file-path> | location of the compiled class-files root (must be original and not instrumented) | + | + |
| --exclude <class-name> | filter to exclude classes, wildcards `*` and `?` are acceptable | | + |
| --excludeAnnotation <annotation-name> | filter to include classes and functions marked by this annotation, wildcards `*` and `?` are acceptable | | + |
| --html <html-dir> | generate a HTML report in the specified path | | |
| --include <class-name> | filter to include classes, wildcards `*` and `?` are acceptable | | + |
| --src <sources-path> | location of the source files root | + | + |
| --title <html-title> | title in the HTML report | | |
| --xml <xml-file-path> | generate a XML report in the specified path | | |

## Off-line instrumentation

Off-line instrumentation is suitable when using runtime environments that do not support Java agents.
It instruments the files located in the file system and saves the result to the specified directory.

To run classes instrumented offline, you need to add `kover-offline` artifact (with group `org.jetbrains.kotlinx`) to the classpath of the application; in build systems, you need to add a dependency.

You also need to pass the system property `kover.offline.report.path` to the application with the path to the file with the collected coverage.
52 changes: 52 additions & 0 deletions kover/kover-cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
kotlin("jvm")
id("kover-publishing-conventions")
}

extensions.configure<Kover_publishing_conventions_gradle.KoverPublicationExtension> {
description.set("Command Line Interface for Kotlin Coverage Toolchain")
}

java {
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
}

dependencies {
implementation(project(":reporter"))
implementation("args4j:args4j:2.33")

testImplementation(kotlin("test"))
}

tasks.jar {
manifest {
attributes("Main-Class" to "kotlinx.kover.cli.MainKt")
}

from(
configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }
) {
exclude("OSGI-OPT/**")
exclude("META-INF/**")
exclude("LICENSE")
}

destinationDirectory.set(rootDir.resolve("dist"))
}
52 changes: 52 additions & 0 deletions kover/kover-cli/src/main/kotlin/kotlinx/kover/cli/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package kotlinx.kover.cli

import kotlinx.kover.cli.commands.Command
import kotlinx.kover.cli.commands.CommandParser
import kotlinx.kover.cli.commands.RootCommand
import kotlinx.kover.cli.printers.TerminalPrinter
import org.kohsuke.args4j.CmdLineException
import java.io.PrintWriter
import kotlin.system.exitProcess

internal fun invokeCli(args: Array<String>): Int {
val output = PrintWriter(System.out, true)
val error = PrintWriter(System.err, true)

val rootCommand: Command = RootCommand()
val parser = CommandParser(rootCommand)
try {
parser.parseArgument(*args)
} catch (e: CmdLineException) {
val errorParser = e.parser
if (errorParser is CommandParser) {
TerminalPrinter.printUsage(errorParser.command, error)
error.println()
}
error.println(e.message)

return -1
}

return rootCommand.call(output, error)
}

fun main(args: Array<String>) {
val code = invokeCli(args)
exitProcess(code)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package kotlinx.kover.cli

import kotlinx.kover.cli.commands.RootCommand
import kotlinx.kover.cli.printers.MarkdownPrinter
import java.io.PrintWriter

fun main() {
val output = PrintWriter(System.out, true)
RootCommand.commands.forEach { command ->
MarkdownPrinter.printUsage(command, output)
}
}

0 comments on commit a2911be

Please sign in to comment.