From 637f1628d1c9555b184dd66044f80bd3e7056538 Mon Sep 17 00:00:00 2001 From: Kostiantyn Liutovych Date: Mon, 27 Dec 2021 11:40:35 +0100 Subject: [PATCH 1/3] Remove Java files from default Maven Groovy formatting All Groovy formatters will default to formatting only the following files: * src/main/groovy/**/*.groovy * src/test/groovy/**/*.groovy They will not touch any .*java files. Fixes #902. --- plugin-maven/CHANGES.md | 2 + plugin-maven/README.md | 2 - .../spotless/maven/groovy/Groovy.java | 4 +- .../maven/generic/LicenseHeaderTest.java | 6 ++- .../spotless/maven/groovy/GrEclipseTest.java | 41 ++++++++++++++++--- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 34922ebf0a..f850c794a0 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Remove Java files from default Maven Groovy formatting ([#1051](https://github.com/diffplug/spotless/pull/1051)). ## [2.18.0] - 2021-12-23 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 9c5a20b5ab..316291d38a 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -246,8 +246,6 @@ This is a workaround to a [pending issue](https://github.com/diffplug/spotless/i src/main/groovy/**/*.groovy src/test/groovy/**/*.groovy - src/main/java/**/*.java - src/test/java/**/*.java diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java index efd8b15cad..e9b3c6c412 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * 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. @@ -29,7 +29,7 @@ */ public class Groovy extends FormatterFactory { - private static final Set DEFAULT_INCLUDES = ImmutableSet.of("src/main/groovy/**/*.groovy", "src/test/groovy/**/*.groovy", "src/main/java/**/*.java", "src/test/java/**/*.java"); + private static final Set DEFAULT_INCLUDES = ImmutableSet.of("src/main/groovy/**/*.groovy", "src/test/groovy/**/*.groovy"); private static final String LICENSE_HEADER_DELIMITER = "package "; @Override diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java index 16be28e6f3..92d74bc659 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java @@ -60,7 +60,11 @@ void fromContentGroovy() throws Exception { "// Does it help to have it in writing?", " ", ""); - runTest(); + + String path = "src/main/groovy/test.groovy"; + setFile(path).toResource("license/MissingLicense.test"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("license/HasLicense.test"); } @Test diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.java index 9c95b73fd1..8807f47cc9 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.java @@ -15,6 +15,8 @@ */ package com.diffplug.spotless.maven.groovy; +import java.io.IOException; + import org.junit.jupiter.api.Test; import com.diffplug.spotless.maven.MavenIntegrationHarness; @@ -23,16 +25,43 @@ class GrEclipseTest extends MavenIntegrationHarness { @Test void testEclipse() throws Exception { - writePomWithGroovySteps( - "", - " ${basedir}/greclipse.properties", - " 4.12.0", - ""); - setFile("greclipse.properties").toResource("groovy/greclipse/format/greclipse.properties"); + writePomWithGrEclipse(); String path = "src/main/groovy/test.groovy"; setFile(path).toResource("groovy/greclipse/format/unformatted.test"); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).sameAsResource("groovy/greclipse/format/formatted.test"); } + + @Test + void doesNotFormatJavaFiles() throws Exception { + writePomWithGrEclipse(); + + String javaPath = "src/main/java/test.java"; + String testJavaPath = "src/test/java/test.java"; + setFile(javaPath).toResource("java/googlejavaformat/JavaCodeUnformatted.test"); + setFile(testJavaPath).toResource("java/googlejavaformat/JavaCodeUnformatted.test"); + + String groovyPath = "src/main/groovy/test.groovy"; + String testGroovyPath = "src/test/groovy/test.groovy"; + setFile(groovyPath).toResource("groovy/greclipse/format/unformatted.test"); + setFile(testGroovyPath).toResource("groovy/greclipse/format/unformatted.test"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + assertFile(javaPath).sameAsResource("java/googlejavaformat/JavaCodeUnformatted.test"); + assertFile(testJavaPath).sameAsResource("java/googlejavaformat/JavaCodeUnformatted.test"); + + assertFile(groovyPath).sameAsResource("groovy/greclipse/format/formatted.test"); + assertFile(testGroovyPath).sameAsResource("groovy/greclipse/format/formatted.test"); + } + + private void writePomWithGrEclipse() throws IOException { + writePomWithGroovySteps( + "", + " ${basedir}/greclipse.properties", + " 4.19.0", + ""); + setFile("greclipse.properties").toResource("groovy/greclipse/format/greclipse.properties"); + } } From bdbeb9c43d1e8688fc0253e20b102de3e94566c0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 29 Dec 2021 17:50:31 -0800 Subject: [PATCH 2/3] Add more detail to the changelog, and clearly mark this as a breaking change. --- plugin-maven/CHANGES.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f850c794a0..683d0785f2 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed -* Remove Java files from default Maven Groovy formatting ([#1051](https://github.com/diffplug/spotless/pull/1051)). +* **BREAKING** Remove Java files from default Maven Groovy formatting ([#1051](https://github.com/diffplug/spotless/pull/1051)). + * This breaking change affects you only if you are using the `` language block **and** you have `.java` files located within `src/main/groovy` or `src/test/groovy`. + * Before `3.0.0`, the default target of groovy was + * `src/main/groovy/**/*.groovy` + * `src/test/groovy/**/*.groovy` + * `src/main/groovy/**/*.java` + * `src/test/groovy/**/*.java` + * This release just removes the `.java` includes. ## [2.18.0] - 2021-12-23 ### Added From a93c79b0d1a8bf7f699d1de48934f2c065f816a3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 30 Dec 2021 18:49:42 -0800 Subject: [PATCH 3/3] The previous behavior was weirder than I had realized, weird enough that it is no longer a "breaking fix". --- plugin-maven/CHANGES.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 683d0785f2..800df98dd3 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,14 +4,13 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed -* **BREAKING** Remove Java files from default Maven Groovy formatting ([#1051](https://github.com/diffplug/spotless/pull/1051)). - * This breaking change affects you only if you are using the `` language block **and** you have `.java` files located within `src/main/groovy` or `src/test/groovy`. - * Before `3.0.0`, the default target of groovy was +* Remove Java files from default Maven Groovy formatting ([#1051](https://github.com/diffplug/spotless/pull/1051)). + * Before this release, the default target of groovy was * `src/main/groovy/**/*.groovy` * `src/test/groovy/**/*.groovy` - * `src/main/groovy/**/*.java` - * `src/test/groovy/**/*.java` - * This release just removes the `.java` includes. + * `src/main/java/**/*.java` + * `src/test/java/**/*.java` + * This release removes the `.java` includes. ## [2.18.0] - 2021-12-23 ### Added