Skip to content

Commit

Permalink
Use task avoidance with forbidden apis (#55034)
Browse files Browse the repository at this point in the history
Currently forbidden apis accounts for 800+ tasks in the build. These
tasks are aggressively created by the plugin. In forbidden apis 3.0, we
will get task avoidance
(policeman-tools/forbidden-apis#162), but we
need to ourselves use the same task avoidance mechanisms to not trigger
these task creations. This commit does that for our foribdden apis
usages, in preparation for upgrading to 3.0 when it is released.
  • Loading branch information
rjernst authored Apr 15, 2020
1 parent 4a2179c commit 842ce32
Show file tree
Hide file tree
Showing 36 changed files with 49 additions and 44 deletions.
2 changes: 1 addition & 1 deletion benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ compileJava.options.compilerArgs.addAll(["-processor", "org.openjdk.jmh.generato
run.executable = "${BuildParams.runtimeJavaHome}/bin/java"

// classes generated by JMH can use all sorts of forbidden APIs but we have no influence at all and cannot exclude these classes
forbiddenApisMain.enabled = false
disableTasks('forbiddenApisMain')

// No licenses for our benchmark deps (we don't ship benchmarks)
dependencyLicenses.enabled = false
Expand Down
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,11 @@ subprojects {
}
}
}

subprojects {
project.ext.disableTasks = { String... tasknames ->
for (String taskname : tasknames) {
project.tasks.named(taskname).configure { onlyIf { false } }
}
}
}
4 changes: 1 addition & 3 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ if (project != rootProject) {
// build-tools is not ready for primetime with these...
dependencyLicenses.enabled = false
dependenciesInfo.enabled = false
forbiddenApisMain.enabled = false
forbiddenApisMinimumRuntime.enabled = false
forbiddenApisTest.enabled = false
disableTasks('forbiddenApisMain', 'forbiddenApisMinimumRuntime', 'forbiddenApisTest')
jarHell.enabled = false
thirdPartyAudit.enabled = false
if (Boolean.parseBoolean(System.getProperty("tests.fips.enabled"))){
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/testKit/elasticsearch.build/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ repositories {
}

// todo remove offending rules
forbiddenApisMain.enabled = false
forbiddenApisTest.enabled = false
tasks.named('forbiddenApisMain').configure { onlyIf { false } }
tasks.named('forbiddenApisTest').configure { onlyIf { false } }
// requires dependency on testing fw
jarHell.enabled = false
// we don't have tests for now
Expand Down
2 changes: 1 addition & 1 deletion client/rest-high-level/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ dependencyLicenses {
}
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
// core does not depend on the httpclient for compile so we add the signatures here. We don't add them for test as they are already
// specified
addSignatureFiles 'http-signatures'
Expand Down
4 changes: 2 additions & 2 deletions client/rest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dependencies {
testCompile "org.elasticsearch:mocksocket:${versions.mocksocket}"
}

tasks.withType(CheckForbiddenApis) {
tasks.withType(CheckForbiddenApis).configureEach {
//client does not depend on server, so only jdk and http signatures should be checked
replaceSignatureFiles('jdk-signatures', 'http-signatures')
}
Expand All @@ -60,7 +60,7 @@ forbiddenPatterns {
exclude '**/*.der'
}

forbiddenApisTest {
tasks.named('forbiddenApisTest').configure {
//we are using jdk-internal instead of jdk-non-portable to allow for com.sun.net.httpserver.* usage
bundledSignatures -= 'jdk-non-portable'
bundledSignatures += 'jdk-internal'
Expand Down
4 changes: 2 additions & 2 deletions client/sniffer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ dependencies {
testCompile "org.elasticsearch:mocksocket:${versions.mocksocket}"
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
//client does not depend on server, so only jdk signatures should be checked
replaceSignatureFiles 'jdk-signatures'
}

forbiddenApisTest {
tasks.named('forbiddenApisTest').configure {
//we are using jdk-internal instead of jdk-non-portable to allow for com.sun.net.httpserver.* usage
bundledSignatures -= 'jdk-non-portable'
bundledSignatures += 'jdk-internal'
Expand Down
4 changes: 2 additions & 2 deletions client/test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ dependencies {
compile "org.hamcrest:hamcrest:${versions.hamcrest}"
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
//client does not depend on core, so only jdk signatures should be checked
replaceSignatureFiles 'jdk-signatures'
}

forbiddenApisTest {
tasks.named('forbiddenApisTest').configure {
//we are using jdk-internal instead of jdk-non-portable to allow for com.sun.net.httpserver.* usage
bundledSignatures -= 'jdk-non-portable'
bundledSignatures += 'jdk-internal'
Expand Down
2 changes: 1 addition & 1 deletion distribution/tools/java-version-checker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'elasticsearch.build'
targetCompatibility = JavaVersion.VERSION_1_7

// java_version_checker do not depend on core so only JDK signatures should be checked
forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
replaceSignatureFiles 'jdk-signatures'
}

Expand Down
2 changes: 1 addition & 1 deletion distribution/tools/launchers/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {

archivesBaseName = 'elasticsearch-launchers'

tasks.withType(CheckForbiddenApis) {
tasks.withType(CheckForbiddenApis).configureEach {
replaceSignatureFiles 'jdk-signatures'
}

Expand Down
2 changes: 1 addition & 1 deletion libs/cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ test.enabled = false
// Since CLI does not depend on :server, it cannot run the jarHell task
jarHell.enabled = false

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
replaceSignatureFiles 'jdk-signatures'
}
2 changes: 1 addition & 1 deletion libs/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
}
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
// :libs:elasticsearch-core does not depend on server
// TODO: Need to decide how we want to handle for forbidden signatures with the changes to server
replaceSignatureFiles 'jdk-signatures'
Expand Down
2 changes: 1 addition & 1 deletion libs/dissect/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {
testCompile "com.fasterxml.jackson.core:jackson-databind:${versions.jackson}"
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
replaceSignatureFiles 'jdk-signatures'
}

2 changes: 1 addition & 1 deletion libs/geo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {
}
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
// geo does not depend on server
// TODO: Need to decide how we want to handle for forbidden signatures with the changes to core
replaceSignatureFiles 'jdk-signatures'
Expand Down
2 changes: 1 addition & 1 deletion libs/grok/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ dependencies {
}
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
replaceSignatureFiles 'jdk-signatures'
}
2 changes: 1 addition & 1 deletion libs/nio/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
}


forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
// nio does not depend on core, so only jdk signatures should be checked
// es-all is not checked as we connect and accept sockets
replaceSignatureFiles 'jdk-signatures'
Expand Down
2 changes: 1 addition & 1 deletion libs/plugin-classloader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
test.enabled = false

// test depend on ES core...
forbiddenApisMain.enabled = false
disableTasks('forbiddenApisMain')
jarHell.enabled = false
2 changes: 1 addition & 1 deletion libs/secure-sm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
}
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
replaceSignatureFiles 'jdk-signatures'
}

Expand Down
2 changes: 1 addition & 1 deletion libs/ssl-config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
}


forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
replaceSignatureFiles 'jdk-signatures'
}

Expand Down
2 changes: 1 addition & 1 deletion libs/x-content/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies {

}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
// x-content does not depend on server
// TODO: Need to decide how we want to handle for forbidden signatures with the changes to core
replaceSignatureFiles 'jdk-signatures'
Expand Down
2 changes: 1 addition & 1 deletion plugins/analysis-icu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ esplugin {
classname 'org.elasticsearch.plugin.analysis.icu.AnalysisICUPlugin'
}

tasks.withType(CheckForbiddenApis) {
tasks.withType(CheckForbiddenApis).configureEach {
signatures += [
"com.ibm.icu.text.Collator#getInstance() @ Don't use default locale, use getInstance(ULocale) instead"
]
Expand Down
4 changes: 2 additions & 2 deletions qa/os/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies {
testCompile "com.fasterxml.jackson.core:jackson-databind:${versions.jackson}"
}

forbiddenApisTest {
tasks.named('forbiddenApisTest').configure {
replaceSignatureFiles 'jdk-signatures'
}

Expand All @@ -58,7 +58,7 @@ tasks.dependenciesInfo.enabled = false
tasks.thirdPartyAudit.ignoreMissingClasses()

tasks.register('destructivePackagingTest') {
dependsOn 'destructiveDistroTest'
dependsOn 'destructiveDistroTest'
}

processTestResources {
Expand Down
2 changes: 1 addition & 1 deletion server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if (!isEclipse) {
targetCompatibility = 12
}

forbiddenApisJava12 {
tasks.named('forbiddenApisJava12').configure {
doFirst {
if (BuildParams.runtimeJavaVersion < JavaVersion.VERSION_12) {
targetCompatibility = JavaVersion.VERSION_12.getMajorVersion()
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
subprojects {
// fixtures are mostly external and by default we don't want to check forbidden apis
forbiddenApisMain.enabled = false
disableTasks('forbiddenApisMain')
}
2 changes: 1 addition & 1 deletion test/framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ compileJava.options.compilerArgs << '-Xlint:-cast,-rawtypes,-unchecked'
compileTestJava.options.compilerArgs << '-Xlint:-rawtypes'

// the main files are actually test files, so use the appropriate forbidden api sigs
forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
replaceSignatureFiles 'jdk-signatures', 'es-all-signatures', 'es-test-signatures'
}

Expand Down
3 changes: 1 addition & 2 deletions test/logger-usage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ dependencies {

loggerUsageCheck.enabled = false

forbiddenApisMain.enabled = true // disabled by parent project
forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
replaceSignatureFiles 'jdk-signatures' // does not depend on core, only jdk signatures
}
jarHell.enabled = true // disabled by parent project
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ forbiddenPatterns {
exclude '**/*.zip'
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
signaturesFiles += files('forbidden/hasher-signatures.txt')
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/identity-provider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ forbiddenPatterns {
exclude '**/*.zip'
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
signaturesFiles += files('forbidden/xml-signatures.txt')
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/security/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ forbiddenPatterns {
exclude '**/*.zip'
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
signaturesFiles += files('forbidden/ldap-signatures.txt', 'forbidden/xml-signatures.txt', 'forbidden/oidc-signatures.txt')
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/security/cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if (BuildParams.inFipsJvm) {
testingConventions.enabled = false
// Forbiden APIs non-portable checks fail because bouncy castle classes being used from the FIPS JDK since those are
// not part of the Java specification - all of this is as designed, so we have to relax this check for FIPS.
tasks.withType(CheckForbiddenApis) {
tasks.withType(CheckForbiddenApis).configureEach {
bundledSignatures -= "jdk-non-portable"
}
}
2 changes: 1 addition & 1 deletion x-pack/plugin/sql/jdbc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'com.github.johnrengelman.shadow'
description = 'JDBC driver for Elasticsearch'
archivesBaseName = "x-pack-sql-jdbc"

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
// does not depend on core, so only jdk and http signatures should be checked
replaceSignatureFiles 'jdk-signatures'
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/sql/qa/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencyLicenses.enabled = false
dependenciesInfo.enabled = false

// the main files are actually test files, so use the appropriate forbidden api sigs
forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
replaceSignatureFiles 'es-all-signatures', 'es-test-signatures'
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/sql/sql-action/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
testCompile project(":test:framework")
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
//sql does not depend on server, so only jdk signatures should be checked
replaceSignatureFiles 'jdk-signatures'
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/sql/sql-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ shadowJar {
}
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
//sql does not depend on server, so only jdk signatures should be checked
replaceSignatureFiles 'jdk-signatures'
signaturesFiles += files('src/forbidden/cli-signatures.txt')
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugin/sql/sql-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ dependencyLicenses {
ignoreSha 'elasticsearch-core'
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
// does not depend on core, so only jdk and http signatures should be checked
replaceSignatureFiles 'jdk-signatures'
}

forbiddenApisTest {
tasks.named('forbiddenApisTest').configure {
bundledSignatures -= 'jdk-non-portable'
bundledSignatures += 'jdk-internal'
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/sql/sql-proto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
testCompile project(":test:framework")
}

forbiddenApisMain {
tasks.named('forbiddenApisMain').configure {
//sql does not depend on server, so only jdk signatures should be checked
replaceSignatureFiles 'jdk-signatures'
}
Expand Down

0 comments on commit 842ce32

Please sign in to comment.