2020-08-30 08:01:04 -04:00
|
|
|
/*
|
2020-01-27 12:05:34 -05:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership.
|
|
|
|
* The ASF licenses this file to You 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.
|
|
|
|
*/
|
|
|
|
|
2020-01-27 11:29:59 -05:00
|
|
|
// This configures application of forbidden API rules
|
|
|
|
// via https://github.com/policeman-tools/forbidden-apis
|
|
|
|
|
2020-08-31 09:35:14 -04:00
|
|
|
def resources = scriptResources(buildscript)
|
|
|
|
|
2020-01-27 11:29:59 -05:00
|
|
|
// Only apply forbidden-apis to java projects.
|
|
|
|
allprojects { prj ->
|
|
|
|
plugins.withId("java", {
|
|
|
|
prj.apply plugin: 'de.thetaphi.forbiddenapis'
|
|
|
|
|
|
|
|
// This helper method appends signature files based on a set of true
|
|
|
|
// dependencies from a given configuration.
|
|
|
|
def dynamicSignatures = { configuration, suffix ->
|
2020-08-25 03:05:06 -04:00
|
|
|
def resolvedMods = configuration.resolvedConfiguration.resolvedArtifacts
|
2020-01-27 11:29:59 -05:00
|
|
|
.collect { a -> a.moduleVersion.id }
|
2020-08-25 03:05:06 -04:00
|
|
|
def deps = resolvedMods
|
2020-01-27 11:29:59 -05:00
|
|
|
.collect { id -> [
|
|
|
|
"${id.group}.${id.name}.all.txt",
|
|
|
|
"${id.group}.${id.name}.${suffix}.txt",
|
|
|
|
]}
|
|
|
|
.flatten()
|
|
|
|
.sort()
|
|
|
|
|
|
|
|
deps += ["defaults.all.txt", "defaults.${suffix}.txt"]
|
|
|
|
|
|
|
|
deps.each { sig ->
|
2020-08-31 09:35:14 -04:00
|
|
|
def signaturesFile = file("${resources}/${sig}")
|
2020-01-27 11:29:59 -05:00
|
|
|
if (signaturesFile.exists()) {
|
|
|
|
logger.info("Signature file applied: ${sig}")
|
|
|
|
signaturesFiles += files(signaturesFile)
|
|
|
|
} else {
|
|
|
|
logger.debug("Signature file omitted (does not exist): ${sig}")
|
|
|
|
}
|
|
|
|
}
|
2020-08-25 03:05:06 -04:00
|
|
|
|
|
|
|
// commons-io is special: forbiddenapis has a versioned bundledSignature.
|
|
|
|
bundledSignatures += resolvedMods
|
|
|
|
.findAll { id -> id.group == 'commons-io' && id.name == 'commons-io' }
|
|
|
|
.collect { id -> "${id.name}-unsafe-${id.version}" as String }
|
2020-01-27 11:29:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Configure defaults for sourceSets.main
|
|
|
|
forbiddenApisMain {
|
|
|
|
bundledSignatures += [
|
|
|
|
'jdk-unsafe',
|
|
|
|
'jdk-deprecated',
|
|
|
|
'jdk-non-portable',
|
|
|
|
'jdk-reflection',
|
|
|
|
'jdk-system-out',
|
|
|
|
]
|
|
|
|
|
|
|
|
suppressAnnotations += [
|
|
|
|
"**.SuppressForbidden"
|
|
|
|
]
|
2021-03-30 06:35:33 -04:00
|
|
|
|
|
|
|
doFirst dynamicSignatures.curry(configurations.compileClasspath, "lucene")
|
2020-01-27 11:29:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Configure defaults for sourceSets.test
|
2021-03-30 06:35:33 -04:00
|
|
|
tasks.matching { it.name in ["forbiddenApisTest", "forbiddenApisTestFixtures"] }.all {
|
2020-01-27 11:29:59 -05:00
|
|
|
bundledSignatures += [
|
|
|
|
'jdk-unsafe',
|
|
|
|
'jdk-deprecated',
|
|
|
|
'jdk-non-portable',
|
|
|
|
'jdk-reflection',
|
|
|
|
]
|
|
|
|
|
|
|
|
signaturesFiles = files(
|
2020-08-31 09:35:14 -04:00
|
|
|
file("${resources}/defaults.tests.txt")
|
2020-01-27 11:29:59 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
suppressAnnotations += [
|
|
|
|
"**.SuppressForbidden"
|
|
|
|
]
|
2021-03-30 06:35:33 -04:00
|
|
|
|
|
|
|
if (it.name == "forbiddenApisTestFixtures") {
|
|
|
|
doFirst dynamicSignatures.curry(configurations.testFixturesCompileClasspath, "lucene")
|
|
|
|
} else {
|
|
|
|
doFirst dynamicSignatures.curry(configurations.testCompileClasspath, "lucene")
|
|
|
|
}
|
2020-01-27 11:29:59 -05:00
|
|
|
}
|
|
|
|
|
2021-02-12 11:03:54 -05:00
|
|
|
// Configure defaults for sourceSets.tools (if present).
|
|
|
|
tasks.matching { it.name == "forbiddenApisTools" }.all {
|
|
|
|
bundledSignatures += [
|
|
|
|
'jdk-unsafe',
|
|
|
|
'jdk-deprecated',
|
|
|
|
'jdk-non-portable',
|
|
|
|
'jdk-reflection',
|
|
|
|
]
|
|
|
|
|
|
|
|
suppressAnnotations += [
|
|
|
|
"**.SuppressForbidden"
|
|
|
|
]
|
|
|
|
|
|
|
|
doFirst dynamicSignatures.curry(configurations.toolsCompileClasspath, "lucene")
|
2021-03-30 06:35:33 -04:00
|
|
|
|
2021-02-12 11:03:54 -05:00
|
|
|
inputs.dir(file(resources))
|
|
|
|
}
|
|
|
|
|
2021-03-30 06:35:33 -04:00
|
|
|
// We rely on resolved configurations to compute the relevant set of rule
|
|
|
|
// files for forbiddenApis. Since we don't want to resolve these configurations until
|
|
|
|
// the task is executed, we can't really use them as task inputs properly. This is a
|
|
|
|
// chicken-and-egg problem.
|
|
|
|
//
|
|
|
|
// This is the simplest workaround possible: just point at all the rule files and indicate
|
|
|
|
// them as inputs. This way if a rule is modified, checks will be reapplied.
|
|
|
|
configure(tasks.matching { it.name.startsWith("forbiddenApis") }) { task ->
|
|
|
|
task.inputs.dir(file(resources))
|
|
|
|
}
|
|
|
|
|
2020-01-27 11:29:59 -05:00
|
|
|
// Disable sysout signatures for these projects.
|
|
|
|
if (prj.path in [
|
|
|
|
":lucene:demo",
|
|
|
|
":lucene:benchmark",
|
2021-03-18 06:04:45 -04:00
|
|
|
":lucene:test-framework"
|
2020-01-27 11:29:59 -05:00
|
|
|
]) {
|
|
|
|
forbiddenApisMain.bundledSignatures -= [
|
|
|
|
'jdk-system-out'
|
|
|
|
]
|
|
|
|
}
|
2021-05-26 04:19:55 -04:00
|
|
|
|
|
|
|
// the test-framework module is special in that its main sources are exported for all tests.
|
|
|
|
// include the test signature file (defaults.tests.txt) to the main sourceset.
|
|
|
|
if (prj.path in [
|
|
|
|
":lucene:test-framework"
|
|
|
|
]) {
|
|
|
|
forbiddenApisMain.signaturesFiles += files(
|
|
|
|
file("${resources}/defaults.tests.txt")
|
|
|
|
)
|
|
|
|
}
|
2020-01-27 11:29:59 -05:00
|
|
|
})
|
2019-12-03 08:40:35 -05:00
|
|
|
}
|