Utility to manage license headers in source files
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
core
core_mocks
docs
fs
fs_mocks
helper
helper_mocks
vcs
vcs_mocks
.gitignore
.headache-run
.travis.yml
CODE_OF_CONDUCT.md
Gopkg.lock
Gopkg.toml
LICENSE
README.md
build.sh
headache.json
license-header.txt
main.go

README.md

Header management

headache manages license headers. It is biased towards Golang but should work on any other language (provided a compatible code comment style is implemented).

Build status

Build Status

Quick start

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 Year parameter in the configuration file):

Copyright {{.Year}} {{.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

    http://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.

Run

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.

Run with custom configuration

Alternatively, the configuration file can be explicitly provided:

 $ go get -u github.com/fbiville/headache
 $ $(GOBIN)/headache --configuration /path/to/configuration.json

Reference documentation

Approach

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.

Configuration

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] One of: SlashStar (/* ... */), SlashSlash (// ...)
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.
Please note that {{.Year}} is a reserved parameter and will automatically be computed based on the files versioning information.