Skip to content

LicenseHeaderStep more permissive with parsing existing years#690

Merged
nedtwigg merged 5 commits intomainfrom
feat/license-generous-copyright-parse
Sep 10, 2020
Merged

LicenseHeaderStep more permissive with parsing existing years#690
nedtwigg merged 5 commits intomainfrom
feat/license-generous-copyright-parse

Conversation

@nedtwigg
Copy link
Copy Markdown
Member

@nedtwigg nedtwigg commented Sep 9, 2020

Seems like a better behavior, based on user's experience in #677.

This PR is all just pure refactor, except this one commit: fbb3dc9

@nedtwigg
Copy link
Copy Markdown
Member Author

And here is the logic for pulling years out of the existing header.

private static final Pattern YYYY = Pattern.compile("[0-9]{4}");

/** Searches the given string for YYYY, and uses that to determine the year range. */
private String calculateYearBySearching(String content) {
Matcher yearMatcher = YYYY.matcher(content);
if (yearMatcher.find()) {
String firstYear = yearMatcher.group();
String secondYear;
if (updateYearWithLatest) {
secondYear = firstYear.equals(yearToday) ? null : yearToday;
} else if (yearMatcher.find(yearMatcher.end() + 1)) {
secondYear = yearMatcher.group();
} else {
secondYear = null;
}
return secondYear == null ? firstYear : firstYear + yearSepOrFull + secondYear;
} else {
System.err.println("Can't parse copyright year '" + content + "', defaulting to " + yearToday);
// couldn't recognize the year format
return yearToday;
}
}

@nedtwigg nedtwigg merged commit a3f8d13 into main Sep 10, 2020
@nedtwigg nedtwigg deleted the feat/license-generous-copyright-parse branch September 10, 2020 18:08
@nedtwigg
Copy link
Copy Markdown
Member Author

Released in plugin-gradle 5.5.0 and plugin-maven 2.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant