-
Notifications
You must be signed in to change notification settings - Fork 40
Avoid creating and configuring tasks when unnecessary #394
Conversation
However, this still doesn't work because
So when actually applied to a project, it fails:
|
Codecov Report
@@ Coverage Diff @@
## master GoogleCloudPlatform/app-gradle-plugin#394 +/- ##
============================================
- Coverage 75.76% 73.14% -2.62%
+ Complexity 277 275 -2
============================================
Files 42 43 +1
Lines 1073 1013 -60
Branches 41 42 +1
============================================
- Hits 813 741 -72
- Misses 242 255 +13
+ Partials 18 17 -1
Continue to review full report at Codecov.
|
Fixed the problem, and the integration tests are passing. However, I don't have strong confidence that it doesn't break anything. Previously, even after the integration tests passing, I encountered an error on a sample project. For now, I'll leave this in the draft state. |
src/main/java/com/google/cloud/tools/gradle/appengine/appyaml/AppEngineAppYamlPlugin.java
Outdated
Show resolved
Hide resolved
@@ -89,10 +91,10 @@ private void configureExtensions() { | |||
// we can only set the default location of "archive" after project evaluation (callback) | |||
if (stageExtension.getArtifact() == null) { | |||
if (project.getPlugins().hasPlugin(WarPlugin.class)) { | |||
War war = (War) project.getProperties().get("war"); | |||
War war = tasks.withType(War.class).getByName("war"); |
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.
For some reason that I don't know, the previous code was returning null.
Also I think the new code may still unnecessarily instantiate the war task.
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.
Right you are. It does instantiate create task.
The way to avoid task creation is stageExtension.setArtifact(tasks.named<War>(WarPlugin.WAR_TASK_NAME).map { it.getArchiveFile() })
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.
Removed getByName()
in another place in bae6dc2. I assume getProject().zipTree(object)
will work fine when given a TaskProvider
. (Previously, it was getting File
directly from getArchivePath()
.) Does this look good?
9018e56
to
877d1d0
Compare
if (injectDeployExtension) { | ||
project.afterEvaluate( | ||
project -> taskProvider.configure(task -> task.setDeployExtension(deployExtension))); | ||
} |
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.
What is the purpose of afterEvaluate
here?
It looks like task.setDeployExtension(deployExtension)
can be called during task registration.
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.
I have the same question. (I have never worked on this repo, and I don't have a lot of Gradle knowledge.)
What I can see is that deployExtension
is instantiated in the following way in Plugin.apply()
.
First, a parent extension is created with .create()
appengineExtension =
project.getExtensions().create("appengine", AppEngineAppYamlExtension.class);
and then the sub-extension (this
below is appengineExtension
created above)
deploy =
((ExtensionAware) this).getExtensions().create(DEPLOY_EXT, DeployExtension.class, project);
This deploy
is what is called deployExtension
in this class (if I am following the code flow correctly).
So the question is, do we still need to use afterEvaluate()
when calling setDeployExtension(deployExtension)
? I guess not, because it's just passing and setting a Java reference. But since I have never worked on this repo, I'm concerned there may be something that I'm not seeing. WDYT?
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.
I guess not, because it's just passing and setting a Java reference
Indeed. If the reference is not changed, then it can be passed without afterEvaluate
.
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.
stageExtension.setArtifact(war.getArchivePath()); | ||
} else if (project.getPlugins().hasPlugin(JavaPlugin.class)) { | ||
Jar jar = (Jar) project.getProperties().get("jar"); | ||
Jar jar = tasks.withType(Jar.class).getByName("jar"); |
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.
Same here: it is better to use tasks.named(...)
task.setStageDirectory(stageExtension.getStagingDirectory()); | ||
task.setDeployExtension(deploy); |
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.
If you use Property<...>
for stageExtension.getStagingDirectory
, then you could move this task configuration outside of afterEvaluate
.
project.afterEvaluate( | ||
project -> stage.configure(task -> task.setStagingConfig(stageExtension))); |
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.
Is afterEvaluate
needed here?
What can be done to continue here, who needs to do the review? |
Jar jar = (Jar) project.getProperties().get("jar"); | ||
stageExtension.setArtifact(jar.getArchivePath()); | ||
stageExtension.setArtifact( | ||
tasks.withType(Jar.class).named("jar").map(jar -> jar.getArchivePath())); |
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.
no need to create a filtered task collection:
tasks.withType(Jar.class).named("jar").map(jar -> jar.getArchivePath())); | |
tasks.named("jar", Jar.class).map(jar -> jar.getArchivePath())); |
Fixes GoogleCloudPlatform/appengine-plugins#1005.
Based on https://docs.gradle.org/current/userguide/task_configuration_avoidance.html