Skip to content

Commit fbb3dc9

Browse files
committed
Change LicenseHeaderStep to be more aggressive about finding the existing copyright years.
1 parent bef0d8e commit fbb3dc9

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ private String format(String raw) {
227227
}
228228
return beforeYear + newYear + afterYear + content;
229229
} else {
230+
String newYear = calculateYearBySearching(raw.substring(0, contentMatcher.start()));
230231
// at worst, we just say that it was made today
231-
return beforeYear + yearToday + afterYear + content;
232+
return beforeYear + newYear + afterYear + content;
232233
}
233234
}
234235
}

testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public void parseExistingYear() throws Exception {
3939
// has existing
4040
.test(hasHeader("This is a fake license, 2007. ACME corp."), hasHeader("This is a fake license, 2007. ACME corp."))
4141
// if prefix changes, the year will get set to today
42-
.test(hasHeader("This is a license, 2007. ACME corp."), hasHeader("This is a fake license, " + currentYear() + ". ACME corp."))
42+
.test(hasHeader("This is a license, 2007. ACME corp."), hasHeader("This is a fake license, 2007. ACME corp."))
4343
// if suffix changes, the year will get set to today
44-
.test(hasHeader("This is a fake license, 2007. Other corp."), hasHeader("This is a fake license, " + currentYear() + ". ACME corp."));
44+
.test(hasHeader("This is a fake license, 2007. Other corp."), hasHeader("This is a fake license, 2007. ACME corp."));
4545
}
4646

4747
@Test
@@ -58,7 +58,7 @@ public void should_apply_license_containing_YEAR_token() throws Throwable {
5858
.testUnaffected(hasHeaderYear(currentYear()))
5959
.testUnaffected(hasHeaderYear("2003"))
6060
.testUnaffected(hasHeaderYear("1990-2015"))
61-
.test(hasHeaderYear("Something before license.*/\n/* \n * " + HEADER_WITH_$YEAR, "2003"), hasHeaderYear(currentYear()))
61+
.test(hasHeaderYear("Something before license.*/\n/* \n * " + HEADER_WITH_$YEAR, "2003"), hasHeaderYear("2003"))
6262
.test(hasHeaderYear(HEADER_WITH_$YEAR + "\n **/\n/* Something after license.", "2003"), hasHeaderYear("2003"))
6363
.test(hasHeaderYear("not a year"), hasHeaderYear(currentYear()));
6464
// Check with variant

0 commit comments

Comments
 (0)