forked from opencypher/morpheus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.licenses.gradle
167 lines (145 loc) · 6.72 KB
/
build.licenses.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// All licenses that we accept, and their aliases
def whitelist = [
[name: 'BSD-2-Clause', url: 'http://opensource.org/licenses/BSD-2-Clause', aliases: [
[name: 'BSD-style', url:'http://www.opensource.org/licenses/bsd-license.php'],
]],
[name: 'BSD-3-Clause', url: 'http://opensource.org/licenses/BSD-3-Clause', aliases: [
[name: 'The BSD 3-Clause License'],
[name: 'The 3-Clause BSD License'],
[name: 'BSD 3-Clause'],
[name: 'BSD 3 Clause'],
[name: 'BSD 3-clause'],
[name: 'New BSD License'],
[name: 'New BSD license'],
[name: 'The New BSD License'],
[name: 'BSD License', url: 'http://www.antlr.org/license.html'],
[name: 'BSD licence', url: 'http://antlr.org/license.html'],
[name: 'The BSD License', url: 'http://www.antlr.org/license.html'],
[name: 'BSD', url: 'http://asm.ow2.org/license.html'],
[name: 'BSD', url: 'http://www.jcraft.com/jsch/LICENSE.txt'],
[name: 'BSD', url: 'https://github.com/sbt/test-interface/blob/master/LICENSE'],
[name: 'BSD', url: 'LICENSE.txt'],
[name: '', url: 'http://asm.ow2.org/license.html'],
]],
[name: 'Apache-2.0', url: 'https://opensource.org/licenses/Apache-2.0', aliases: [
[name: 'The Apache Software License, Version 2.0'],
[name: 'The Apache License, Version 2.0'],
[name: 'Apache 2'],
[name: 'Apache v2'],
[name: 'Apache License, Version 2.0'],
[name: 'Apache License, Version 2'],
[name: 'Apache Software License - Version 2.0'],
[name: 'Apache License 2.0'],
[name: 'Apache License'],
[name: 'Apache 2.0'],
[name: 'Apache-2.0'],
[name: 'Apache 2.0 License'],
[name: 'ASL'],
[name: 'ASL 2.0'],
[name: 'the Apache License, ASL Version 2.0'],
[name: '', url: 'http://www.apache.org/licenses/LICENSE-2.0.txt'],
]],
[name: 'MIT', url: 'https://opensource.org/licenses/MIT', aliases: [
[name: 'MIT'],
[name: 'MIT license'],
[name: 'MIT License'],
[name: 'The MIT License'],
[name: 'Bouncy Castle Licence'],
]]
]
subprojects {
apply plugin: 'base'
apply plugin: "com.github.hierynomus.license"
// License header checking and insertion
license {
header = rootProject.file("etc/licenses/headers/NOTICE-header.txt")
// what comment style to use
mapping {
scala = 'SLASHSTAR_STYLE'
}
// https://github.com/hierynomus/license-gradle-plugin/issues/145
// exclude 'test/resources/**'
// exclude 'main/resources/**'
include '**/*.scala'
include '**/*.java'
}
tasks.check.dependsOn tasks.license
// Dependency license reporting
downloadLicenses {
dependencyConfiguration = 'compile'
aliases = whitelist.collectEntries { lic ->
def actual = license(lic.name, lic.url)
def alternatives = lic.aliases.collect { it.url ? license(it.name, it.url) : it.name }
[(actual): alternatives]
}
}
tasks.downloadLicenses.outputs.upToDateWhen { false }
tasks.downloadLicenses.ext.licencesJson = { ->
def jsonDir = tasks.downloadLicenses.jsonDestination
def jsonFile = file("$jsonDir/license-dependency.json")
new groovy.json.JsonSlurper().parseText(jsonFile.text)
}
// Dependency license validation
task validateLicenses {
group 'license'
description 'Checks dependency licenses against a whitelist'
dependsOn tasks.downloadLicenses
doLast {
File errFile = file("$tasks.downloadLicenses.jsonDestination/license-errors.txt")
errFile.text = ""
tasks.downloadLicenses.licencesJson().licences
.findAll { lic -> !whitelist.any { lic.name == it.name } }
.sort { lic -> lic.name }
.each { lic -> logger.error("The license '$lic.name' is not in the license whitelist. Details: ${lic.toMapString()}") }
.each { lic -> errFile << '\n' << lic.toMapString() }
.each { lic -> throw new GradleException("The license '$lic.name' is not in the license whitelist") }
}
}
tasks.check.dependsOn tasks.validateLicenses
// Compound dependency licenses files
task generateLicensesFiles {
description 'Generates dependency license report files'
dependsOn tasks.downloadLicenses
ext.licensesFile = file("$tasks.downloadLicenses.jsonDestination/LICENSES.txt")
ext.noticeFile = file("$tasks.downloadLicenses.jsonDestination/NOTICE.txt")
outputs.file(ext.licensesFile)
outputs.file(ext.noticeFile)
doLast {
licensesFile.createNewFile()
licensesFile.text = rootProject.file("etc/licenses/headers/LICENSES-header.txt").text
tasks.downloadLicenses.licencesJson().licences.sort { it.name }.each {
licensesFile << '\n\n'
licensesFile << "------------------------------------------------------------------------------\n"
licensesFile << "$it.name\n"
it.dependencies.sort { it }.each { licensesFile << " $it\n" }
licensesFile << "------------------------------------------------------------------------------\n"
licensesFile << '\n'
licensesFile << rootProject.file("etc/licenses/text/$it.name").text
}
noticeFile.createNewFile()
noticeFile.text = rootProject.file("etc/licenses/headers/NOTICE-header.txt").text
noticeFile << '\n\n'
noticeFile << "Third-party licenses\n"
noticeFile << "--------------------\n"
tasks.downloadLicenses.licencesJson().licences.sort { it.name }.each {
noticeFile << '\n'
noticeFile << "$it.name\n"
it.dependencies.sort { it }.each { noticeFile << " $it\n" }
}
}
}
tasks.check.dependsOn tasks.generateLicensesFiles
}
// Disable dependency license validation on test and documentation projects
['okapi-tck',
'okapi-testing',
'okapi-neo4j-io-testing',
'spark-cypher-examples',
'spark-cypher-tck',
'spark-cypher-testing',
'spark-cypher-jmh',
'documentation',
].each {
project(it).tasks.validateLicenses.enabled = false
project(it).tasks.generateLicensesFiles.enabled = false
}