Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[*.kt]
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_function_naming_ignore_when_annotated_with = Test, ParameterizedWithGradleVersions
6 changes: 3 additions & 3 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
compilerOptions {
jvmTarget = JvmTarget.JVM_11
jvmTarget = JvmTarget.JVM_17
}
}

Expand All @@ -24,8 +24,8 @@ sourceSets {
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ import org.gradle.api.flow.FlowParameters
import org.gradle.api.flow.FlowScope
import javax.inject.Inject

class FlushJacocoPlugin @Inject constructor(
private val flowScope: FlowScope
) : Plugin<Project> {
override fun apply(target: Project) {
flowScope.always(DumpAction::class.java) { }
class FlushJacocoPlugin
@Inject
constructor(
private val flowScope: FlowScope
) : Plugin<Project> {
override fun apply(target: Project) {
flowScope.always(DumpAction::class.java) { }
}
}
}

class DumpAction : FlowAction<FlowParameters.None> {
override fun execute(parameters: FlowParameters.None) {
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
kotlin = "2.3.21"

nexus = "2.0.0"
ktlint = "0.50.0"
spotless = "6.21.0"
ktlint = "1.8.0"
spotless = "8.4.0"

jacoco = "0.8.14"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,30 @@ class FlushJacocoPluginIntegrationTest {
""".trimIndent()
)

TestProjectExtension.createProject(
projectDir = projectDir,
gradleVersion = GradleVersionArgument.of("8.7"),
cleanup = true,
coverageRecorder = recorder
).build("build", "--configuration-cache", "--stacktrace")
TestProjectExtension
.createProject(
projectDir = projectDir,
gradleVersion = GradleVersionArgument.of("8.7"),
cleanup = true,
coverageRecorder = recorder
).build("build", "--configuration-cache", "--stacktrace")
}

recorder.close()

val classes = hashSetOf<String>()

file.inputStream().buffered().use {
ExecutionDataReader(it).apply {
setExecutionDataVisitor { data ->
if (data.name.startsWith("com/toasttab")) {
classes.add(data.name)
ExecutionDataReader(it)
.apply {
setExecutionDataVisitor { data ->
if (data.name.startsWith("com/toasttab")) {
classes.add(data.name)
}
}
}

setSessionInfoVisitor { }
}.read()
setSessionInfoVisitor { }
}.read()
}

expectThat(classes).contains(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ private class ReflectiveJacocoAgent(
) : JacocoAgent {
private val options by lazy {
// agent.options
agent.javaClass.getDeclaredField("options").apply { isAccessible = true }.get(agent)
agent.javaClass
.getDeclaredField("options")
.apply { isAccessible = true }
.get(agent)
}

override val location: String
Expand All @@ -53,11 +56,12 @@ object JacocoRt {

private val agentLookup by lazy {
runCatching {
val rt = try {
ClassLoader.getSystemClassLoader().loadClass(RT_CLASS)
} catch (e: ClassNotFoundException) {
JacocoRt::class.java.classLoader.loadClass(RT_CLASS)
}
val rt =
try {
ClassLoader.getSystemClassLoader().loadClass(RT_CLASS)
} catch (e: ClassNotFoundException) {
JacocoRt::class.java.classLoader.loadClass(RT_CLASS)
}

ReflectiveJacocoAgent(rt.getMethod("getAgent").invoke(null))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,35 @@ private class ReaderTask(
private val readingSession = AtomicBoolean(false)
private val running = AtomicBoolean(true)

private val reader = object : RemoteControlReader(sock.getInputStream()) {
init {
setSessionInfoVisitor { s ->
readingSession.set(true)
}
private val reader =
object : RemoteControlReader(sock.getInputStream()) {
init {
setSessionInfoVisitor { s ->
readingSession.set(true)
}

setExecutionDataVisitor { ex ->
synchronized(writer) {
writer.visitClassExecution(ex)
setExecutionDataVisitor { ex ->
synchronized(writer) {
writer.visitClassExecution(ex)
}
}
}
}

override fun readBlock(blockid: Byte): Boolean {
if (blockid == 32.toByte()) {
// OK message which follows jacoco tcpclient dumping execution data
finishSession()
override fun readBlock(blockid: Byte): Boolean {
if (blockid == 32.toByte()) {
// OK message which follows jacoco tcpclient dumping execution data
finishSession()
}
return super.readBlock(blockid)
}
return super.readBlock(blockid)
}

override fun read() =
try {
super.read()
} catch (e: Exception) {
false
}
}
override fun read() =
try {
super.read()
} catch (e: Exception) {
false
}
}

init {
start()
Expand Down Expand Up @@ -103,21 +104,23 @@ class CoverageRecorder(

private val tasks = mutableListOf<ReaderTask>()

private val runner = thread {
while (!server.isClosed) {
val sock = try {
server.accept()
} catch (e: Exception) {
break
private val runner =
thread {
while (!server.isClosed) {
val sock =
try {
server.accept()
} catch (e: Exception) {
break
}

tasks.add(ReaderTask(sock, writer))
}

tasks.add(ReaderTask(sock, writer))
}

for (task in tasks) {
task.done()
for (task in tasks) {
task.done()
}
}
}

val port: Int get() = server.localPort

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ annotation class GradleVersion(
)

@Retention(AnnotationRetention.RUNTIME)
annotation class Property(val key: String, val value: String)
annotation class Property(
val key: String,
val value: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ class GradleVersionArgument private constructor(
) {
fun property(key: String): String? = properties[key]

override fun toString() = when {
version == null -> "default"
properties.isEmpty() -> version
else -> "$version${properties.entries.joinToString(prefix = " [", postfix = "]") { "${it.key}=${it.value}" }}"
}
override fun toString() =
when {
version == null -> "default"
properties.isEmpty() -> version
else -> "$version${properties.entries.joinToString(prefix = " [", postfix = "]") { "${it.key}=${it.value}" }}"
}

companion object {
fun of(version: String, properties: Map<String, String> = emptyMap()) =
GradleVersionArgument(version, properties)
fun of(
version: String,
properties: Map<String, String> = emptyMap()
) = GradleVersionArgument(version, properties)

fun of(spec: GradleVersion) =
GradleVersionArgument(spec.version, spec.properties.associate { it.key to it.value })
fun of(spec: GradleVersion) = GradleVersionArgument(spec.version, spec.properties.associate { it.key to it.value })

val DEFAULT = GradleVersionArgument(null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ import java.nio.file.Path
import kotlin.io.path.Path

interface ProjectLocator {
fun projectPath(root: String, context: ExtensionContext): Path
fun projectPath(
root: String,
context: ExtensionContext
): Path
}

class SimpleNameProjectLocator : ProjectLocator {
override fun projectPath(root: String, context: ExtensionContext) =
Path(root, context.requiredTestClass.simpleName, context.requiredTestMethod.name)
override fun projectPath(
root: String,
context: ExtensionContext
) = Path(root, context.requiredTestClass.simpleName, context.requiredTestMethod.name)
}

class FullyQualifiedNameProjectLocator : ProjectLocator {
override fun projectPath(root: String, context: ExtensionContext) =
Path(root, context.requiredTestClass.name.replace('.', '/'), context.requiredTestMethod.name)
override fun projectPath(
root: String,
context: ExtensionContext
) = Path(root, context.requiredTestClass.name.replace('.', '/'), context.requiredTestMethod.name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ import org.junit.jupiter.api.DisplayNameGenerator.Standard
import java.lang.reflect.Method

class TestKitDisplayNameGenerator : Standard() {
override fun generateDisplayNameForMethod(cls: Class<*>, method: Method) =
method.name + method.parameterTypes.filter {
it != TestProject::class.java
}.joinToString(", ", prefix = "(", postfix = ")") {
it.simpleName
}
override fun generateDisplayNameForMethod(
cls: Class<*>,
method: Method
) = method.name +
method.parameterTypes
.filter {
it != TestProject::class.java
}.joinToString(", ", prefix = "(", postfix = ")") {
it.simpleName
}
}
20 changes: 11 additions & 9 deletions junit5/src/main/kotlin/com/toasttab/gradle/testkit/TestProject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ class TestProject(

private fun createRunner(vararg args: String) = createRunner().withArguments(initArgs + args)

private fun createRunner() = GradleRunner.create()
.withProjectDir(dir.toFile())
.forwardStdOutput(output)
.forwardStdError(output).apply {
if (gradleVersion.version != null) {
withGradleVersion(gradleVersion.version)
}
}
.withArguments()
private fun createRunner() =
GradleRunner
.create()
.withProjectDir(dir.toFile())
.forwardStdOutput(output)
.forwardStdError(output)
.apply {
if (gradleVersion.version != null) {
withGradleVersion(gradleVersion.version)
}
}.withArguments()

fun logOutputOnce() {
if (!outputLogged.getAndSet(true)) {
Expand Down
Loading
Loading