From c8b76091fa365dffc78a134909981a2bfdb17010 Mon Sep 17 00:00:00 2001 From: Pablo Baxter Date: Fri, 5 Jul 2024 14:23:01 -0700 Subject: [PATCH 1/3] Allow build scans to run on affected-paths runs with Gradle. --- CHANGELOG.md | 1 + .../paths/app/options/BaseConfigurationOptions.kt | 7 +++++++ .../affected/paths/app/utils/CoreOptionsUtils.kt | 1 + .../com/squareup/affected/paths/core/CoreAnalyzer.kt | 3 +++ .../com/squareup/affected/paths/core/CoreOptions.kt | 11 +++++++++++ 5 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39a108d..77f00f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## Unreleased +- `affected-paths-core`: Add in flag for enabling build scans on affected-paths runs ## v0.1.3 - `affected-paths-core`: Fix custom Gradle flags not being properly set diff --git a/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/options/BaseConfigurationOptions.kt b/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/options/BaseConfigurationOptions.kt index f82007e..8444712 100644 --- a/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/options/BaseConfigurationOptions.kt +++ b/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/options/BaseConfigurationOptions.kt @@ -127,4 +127,11 @@ internal class BaseConfigurationOptions { ) var gradleInstallationPath: Path? = null internal set + + @Option( + names = ["--build-scan"], + description = ["Capture the Gradle build scan"] + ) + var gradleBuildScan: Boolean = false + internal set } diff --git a/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/utils/CoreOptionsUtils.kt b/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/utils/CoreOptionsUtils.kt index 8d56b57..4ddbdc4 100644 --- a/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/utils/CoreOptionsUtils.kt +++ b/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/utils/CoreOptionsUtils.kt @@ -34,5 +34,6 @@ internal fun BaseConfigurationOptions.toCoreOptions(): CoreOptions { autoInjectPlugin = autoInject, changedFiles = changedFiles, gradleInstallationPath = gradleInstallationPath, + useBuildScan = gradleBuildScan ) } diff --git a/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreAnalyzer.kt b/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreAnalyzer.kt index bb77b41..9735f0f 100644 --- a/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreAnalyzer.kt +++ b/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreAnalyzer.kt @@ -96,6 +96,9 @@ public class CoreAnalyzer @JvmOverloads constructor(private val coreOptions: Cor ) ) actionExecutor.withCancellationToken(cancellationTokenSource.token()) + if (coreOptions.useBuildScan) { + actionExecutor.forTasks(emptyList()) + } actionExecutor.addArguments(coreOptions.gradleArgs) actionExecutor.addJvmArguments(coreOptions.jvmArgs) diff --git a/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreOptions.kt b/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreOptions.kt index 00fc629..3965c96 100644 --- a/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreOptions.kt +++ b/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreOptions.kt @@ -72,6 +72,14 @@ public data class CoreOptions @JvmOverloads constructor( /** Pass in a custom Gradle installation, instead of using the build distribution */ val gradleInstallationPath: Path? = null, + + /** + * Add the build scan flag to the tooling. + * + * **Note**: This will cause the default tasks of a build to run. + */ + + val useBuildScan: Boolean = false, ) { init { @@ -123,5 +131,8 @@ public data class CoreOptions @JvmOverloads constructor( }.absolutePath ) } + if (useBuildScan) { + add("--scan") + } } } From 5660cba7011959dcd492de8d79b46a5ba57ae15e Mon Sep 17 00:00:00 2001 From: Pablo Baxter Date: Thu, 18 Jul 2024 17:20:44 -0700 Subject: [PATCH 2/3] Allow better control of the Gradle daemon --- .../app/options/BaseConfigurationOptions.kt | 37 +++++++++++++++++++ .../paths/app/utils/CoreOptionsUtils.kt | 9 +++-- .../affected/paths/core/CoreAnalyzer.kt | 19 ++++++++-- .../affected/paths/core/CoreOptions.kt | 19 +++++++++- 4 files changed, 76 insertions(+), 8 deletions(-) diff --git a/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/options/BaseConfigurationOptions.kt b/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/options/BaseConfigurationOptions.kt index 8444712..99d403c 100644 --- a/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/options/BaseConfigurationOptions.kt +++ b/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/options/BaseConfigurationOptions.kt @@ -134,4 +134,41 @@ internal class BaseConfigurationOptions { ) var gradleBuildScan: Boolean = false internal set + + @Option( + names = ["--gradle-jvm-flags"], + description = ["List of JVM flags to pass to the Gradle daemon"], + split = " " + ) + var gradleJvmFlags: List = emptyList() + internal set + + @Option( + names = ["--gradle-flags"], + description = ["Gradle flags to use on model queries and task runs"], + split = " " + ) + var gradleFlags: List = emptyList() + internal set + + @Option( + names = ["--distribution-path"], + description = ["Gradle distribution path"] + ) + var gradleDistributionPath: Path? = null + internal set + + @Option( + names = ["--gradle-version"], + description = ["Gradle version to use"] + ) + var gradleVersion: String? = null + internal set + + @Option( + names = ["--gradle-user-home"], + description = ["Gradle user home path to use"] + ) + var gradleUserHome: Path? = null + internal set } diff --git a/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/utils/CoreOptionsUtils.kt b/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/utils/CoreOptionsUtils.kt index 4ddbdc4..41d8669 100644 --- a/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/utils/CoreOptionsUtils.kt +++ b/affected-paths/app/src/main/kotlin/com/squareup/affected/paths/app/utils/CoreOptionsUtils.kt @@ -29,11 +29,14 @@ internal fun BaseConfigurationOptions.toCoreOptions(): CoreOptions { allowGradleParallel = allowGradleParallel, initialGradleMemory = initialGradleMemory, maxGradleMemory = maxGradleMemory, - customJvmFlags = listOf("-XX:-MaxFDLimit"), - customGradleFlags = listOf("--stacktrace"), + customJvmFlags = gradleJvmFlags, + customGradleFlags = gradleFlags, autoInjectPlugin = autoInject, changedFiles = changedFiles, gradleInstallationPath = gradleInstallationPath, - useBuildScan = gradleBuildScan + useBuildScan = gradleBuildScan, + gradleDistributionPath = gradleDistributionPath, + gradleVersion = gradleVersion, + gradleUserHome = gradleUserHome ) } diff --git a/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreAnalyzer.kt b/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreAnalyzer.kt index 9735f0f..5ee71ab 100644 --- a/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreAnalyzer.kt +++ b/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreAnalyzer.kt @@ -79,10 +79,21 @@ public class CoreAnalyzer @JvmOverloads constructor(private val coreOptions: Cor val projectConnection = with(affectedPathsApplication.koin.get()) { forProjectDirectory(rootDir.toFile()) - if (coreOptions.gradleInstallationPath != null) { - useInstallation(coreOptions.gradleInstallationPath.toFile()) - } else { - useBuildDistribution() + when { + coreOptions.gradleDistributionPath != null -> { + useDistribution(coreOptions.gradleDistributionPath.toUri()) + } + coreOptions.gradleInstallationPath != null -> { + useInstallation(coreOptions.gradleInstallationPath.toFile()) + } + coreOptions.gradleVersion != null -> { + useGradleVersion(coreOptions.gradleVersion) + } + else -> useBuildDistribution() + } + + if (coreOptions.gradleUserHome != null) { + useGradleUserHomeDir(coreOptions.gradleUserHome.toFile()) } return@with connect() } diff --git a/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreOptions.kt b/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreOptions.kt index 3965c96..f7b0c22 100644 --- a/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreOptions.kt +++ b/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreOptions.kt @@ -70,9 +70,26 @@ public data class CoreOptions @JvmOverloads constructor( /** Include any "includeBuild" builds from the current build */ val useIncludeBuild: Boolean = true, - /** Pass in a custom Gradle installation, instead of using the build distribution */ + /** Gradle distribution file to use */ + val gradleDistributionPath: Path? = null, + + /** + * Pass in a custom Gradle installation, instead of using the build distribution + * + * **NOTE**: This will override `gradleDistributionPath` if used. + */ val gradleInstallationPath: Path? = null, + /** + * Gradle version to use for the current build + * + * **NOTE**: This will override `gradleInstallationPath` and `gradleDistributionPath` if used. + */ + val gradleVersion: String? = null, + + /** Gradle user home directory to use */ + val gradleUserHome: Path? = null, + /** * Add the build scan flag to the tooling. * From a0f6013808ba10de1e0f0bd356c48b30da20c33f Mon Sep 17 00:00:00 2001 From: Pablo Baxter Date: Thu, 12 Dec 2024 11:13:50 -0800 Subject: [PATCH 3/3] Prep for v0.1.4 release --- CHANGELOG.md | 3 +++ .../kotlin/com/squareup/affected/paths/core/CoreOptions.kt | 2 +- gradle.properties | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77f00f5..a39aaf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Unreleased + +## v0.1.4 - `affected-paths-core`: Add in flag for enabling build scans on affected-paths runs +- `affected-paths-core`: Allow better control of the Gradle daemon ## v0.1.3 - `affected-paths-core`: Fix custom Gradle flags not being properly set diff --git a/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreOptions.kt b/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreOptions.kt index f7b0c22..d5f7c95 100644 --- a/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreOptions.kt +++ b/affected-paths/core/src/main/kotlin/com/squareup/affected/paths/core/CoreOptions.kt @@ -133,7 +133,7 @@ public data class CoreOptions @JvmOverloads constructor( mavenCentral() } dependencies { - classpath "com.squareup.affected.paths:tooling-support:0.1.3" + classpath "com.squareup.affected.paths:tooling-support:0.1.4" } } } diff --git a/gradle.properties b/gradle.properties index 4237d4f..d5955d9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 kotlin.code.style=official GROUP=com.squareup.affected.paths -VERSION_NAME=0.1.3 +VERSION_NAME=0.1.4 POM_URL=https://github.com/squareup/affected-paths POM_SCM_URL=https://github.com/squareup/affected-paths