KISS

Keep It Simple Stupid

Source Code License Check in Jenkins: Revised

| comments

This is a revised post on how to setup source code license check on your Jenkins. The first version is here. The basic idea is the same, but there are a few important changes described below. So to set this up, please follow the first post, except for a few values overridden here.

Changes in this version

  • added *.pch files to the check (aka pre-compiled headers);
  • based on the section on applying the Apache license, your sources should also have a line like Copyright [yyyy] [name of copyright owner], so I added another check for that;
  • removed *.json files from checking – JSON format doesn’t support comments, a workaround would be to add a _license/_copyright key, but that would hardly be readable, so I decided to opt out (it’s up to you to enable);
  • if the project uses CocoaPods, excluding the Pods directory from the check;
  • for readability and understandability, I use full grep options now.

Parser Setup

Regular Expression: ^(\S+) (.+)$

Mapping script:

1
2
3
4
5
6
7
import hudson.plugins.warnings.parser.Warning

String type = matcher.group(1)
String filename = matcher.group(2)
String description = "Missing ${type} in the file"

return new Warning(filename, 1, "License Check", "warning", description);

Example log message: license ./AppDelegate.h

Build Step

1
2
3
4
5
6
7
8
9
function grephere() {
    grep --files-without-match --recursive \
        --include '*.h' --include '*.m' --include '*.strings' --include '*.xml' --include '*.pch' \
        --exclude-dir '*build' --exclude-dir './ExternalFrameworks' \
        --exclude-dir 'Pods' "$1" "$2"
}
grephere 'Licensed under the Apache License, Version 2.0 (the "License");' . | sed 's/^/license /' > "out/license.check"
COPYRIGHT_NAME='[put your/company name here]'
grephere 'Copyright.\+'"${COPYRIGHT_NAME}" . | sed 's/^/copyright /' >> "out/license.check"

Comments