diff --git a/README.md b/README.md index 1a5942e..58c87e8 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Apply the plugin in the main `build.gradle(.kts)` configuration file: Using the plugins DSL: ``` groovy plugins { - id("io.github.cdsap.kotlinprocess") version "0.1.5" + id("io.github.cdsap.kotlinprocess") version "0.1.6" } ``` @@ -20,7 +20,7 @@ buildscript { gradlePluginPortal() } dependencies { - classpath("io.github.cdsap:infokotlinprocess:0.1.5") + classpath("io.github.cdsap:infokotlinprocess:0.1.6") } } @@ -31,7 +31,7 @@ apply(plugin = "io.github.cdsap.kotlinprocess") Using the plugins DSL: ``` groovy plugins { - id "io.github.cdsap.kotlinprocess" version "0.1.5" + id "io.github.cdsap.kotlinprocess" version "0.1.6" } ``` @@ -43,7 +43,7 @@ buildscript { gradlePluginPortal() } dependencies { - classpath "io.github.cdsap:infokotlinprocess:0.1.5" + classpath "io.github.cdsap:infokotlinprocess:0.1.6" } } @@ -73,9 +73,11 @@ BUILD SUCCESSFUL in 35s ``` + ## Requirements * Gradle 7.5 ## Libraries -* com.gradle.enterprise:com.gradle.enterprise.gradle.plugin -* com.jakewharton.picnic:picnic +* `com.gradle:develocity-gradle-plugin` +* `com.gradle.enterprise:com.gradle.enterprise.gradle.plugin` +* `com.jakewharton.picnic:picnic` diff --git a/build.gradle.kts b/build.gradle.kts index 1953f62..484eead 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "io.github.cdsap" -version = "0.1.5" +version = "0.1.6" java { toolchain { @@ -18,6 +18,7 @@ dependencies { implementation("io.github.cdsap:jdk-tools-parser:0.1.1") implementation("io.github.cdsap:commandline-value-source:0.1.0") implementation("com.jakewharton.picnic:picnic:0.6.0") + implementation("com.gradle:develocity-gradle-plugin:3.17.2") implementation("com.gradle.enterprise:com.gradle.enterprise.gradle.plugin:3.12.3") testImplementation("junit:junit:4.13.2") } diff --git a/src/main/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPlugin.kt b/src/main/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPlugin.kt index e6e9282..ef7ec03 100644 --- a/src/main/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPlugin.kt +++ b/src/main/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPlugin.kt @@ -1,22 +1,31 @@ package io.github.cdsap.kotlinprocess +import com.gradle.develocity.agent.gradle.DevelocityConfiguration import com.gradle.scan.plugin.BuildScanExtension import io.github.cdsap.jdk.tools.parser.ConsolidateProcesses +import io.github.cdsap.jdk.tools.parser.model.Process import io.github.cdsap.jdk.tools.parser.model.TypeProcess -import io.github.cdsap.kotlinprocess.output.BuildScanOutput +import io.github.cdsap.kotlinprocess.output.DevelocityValues +import io.github.cdsap.kotlinprocess.output.EnterpriseValues import io.github.cdsap.valuesourceprocess.jInfo import io.github.cdsap.valuesourceprocess.jStat import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.provider.Provider class InfoKotlinProcessPlugin : Plugin { private val nameProcess = "KotlinCompileDaemon" override fun apply(target: Project) { target.gradle.rootProject { - val buildScanExtension = extensions.findByType(com.gradle.scan.plugin.BuildScanExtension::class.java) - if (buildScanExtension != null) { - buildScanReporting(project, buildScanExtension) + + val develocityConfiguration = extensions.findByType(DevelocityConfiguration::class.java) + val enterpriseExtension = extensions.findByType(com.gradle.scan.plugin.BuildScanExtension::class.java) + + if (develocityConfiguration != null) { + buildScanDevelocityReporting(project, develocityConfiguration) + } else if (enterpriseExtension != null) { + buildScanEnterpriseReporting(project, enterpriseExtension) } else { consoleReporting(target) } @@ -32,16 +41,41 @@ class InfoKotlinProcessPlugin : Plugin { }.get() } - private fun buildScanReporting( + private fun buildScanEnterpriseReporting( project: Project, buildScanExtension: BuildScanExtension ) { - val jStat = project.jStat(nameProcess) - val jInfo = project.jInfo(nameProcess) + val (jStat, jInfo) = providerPair(project) buildScanExtension.buildFinished { - val processes = ConsolidateProcesses().consolidate(jStat.get(), jInfo.get(), TypeProcess.Kotlin) - BuildScanOutput(buildScanExtension, processes).addProcessesInfoToBuildScan() + val processes = processes(jStat, jInfo) + EnterpriseValues(buildScanExtension, processes).addProcessesInfoToBuildScan() + } + } + + private fun buildScanDevelocityReporting( + project: Project, + buildScanExtension: DevelocityConfiguration + ) { + val (jStat, jInfo) = providerPair(project) + + buildScanExtension.buildScan.buildFinished { + val processes = processes(jStat, jInfo) + DevelocityValues(buildScanExtension, processes).addProcessesInfoToBuildScan() } } + + private fun processes( + jStat: Provider, + jInfo: Provider + ): List { + val processes = ConsolidateProcesses().consolidate(jStat.get(), jInfo.get(), TypeProcess.Kotlin) + return processes + } + + private fun providerPair(project: Project): Pair, Provider> { + val jStat = project.jStat(nameProcess) + val jInfo = project.jInfo(nameProcess) + return Pair(jStat, jInfo) + } } diff --git a/src/main/kotlin/io/github/cdsap/kotlinprocess/output/BuildScanOutput.kt b/src/main/kotlin/io/github/cdsap/kotlinprocess/output/BuildScanOutput.kt deleted file mode 100644 index 2ce07d9..0000000 --- a/src/main/kotlin/io/github/cdsap/kotlinprocess/output/BuildScanOutput.kt +++ /dev/null @@ -1,39 +0,0 @@ -package io.github.cdsap.kotlinprocess.output - -import com.gradle.scan.plugin.BuildScanExtension -import io.github.cdsap.jdk.tools.parser.model.Process - -class BuildScanOutput( - private val buildScanExtension: BuildScanExtension, - private val processes: List, -) { - - fun addProcessesInfoToBuildScan() { - processes.map { - buildScanExtension.value( - "Kotlin-Process-${it.pid}-max", - "${it.max} GB" - ) - buildScanExtension.value( - "Kotlin-Process-${it.pid}-usage", - "${it.usage} GB" - ) - buildScanExtension.value( - "Kotlin-Process-${it.pid}-capacity", - "${it.capacity} GB" - ) - buildScanExtension.value( - "Kotlin-Process-${it.pid}-uptime", - "${it.uptime} minutes" - ) - buildScanExtension.value( - "Kotlin-Process-${it.pid}-gcTime", - "${it.gcTime} minutes" - ) - buildScanExtension.value( - "Kotlin-Process-${it.pid}-gcType", - it.typeGc - ) - } - } -} diff --git a/src/main/kotlin/io/github/cdsap/kotlinprocess/output/DevelocityValues.kt b/src/main/kotlin/io/github/cdsap/kotlinprocess/output/DevelocityValues.kt new file mode 100644 index 0000000..37ad085 --- /dev/null +++ b/src/main/kotlin/io/github/cdsap/kotlinprocess/output/DevelocityValues.kt @@ -0,0 +1,23 @@ +package io.github.cdsap.kotlinprocess.output + +import com.gradle.develocity.agent.gradle.DevelocityConfiguration +import io.github.cdsap.jdk.tools.parser.model.Process + +class DevelocityValues( + private val develocityConfiguration: DevelocityConfiguration, + private val processes: List, +) { + + fun addProcessesInfoToBuildScan() { + processes.map { + develocityConfiguration.buildScan { + value("Kotlin-Process-${it.pid}-max", "${it.max} GB") + value("Kotlin-Process-${it.pid}-usage", "${it.usage} GB") + value("Kotlin-Process-${it.pid}-capacity", "${it.capacity} GB") + value("Kotlin-Process-${it.pid}-uptime", "${it.uptime} minutes") + value("Kotlin-Process-${it.pid}-gcTime", "${it.gcTime} minutes") + value("Kotlin-Process-${it.pid}-gcType", it.typeGc) + } + } + } +} diff --git a/src/main/kotlin/io/github/cdsap/kotlinprocess/output/EnterpriseValues.kt b/src/main/kotlin/io/github/cdsap/kotlinprocess/output/EnterpriseValues.kt new file mode 100644 index 0000000..69aebd1 --- /dev/null +++ b/src/main/kotlin/io/github/cdsap/kotlinprocess/output/EnterpriseValues.kt @@ -0,0 +1,23 @@ +package io.github.cdsap.kotlinprocess.output + +import com.gradle.scan.plugin.BuildScanExtension +import io.github.cdsap.jdk.tools.parser.model.Process + +class EnterpriseValues( + private val buildScanExtension: BuildScanExtension, + private val processes: List, +) { + + fun addProcessesInfoToBuildScan() { + processes.map { + with(buildScanExtension) { + value("Kotlin-Process-${it.pid}-max", "${it.max} GB") + value("Kotlin-Process-${it.pid}-usage", "${it.usage} GB") + value("Kotlin-Process-${it.pid}-capacity", "${it.capacity} GB") + value("Kotlin-Process-${it.pid}-uptime", "${it.uptime} minutes") + value("Kotlin-Process-${it.pid}-gcTime", "${it.gcTime} minutes") + value("Kotlin-Process-${it.pid}-gcType", it.typeGc) + } + } + } +} diff --git a/src/test/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPluginTest.kt b/src/test/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPluginTest.kt index 3cb45d0..f6fe361 100644 --- a/src/test/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPluginTest.kt +++ b/src/test/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPluginTest.kt @@ -10,7 +10,7 @@ import org.junit.rules.TemporaryFolder class InfoKotlinProcessPluginTest { - private val gradleVersions = listOf("7.5.1", "7.6", "8.0.1", "8.1.1") + private val gradleVersions = listOf("7.6.2", "8.1.1", "8.6", "8.7") @Rule @JvmField diff --git a/src/test/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPluginWtihBuildScanTest.kt b/src/test/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPluginWtihBuildScanTest.kt index 2aefb09..3da1d75 100644 --- a/src/test/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPluginWtihBuildScanTest.kt +++ b/src/test/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPluginWtihBuildScanTest.kt @@ -65,4 +65,56 @@ class InfoKotlinProcessPluginWtihBuildScanTest { TestCase.assertTrue(secondBuild.output.contains("Configuration cache entry reused.")) } } + + @Test + fun testPluginIsCompatibleWithConfigurationCacheWithDevelocity() { + Assume.assumeTrue( + "Gradle Enterprise URL and Access Key are set", + System.getenv("GE_URL") != null && System.getenv("GE_API_KEY") != null + ) + + testProjectDir.newFile("settings.gradle").appendText( + """ + plugins { + id 'com.gradle.develocity' version '3.17.2' + } + develocity { + server = "${System.getenv("GE_URL")}" + accessKey="${System.getenv("GE_API_KEY")}" + buildScan { + publishing { true } + } + } + """.trimIndent() + ) + testProjectDir.newFile("build.gradle").appendText( + """ + plugins { + id 'org.jetbrains.kotlin.jvm' version '1.7.21' + id 'application' + id 'io.github.cdsap.kotlinprocess' + } + repositories { + mavenCentral() + } + + """.trimIndent() + ) + listOf("8.1.1").forEach { + val firstBuild = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments("compileKotlin", "--configuration-cache") + .withPluginClasspath() + .withGradleVersion(it) + .build() + val secondBuild = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments("compileKotlin", "--configuration-cache") + .withPluginClasspath() + .withGradleVersion(it) + .build() + TestCase.assertTrue(firstBuild.output.contains("Configuration cache entry stored")) + TestCase.assertTrue(secondBuild.output.contains("Configuration cache entry reused.")) + } + } }