|
40 | 40 | import com.diffplug.spotless.LineEnding;
|
41 | 41 | import com.diffplug.spotless.OnMatch;
|
42 | 42 | import com.diffplug.spotless.SerializableFileFilter;
|
| 43 | +import com.diffplug.spotless.SerializedFunction; |
43 | 44 | import com.diffplug.spotless.ThrowingEx;
|
44 | 45 |
|
45 | 46 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
@@ -119,13 +120,22 @@ public LicenseHeaderStep withSkipLinesMatching(@Nullable String skipLinesMatchin
|
119 | 120 | return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching);
|
120 | 121 | }
|
121 | 122 |
|
| 123 | + private static class SetLicenseHeaderYearsFromGitHistory implements SerializedFunction<Runtime, FormatterFunc> { |
| 124 | + private static final long serialVersionUID = 1L; |
| 125 | + |
| 126 | + @Override |
| 127 | + public FormatterFunc apply(Runtime input) throws Exception { |
| 128 | + return FormatterFunc.needsFile(input::setLicenseHeaderYearsFromGitHistory); |
| 129 | + } |
| 130 | + } |
| 131 | + |
122 | 132 | public FormatterStep build() {
|
123 | 133 | FormatterStep formatterStep;
|
124 | 134 | if (yearMode.get() == YearMode.SET_FROM_GIT) {
|
125 | 135 | formatterStep = FormatterStep.createLazy(name, () -> {
|
126 | 136 | boolean updateYear = false; // doesn't matter
|
127 | 137 | return new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesMatching);
|
128 |
| - }, step -> FormatterFunc.needsFile(step::format)); |
| 138 | + }, new SetLicenseHeaderYearsFromGitHistory()); |
129 | 139 | } else {
|
130 | 140 | formatterStep = FormatterStep.createLazy(name, () -> {
|
131 | 141 | // by default, we should update the year if the user is using ratchetFrom
|
|
0 commit comments