-
Notifications
You must be signed in to change notification settings - Fork 25
Add Gradle Configuration Cache Support #272
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
Draft
tnj
wants to merge
9
commits into
master
Choose a base branch
from
feat/support-configuration-cache
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
83d0f3d
feat: Add Gradle Configuration Cache support
tnj e7b96a1
feat: Add Gradle Configuration Cache support
tnj 60426e0
Refactor DeployGate Gradle Plugin for Configuration Cache Compatibility
tnj d093f16
Fix configuration cache compatibility issues
tnj e646dd3
Fix test failures for configuration cache support
tnj 19e05c7
apply spotless
tnj 424208a
Fix test failures for configuration cache support
tnj d4eaa6b
update printAGPVersion task to follow the signature change
tnj b2e20a7
fix task descriptions were not shown
tnj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -6,6 +6,8 @@ import static com.deploygate.gradle.plugins.internal.agp.AndroidGradlePlugin.and | |||
| import static com.deploygate.gradle.plugins.internal.agp.AndroidGradlePlugin.androidBundleTaskName | ||||
| import static com.deploygate.gradle.plugins.internal.gradle.ProviderFactoryUtils.environmentVariable | ||||
|
|
||||
| import com.deploygate.gradle.plugins.artifacts.AabInfo | ||||
| import com.deploygate.gradle.plugins.artifacts.ApkInfo | ||||
| import com.deploygate.gradle.plugins.artifacts.DefaultPresetAabInfo | ||||
| import com.deploygate.gradle.plugins.artifacts.DefaultPresetApkInfo | ||||
| import com.deploygate.gradle.plugins.dsl.DeployGateExtension | ||||
|
|
@@ -55,26 +57,47 @@ class DeployGatePlugin implements Plugin<Project> { | |||
|
|
||||
| setupExtension(project) | ||||
|
|
||||
| GradleCompat.init(project) | ||||
|
|
||||
| // the presence of the value is same to the existence of the directory. | ||||
| // Defer file operations to execution time for Configuration Cache compatibility | ||||
| Provider<String> credentialDirPathProvider = project.providers.systemProperty("user.home").map { home -> | ||||
| File f = new File(home, '.dg') | ||||
| (f.directory || f.mkdirs()) ? f.absolutePath : null | ||||
| new File(home, '.dg').absolutePath | ||||
| } | ||||
|
|
||||
| // Detect AGP version for HttpClient | ||||
| def agpVersionProvider = project.providers.provider { | ||||
| try { | ||||
| def agpPlugin = project.plugins.findPlugin("com.android.application") | ||||
| if (agpPlugin) { | ||||
| return AndroidGradlePlugin.getVersionString(agpPlugin.class.classLoader) | ||||
| } | ||||
| } catch (Throwable ignored) { | ||||
| } | ||||
| return "unknown" | ||||
| } | ||||
|
|
||||
| def httpClientProvider = project.gradle.sharedServices.registerIfAbsent("httpclient", HttpClient) { spec -> | ||||
| spec.parameters.endpoint.set(environmentVariable(project.providers, "TEST_SERVER_URL").orElse(Config.getDEPLOYGATE_ROOT())) | ||||
| spec.parameters.agpVersion.set(agpVersionProvider) | ||||
| spec.parameters.pluginVersion.set(project.providers.provider { Config.VERSION }) | ||||
| spec.parameters.pluginVersionCode.set(project.providers.provider { Config.VERSION_CODE.toString() }) | ||||
| spec.parameters.pluginVersionName.set(project.providers.provider { Config.VERSION_NAME }) | ||||
| } | ||||
|
|
||||
| def localServerProvider = project.gradle.sharedServices.registerIfAbsent("httpserver", LocalServer) { spec -> | ||||
| spec.parameters.httpClient.set(httpClientProvider) | ||||
| spec.parameters.credentialsDirPath.set(credentialDirPathProvider) | ||||
| } | ||||
|
|
||||
| // Use Provider API for configuration cache compatibility | ||||
| def extension = project.extensions.getByName(EXTENSION_NAME) as DeployGateExtension | ||||
| def appOwnerNameProvider = project.providers.provider { extension.appOwnerName } | ||||
| def apiTokenProvider = project.providers.provider { extension.apiToken } | ||||
| def endpointProvider = project.providers.provider { extension.endpoint } | ||||
| def openBrowserProvider = environmentVariable(project.providers, ENV_NAME_OPEN_APP_DETAIL_AFTER_UPLOAD).map { it?.toBoolean() ?: false } | ||||
|
|
||||
| def loginTaskProvider = project.tasks.register(Constants.LOGIN_TASK_NAME, LoginTask) { task -> | ||||
| task.explicitAppOwnerName.set(project.deploygate.appOwnerName) | ||||
| task.explicitApiToken.set(project.deploygate.apiToken) | ||||
| task.explicitAppOwnerName.set(appOwnerNameProvider) | ||||
| task.explicitApiToken.set(apiTokenProvider) | ||||
| task.credentialsDirPath.set(credentialDirPathProvider) | ||||
| task.httpClient.set(httpClientProvider) | ||||
| task.localServer.set(localServerProvider) | ||||
|
|
@@ -98,37 +121,47 @@ class DeployGatePlugin implements Plugin<Project> { | |||
| task.group = Constants.TASK_GROUP_NAME | ||||
| } | ||||
|
|
||||
| project.deploygate.deployments.configureEach { NamedDeployment deployment -> | ||||
| extension.deployments.configureEach { NamedDeployment deployment -> | ||||
| project.tasks.named(Constants.SUFFIX_APK_TASK_NAME).configure { task -> | ||||
| task.dependsOn(Constants.uploadApkTaskName(deployment.name)) | ||||
| } | ||||
|
|
||||
| project.tasks.named(Constants.SUFFIX_AAB_TASK_NAME).configure { task -> | ||||
| task.dependsOn(Constants.uploadAabTaskName(deployment.name)) | ||||
| } | ||||
|
|
||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [spotless] reported by reviewdog 🐶
Suggested change
|
||||
| project.tasks.register(Constants.uploadApkTaskName(deployment.name), UploadApkTask) { task -> | ||||
| task.description = "Deploy assembled ${deployment.name} APK to DeployGate" | ||||
| task.group = Constants.TASK_GROUP_NAME | ||||
|
|
||||
| if (!deployment.skipAssemble) { | ||||
| task.logger.debug("${deployment.name} required assmble but ignored") | ||||
| task.logger.debug("${deployment.name} required assemble but ignored") | ||||
| } | ||||
|
|
||||
| task.credentials.set(loginTaskProvider.map { it.credentials }) | ||||
| task.deployment.copyFrom(deployment) | ||||
| task.apkInfo.set(new DefaultPresetApkInfo(deployment.name)) | ||||
| task.httpClient.set(httpClientProvider) | ||||
| task.endpoint.set(endpointProvider) | ||||
| task.openBrowserAfterUpload.set(openBrowserProvider) | ||||
| task.usesService(httpClientProvider) | ||||
| task.dependsOn(loginTaskProvider) | ||||
| } | ||||
|
|
||||
| project.tasks.register(Constants.uploadAabTaskName(deployment.name), UploadAabTask) { task -> | ||||
| task.description = "Deploy bundled ${deployment.name} AAB to DeployGate" | ||||
| task.group = Constants.TASK_GROUP_NAME | ||||
|
|
||||
| if (!deployment.skipAssemble) { | ||||
| task.logger.debug("${deployment.name} required assmble but ignored") | ||||
| task.logger.debug("${deployment.name} required assemble but ignored") | ||||
| } | ||||
|
|
||||
| task.credentials.set(loginTaskProvider.map { it.credentials }) | ||||
| task.deployment.copyFrom(deployment) | ||||
| task.aabInfo.set(new DefaultPresetAabInfo(deployment.name)) | ||||
| task.httpClient.set(httpClientProvider) | ||||
| task.endpoint.set(endpointProvider) | ||||
| task.openBrowserAfterUpload.set(openBrowserProvider) | ||||
| task.usesService(httpClientProvider) | ||||
| task.dependsOn(loginTaskProvider) | ||||
| } | ||||
|
|
@@ -139,10 +172,13 @@ class DeployGatePlugin implements Plugin<Project> { | |||
| def variantProxy = new IApplicationVariantImpl(variant) | ||||
|
|
||||
| namedOrRegister(project, Constants.uploadApkTaskName(variantProxy.name), UploadApkTask).configure { task -> | ||||
| task.description = "Deploy assembled ${variantProxy.name} APK to DeployGate" | ||||
| task.credentials.set(loginTaskProvider.map { it.credentials }) | ||||
|
|
||||
| task.apkInfo.set(variantProxy.packageApplicationTaskProvider().map {getApkInfo(it, variantProxy.name) }) | ||||
| task.apkInfo.set(createApkInfoProvider(variantProxy, agpVersionProvider)) | ||||
| task.httpClient.set(httpClientProvider) | ||||
| task.endpoint.set(endpointProvider) | ||||
| task.openBrowserAfterUpload.set(openBrowserProvider) | ||||
| task.usesService(httpClientProvider) | ||||
|
|
||||
| if (deployment.skipAssemble.get()) { | ||||
|
|
@@ -153,10 +189,13 @@ class DeployGatePlugin implements Plugin<Project> { | |||
| } | ||||
|
|
||||
| namedOrRegister(project, Constants.uploadAabTaskName(variantProxy.name), UploadAabTask).configure { task -> | ||||
| task.description = "Deploy bundled ${variantProxy.name} AAB to DeployGate" | ||||
| task.credentials.set(loginTaskProvider.map { it.credentials }) | ||||
|
|
||||
| task.aabInfo.set(variantProxy.packageApplicationTaskProvider().map {getAabInfo(it, variantProxy.name, project.buildDir) }) | ||||
| task.aabInfo.set(createAabInfoProvider(variantProxy, agpVersionProvider, project)) | ||||
| task.httpClient.set(httpClientProvider) | ||||
| task.endpoint.set(endpointProvider) | ||||
| task.openBrowserAfterUpload.set(openBrowserProvider) | ||||
| task.usesService(httpClientProvider) | ||||
|
|
||||
| if (deployment.skipAssemble.get()) { | ||||
|
|
@@ -182,4 +221,42 @@ class DeployGatePlugin implements Plugin<Project> { | |||
| // TODO we should use ExtensionSyntax as the 1st argument but we need to investigate the expected side effects first. | ||||
| project.extensions.create(DeployGateExtension, EXTENSION_NAME, DeployGateExtension, deployments) | ||||
| } | ||||
|
|
||||
| /** | ||||
| * Creates a provider for APK info that properly chains the package task provider | ||||
| * with the AGP version provider for configuration cache compatibility. | ||||
| * | ||||
| * @param variantProxy The application variant proxy | ||||
| * @param agpVersionProvider Provider for the AGP version string | ||||
| * @return Provider for ApkInfo | ||||
| */ | ||||
| private static Provider<ApkInfo> createApkInfoProvider( | ||||
| @NotNull IApplicationVariantImpl variantProxy, | ||||
| @NotNull Provider<String> agpVersionProvider) { | ||||
| return variantProxy.packageApplicationTaskProvider().flatMap { packageTask -> | ||||
| agpVersionProvider.map { agpVersion -> | ||||
| getApkInfo(packageTask, variantProxy.name, agpVersion) | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
||||
| /** | ||||
| * Creates a provider for AAB info that properly chains the package task provider | ||||
| * with the AGP version provider for configuration cache compatibility. | ||||
| * | ||||
| * @param variantProxy The application variant proxy | ||||
| * @param agpVersionProvider Provider for the AGP version string | ||||
| * @param project The project instance for accessing build directory | ||||
| * @return Provider for AabInfo | ||||
| */ | ||||
| private static Provider<AabInfo> createAabInfoProvider( | ||||
| @NotNull IApplicationVariantImpl variantProxy, | ||||
| @NotNull Provider<String> agpVersionProvider, | ||||
| @NotNull Project project) { | ||||
| return variantProxy.packageApplicationTaskProvider().flatMap { packageTask -> | ||||
| agpVersionProvider.map { agpVersion -> | ||||
| getAabInfo(packageTask, variantProxy.name, project.layout.buildDirectory.get().asFile, agpVersion) | ||||
| } | ||||
| } | ||||
| } | ||||
| } | ||||
9 changes: 9 additions & 0 deletions
9
src/main/groovy/com/deploygate/gradle/plugins/artifacts/AabInfo.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,21 @@ | ||
| package com.deploygate.gradle.plugins.artifacts | ||
|
|
||
| import org.gradle.api.tasks.Input | ||
| import org.gradle.api.tasks.InputFile | ||
| import org.gradle.api.tasks.Optional | ||
| import org.gradle.api.tasks.PathSensitive | ||
| import org.gradle.api.tasks.PathSensitivity | ||
| import org.jetbrains.annotations.NotNull | ||
| import org.jetbrains.annotations.Nullable | ||
|
|
||
| interface AabInfo { | ||
| @Input | ||
| @NotNull | ||
| String getVariantName() | ||
|
|
||
| @InputFile | ||
| @Optional | ||
| @PathSensitive(PathSensitivity.ABSOLUTE) | ||
| @Nullable | ||
| File getAabFile() | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/groovy/com/deploygate/gradle/plugins/artifacts/ApkInfo.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,27 @@ | ||
| package com.deploygate.gradle.plugins.artifacts | ||
|
|
||
| import org.gradle.api.tasks.Input | ||
| import org.gradle.api.tasks.InputFile | ||
| import org.gradle.api.tasks.Optional | ||
| import org.gradle.api.tasks.PathSensitive | ||
| import org.gradle.api.tasks.PathSensitivity | ||
| import org.jetbrains.annotations.NotNull | ||
| import org.jetbrains.annotations.Nullable | ||
|
|
||
| interface ApkInfo { | ||
| @Input | ||
| @NotNull | ||
| String getVariantName() | ||
|
|
||
| @InputFile | ||
| @Optional | ||
| @PathSensitive(PathSensitivity.ABSOLUTE) | ||
| @Nullable | ||
| File getApkFile() | ||
|
|
||
| @Input | ||
| boolean isSigningReady() | ||
|
|
||
| @Input | ||
| boolean isUniversalApk() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced with
openBrowserAfterUploadproperty inUploadArtifactTask