From 8d5a9661968ad41fda07374eb03005d6c08e75d9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 1 Jun 2020 17:53:57 -0700 Subject: [PATCH 1/7] Update our dogfood to latest, and adjust for the 4.x deprecations --- gradle/spotless-freshmark.gradle | 3 +-- gradle/spotless.gradle | 1 - settings.gradle | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/gradle/spotless-freshmark.gradle b/gradle/spotless-freshmark.gradle index 7209160501..be8a646950 100644 --- a/gradle/spotless-freshmark.gradle +++ b/gradle/spotless-freshmark.gradle @@ -39,8 +39,7 @@ if (tasks.names.contains('changelogCheck')) { // that uses versionNext as versionLast it.put('versionLast', spotlessChangelog.versionNext) } - def changelogBumpFreshmark = freshmark.createIndependentTask('changelogBumpFreshmark') - changelogBumpFreshmark.setApply() + def changelogBumpFreshmark = freshmark.createIndependentApplyTask('changelogBumpFreshmark') // freshmark should run after the changelog bump changelogBumpFreshmark.dependsOn tasks.named('changelogBump') diff --git a/gradle/spotless.gradle b/gradle/spotless.gradle index 151b6dd58e..68bedd2e1b 100644 --- a/gradle/spotless.gradle +++ b/gradle/spotless.gradle @@ -26,7 +26,6 @@ spotless { } groovyGradle { target '*.gradle' - paddedCell() greclipse().configFile rootProject.files('gradle/spotless.eclipseformat.xml', 'gradle/spotless.groovyformat.prefs') } } diff --git a/settings.gradle b/settings.gradle index 4cb4fb69b4..037f976152 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.gradle.spotless' version '3.27.0' + id 'com.diffplug.gradle.spotless' version '4.2.0' } } plugins { From ca14257360de6e0311e48076110add43cb0ad9d8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 2 Jun 2020 16:23:27 -0700 Subject: [PATCH 2/7] Use ratchet to update license headers. --- gradle/spotless.gradle | 1 + gradle/spotless.license | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/gradle/spotless.gradle b/gradle/spotless.gradle index 68bedd2e1b..0767695657 100644 --- a/gradle/spotless.gradle +++ b/gradle/spotless.gradle @@ -15,6 +15,7 @@ spotless { if (project.name != 'ide' && project != rootProject) { // the rootProject and ide projects don't have any java java { + ratchetFrom 'origin/master' custom 'noInternalDeps', noInternalDepsClosure bumpThisNumberIfACustomStepChanges(1) licenseHeaderFile rootProject.file('gradle/spotless.license') diff --git a/gradle/spotless.license b/gradle/spotless.license index d8ca549797..924be6aed3 100644 --- a/gradle/spotless.license +++ b/gradle/spotless.license @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright $YEAR DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 0a45d8d23627148c0cc927cdd329747bb93e2f18 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 3 Jun 2020 00:03:38 -0700 Subject: [PATCH 3/7] Update SelfTest. --- .../diffplug/gradle/spotless/SelfTest.java | 108 +++++------------- 1 file changed, 31 insertions(+), 77 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java index 1457b7630d..1e97e5f1cb 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,123 +16,77 @@ package com.diffplug.gradle.spotless; import java.io.File; +import java.util.ArrayList; +import java.util.List; import java.util.function.Consumer; +import org.gradle.api.Action; import org.gradle.api.Project; import org.gradle.api.tasks.incremental.IncrementalTaskInputs; import org.gradle.testkit.runner.GradleRunner; -import org.junit.Ignore; -import org.junit.Test; -import com.diffplug.common.base.Errors; import com.diffplug.common.base.StandardSystemProperty; +import com.diffplug.common.collect.MoreCollectors; import com.diffplug.spotless.TestProvisioner; /** * If you'd like to step through the full spotless plugin, * these tests make that easier. Uncomment ignore to do it. */ -@Ignore public class SelfTest { - enum Type { - CHECK { - @Override - public void runAllTasks(Project project) { - project.getTasks().stream() - .filter(task -> task instanceof SpotlessTask) - .map(task -> (SpotlessTask) task) - .forEach(task -> Errors.rethrow().run(() -> { - IncrementalTaskInputs inputs = Mocks.mockIncrementalTaskInputs(task.getTarget()); - task.performAction(inputs); - })); - } - - @Override - public T checkApply(T check, T apply) { - return check; - } - }, - APPLY { - @Override - public void runAllTasks(Project project) { - project.getTasks().stream() - .filter(task -> task instanceof SpotlessTask) - .map(task -> (SpotlessTask) task) - .forEach(task -> Errors.rethrow().run(() -> { - IncrementalTaskInputs inputs = Mocks.mockIncrementalTaskInputs(task.getTarget()); - task.performAction(inputs); - })); - } - - @Override - public T checkApply(T check, T apply) { - return apply; - } - }; - - public abstract void runAllTasks(Project project); - - public abstract T checkApply(T check, T apply); - } - - @Test - public void spotlessApply() throws Exception { - runTasksManually(Type.APPLY); - } - - @Test - public void spotlessCheck() throws Exception { - runTasksManually(Type.CHECK); + public static void main(String[] args) throws Exception { + //runTaskManually(); + runWithTestKit("spotlessApply"); } /** Runs a full task manually, so you can step through all the logic. */ - private static void runTasksManually(Type type) throws Exception { + private static void runTaskManually() throws Exception { Project project = createProject(extension -> { + extension.ratchetFrom("origin/master"); extension.java(java -> { - java.target("**/*.java"); - java.licenseHeaderFile("spotless.license.java"); - java.importOrderFile("spotless.importorder"); - java.eclipse().configFile("spotless.eclipseformat.xml"); + java.target("src/*/java/**/*.java"); + java.licenseHeaderFile("../gradle/spotless.license"); + java.importOrderFile("../gradle/spotless.importorder"); + java.eclipse().configFile("../gradle/spotless.eclipseformat.xml"); java.trimTrailingWhitespace(); - java.customLazy("Lambda fix", () -> raw -> { - if (!raw.contains("public class SelfTest ")) { - // don't format this line away, lol - return raw.replace("} )", "})").replace("} ,", "},"); - } else { - return raw; - } - }); - }); - extension.format("misc", misc -> { - misc.target("**/*.gradle", "**/*.md", "**/*.gitignore"); - misc.indentWithTabs(); - misc.trimTrailingWhitespace(); - misc.endWithNewline(); + java.removeUnusedImports(); }); }); - type.runAllTasks(project); + project.getBuildscript().getRepositories().mavenCentral(); + SpotlessTask onlyTask = project.getTasks().stream() + .filter(task -> task instanceof SpotlessTask) + .map(task -> (SpotlessTask) task) + .collect(MoreCollectors.singleOrEmpty()).get(); + + IncrementalTaskInputs inputs = Mocks.mockIncrementalTaskInputs(onlyTask.getTarget()); + onlyTask.performAction(inputs); + // it will run forever with empty threads, so we have to kill it + System.exit(0); } /** Creates a Project which has had the SpotlessExtension setup. */ private static Project createProject(Consumer test) throws Exception { + List> afterEvaluate = new ArrayList<>(); + //Project project = Mocks.mockProject(TestProvisioner.gradleProject(new File("").getAbsoluteFile()), afterEvaluate); Project project = TestProvisioner.gradleProject(new File("").getAbsoluteFile()); // create the spotless plugin SpotlessPlugin plugin = project.getPlugins().apply(SpotlessPlugin.class); // setup the plugin test.accept(plugin.getExtension()); + // run the afterEvaluate section + ((ProjectInternal) project).getProjectEvaluationBroadcaster().afterEvaluate(project, project.getState()); // return the configured plugin return project; } /** Runs against the `spotlessSelfApply.gradle` file. */ - static void runWithTestKit(Type type) throws Exception { + static void runWithTestKit(String taskType) throws Exception { GradleRunner.create() .withPluginClasspath() .withProjectDir(new File(StandardSystemProperty.USER_DIR.value()).getParentFile()) .withArguments( - "--build-file", "spotlessSelf.gradle", "--project-cache-dir", ".gradle-selfapply", - "spotless" + type.checkApply("Check", "Apply"), + taskType, "--stacktrace") .forwardOutput() .build(); From f59e724a09bf62f2c01e4a200b1bd7105c63b6c1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 3 Jun 2020 00:08:25 -0700 Subject: [PATCH 4/7] Update changelog. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index a3ed84cea6..caa714dadc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +* Build now uses `ratchetFrom` and `licenseHeader` with a `$YEAR` token to ensure that Spotless copyright headers stay up-to-date without adding noise to file history. ([#595](https://github.com/diffplug/spotless/pull/595)) ## [1.33.0] - 2020-06-03 ### Added From efe9faf48fe5a3ca3456d4f351972796efb566a1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 3 Jun 2020 00:17:15 -0700 Subject: [PATCH 5/7] Fix SelfTest import. --- gradle/spotless.gradle | 2 +- .../src/test/java/com/diffplug/gradle/spotless/SelfTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/gradle/spotless.gradle b/gradle/spotless.gradle index 0767695657..9fe948ba1b 100644 --- a/gradle/spotless.gradle +++ b/gradle/spotless.gradle @@ -6,7 +6,7 @@ spotless { * No good way to get around using this import: * https://github.com/gradle/gradle/issues/3191 */ - String regex = "import org\\.gradle\\.api\\.internal\\.(?!plugins\\.DslObject)" + String regex = "import org\\.gradle\\.api\\.internal\\.(?!plugins\\.DslObject)(?!project\\.ProjectInternal)" if ((text.contains('import org.gradle.internal.') || text.find(regex)) && !text.contains('def noInternalDepsClosure')) { throw new AssertionError("Accidental internal import") diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java index 1e97e5f1cb..672ec233b6 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java @@ -22,6 +22,7 @@ import org.gradle.api.Action; import org.gradle.api.Project; +import org.gradle.api.internal.project.ProjectInternal; import org.gradle.api.tasks.incremental.IncrementalTaskInputs; import org.gradle.testkit.runner.GradleRunner; From bd906b6299b001990db58735918a8313cc719566 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 3 Jun 2020 00:21:06 -0700 Subject: [PATCH 6/7] Fix now-broken mains. --- .../diffplug/gradle/spotless/SelfTest.java | 8 ++----- .../gradle/spotless/SelfTestApply.java | 22 ------------------- .../gradle/spotless/SelfTestCheck.java | 22 ------------------- 3 files changed, 2 insertions(+), 50 deletions(-) delete mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTestApply.java delete mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTestCheck.java diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java index 672ec233b6..78867d26ef 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java @@ -16,11 +16,8 @@ package com.diffplug.gradle.spotless; import java.io.File; -import java.util.ArrayList; -import java.util.List; import java.util.function.Consumer; -import org.gradle.api.Action; import org.gradle.api.Project; import org.gradle.api.internal.project.ProjectInternal; import org.gradle.api.tasks.incremental.IncrementalTaskInputs; @@ -36,8 +33,8 @@ */ public class SelfTest { public static void main(String[] args) throws Exception { - //runTaskManually(); - runWithTestKit("spotlessApply"); + runTaskManually(); + //runWithTestKit("spotlessApply"); } /** Runs a full task manually, so you can step through all the logic. */ @@ -67,7 +64,6 @@ private static void runTaskManually() throws Exception { /** Creates a Project which has had the SpotlessExtension setup. */ private static Project createProject(Consumer test) throws Exception { - List> afterEvaluate = new ArrayList<>(); //Project project = Mocks.mockProject(TestProvisioner.gradleProject(new File("").getAbsoluteFile()), afterEvaluate); Project project = TestProvisioner.gradleProject(new File("").getAbsoluteFile()); // create the spotless plugin diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTestApply.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTestApply.java deleted file mode 100644 index f614f74a84..0000000000 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTestApply.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2016 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; - -public class SelfTestApply { - public static void main(String[] args) throws Exception { - SelfTest.runWithTestKit(SelfTest.Type.APPLY); - } -} diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTestCheck.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTestCheck.java deleted file mode 100644 index 2fe94115fc..0000000000 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTestCheck.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2016 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; - -public class SelfTestCheck { - public static void main(String[] args) throws Exception { - SelfTest.runWithTestKit(SelfTest.Type.CHECK); - } -} From 03c1f077497f74716b1d2319afde29460dfd48bc Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 3 Jun 2020 00:32:15 -0700 Subject: [PATCH 7/7] Improve changelog wording. --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index caa714dadc..7192fa2e6e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] -* Build now uses `ratchetFrom` and `licenseHeader` with a `$YEAR` token to ensure that Spotless copyright headers stay up-to-date without adding noise to file history. ([#595](https://github.com/diffplug/spotless/pull/595)) +* We are now dogfooding `ratchetFrom` and `licenseHeader` with a `$YEAR` token to ensure that Spotless copyright headers stay up-to-date without adding noise to file history. ([#595](https://github.com/diffplug/spotless/pull/595)) ## [1.33.0] - 2020-06-03 ### Added