headache
manages license headers.
It is biased towards Golang but should work on any other language (provided a compatible code comment style is implemented).
By default, headache
looks for a configuration file named headache.json
in the directory in which it is invoked:
{
"headerFile": "./license-header.txt",
"style": "SlashStar",
"includes": ["**/*.go"],
"excludes": ["vendor/**/*"],
"data": {
"Owner": "The original author or authors"
}
}
license-header.txt
(note the absence of YearRange
parameter in the configuration file):
Copyright {{.YearRange}} {{.Owner}}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
All you have to do then is:
$ go get -u github.com/fbiville/headache
$ $(GOBIN)/headache
As a result, source files will be changed and .headache-run
will be generated to keep track of headache
last execution.
This file must be versioned along with the source file changes.
Alternatively, the configuration file can be explicitly provided:
$ go get -u github.com/fbiville/headache
$ $(GOBIN)/headache --configuration /path/to/configuration.json
headache
approach to copyright is well explained in this stackoverflow answer,
read it first!
Now that you read this, here are two important points:
- Copyright years have to be updated when a significant change occurs.
There is, to the author knowledge, no automatic solution to distinguish a trivial change from a significant one.
Based on this premise, headache
will process all files matching the configuration and that have been changed since its last execution.
headache
will then compute the copyright year, file by file, from their available versioning information (typically by retrieving the relevant dates from Git commits).
It is up to the project maintainer to discard the generated changes if they are not relevant.
-
The [first] date on the [copyright] notice establishes how far back the claim is made.
This claim could predate any commit associated to the file (imagine a file copied from project to project for years).
headache
will never overwrite the start date of the copyright year if it finds one, if and only if that date occurs earlier than the first commit date of the file.
headache
relies on the emerging JSON Schema standard to validate its configuration.
headache
schema is defined here.
In layman's terms, here are all the possible settings:
Setting | Type | Definition |
---|---|---|
headerFile |
string | [required] Path to the parameterized license header. Parameters are referenced with the following syntax: {{.PARAMETER-NAME}} |
style |
string | [required] See all the possible names here |
includes |
array of strings | [required, min size=1] File globs to include (* and ** are supported) |
excludes |
array of strings | File globs to exclude (* and ** are supported) |
data |
map of string to string | Key-value pairs, matching the parameters used in headerFile except for the reserved parameters (see below section). |
{{.YearRange}}
(formerly{{.Year}}
) is automatically substituted with either:- a single year if both years in the range are the same
- a year range with the earliest commit's year* and latest commit's year
{{.StartYear}}
is substituted with the earliest commit's year{{.EndYear}}
is substituted with the latest commit's year
As explained earlier, if a file specifies a start date in its header that is earlier than any commit's year, then that date is preserved.
If you want to avoid copyright dates like 2019-2019
, then rely on {{.YearRange}}
.
If you need something like 2018-present
, then use {{.StartYear}}-present
instead.