Skip to content

Commit

Permalink
Fix Config Cache External Process Issue (#1777 fixes #1644 and #1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Aug 7, 2023
2 parents 8b1713d + 35be272 commit b99ec3d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Fixed
* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
* Fix configuration cache failure when using LineEnding.GIT_ATTRIBUTES ([#1644](https://github.com/diffplug/spotless/issues/1644))
### Changes
* Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761))
* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.file.ConfigurableFileTree;
import org.gradle.api.file.Directory;
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.tasks.TaskProvider;
Expand Down Expand Up @@ -925,7 +926,8 @@ protected void setupTask(SpotlessTask task) {
steps.replaceAll(formatterStep -> formatterStep.filterByContent(OnMatch.EXCLUDE, targetExcludeContentPattern));
}
task.setSteps(steps);
task.setLineEndingsPolicy(getLineEndings().createPolicy(getProject().getProjectDir(), () -> totalTarget));
Directory projectDir = getProject().getLayout().getProjectDirectory();
task.setLineEndingsPolicy(getProject().provider(() -> getLineEndings().createPolicy(projectDir.getAsFile(), () -> totalTarget)));
spotless.getRegisterDependenciesTask().hookSubprojectTask(task);
task.setupRatchet(getRatchetFrom() != null ? getRatchetFrom() : "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileCollection;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Internal;
Expand Down Expand Up @@ -64,14 +65,14 @@ public void setEncoding(String encoding) {
this.encoding = Objects.requireNonNull(encoding);
}

protected final LiveCache<LineEnding.Policy> lineEndingsPolicy = createLive("lineEndingsPolicy");
protected final LiveCache<Provider<LineEnding.Policy>> lineEndingsPolicy = createLive("lineEndingsPolicy");

@Input
public LineEnding.Policy getLineEndingsPolicy() {
public Provider<LineEnding.Policy> getLineEndingsPolicy() {
return lineEndingsPolicy.get();
}

public void setLineEndingsPolicy(LineEnding.Policy lineEndingsPolicy) {
public void setLineEndingsPolicy(Provider<LineEnding.Policy> lineEndingsPolicy) {
this.lineEndingsPolicy.set(lineEndingsPolicy);
}

Expand Down Expand Up @@ -185,7 +186,7 @@ String formatName() {
Formatter buildFormatter() {
return Formatter.builder()
.name(formatName())
.lineEndingsPolicy(lineEndingsPolicy.get())
.lineEndingsPolicy(lineEndingsPolicy.get().get())
.encoding(Charset.forName(encoding))
.rootDir(getProjectDir().get().getAsFile().toPath())
.steps(steps.get())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 DiffPlug
* Copyright 2016-2023 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -62,7 +62,7 @@ public BuildServiceParameters.None getParameters() {
private SpotlessTaskImpl createFormatTask(String name) {
SpotlessTaskImpl task = project.getTasks().create("spotless" + SpotlessPlugin.capitalize(name), SpotlessTaskImpl.class);
task.init(taskService);
task.setLineEndingsPolicy(LineEnding.UNIX.createPolicy());
task.setLineEndingsPolicy(project.provider(LineEnding.UNIX::createPolicy));
task.setTarget(Collections.singletonList(file));
return task;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ private Bundle create(File... files) throws IOException {

private Bundle create(List<File> files) throws IOException {
Bundle bundle = new Bundle("underTest");
bundle.task.setLineEndingsPolicy(LineEnding.UNIX.createPolicy());
bundle.task.setLineEndingsPolicy(bundle.project.provider(LineEnding.UNIX::createPolicy));
bundle.task.setTarget(files);
return bundle;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2023 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,7 +35,7 @@ class FormatTaskTest extends ResourceHarness {
void createTask() {
Project project = TestProvisioner.gradleProject(rootFolder());
spotlessTask = project.getTasks().create("spotlessTaskUnderTest", SpotlessTaskImpl.class);
spotlessTask.setLineEndingsPolicy(LineEnding.UNIX.createPolicy());
spotlessTask.setLineEndingsPolicy(project.provider(LineEnding.UNIX::createPolicy));
spotlessTask.init(GradleIntegrationHarness.providerOf(new SpotlessTaskService() {
@Override
public BuildServiceParameters.None getParameters() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2023 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,7 +66,7 @@ private SpotlessTaskImpl createFormatTask(String name, FormatterStep step) {
SpotlessTaskImpl task = project.getTasks().create("spotless" + SpotlessPlugin.capitalize(name), SpotlessTaskImpl.class);
task.init(taskService);
task.addStep(step);
task.setLineEndingsPolicy(LineEnding.UNIX.createPolicy());
task.setLineEndingsPolicy(project.provider(LineEnding.UNIX::createPolicy));
task.setTarget(Collections.singletonList(file));
return task;
}
Expand Down

0 comments on commit b99ec3d

Please sign in to comment.