-
Notifications
You must be signed in to change notification settings - Fork 494
/
licenses-3rdparties.gradle
237 lines (220 loc) · 12.1 KB
/
licenses-3rdparties.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// All licenses that we accept, and their aliases
def allowList = [
[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', url: 'http://www.opensource.org/licenses/bsd-license.php'],
[name: 'The BSD License', url: 'http://www.opensource.org/licenses/bsd-license.php'],
[name: 'BSD 2-Clause License'],
[name: 'BSD 2-Clause license', url: 'http://opensource.org/licenses/BSD-2-Clause'],
[name: 'BSD', url: 'http://www.jcraft.com/jzlib/LICENSE.txt'],
[name: 'Revised BSD', url: 'http://www.jcraft.com/jsch/LICENSE.txt'],
]],
[name: 'BSD-3-Clause', url: 'http://opensource.org/licenses/BSD-3-Clause', aliases: [
[name: 'BSD-3-Clause', url: 'https://asm.ow2.io/license.html'],
[name: 'The BSD 3-Clause License'],
[name: 'The 3-Clause BSD License'],
[name: '3-Clause BSD License'],
[name: 'BSD 3-Clause'],
[name: 'BSD 3 Clause'],
[name: 'BSD 3-clause'],
[name: 'BSD 3-Clause License'],
[name: 'BSD Licence 3'],
[name: 'BSD License 3'],
[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: 'BSD 3-Clause "New" or "Revised" License (BSD-3-Clause)'],
[name: '', url: 'http://asm.ow2.org/license.html'],
[name: 'BSD', url: 'http://asm.objectweb.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: 'The Apache Software 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: 'Apache License V2.0'],
[name: 'Apache License v2.0'],
[name: 'Apache License 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'],
[name: 'MIT-0', url: 'https://spdx.org/licenses/MIT-0.html'],
]],
[name: 'Eclipse Distribution License - v 1.0', url: 'https://www.eclipse.org/licenses/edl-v10.html', aliases: [
[name: 'Eclipse Distribution License - v 1.0', url: 'http://www.eclipse.org/org/documents/edl-v10.php'],
[name: 'EDL 1.0'],
]],
[name: 'Eclipse Public License - v 1.0', url: 'https://www.eclipse.org/legal/epl-v10.html', aliases: [
[name: 'Eclipse Public License 1.0'],
[name: 'EPL', url: 'http://www.eclipse.org/legal/epl-v10.html']
]],
[name: 'Eclipse Public License - v 2.0', url: 'http://www.eclipse.org/legal/epl-2.0.html', aliases: [
[name: 'Eclipse Public License 2.0'],
[name: 'Eclipse Public License v2.0', url: 'https://www.eclipse.org/legal/epl-v20.html'],
[name: 'EPL 2.0', url: 'http://www.eclipse.org/legal/epl-2.0'],
[name: 'Eclipse Public License - v 2.0', url: 'https://www.eclipse.org/legal/epl-v20.html']
]],
[name: 'GNU General Public License (GPL), version 2, with the Classpath exception', url: 'http://openjdk.java.net/legal/gplv2+ce.html', aliases: [
[name: 'GPL-2.0'],
[name: 'GPL'],
[name: 'GNU General Public License Version 2', url: 'http://www.gnu.org/copyleft/gpl.html']
]],
[name: 'GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1', url: 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html'],
[name: 'Public Domain, per Creative Commons CC0', url: 'http://creativecommons.org/publicdomain/zero/1.0/', aliases: [
[name: 'CC0'],
[name: 'Public Domain'],
]],
[name: 'MPL-2.0', url: 'https://www.mozilla.org/MPL/2.0/', aliases: [
[name: 'Mozilla Public License Version 2.0'],
[name: 'Mozilla Public License, v. 2.0', url: 'http://mozilla.org/MPL/2.0/'],
]],
[name: 'Common Development and Distribution License Version 1.0', aliases: [
[name: 'COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0']
]],
[name: 'Common Development and Distribution License Version 1.1', aliases: [
[name: 'CDDL1.1'],
[name: 'CDDL 1.1'],
[name: 'Common Development and Distribution License (CDDL), Version 1.1'],
[name: 'CDDL License', url: 'http://www.opensource.org/licenses/cddl1.php']
]],
[name: 'Common Development and Distribution License Version 1.1 and GNU General Public License, version 2 with the Classpath Exception', aliases: [
[name: 'CDDL1.1-GPL2/CPE'],
[name: 'Dual license consisting of the CDDL v1.1 and GPL v2'],
[name: 'CDDL + GPLv2 with classpath exception'],
]],
[name: 'The Go license', url: 'https://golang.org/LICENSE'],
[name: 'The OpenLDAP Public License', url: 'http://www.openldap.org/software/release/license.html'],
]
// Dependency license reporting
downloadLicenses {
dependencyConfiguration = 'runtimeClasspath'
// Add licenses to some libraries which don't declare their license inside the POM. Should be rechecked if the version is updated.
licenses = [
'javax.servlet.jsp:jsp-api:2.1' : license('Common Development and Distribution License Version 1.1', null),
'org.antlr:ST4:4.1' : license('BSD-3-Clause', null),
'org.gradle:gradle-tooling-api:6.1.1' : license('Apache-2.0', null),
'org.jline:jline:3.22.0' : license('BSD-2-Clause', 'http://opensource.org/licenses/BSD-2-Clause'),
'com.sun.codemodel:codemodel:2.6' : license('Common Development and Distribution License Version 1.1', null),
]
aliases = allowList.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.ext.licenseToDependencyJson = { ->
def jsonDir = tasks.downloadLicenses.jsonDestination
def jsonFile = file("$jsonDir/license-dependency.json")
new groovy.json.JsonSlurper().parseText(jsonFile.text)
}
tasks.downloadLicenses.ext.dependencyToLicenseJson = { ->
def jsonDir = tasks.downloadLicenses.jsonDestination
def jsonFile = file("$jsonDir/dependency-license.json")
new groovy.json.JsonSlurper().parseText(jsonFile.text)
}
// Dependency license validation
tasks.register("validateLicenses") {
group = 'license'
description = 'Checks 3rd-party dependency licenses against an allowlist'
dependsOn tasks.downloadLicenses
def excludeNeo4jPattern = /^(org|com)\.neo4j.*/
doLast {
def allowListedNames = allowList.collect { it.name }
tasks.downloadLicenses.dependencyToLicenseJson().dependencies
.findAll { dep -> !dep.name.matches(excludeNeo4jPattern) }
.findAll { dep -> allowListedNames.intersect(dep.licenses.collect { it.name }).isEmpty() }
.each { dep -> logger.error("In project ${project.name}: Could not find an allowed license for dependency '$dep.name'. Details: ${dep.toMapString()}") }
.each { dep -> throw new GradleException("The dependency '$dep.name' has no allowed license") }
}
}
tasks.check.dependsOn tasks.validateLicenses
tasks.register("generateLicensesFiles") {
group = 'license'
description 'Generates a LICENSES and NOTICE file with 3rd-party dependency license information'
dependsOn tasks.downloadLicenses, tasks.validateLicenses
def licenseFile = "$tasks.downloadLicenses.jsonDestination/LICENSES.txt"
def noticesFile = "$tasks.downloadLicenses.jsonDestination/NOTICE.txt"
ext.licensesFile = file(licenseFile)
ext.noticeFile = file(noticesFile)
outputs.file(ext.licensesFile)
outputs.file(ext.noticeFile)
doLast {
// LICENSES.txt
licensesFile.createNewFile()
licensesFile.text = rootProject.file("$publicDir/licenses/headers/LICENSES-header.txt").text
tasks.downloadLicenses.licenseToDependencyJson().licences
.findAll { lic -> allowList.any { lic.name == it.name }}
.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("$publicDir/licenses/text/$it.name").text
}
// NOTICE.txt
noticeFile.createNewFile()
noticeFile.text = rootProject.file("$publicDir/licenses/headers/NOTICE-header.txt").text
noticeFile << '\n\n'
noticeFile << "Third-party licenses\n"
noticeFile << "--------------------\n"
tasks.downloadLicenses.licenseToDependencyJson().licences.sort { it.name }.each {
noticeFile << '\n'
noticeFile << "$it.name\n"
it.dependencies.sort { it }.each { noticeFile << " $it\n" }
}
// Compare this file to what we have stored already, fail if they differ so that the PR fails and we are forced
// to update it instead!
File storedLicenseFile = new File("$project.rootDir/LICENSES.txt")
boolean throwError = false
if (licensesFile.readLines().size() != storedLicenseFile.readLines().size()) {
throwError = true
}
for (def i = 0; i < licensesFile.readLines().size(); i++) {
if (throwError) break
if (licensesFile.readLines().get(i) != storedLicenseFile.readLines().get(i)) {
throwError = true
}
}
// Copy files to root project so they can be tracked
copy {
from licenseFile
into "$project.rootDir"
}
copy {
from noticesFile
into "$project.rootDir"
}
// Throw after copy task gets run and the file is updated ready for commit :)
// Note: You might need to do a `./gradlew clean` first if your file isn't updating!
if (throwError) {
throw new GradleException("The LICENSES.txt file has updated depenencies, please update by running `./gradlew generateLicensesFiles` and committing the changes.")
}
}
}
tasks.check.dependsOn tasks.generateLicensesFiles