Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LicenseHeaderStep more permissive with parsing existing years #690

Merged
merged 5 commits into from
Sep 10, 2020

Conversation

nedtwigg
Copy link
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
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
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.

None yet

1 participant