-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The version of the jacoco used to pre-instrument classes must match the version of jacoco used at runtime. Instead of having the coverage plugin depend on the jacoco runtime, we inject the jacoco dependency (with the right version) when we publish a plugin under test into the integration repository
- Loading branch information
Showing
6 changed files
with
118 additions
and
30 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
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
40 changes: 40 additions & 0 deletions
40
shared-build-logic/src/main/kotlin/com/toasttab/gradle/testkit/shared/Jacoco.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,40 @@ | ||
/* | ||
* Copyright (c) 2024 Toast Inc. | ||
* | ||
* 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 com.toasttab.gradle.testkit.shared | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.Configuration | ||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier | ||
import org.gradle.testing.jacoco.plugins.JacocoPlugin | ||
|
||
sealed interface CoverageConfiguration { | ||
object None: CoverageConfiguration | ||
|
||
class Jacoco( | ||
val configuration: Configuration | ||
): CoverageConfiguration { | ||
val version by lazy { | ||
configuration.artifacts().map { it.id.componentIdentifier } | ||
.filterIsInstance<ModuleComponentIdentifier>() | ||
.first { it.group == "org.jacoco" && it.module == "org.jacoco.ant" } | ||
.version | ||
} | ||
} | ||
} | ||
|
||
fun Project.coverage() = configurations.findByName(JacocoPlugin.ANT_CONFIGURATION_NAME)?.let { | ||
CoverageConfiguration.Jacoco(it) | ||
} ?: CoverageConfiguration.None |
34 changes: 34 additions & 0 deletions
34
shared-build-logic/src/main/kotlin/com/toasttab/gradle/testkit/shared/Pom.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,34 @@ | ||
/* | ||
* Copyright (c) 2024 Toast Inc. | ||
* | ||
* 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 com.toasttab.gradle.testkit.shared | ||
|
||
import groovy.namespace.QName | ||
import groovy.util.Node | ||
import org.gradle.api.publish.maven.MavenPom | ||
|
||
fun MavenPom.injectDependency(groupId: String, artifactId: String, version: String, classifier: String) { | ||
withXml { | ||
asNode().findOrCreateChild("dependencies").appendNode("dependency").apply { | ||
appendNode("groupId", groupId) | ||
appendNode("artifactId", artifactId) | ||
appendNode("version", version) | ||
appendNode("classifier", classifier) | ||
} | ||
} | ||
} | ||
|
||
private fun Node.findChild(localName: String) = children().filterIsInstance<Node>().firstOrNull { (it.name() as QName).localPart == localName } | ||
private fun Node.findOrCreateChild(localName: String) = findChild(localName) ?: appendNode(localName) |