mathieucarbou / license-maven-plugin

Manage license headers in your source files

Home Page:https://oss.carbou.me/license-maven-plugin/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keep existing copyright lines, use template for default

dbwiddis opened this issue · comments

Software copyright statements are not always as consistent across all files as this plugin assumes, and there is no facility provided to permit different years or different authors other than the few provided substitutions (inception, file creation, latest change).

In order to use this plugin, maintainers are forced to adopt some text that applies to everyone, e.g., "Copyright 2020 the original author or authors" or in one project I maintain, a link to the Github "contributors" page. But in another project I maintain, the convention is for the original author of a file to provide the copyright, e.g., one file might have

Copyright 2012 Author Name

And another file might have

Copyright 2015 Different Author

And perhaps on a third file

Copyright 2012, 2016 Author Name and Different Author

(All with the boilerplate license text surrounding the copyright statement.)

A project which chooses to use the above format/policy has no way to effectively use this plugin. However, there is no need to be so strict. License header templates all use the general format:

  • Stuff
  • Copyright © year(s) owner(s)
  • Other stuff

Currently the plugin has special treatment for the first and last lines, and there's an open PR (#243) to handle middle lines that could, in theory and with a lot of effort, be configured to handle this use case. However, given the commonality across all licence headers (the copyright line is always on its own line) it should be easy to identify just that line using a well known regex (the word Copyright in between carriage returns). The document and the header template could both be tokenized to compare the 3 "stuff" categories shown above, with the following caveat: When no header exists at all, the template would fill in the copyright line; when a header exists containing the word Copyright in between CRs, it would be left completely alone.

I'm willing to submit a PR for this if there is interest.

  1. One solution would be similar to my draft PR #286, except instead of just skipping the first year, it would skip the entire line.
  • If no copyright line exists, would specify what to put in, e.g., current year, file creation year/author, etc.
  • If a copyright line exists, would totally ignore it
  1. Another solution would be to add new substitutions (or a prefix before a substitution) for both year(s) and author(s) in which:
  • If no copyright line exists, would specify what to put in, e.g., current year, file creation year/author, etc.
  • If a copyright line exists, would append year(s) and name(s) if needed to existing

Let me know which you'd prefer, if there is interest.

Hi,
I'm always ok for new features and improvements.
This is however a pretty big rewrite, and it will have to be backward compatible, so that's challenging...
But it would definitely help solve several use cases and issues reported, of course.
Thanks 👍

I don't think it's that big. Finding the copyright header is relatively easy and already done in (draft) #323 along with the logic to "skip". You just parse both the file header and license header looking for "copyright" and grab to the end of the line, then swap from the file into the license header before rewriting. It's parameter driven, off by default, and thus compatible.

But the marginal benefit from just skipping any existing header isn't much (if any) for most use cases. The real value is in doing the same steps for the rewrite, very useful for changing license versions (or licenses), changing to slashdot style, etc. while preserving the copyright line.