Skip to content

Commit 13515b5

Browse files
committed
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.
1 parent eddfc38 commit 13515b5

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

plugin-maven/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ This is a workaround to a [pending issue](https://github.com/diffplug/spotless/i
246246
<includes>
247247
<include>src/main/groovy/**/*.groovy</include>
248248
<include>src/test/groovy/**/*.groovy</include>
249-
<include>src/main/java/**/*.java</include>
250-
<include>src/test/java/**/*.java</include>
251249
</includes>
252250

253251
<importOrder /> <!-- standard import order -->

plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 DiffPlug
2+
* Copyright 2020-2021 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@
2929
*/
3030
public class Groovy extends FormatterFactory {
3131

32-
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");
32+
private static final Set<String> DEFAULT_INCLUDES = ImmutableSet.of("src/main/groovy/**/*.groovy", "src/test/groovy/**/*.groovy");
3333
private static final String LICENSE_HEADER_DELIMITER = "package ";
3434

3535
@Override

plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.java

+35-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.diffplug.spotless.maven.groovy;
1717

18+
import java.io.IOException;
19+
1820
import org.junit.jupiter.api.Test;
1921

2022
import com.diffplug.spotless.maven.MavenIntegrationHarness;
@@ -23,16 +25,43 @@ class GrEclipseTest extends MavenIntegrationHarness {
2325

2426
@Test
2527
void testEclipse() throws Exception {
26-
writePomWithGroovySteps(
27-
"<greclipse>",
28-
" <file>${basedir}/greclipse.properties</file>",
29-
" <version>4.12.0</version>",
30-
"</greclipse>");
31-
setFile("greclipse.properties").toResource("groovy/greclipse/format/greclipse.properties");
28+
writePomWithGrEclipse();
3229

3330
String path = "src/main/groovy/test.groovy";
3431
setFile(path).toResource("groovy/greclipse/format/unformatted.test");
3532
mavenRunner().withArguments("spotless:apply").runNoError();
3633
assertFile(path).sameAsResource("groovy/greclipse/format/formatted.test");
3734
}
35+
36+
@Test
37+
void doesNotFormatJavaFiles() throws Exception {
38+
writePomWithGrEclipse();
39+
40+
String javaPath = "src/main/java/test.java";
41+
String testJavaPath = "src/test/java/test.java";
42+
setFile(javaPath).toResource("java/googlejavaformat/JavaCodeUnformatted.test");
43+
setFile(testJavaPath).toResource("java/googlejavaformat/JavaCodeUnformatted.test");
44+
45+
String groovyPath = "src/main/groovy/test.groovy";
46+
String testGroovyPath = "src/test/groovy/test.groovy";
47+
setFile(groovyPath).toResource("groovy/greclipse/format/unformatted.test");
48+
setFile(testGroovyPath).toResource("groovy/greclipse/format/unformatted.test");
49+
50+
mavenRunner().withArguments("spotless:apply").runNoError();
51+
52+
assertFile(javaPath).sameAsResource("java/googlejavaformat/JavaCodeUnformatted.test");
53+
assertFile(testJavaPath).sameAsResource("java/googlejavaformat/JavaCodeUnformatted.test");
54+
55+
assertFile(groovyPath).sameAsResource("groovy/greclipse/format/formatted.test");
56+
assertFile(testGroovyPath).sameAsResource("groovy/greclipse/format/formatted.test");
57+
}
58+
59+
private void writePomWithGrEclipse() throws IOException {
60+
writePomWithGroovySteps(
61+
"<greclipse>",
62+
" <file>${basedir}/greclipse.properties</file>",
63+
" <version>4.19.0</version>",
64+
"</greclipse>");
65+
setFile("greclipse.properties").toResource("groovy/greclipse/format/greclipse.properties");
66+
}
3867
}

0 commit comments

Comments
 (0)