Skip to content
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

Remove Java files from default Maven Groovy formatting #1051

Merged
merged 4 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [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 `<groovy>` 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`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small correction. I removed the following file masks:

  • src/main/java/**/*.java
  • src/test/java/**/*.java

The Groovy formatter tried to format Java sources that live under the Java sources root. I think it is weird and perhaps even undesirable to format such source files with a Groovy formatter. This PR changes the default behavior, but it is more like a fix in my opinion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man that is super weird! It's so weird my brain couldn't read it the first time, thanks for pointing that out! I always agreed that it was a fix, but now I also agree that it is not a "breaking fix".

* `src/test/groovy/**/*.java`
* This release just removes the `.java` includes.

## [2.18.0] - 2021-12-23
### Added
Expand Down
2 changes: 0 additions & 2 deletions plugin-maven/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ This is a workaround to a [pending issue](https://github.com/diffplug/spotless/i
<includes>
<include>src/main/groovy/**/*.groovy</include>
<include>src/test/groovy/**/*.groovy</include>
<include>src/main/java/**/*.java</include>
<include>src/test/java/**/*.java</include>
</includes>

<importOrder /> <!-- standard import order -->
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -29,7 +29,7 @@
*/
public class Groovy extends FormatterFactory {

private static final Set<String> DEFAULT_INCLUDES = ImmutableSet.of("src/main/groovy/**/*.groovy", "src/test/groovy/**/*.groovy", "src/main/java/**/*.java", "src/test/java/**/*.java");
private static final Set<String> DEFAULT_INCLUDES = ImmutableSet.of("src/main/groovy/**/*.groovy", "src/test/groovy/**/*.groovy");
private static final String LICENSE_HEADER_DELIMITER = "package ";

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ void fromContentGroovy() throws Exception {
"// Does it help to have it in writing?",
" </content>",
"</licenseHeader>");
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,16 +25,43 @@ class GrEclipseTest extends MavenIntegrationHarness {

@Test
void testEclipse() throws Exception {
writePomWithGroovySteps(
"<greclipse>",
" <file>${basedir}/greclipse.properties</file>",
" <version>4.12.0</version>",
"</greclipse>");
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(
"<greclipse>",
" <file>${basedir}/greclipse.properties</file>",
" <version>4.19.0</version>",
"</greclipse>");
setFile("greclipse.properties").toResource("groovy/greclipse/format/greclipse.properties");
}
}