-
Notifications
You must be signed in to change notification settings - Fork 461
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
Configuration cache, part 1 (play nice with others) #720
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c9f5cf5
We're going to need BuildService to fix configuration cache, and that…
nedtwigg ef8b077
Ensure that Spotless doesn't interfere with config cache when its tas…
nedtwigg 02ec8ee
Does spotless interfere with config cache if its tasks are configured…
nedtwigg fa01f46
Convert GitRatchetGradle into a BuildService, just to get around `bui…
nedtwigg 62794d4
Merge branch 'main' into feat/dont-break-config-cache
nedtwigg 2a43453
Run spotless to update PR for 2021.
nedtwigg 7ba9184
Let RegisterDependenciesTask properly declare its usage of the GitRat…
eskatos 2cf2705
Register GitRatchetGradle as an OperationCompletionListener
eskatos e13f97a
./gradlew :plugin-gradle:spotlessApply
eskatos dd1dd60
Some refinements on top of PR #720 (#937)
nedtwigg 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 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 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 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,5 +1,5 @@ | ||
/* | ||
* Copyright 2016-2020 DiffPlug | ||
* Copyright 2016-2021 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -20,23 +20,23 @@ | |
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Stream; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.execution.TaskExecutionGraph; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.provider.Provider; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.Internal; | ||
import org.gradle.api.tasks.OutputFile; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.build.event.BuildEventsListenerRegistry; | ||
|
||
import com.diffplug.common.base.Preconditions; | ||
import com.diffplug.common.io.Files; | ||
import com.diffplug.spotless.FormatterStep; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import groovy.lang.Closure; | ||
|
||
/** | ||
* NOT AN END-USER TASK, DO NOT USE FOR ANYTHING! | ||
* | ||
|
@@ -47,7 +47,7 @@ | |
* - When this "registerDependencies" task does its up-to-date check, it queries the task execution graph to see which | ||
* SpotlessTasks are at risk of being executed, and causes them all to be evaluated safely in the root buildscript. | ||
*/ | ||
public class RegisterDependenciesTask extends DefaultTask { | ||
public abstract class RegisterDependenciesTask extends DefaultTask { | ||
static final String TASK_NAME = "spotlessInternalRegisterDependencies"; | ||
|
||
@Input | ||
|
@@ -87,18 +87,13 @@ public GradleProvisioner.RootProvisioner getRootProvisioner() { | |
return rootProvisioner; | ||
} | ||
|
||
@SuppressWarnings({"rawtypes", "serial"}) | ||
void setup() { | ||
Preconditions.checkArgument(getProject().getRootProject() == getProject(), "Can only be used on the root project"); | ||
unitOutput = new File(getProject().getBuildDir(), "tmp/spotless-register-dependencies"); | ||
rootProvisioner = new GradleProvisioner.RootProvisioner(getProject()); | ||
getProject().getGradle().buildFinished(new Closure(null) { | ||
@SuppressFBWarnings("UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS") | ||
public Object doCall() { | ||
gitRatchet.close(); | ||
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. Here is where we used to call |
||
return null; | ||
} | ||
}); | ||
Provider<GitRatchetGradle> gitRatchetProvider = getProject().getGradle().getSharedServices().registerIfAbsent("GitRatchetGradle", GitRatchetGradle.class, unused -> {}); | ||
getBuildEventsListenerRegistry().onTaskCompletion(gitRatchetProvider); | ||
getGitRatchet().set(gitRatchetProvider); | ||
} | ||
|
||
@TaskAction | ||
|
@@ -107,10 +102,9 @@ public void trivialFunction() throws IOException { | |
Files.write(Integer.toString(getSteps().size()), unitOutput, StandardCharsets.UTF_8); | ||
} | ||
|
||
GitRatchetGradle gitRatchet = new GitRatchetGradle(); | ||
|
||
@Internal | ||
GitRatchetGradle getGitRatchet() { | ||
return gitRatchet; | ||
} | ||
public abstract Property<GitRatchetGradle> getGitRatchet(); | ||
|
||
@Inject | ||
protected abstract BuildEventsListenerRegistry getBuildEventsListenerRegistry(); | ||
} |
This file contains 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
69 changes: 69 additions & 0 deletions
69
plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2020-2021 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.gradle.spotless; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
public class ConfigurationCacheTest extends GradleIntegrationHarness { | ||
protected void runTasks(String... tasks) throws IOException { | ||
setFile("gradle.properties").toContent("org.gradle.unsafe.configuration-cache=true"); | ||
List<String> args = new ArrayList<>(); | ||
args.addAll(Arrays.asList(tasks)); | ||
gradleRunner() | ||
.withGradleVersion(GradleVersionSupport.CONFIGURATION_CACHE.version) | ||
.withArguments(args) | ||
.forwardOutput() | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void helpConfigures() throws IOException { | ||
setFile("build.gradle").toLines( | ||
"buildscript { repositories { mavenCentral() } }", | ||
"plugins {", | ||
" id 'com.diffplug.spotless'", | ||
"}", | ||
"apply plugin: 'java'", | ||
"spotless {", | ||
" java {", | ||
" googleJavaFormat('1.2')", | ||
" }", | ||
"}"); | ||
runTasks("help"); | ||
} | ||
|
||
@Test | ||
public void helpConfiguresIfTasksAreCreated() throws IOException { | ||
setFile("build.gradle").toLines( | ||
"buildscript { repositories { mavenCentral() } }", | ||
"plugins {", | ||
" id 'com.diffplug.spotless'", | ||
"}", | ||
"apply plugin: 'java'", | ||
"spotless {", | ||
" java {", | ||
" googleJavaFormat('1.2')", | ||
" }", | ||
"}", | ||
"tasks.named('spotlessJavaApply').get()"); | ||
runTasks("help"); | ||
} | ||
} |
This file contains 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 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 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
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.
Just want to confirm that we don't need to call
close()
here?GitRatchet implements AutoCloseable
, so if Gradle is promising to callclose()
then I guess we're good, but it's odd that there's also anonFinish()
which seems like it would get called at the same time asclose()
?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.
OperationCompletionListener.onFinish
is called on each "task finish" event.AutoCloseable.close
is called at the end of the build.My understanding is that we are good.