From 595cecdb97437e3b7440ac1ec9cab2c7567c1c12 Mon Sep 17 00:00:00 2001 From: Tyler Bertrand Date: Tue, 1 Aug 2023 19:54:44 -0500 Subject: [PATCH 1/3] Utilize providers for line endings This way the external git processes are launched at execution time and not during configuration --- .../com/diffplug/gradle/spotless/FormatExtension.java | 4 +++- .../java/com/diffplug/gradle/spotless/SpotlessTask.java | 9 +++++---- .../gradle/spotless/DiffMessageFormatterTest.java | 4 ++-- .../com/diffplug/gradle/spotless/FormatTaskTest.java | 2 +- .../com/diffplug/gradle/spotless/PaddedCellTaskTest.java | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index e28ec13dcd..7a62f8cabf 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -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; @@ -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() : ""); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java index c23cea0845..2af9a80b7a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java @@ -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; @@ -64,14 +65,14 @@ public void setEncoding(String encoding) { this.encoding = Objects.requireNonNull(encoding); } - protected final LiveCache lineEndingsPolicy = createLive("lineEndingsPolicy"); + protected final LiveCache> lineEndingsPolicy = createLive("lineEndingsPolicy"); @Input - public LineEnding.Policy getLineEndingsPolicy() { + public Provider getLineEndingsPolicy() { return lineEndingsPolicy.get(); } - public void setLineEndingsPolicy(LineEnding.Policy lineEndingsPolicy) { + public void setLineEndingsPolicy(Provider lineEndingsPolicy) { this.lineEndingsPolicy.set(lineEndingsPolicy); } @@ -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()) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java index ef72043a47..c564664f10 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java @@ -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; } @@ -100,7 +100,7 @@ private Bundle create(File... files) throws IOException { private Bundle create(List 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; } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java index 8985cd7a14..c4c055c799 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java @@ -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() { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java index bc7a2fdc96..db55077d00 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java @@ -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; } From 2c33cd319b73f1aa5b86cef2414ebd6656f8f6f1 Mon Sep 17 00:00:00 2001 From: Tyler Bertrand Date: Wed, 2 Aug 2023 15:29:22 -0500 Subject: [PATCH 2/3] Update plugin-gradle changelog --- plugin-gradle/CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b21debb36f..5ffc7912ba 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -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)) From 35be272b300d9a3a4a939b706728050cbf1b9c69 Mon Sep 17 00:00:00 2001 From: Tyler Bertrand Date: Thu, 3 Aug 2023 20:17:56 -0500 Subject: [PATCH 3/3] spotlessApply --- .../com/diffplug/gradle/spotless/DiffMessageFormatterTest.java | 2 +- .../test/java/com/diffplug/gradle/spotless/FormatTaskTest.java | 2 +- .../java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java index c564664f10..bc556ac06e 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java @@ -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. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java index c4c055c799..ddd813468d 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java @@ -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. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java index db55077d00..4fe78d884d 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java @@ -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.