Skip to content

Commit

Permalink
[java] NullAway added for the entire project
Browse files Browse the repository at this point in the history
  • Loading branch information
mk868 committed Aug 29, 2024
1 parent 8c0bffd commit 6f1d082
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 26 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions java/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down Expand Up @@ -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",
},
)
3 changes: 2 additions & 1 deletion java/private/export.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
52 changes: 52 additions & 0 deletions java/private/java_library.bzl
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion java/private/library.bzl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 0 additions & 8 deletions java/src/org/openqa/selenium/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 0 additions & 16 deletions java/src/org/openqa/selenium/support/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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'
],
)

0 comments on commit 6f1d082

Please sign in to comment.