Skip to content

Commit 57165d6

Browse files
committed
Removed LicenseHeaderStep#name and replaced with code duplication.
It doesn't seem wise to expose something in spotless-lib which is only used in one place in plugin-gradle and which may be rendered useless if plugin-gradle's implementation details change. This is especially considering that spotless-lib may be used by people other than ourselves, and so we will want to ensure we can evolve spotless-lib in a semver-compatible way that doesn't inconvenience other users. Therefore I believe that replacing LicenseHeaderStep#name with the code duplication I introduced in this commit is a worthwhile trade-off.
1 parent 6c85d00 commit 57165d6

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
public final class LicenseHeaderStep implements Serializable {
3131
private static final long serialVersionUID = 1L;
3232

33+
// If this value changes, don't forget to change it in
34+
// plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension#setupTask as well.
3335
private static final String NAME = "licenseHeader";
3436

3537
private final String licenseHeader;
@@ -52,10 +54,6 @@ public static FormatterStep createFromFile(File licenseHeaderFile, Charset encod
5254
step -> step::format);
5355
}
5456

55-
public static String name() {
56-
return NAME;
57-
}
58-
5957
/** The license that we'd like enforced. */
6058
// TODO: Make package-private when LicenseHeaderStepTest is migrated to testlib
6159
public LicenseHeaderStep(String licenseHeader, String delimiter) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ protected void setupTask(BaseFormatTask task) {
9595
// LicenseHeaderStep completely blows apart package-info.java - this common-sense check ensures that
9696
// it skips package-info.java. See https://github.com/diffplug/spotless/issues/1
9797
steps.replaceAll(step -> {
98-
if (LicenseHeaderStep.name().equals(step.getName())) {
98+
// If the string "licenseHeader" below changes, don't forget to change it in
99+
// lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.NAME as well.
100+
if ("licenseHeader".equals(step.getName())) {
99101
return step.filterByFile(SerializableFileFilter.skipFilesNamed("package-info.java"));
100102
} else {
101103
return step;

0 commit comments

Comments
 (0)