Make -try xlint warning disabled by default. (#40833)

Many gradle projects specifically use the -try exclude flag, because
there are many cases where auto-closeable resource ignore is never
referenced in body of corresponding try statement. Suppressing this
warning specifically in each case that it happens using
`@SuppressWarnings("try")` would be very verbose.

This change removes `-try` from any gradle project and adds it to the
build plugin. Also this change removes exclude flags from gradle projects
that is already specified in build plugin (for example -deprecation).

Relates to #40366
This commit is contained in:
Martijn van Groningen 2019-04-05 08:01:56 +02:00
parent 5a2eb07c0e
commit 809a5f13a4
No known key found for this signature in database
GPG Key ID: AB236F4FCF2AF12A
14 changed files with 18 additions and 22 deletions

View File

@ -39,7 +39,7 @@ dependencies {
runtime 'org.apache.commons:commons-math3:3.2'
}
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked,-processing"
compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked,-processing"
// enable the JMH's BenchmarkProcessor to generate the final benchmark classes
// needs to be added separately otherwise Gradle will quote it and javac will fail
compileJava.options.compilerArgs.addAll(["-processor", "org.openjdk.jmh.generators.BenchmarkProcessor"])

View File

@ -752,7 +752,7 @@ class BuildPlugin implements Plugin<Project> {
*/
// don't even think about passing args with -J-xxx, oracle will ask you to submit a bug report :)
// fail on all javac warnings
options.compilerArgs << '-Werror' << '-Xlint:all,-path,-serial,-options,-deprecation' << '-Xdoclint:all' << '-Xdoclint:-missing'
options.compilerArgs << '-Werror' << '-Xlint:all,-path,-serial,-options,-deprecation,-try' << '-Xdoclint:all' << '-Xdoclint:-missing'
// either disable annotation processor completely (default) or allow to enable them if an annotation processor is explicitly defined
if (options.compilerArgs.contains("-processor") == false) {

View File

@ -33,7 +33,7 @@ assemble.enabled = false
dependencyLicenses.enabled = false
dependenciesInfo.enabled = false
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
// no unit tests
unitTest.enabled = false

View File

@ -29,8 +29,7 @@ esplugin {
hasClientJar = true
}
compileJava.options.compilerArgs << "-Xlint:-try"
compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
dependencies {
// network stack

View File

@ -151,8 +151,8 @@ if (isEclipse) {
}
}
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
forbiddenPatterns {
exclude '**/*.json'

View File

@ -35,7 +35,7 @@ dependencies {
compile "org.elasticsearch:mocksocket:${versions.mocksocket}"
}
compileJava.options.compilerArgs << '-Xlint:-cast,-rawtypes,-try,-unchecked'
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

View File

@ -15,9 +15,6 @@ archivesBaseName = 'x-pack-ccr'
integTest.enabled = false
compileJava.options.compilerArgs << "-Xlint:-try"
compileTestJava.options.compilerArgs << "-Xlint:-try"
// Integration Test classes that cannot run with the security manager
String[] noSecurityManagerITClasses = [ "**/CloseFollowerIndexIT.class" ]

View File

@ -85,8 +85,8 @@ forbiddenPatterns {
exclude '**/*.zip'
}
compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
licenseHeaders {
approvedLicenses << 'BCrypt (BSD-like)'

View File

@ -26,8 +26,8 @@ dependencies {
testCompile "org.elasticsearch.plugin:x-pack-ilm:${version}"
}
compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
configurations {
testArtifacts.extendsFrom testRuntime

View File

@ -123,8 +123,8 @@ dependencies {
testCompile('org.apache.directory.mavibot:mavibot:1.0.0-M8')
}
compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
configurations {
testArtifacts.extendsFrom testRuntime

View File

@ -14,8 +14,8 @@ archivesBaseName = 'x-pack-watcher'
ext.compactProfile = 'full'
compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
dependencyLicenses {
mapping from: /owasp-java-html-sanitizer.*/, to: 'owasp-java-html-sanitizer'

View File

@ -134,7 +134,7 @@ task bwcTestSnapshots {
}
check.dependsOn(bwcTestSnapshots)
compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
// copy x-pack plugin info so it is on the classpath and security manager has the right permissions
task copyXPackRestSpec(type: Copy) {

View File

@ -68,7 +68,7 @@ Closure waitWithAuth = { NodeInfo node, AntBuilder ant ->
return tmpFile.exists()
}
compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
forbiddenPatterns {
exclude '**/system_key'

View File

@ -10,7 +10,7 @@ testFixtures.useFixture ":x-pack:test:smb-fixture"
// add test resources from security, so tests can use example certs
sourceSets.test.resources.srcDirs(project(xpackModule('security')).sourceSets.test.resources.srcDirs)
compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
// we have to repeat these patterns because the security test resources are effectively in the src of this project
forbiddenPatterns {