Skip to content

Commit

Permalink
update dv api (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdsap authored Apr 25, 2024
1 parent 32dec51 commit 3901764
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 16 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.gradleprocess") version "0.1.1"
id("io.github.cdsap.gradleprocess") version "0.1.2"
}
```

Expand All @@ -20,7 +20,7 @@ buildscript {
gradlePluginPortal()
}
dependencies {
classpath("io.github.cdsap:infogradleprocess:0.1.1")
classpath("io.github.cdsap:infogradleprocess:0.1.2")
}
}
Expand All @@ -31,7 +31,7 @@ apply(plugin = "io.github.cdsap.gradleprocess")
Using the plugins DSL:
``` groovy
plugins {
id "io.github.cdsap.gradleprocess" version "0.1.1"
id "io.github.cdsap.gradleprocess" version "0.1.2"
}
```
Expand All @@ -43,7 +43,7 @@ buildscript {
gradlePluginPortal()
}
dependencies {
classpath "io.github.cdsap:infogradleprocess:0.1.1"
classpath "io.github.cdsap:infogradleprocess:0.1.2"
}
}
Expand Down Expand Up @@ -77,5 +77,6 @@ BUILD SUCCESSFUL in 35s
* 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`
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "io.github.cdsap"
version = "0.1.1"
version = "0.1.2"

java {
toolchain {
Expand All @@ -19,6 +19,7 @@ dependencies {
implementation("io.github.cdsap:commandline-value-source:0.1.0")
implementation("com.jakewharton.picnic:picnic:0.6.0")
implementation("com.gradle.enterprise:com.gradle.enterprise.gradle.plugin:3.12.3")
implementation("com.gradle:develocity-gradle-plugin:3.17.2")
testImplementation("junit:junit:4.13.2")
}
tasks.withType<Test>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
package io.github.cdsap.gradleprocess

import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import com.gradle.scan.plugin.BuildScanExtension
import io.github.cdsap.gradleprocess.output.BuildScanOutput
import io.github.cdsap.gradleprocess.output.DevelocityValues
import io.github.cdsap.gradleprocess.output.EnterpriseValues
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.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 InfoGradleProcessPlugin : Plugin<Project> {
private val nameProcess = "GradleDaemon"
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)
}
}
}


private fun consoleReporting(project: Project) {
project.gradle.sharedServices.registerIfAbsent(
"gradleProcessService", InfoGradleProcessBuildService::class.java
Expand All @@ -31,16 +42,41 @@ class InfoGradleProcessPlugin : Plugin<Project> {
}.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<String>,
jInfo: Provider<String>
): List<Process> {
val processes = ConsolidateProcesses().consolidate(jStat.get(), jInfo.get(), TypeProcess.Kotlin)
return processes
}

private fun providerPair(project: Project): Pair<Provider<String>, Provider<String>> {
val jStat = project.jStat(nameProcess)
val jInfo = project.jInfo(nameProcess)
return Pair(jStat, jInfo)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.cdsap.gradleprocess.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<Process>,
) {

fun addProcessesInfoToBuildScan() {
processes.map {
develocityConfiguration.buildScan {
value("Gradle-Process-${it.pid}-max", "${it.max} GB")
value("Gradle-Process-${it.pid}-usage", "${it.usage} GB")
value("Gradle-Process-${it.pid}-capacity", "${it.capacity} GB")
value("Gradle-Process-${it.pid}-uptime", "${it.uptime} minutes")
value("Gradle-Process-${it.pid}-gcTime", "${it.gcTime} minutes")
value("Gradle-Process-${it.pid}-gcType", it.typeGc)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.cdsap.gradleprocess.output

import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import io.github.cdsap.jdk.tools.parser.model.Process

import com.gradle.scan.plugin.BuildScanExtension

class EnterpriseValues(
private val buildScanExtension: BuildScanExtension,
private val processes: List<Process>,
) {

fun addProcessesInfoToBuildScan() {
processes.map {
with(buildScanExtension) {
value("Gradle-Process-${it.pid}-max", "${it.max} GB")
value("Gradle-Process-${it.pid}-usage", "${it.usage} GB")
value("Gradle-Process-${it.pid}-capacity", "${it.capacity} GB")
value("Gradle-Process-${it.pid}-uptime", "${it.uptime} minutes")
value("Gradle-Process-${it.pid}-gcTime", "${it.gcTime} minutes")
value("Gradle-Process-${it.pid}-gcType", it.typeGc)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.junit.rules.TemporaryFolder

class InfoGradleProcessPluginTest {

private val gradleVersions = listOf("7.6", "8.0.1", "8.1.1")
private val gradleVersions = listOf("7.6.2", "8.1.1", "8.6", "8.7")

@Rule
@JvmField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,55 @@ class InfoGradleProcessPluginWtihBuildScanTest {
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.gradleprocess'
}
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."))
}
}
}

0 comments on commit 3901764

Please sign in to comment.