File tree Expand file tree Collapse file tree 4 files changed +12
-17
lines changed
lib/src/main/java/com/diffplug/spotless/generic
plugin-gradle/src/main/java/com/diffplug/gradle/spotless
plugin-maven/src/main/java/com/diffplug/spotless/maven/generic Expand file tree Collapse file tree 4 files changed +12
-17
lines changed Original file line number Diff line number Diff line change 27
27
28
28
import com .diffplug .spotless .FormatterStep ;
29
29
import com .diffplug .spotless .LineEnding ;
30
+ import com .diffplug .spotless .SerializableFileFilter ;
30
31
31
32
/** Prefixes a license header before the package statement. */
32
33
public final class LicenseHeaderStep implements Serializable {
@@ -35,6 +36,9 @@ public final class LicenseHeaderStep implements Serializable {
35
36
private static final String NAME = "licenseHeader" ;
36
37
private static final String DEFAULT_YEAR_DELIMITER = "-" ;
37
38
39
+ private static final SerializableFileFilter UNSUPPORTED_JVM_FILES_FILTER = SerializableFileFilter .skipFilesNamed (
40
+ "package-info.java" , "package-info.groovy" , "module-info.java" );
41
+
38
42
private final String licenseHeader ;
39
43
private final Pattern delimiterPattern ;
40
44
private Pattern yearMatcherPattern ;
@@ -87,6 +91,10 @@ public static String defaultYearDelimiter() {
87
91
return DEFAULT_YEAR_DELIMITER ;
88
92
}
89
93
94
+ public static SerializableFileFilter unsupportedJvmFilesFilter () {
95
+ return UNSUPPORTED_JVM_FILES_FILTER ;
96
+ }
97
+
90
98
/** The license that we'd like enforced. */
91
99
private LicenseHeaderStep (String licenseHeader , String delimiter , String yearSeparator ) {
92
100
if (delimiter .contains ("\n " )) {
Original file line number Diff line number Diff line change 30
30
import org .gradle .api .tasks .SourceSet ;
31
31
32
32
import com .diffplug .common .base .StringPrinter ;
33
- import com .diffplug .spotless .SerializableFileFilter ;
34
33
import com .diffplug .spotless .extra .EclipseBasedStepBuilder ;
35
34
import com .diffplug .spotless .extra .groovy .GrEclipseFormatterStep ;
36
35
import com .diffplug .spotless .generic .LicenseHeaderStep ;
@@ -140,7 +139,7 @@ protected void setupTask(SpotlessTask task) {
140
139
// ensures that it skips both. See https://github.com/diffplug/spotless/issues/1
141
140
steps .replaceAll (step -> {
142
141
if (LicenseHeaderStep .name ().equals (step .getName ())) {
143
- return step .filterByFile (SerializableFileFilter . skipFilesNamed ( "package-info.java" , "package-info.groovy" ));
142
+ return step .filterByFile (LicenseHeaderStep . unsupportedJvmFilesFilter ( ));
144
143
} else {
145
144
return step ;
146
145
}
Original file line number Diff line number Diff line change 28
28
29
29
import com .diffplug .common .base .StringPrinter ;
30
30
import com .diffplug .spotless .FormatterStep ;
31
- import com .diffplug .spotless .SerializableFileFilter ;
32
31
import com .diffplug .spotless .extra .EclipseBasedStepBuilder ;
33
32
import com .diffplug .spotless .extra .java .EclipseFormatterStep ;
34
33
import com .diffplug .spotless .extra .java .EclipseJdtFormatterStep ;
@@ -187,17 +186,10 @@ protected void setupTask(SpotlessTask task) {
187
186
}
188
187
target = union ;
189
188
}
190
- // LicenseHeaderStep completely blows apart package-info.java & module-info.java;
191
- // this common-sense check ensures that it skips package-info.java & module-info.java.
192
- //
193
- // See:
194
- // - https://github.com/diffplug/spotless/issues/1
195
- // - https://github.com/diffplug/spotless/issues/270
189
+
196
190
steps .replaceAll (step -> {
197
191
if (LicenseHeaderStep .name ().equals (step .getName ())) {
198
- return step .filterByFile (SerializableFileFilter .skipFilesNamed (
199
- "package-info.java" ,
200
- "module-info.java" ));
192
+ return step .filterByFile (LicenseHeaderStep .unsupportedJvmFilesFilter ());
201
193
} else {
202
194
return step ;
203
195
}
Original file line number Diff line number Diff line change 20
20
import org .apache .maven .plugins .annotations .Parameter ;
21
21
22
22
import com .diffplug .spotless .FormatterStep ;
23
- import com .diffplug .spotless .SerializableFileFilter ;
24
23
import com .diffplug .spotless .generic .LicenseHeaderStep ;
25
24
import com .diffplug .spotless .maven .FormatterStepConfig ;
26
25
import com .diffplug .spotless .maven .FormatterStepFactory ;
27
26
28
27
public class LicenseHeader implements FormatterStepFactory {
29
28
30
- private static final SerializableFileFilter UNSUPPORTED_FILES_FILTER = SerializableFileFilter .skipFilesNamed (
31
- "package-info.java" , "module-info.java" );
32
-
33
29
@ Parameter
34
30
private String file ;
35
31
@@ -51,7 +47,7 @@ public final FormatterStep newFormatterStep(FormatterStepConfig config) {
51
47
? createStepFromFile (config , delimiterString )
52
48
: createStepFromContent (delimiterString );
53
49
54
- return step .filterByFile (UNSUPPORTED_FILES_FILTER );
50
+ return step .filterByFile (LicenseHeaderStep . unsupportedJvmFilesFilter () );
55
51
} else {
56
52
throw new IllegalArgumentException ("Must specify exactly one of 'file' or 'content'." );
57
53
}
You can’t perform that action at this time.
0 commit comments