Skip to content

Commit d540ada

Browse files
authored
Merge pull request #60 from ajoberstar/alljava
Detect all Java source by default
2 parents b8fa86a + 58f7da6 commit d540ada

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/main/java/com/diffplug/gradle/spotless/java/JavaExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected void setupTask(FormatTask task) throws Exception {
8181
}
8282
UnionFileCollection union = new UnionFileCollection();
8383
for (SourceSet sourceSet : javaPlugin.getSourceSets()) {
84-
union.add(sourceSet.getJava());
84+
union.add(sourceSet.getAllJava());
8585
}
8686
target = union;
8787
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2016 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.gradle.spotless.java;
17+
18+
import java.io.IOException;
19+
20+
import org.junit.Assert;
21+
import org.junit.Test;
22+
23+
import com.diffplug.gradle.spotless.GradleIntegrationTest;
24+
25+
public class JavaDefaultTargetTest extends GradleIntegrationTest {
26+
@Test
27+
public void integration() throws IOException {
28+
write("build.gradle",
29+
"plugins {",
30+
" id 'com.diffplug.gradle.spotless'",
31+
"}",
32+
"repositories { mavenCentral() }",
33+
"",
34+
"apply plugin: 'groovy'",
35+
"",
36+
"spotless {",
37+
" java {",
38+
" googleJavaFormat()",
39+
" }",
40+
"}");
41+
String input = getTestResource("java/googlejavaformat/JavaCodeUnformatted.test");
42+
write("src/main/java/test.java", input);
43+
write("src/main/groovy/test.java", input);
44+
write("src/main/groovy/test.groovy", input);
45+
46+
// write appends a line ending so re-read to see what groovy currently looks like
47+
String groovyInput = read("src/main/groovy/test.groovy");
48+
49+
gradleRunner().forwardOutput().withArguments("spotlessApply").build();
50+
51+
String result = read("src/main/java/test.java");
52+
String output = getTestResource("java/googlejavaformat/JavaCodeFormatted.test");
53+
Assert.assertEquals("Java code in the java directory should be formatted.", output, result);
54+
55+
result = read("src/main/groovy/test.java");
56+
Assert.assertEquals("Java code in the groovy directory should be formatted.", output, result);
57+
58+
result = read("src/main/groovy/test.groovy");
59+
Assert.assertEquals("Groovy code in the groovy directory should not be formatted.", groovyInput, result);
60+
}
61+
}

0 commit comments

Comments
 (0)