-
Notifications
You must be signed in to change notification settings - Fork 40
Remove usage of Project during task execution #455
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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(); | ||||||||||
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.
Suggested change
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. Don't take my usage of 5.1 as a guide :) I used the lowest possible point where the new API is available. During maintenance this makes the condition disappear faster than if it's at the point of deprecation. A more relevant discussion might be: #450 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. So the minimum supported version is Gradle 4.0, which means this suggestion can't work. I think the
but until then it's safe to use as the Alternatively we could use some other library to do the same. e.g.
or
or plain old Java 8 (assuming minimum supported version allows, what is the minimum Java for this plugin? Gradle 4.0 supports Java 7 minimum): Files.walk(pathToBeDeleted)
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete); and since the 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.
Suggested change
|
||||||||||
|
||||||||||
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()); | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,13 @@ | |
import com.google.cloud.tools.managedcloudsdk.ConsoleListener; | ||
import org.gradle.api.Project; | ||
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.
|
||
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); | ||
} | ||
} | ||
|
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.
Please do not import
org.gradle.api.internal
packages. Those are not meant for general use in plugin codeThere 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.
It's not possible to use the public API here, because it was added in Gradle 6.0 as you said.