Skip to content

Commit

Permalink
Remove usage of Project during task execution
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
liutikas committed Mar 1, 2023
1 parent 33babd4 commit 3e26e26
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 3e26e26

Please sign in to comment.