From 3e26e264de269f7ea5626dd8cc592b3f0acd86bc Mon Sep 17 00:00:00 2001 From: Aurimas Liutikas Date: Wed, 1 Mar 2023 12:40:55 -0800 Subject: [PATCH] Remove usage of Project during task execution - Replace project with injected FileOperations object - Replace project with logger as that's the only thing used Fixes part of #454 issue Test: existing tests pass --- .../gradle/appengine/appyaml/StageAppYamlTask.java | 11 ++++++++--- .../gradle/appengine/core/DownloadCloudSdkTask.java | 2 +- .../core/DownloadCloudSdkTaskConsoleListener.java | 9 +++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/google/cloud/tools/gradle/appengine/appyaml/StageAppYamlTask.java b/src/main/java/com/google/cloud/tools/gradle/appengine/appyaml/StageAppYamlTask.java index 7d4ec7f0..95fcf4ad 100644 --- a/src/main/java/com/google/cloud/tools/gradle/appengine/appyaml/StageAppYamlTask.java +++ b/src/main/java/com/google/cloud/tools/gradle/appengine/appyaml/StageAppYamlTask.java @@ -19,12 +19,17 @@ import com.google.cloud.tools.appengine.AppEngineException; import com.google.cloud.tools.appengine.operations.AppYamlProjectStaging; +import javax.inject.Inject; import org.gradle.api.DefaultTask; +import org.gradle.api.internal.file.FileOperations; import org.gradle.api.tasks.Nested; import org.gradle.api.tasks.TaskAction; /** Stage App Engine app.yaml based applications for deployment. */ -public class StageAppYamlTask extends DefaultTask { +public abstract class StageAppYamlTask extends DefaultTask { + + @Inject + abstract public FileOperations getFileOperations(); private StageAppYamlExtension appYamlExtension; @@ -40,8 +45,8 @@ public void setStagingConfig(StageAppYamlExtension stagingConfig) { /** Task entrypoint : Stage the app.yaml based application. */ @TaskAction public void stageAction() throws AppEngineException { - getProject().delete(appYamlExtension.getStagingDirectory()); - getProject().mkdir(appYamlExtension.getStagingDirectory().getAbsolutePath()); + getFileOperations().delete(appYamlExtension.getStagingDirectory()); + getFileOperations().mkdir(appYamlExtension.getStagingDirectory().getAbsolutePath()); AppYamlProjectStaging staging = new AppYamlProjectStaging(); staging.stageArchive(appYamlExtension.toAppYamlProjectStageConfiguration()); diff --git a/src/main/java/com/google/cloud/tools/gradle/appengine/core/DownloadCloudSdkTask.java b/src/main/java/com/google/cloud/tools/gradle/appengine/core/DownloadCloudSdkTask.java index b41ae988..69838818 100644 --- a/src/main/java/com/google/cloud/tools/gradle/appengine/core/DownloadCloudSdkTask.java +++ b/src/main/java/com/google/cloud/tools/gradle/appengine/core/DownloadCloudSdkTask.java @@ -69,7 +69,7 @@ public void downloadCloudSdkAction() } ProgressListener progressListener = new NoOpProgressListener(); - ConsoleListener consoleListener = new DownloadCloudSdkTaskConsoleListener(getProject()); + ConsoleListener consoleListener = new DownloadCloudSdkTaskConsoleListener(getLogger()); // Install sdk if not installed if (!managedCloudSdk.isInstalled()) { diff --git a/src/main/java/com/google/cloud/tools/gradle/appengine/core/DownloadCloudSdkTaskConsoleListener.java b/src/main/java/com/google/cloud/tools/gradle/appengine/core/DownloadCloudSdkTaskConsoleListener.java index bfb62359..c2d08cc5 100644 --- a/src/main/java/com/google/cloud/tools/gradle/appengine/core/DownloadCloudSdkTaskConsoleListener.java +++ b/src/main/java/com/google/cloud/tools/gradle/appengine/core/DownloadCloudSdkTaskConsoleListener.java @@ -20,12 +20,13 @@ import com.google.cloud.tools.managedcloudsdk.ConsoleListener; import org.gradle.api.Project; import org.gradle.api.logging.LogLevel; +import org.gradle.api.logging.Logger; public class DownloadCloudSdkTaskConsoleListener implements ConsoleListener { - private Project project; + private Logger logger; - public DownloadCloudSdkTaskConsoleListener(Project project) { - this.project = project; + public DownloadCloudSdkTaskConsoleListener(Logger logger) { + this.logger = logger; } @Override @@ -36,7 +37,7 @@ public void console(String rawString) { // is that Gradle redirects standard output to its logging system at the QUIET level. So, in // order to print to LIFECYCLE without adding a newline, we just check that our desired level // is enabled before trying to print. - if (project.getLogger().isEnabled(LogLevel.LIFECYCLE)) { + if (logger.isEnabled(LogLevel.LIFECYCLE)) { System.out.print(rawString); } }