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

Support injecting Copyright Years based on file existence #240

Merged

Conversation

rvesse
Copy link
Contributor

@rvesse rvesse commented Oct 20, 2021

For some Copyright policies the years in the header should reflect only
the existence of that file not the project as a whole. While this can
be achieved by using ${license.git.copyrightCreationYear} and
${license.git.copyrightLastYear} in the header template you end up
generating awkward headers for some files e.g. 2021-2021. And you
cannot use ${license.git.copyrightYears} for this use case because that
will use the project inception year giving you something like 2019-2021.

This commit adds a new calculated property
${license.git.copyrightExistenceYears} which provides this information
and may be used in header templates where this behaviour is desired. This
should basically address the issue described in adobe/S3Mock#241

It also fixes a bug in GitLookup whereby if you had modified the file
it would incorrectly calculate the year range (because the creation year
was always defaulted to current year for modified files) and falsely flag
a license header as missing (or reformat unncessarily).

For some Copyright policies the years in the header should reflect only
the existence of that file not the project as a whole.  While this can
be achieved by using ${license.git.copyrightCreationYear} and
${license.git.copyrightLastYear} in the header template you end up
generating awkward headers for some files e.g. 2021-2021.  And you
cannot use ${license.git.copyrightYears} for this use case because that
will use the project inception year giving you something like 2019-2021.

This commit adds a new calculated property
${license.git.copyrightExistenceYears} which provides this information
and may be used in header templates where this behaviour is desired.

It also fixes a bug in GitLookup whereby if you had modified the file
it would incorrectly calculate the year range (because the creation year
was always defaulted to current year for modified files) and falsely flag
a license header as missing (or reformat unncessarily).
@mathieucarbou mathieucarbou added in:core MLP core module is:enhancement Enhancement to an existing feature todo Accepted items from the backlog which can be worked on labels Nov 26, 2021
@mathieucarbou mathieucarbou added this to the 4.2 milestone Nov 26, 2021
@mathieucarbou
Copy link
Owner

Sorry for the delay, I will merge and issue a 4.2.rc2.
Thanks!

@mathieucarbou mathieucarbou merged commit 037cf8a into mathieucarbou:master Nov 26, 2021
@mathieucarbou mathieucarbou added in:git MLP Git integration and removed in:core MLP core module labels Nov 26, 2021
@rvesse
Copy link
Contributor Author

rvesse commented Nov 30, 2021

@mathieucarbou No worries, thanks for accepting this PR 👍

@mathieucarbou
Copy link
Owner

@rvesse : FYI a (minor) bug was discovered in a part implemented by @rremer so I will probably wait a little more before a new rc to get the chance to fix that. But if you need that sooner please let me know...

@rvesse
Copy link
Contributor Author

rvesse commented Nov 30, 2021

@mathieucarbou No great rush on my end

@dbwiddis
Copy link
Contributor

dbwiddis commented Jan 1, 2022

I just discovered this new feature and I'd like to implement it. Any chance of rc2 soon-ish? I tried using SNAPSHOT but it appears only the metadata is there and no actual release files.

@mathieucarbou
Copy link
Owner

I just discovered this new feature and I'd like to implement it. Any chance of rc2 soon-ish? I tried using SNAPSHOT but it appears only the metadata is there and no actual release files.

Yes it's planned next week 😊

@dbwiddis
Copy link
Contributor

I'm running into an odd issue with this plugin. It's rewriting all headers and removing the earlier year, but only on OpenBSD.

For a sample file:

mvn verify

Changes the file thus:

- * Copyright (c) 2020-2021 ...
+ * Copyright (c) 2021 ...

This of course modifies the file so running it again turns it all into 2021-2022 on the next pass...

Should I create a new issue? Anything else I can help test/debug? Some configuration I'm missing?

@dbwiddis
Copy link
Contributor

Ah, figured it out. On that VM I had a shallow clone so the year determination was only going back a few hundred commits.

So, the follow on question: would it be possible for the plugin to detect the presence of a shallow clone and not rewrite if that is the case?

@mathieucarbou
Copy link
Owner

@dbwiddis : I think this is a legitimate use case, yes. We could add an option in the plugin. I have created #252.
I won't / cannot work on it now, if you would like to contribute it, you are welcomed to 👍
The new RC was done on Monday, by the way ;-)

@rvesse rvesse deleted the copyright-existence-years branch January 13, 2022 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in:git MLP Git integration is:enhancement Enhancement to an existing feature todo Accepted items from the backlog which can be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants