diff --git a/.github/workflows/ci-java.yml b/.github/workflows/ci-java.yml index 569d68d562440..cb266150916c0 100644 --- a/.github/workflows/ci-java.yml +++ b/.github/workflows/ci-java.yml @@ -71,3 +71,11 @@ jobs: java-version: 17 run: | bazel test --flaky_test_attempts 3 //java/test/org/openqa/selenium/chrome:ChromeDriverFunctionalTest-remote + + nullaway-checks: + name: NullAway Checks + uses: ./.github/workflows/bazel.yml + with: + name: NullAway Checks + java-version: 17 + run: bazel build //java/... --//java:nullaway_level=ERROR diff --git a/java/BUILD.bazel b/java/BUILD.bazel index 342d23637be7c..169736d5c545a 100644 --- a/java/BUILD.bazel +++ b/java/BUILD.bazel @@ -1,5 +1,6 @@ load("@contrib_rules_jvm//java:defs.bzl", "spotbugs_config") load(":defs.bzl", "artifact") +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") exports_files( srcs = [ @@ -53,3 +54,23 @@ spotbugs_config( "//visibility:public", ], ) + +string_flag( + name = "nullaway_level", + values = ["NONE", "WARN", "ERROR"], + build_setting_default = "NONE", +) + +config_setting( + name = "use_nullaway_level_warn", + flag_values = { + ":nullaway_level": "WARN", + }, +) + +config_setting( + name = "use_nullaway_level_error", + flag_values = { + ":nullaway_level": "ERROR", + }, +) diff --git a/java/private/export.bzl b/java/private/export.bzl index 1d3e9b0498b46..33e7b640b4969 100644 --- a/java/private/export.bzl +++ b/java/private/export.bzl @@ -7,6 +7,7 @@ load("@rules_jvm_external//private/rules:maven_bom_fragment.bzl", "maven_bom_fra load("@rules_jvm_external//private/rules:maven_project_jar.bzl", "maven_project_jar") load("@rules_jvm_external//private/rules:maven_publish.bzl", "maven_publish") load("//java/private:module.bzl", "java_module") +load(":java_library.bzl", "java_library") def java_export( name, @@ -24,7 +25,7 @@ def java_export( lib_name = "%s-lib" % name # Construct the java_library we'll export from here. - native.java_library( + java_library( name = lib_name, tags = tags, exports = exports, diff --git a/java/private/java_library.bzl b/java/private/java_library.bzl new file mode 100644 index 0000000000000..b1dcc2f01597f --- /dev/null +++ b/java/private/java_library.bzl @@ -0,0 +1,52 @@ +load( + "@contrib_rules_jvm//java:defs.bzl", + _java_library = "java_library" +) + +def java_library( + name, + deps = [], + srcs = [], + exports = [], + tags = [], + visibility = None, + javacopts = [], + plugins = [], + **kwargs): + + # NullAway configuration + nullaway_plugins = select({ + "//java:use_nullaway_level_warn": [ + "//java:nullaway" + ], + "//java:use_nullaway_level_error": [ + "//java:nullaway" + ], + "//conditions:default": [], + }) + nullaway_javacopts = select({ + "//java:use_nullaway_level_warn": [ + '-Xep:NullAway:WARN', + '-XepOpt:NullAway:AnnotatedPackages=org.openqa.selenium', + '-XepOpt:NullAway:JSpecifyMode=true' + ], + "//java:use_nullaway_level_error": [ + '-Xep:NullAway:ERROR', + '-XepOpt:NullAway:AnnotatedPackages=org.openqa.selenium', + '-XepOpt:NullAway:JSpecifyMode=true' + ], + "//conditions:default": [], + }) + + # global place for NullAway plugin use + _java_library( + name = name, + deps = deps, + srcs = srcs, + exports = exports, + tags = tags, + visibility = visibility, + plugins = plugins + nullaway_plugins, + javacopts = javacopts + nullaway_javacopts, + **kwargs + ) diff --git a/java/private/library.bzl b/java/private/library.bzl index f2f7d7f69a2d8..a83b738e152b1 100644 --- a/java/private/library.bzl +++ b/java/private/library.bzl @@ -1,9 +1,9 @@ load( "@contrib_rules_jvm//java:defs.bzl", - _java_library = "java_library", _java_test = "java_test", ) load(":export.bzl", _java_export = "java_export") +load(":java_library.bzl", _java_library = "java_library") java_export = _java_export java_library = _java_library diff --git a/java/src/org/openqa/selenium/BUILD.bazel b/java/src/org/openqa/selenium/BUILD.bazel index a6262047d012f..a10ac67d52a0f 100644 --- a/java/src/org/openqa/selenium/BUILD.bazel +++ b/java/src/org/openqa/selenium/BUILD.bazel @@ -38,14 +38,6 @@ java_export( ":manifest", artifact("org.jspecify:jspecify"), ], - plugins = [ - "//java:nullaway" - ], - javacopts = [ - '-Xep:NullAway:WARN', - '-XepOpt:NullAway:AnnotatedPackages=org.openqa.selenium', - '-XepOpt:NullAway:JSpecifyMode=true' - ], ) java_export( diff --git a/java/src/org/openqa/selenium/support/BUILD.bazel b/java/src/org/openqa/selenium/support/BUILD.bazel index e768935159903..f7fecdc481463 100644 --- a/java/src/org/openqa/selenium/support/BUILD.bazel +++ b/java/src/org/openqa/selenium/support/BUILD.bazel @@ -36,14 +36,6 @@ java_export( "//java/src/org/openqa/selenium/support/ui:elements", "//java/src/org/openqa/selenium/support/ui:wait", ], - plugins = [ - "//java:nullaway" - ], - javacopts = [ - '-Xep:NullAway:WARN', - '-XepOpt:NullAway:AnnotatedPackages=org.openqa.selenium', - '-XepOpt:NullAway:JSpecifyMode=true' - ], ) java_library( @@ -66,12 +58,4 @@ java_library( "//java/src/org/openqa/selenium:core", "//java/src/org/openqa/selenium/support/ui:components", ], - plugins = [ - "//java:nullaway" - ], - javacopts = [ - '-Xep:NullAway:WARN', - '-XepOpt:NullAway:AnnotatedPackages=org.openqa.selenium', - '-XepOpt:NullAway:JSpecifyMode=true' - ], )