Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated gradle data capturing samples to Develocity #1325

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Migrated samples in build-data-capturing-gradle-samples to Develocity…
… api
  • Loading branch information
ribafish committed Aug 6, 2024

Verified

This commit was signed with the committer’s verified signature.
ribafish Gašper Kojek
commit 5fb343eb1b87c94db983889097d48231bc6bbef5
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension
import com.gradle.develocity.agent.gradle.DevelocityConfiguration

/**
* This Kotlin script captures the Develocity Gradle plugin version as a custom value.
*/
project.extensions.configure<GradleEnterpriseExtension>() {

project.extensions.configure<DevelocityConfiguration> {
buildScan {
val url = GradleEnterpriseExtension::class.java.classLoader.getResource("com.gradle.scan.plugin.internal.meta.buildAgentVersion.txt")
val url = DevelocityConfiguration::class.java.classLoader.getResource("com.gradle.scan.plugin.internal.meta.buildAgentVersion.txt")
val buildAgentVersion = url.readText()
value("Develocity Gradle plugin version", buildAgentVersion)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension
import com.gradle.scan.plugin.BuildScanExtension
import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import com.gradle.develocity.agent.gradle.scan.BuildScanConfiguration
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper

@@ -17,7 +17,7 @@ import java.util.concurrent.TimeUnit
* See https://docs.github.com/en/rest/gists/gists#create-a-gist for reference.
*/

project.extensions.configure<GradleEnterpriseExtension>() {
project.extensions.configure<DevelocityConfiguration> {

val capture = Capture(gradle.startParameter.isOffline,
gradle.startParameter.isContinuous,
@@ -49,7 +49,7 @@ class Capture(val offline: Boolean,
return true
}

fun captureGitDiffInGist(api: BuildScanExtension) {
fun captureGitDiffInGist(api: BuildScanConfiguration) {
val hasCredentials = gistTokenProvider.isPresent
if (!hasCredentials) {
logger.warn("User has not set 'gistToken'. Cannot publish gist.")
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension
import com.gradle.develocity.agent.gradle.DevelocityConfiguration

project.extensions.configure<GradleEnterpriseExtension>() {
project.extensions.configure<DevelocityConfiguration>() {
buildScan {
allprojects {
tasks.withType<Test>().configureEach {
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension
import com.gradle.scan.plugin.BuildScanExtension
import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import com.gradle.develocity.agent.gradle.scan.BuildScanConfiguration
import java.nio.charset.Charset
import java.util.concurrent.TimeUnit

@@ -8,7 +8,7 @@ import java.util.concurrent.TimeUnit
* and adds these as a custom value.
*/

project.extensions.configure<GradleEnterpriseExtension>() {
project.extensions.configure<DevelocityConfiguration>() {
buildScan {
background {
Capture.captureOsProcesses(buildScan)
@@ -18,7 +18,7 @@ project.extensions.configure<GradleEnterpriseExtension>() {

class Capture {
companion object {
fun captureOsProcesses(api: BuildScanExtension) {
fun captureOsProcesses(api: BuildScanConfiguration) {
val psOutput = execAndGetStdout("ps", "-o pid,ppid,time,command")
api.value("OS processes", psOutput)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension
import com.gradle.scan.plugin.BuildScanExtension
import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import com.gradle.develocity.agent.gradle.scan.BuildScanConfiguration
import java.nio.charset.Charset
import java.util.concurrent.TimeUnit

@@ -8,7 +8,7 @@ import java.util.concurrent.TimeUnit
* and adds these as a custom value.
*/

project.extensions.configure<GradleEnterpriseExtension>() {
project.extensions.configure<DevelocityConfiguration>() {
buildScan {
background {
Capture.captureProcessorArch(buildScan)
@@ -18,7 +18,7 @@ project.extensions.configure<GradleEnterpriseExtension>() {

class Capture {
companion object {
fun captureProcessorArch(api: BuildScanExtension) {
fun captureProcessorArch(api: BuildScanConfiguration) {
val osName = System.getProperty("os.name")
api.value("os.name", osName)

Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension
import com.gradle.scan.plugin.BuildScanExtension
import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import groovy.xml.XmlSlurper
import groovy.xml.slurpersupport.Node
import groovy.xml.slurpersupport.NodeChild
import groovy.xml.slurpersupport.NodeChildren
import groovy.xml.slurpersupport.GPathResult

/**
* This Gradle script captures issues found by reporting tasks,
* and adds these as custom values.
*/

project.extensions.configure<GradleEnterpriseExtension>() {
project.extensions.configure<DevelocityConfiguration>() {
buildScan {
gradle.taskGraph.beforeTask {
if (this.reportingSupported && this is Reporting<*>) {
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension
import com.gradle.scan.plugin.BuildScanExtension
import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import com.gradle.develocity.agent.gradle.scan.BuildScanConfiguration

/**
* This Gradle script captures all tasks of a given type taking longer to execute than a certain threshold,
* and adds these as custom values.
*/

project.extensions.configure<GradleEnterpriseExtension>() {
project.extensions.configure<DevelocityConfiguration>() {
buildScan {
val THRESHOLD_MILLIS = 15 * 60 * 1000 // 15 min
val api = buildScan
@@ -29,7 +29,7 @@ project.extensions.configure<GradleEnterpriseExtension>() {

class Capture {
companion object {
fun addbuildScanValue(api: BuildScanExtension, key: String, value: String) {
fun addbuildScanValue(api: BuildScanConfiguration, key: String, value: String) {
api.value(key, value)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension
import com.gradle.scan.plugin.BuildScanExtension
import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import com.gradle.develocity.agent.gradle.scan.BuildScanConfiguration
import java.nio.charset.StandardCharsets
import java.security.MessageDigest

@@ -8,7 +8,7 @@ import java.security.MessageDigest
* and adds these as custom values.
*/

project.extensions.configure<GradleEnterpriseExtension>() {
project.extensions.configure<DevelocityConfiguration>() {
buildScan {
val api = buildScan
allprojects {
@@ -25,7 +25,7 @@ class Capture {
companion object {
val MESSAGE_DIGEST = MessageDigest.getInstance("SHA-256")

fun addbuildScanValue(api: BuildScanExtension, key: String, value: Any?) {
fun addbuildScanValue(api: BuildScanConfiguration, key: String, value: Any?) {
api.value(key, hash(value))
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension
import com.gradle.scan.plugin.BuildScanExtension
import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import com.gradle.develocity.agent.gradle.scan.BuildScanConfiguration
import org.gradle.util.internal.VersionNumber
import java.nio.charset.StandardCharsets
import java.util.Collections
@@ -14,7 +14,7 @@ import groovy.transform.Field
* adding a flag as custom value.
*/

project.extensions.configure<GradleEnterpriseExtension>() {
project.extensions.configure<DevelocityConfiguration>() {
buildScan {
val api = buildScan
val capture = Capture(api, gradle.rootProject.logger)
@@ -28,7 +28,7 @@ project.extensions.configure<GradleEnterpriseExtension>() {
}
}

class Capture(val api: BuildScanExtension, val logger: Logger) {
class Capture(val api: BuildScanConfiguration, val logger: Logger) {
val supportedEngines: Map<String, String> = mapOf(
"org.junit.support.testng.engine.TestNGTestEngine" to "testng",
"org.junit.jupiter.engine.JupiterTestEngine" to "junit-jupiter",
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import org.gradle.api.internal.project.ProjectInternal
import org.gradle.api.services.BuildService
import org.gradle.api.services.BuildServiceParameters
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension
import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import com.gradle.develocity.agent.gradle.scan.BuildScanConfiguration
import org.gradle.internal.os.OperatingSystem
import com.gradle.scan.plugin.BuildScanExtension

import java.nio.charset.Charset
import java.util.concurrent.ConcurrentLinkedQueue
@@ -26,7 +26,7 @@ import org.gradle.tooling.events.FinishEvent
* - This is supported on MacOS only.
*/

project.extensions.configure<GradleEnterpriseExtension>() {
project.extensions.configure<DevelocityConfiguration>() {
buildScan {
val api = buildScan
if (OperatingSystem.current().isMacOsX()) {
@@ -92,7 +92,7 @@ abstract class ThermalThrottlingService : BuildService<BuildServiceParameters.No
}
}

fun processResults(api: BuildScanExtension) {
fun processResults(api: BuildScanConfiguration) {
if (!samples.isEmpty()) {
val average = samples.stream().mapToInt{ it as Int }.average().getAsDouble()
if (average < 100.0) {