From 1206364cf622eb7ccddb5bd30538a0baa98a5ce2 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Tue, 25 Oct 2022 05:27:24 -0700 Subject: [PATCH] Use javax.annotation.Nullable instead of androidx.annotation.Nullable to decouple Android dependency (#23310) * Use JSR305 Annotations instead of Android:annotations * Address review comments --- examples/java-matter-controller/BUILD.gn | 7 +----- scripts/build/builders/android.py | 5 +++++ .../dry_run_android-arm64-chip-tool.txt | 3 +++ src/controller/java/BUILD.gn | 2 +- .../ChipDeviceController.java | 2 +- .../devicecontroller/ControllerParams.java | 2 +- .../devicecontroller/NetworkCredentials.java | 2 +- .../OperationalKeyConfig.java | 2 +- .../devicecontroller/ReportCallbackJni.java | 2 +- .../ReportEventCallbackJni.java | 2 +- .../devicecontroller/model/ClusterState.java | 2 +- .../devicecontroller/model/EndpointState.java | 2 +- .../devicecontroller/model/NodeState.java | 2 +- .../java/templates/ChipClusters-java.zapt | 2 +- .../java/templates/ChipEventStructs-java.zapt | 2 +- .../java/templates/ChipStructs-java.zapt | 2 +- .../java/templates/ClusterInfo-java.zapt | 4 ++-- .../chip/devicecontroller/ChipClusters.java | 2 +- .../devicecontroller/ChipEventStructs.java | 2 +- .../chip/devicecontroller/ChipStructs.java | 2 +- .../devicecontroller/ClusterInfoMapping.java | 2 +- third_party/java_deps/.gitignore | 1 + third_party/java_deps/BUILD.gn | 22 +++++++++++++++++++ third_party/java_deps/set_up_java_deps.sh | 20 +++++++++++++++++ 24 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 third_party/java_deps/.gitignore create mode 100644 third_party/java_deps/BUILD.gn create mode 100755 third_party/java_deps/set_up_java_deps.sh diff --git a/examples/java-matter-controller/BUILD.gn b/examples/java-matter-controller/BUILD.gn index a82349286cc7e4..8f0d8a43a3763d 100644 --- a/examples/java-matter-controller/BUILD.gn +++ b/examples/java-matter-controller/BUILD.gn @@ -23,10 +23,9 @@ android_binary("java-matter-controller") { output_name = "java-matter-controller" deps = [ - ":android", "${chip_root}/src/controller/java", "${chip_root}/src/setup_payload/java", - "${chip_root}/third_party/android_deps:annotation", + "${chip_root}/third_party/java_deps:annotation", ] sources = [ "java/src/com/matter/controller/Main.java" ] @@ -34,10 +33,6 @@ android_binary("java-matter-controller") { javac_flags = [ "-Xlint:deprecation" ] } -java_prebuilt("android") { - jar_path = "${android_sdk_root}/platforms/android-21/android.jar" -} - group("default") { deps = [ ":java-matter-controller" ] } diff --git a/scripts/build/builders/android.py b/scripts/build/builders/android.py index b34382fdc06ca9..d8f4e46ae0176e 100644 --- a/scripts/build/builders/android.py +++ b/scripts/build/builders/android.py @@ -310,6 +310,11 @@ def generate(self): title="Setting up Android deps through Gradle", ) + self._Execute( + ["third_party/java_deps/set_up_java_deps.sh"], + title="Setting up Java deps", + ) + if not os.path.exists(self.output_dir): # NRF does a in-place update of SDK tools if not self._runner.dry_run: diff --git a/scripts/build/testdata/dry_run_android-arm64-chip-tool.txt b/scripts/build/testdata/dry_run_android-arm64-chip-tool.txt index c88cdc778386e4..955c3db11689ef 100644 --- a/scripts/build/testdata/dry_run_android-arm64-chip-tool.txt +++ b/scripts/build/testdata/dry_run_android-arm64-chip-tool.txt @@ -4,6 +4,9 @@ cd "{root}" # Setting up Android deps through Gradle python3 third_party/android_deps/set_up_android_deps.py +# Setting up Java deps +third_party/java_deps/set_up_java_deps.sh + # Generating android-arm64-chip-tool gn gen --check --fail-on-unused-args {out}/android-arm64-chip-tool '--args=target_os="android" target_cpu="arm64" android_ndk_root="TEST_ANDROID_NDK_HOME" android_sdk_root="TEST_ANDROID_HOME" ' diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 61244807707b8b..69137520fad329 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -69,7 +69,7 @@ android_library("java") { deps = [ ":android", - "${chip_root}/third_party/android_deps:annotation", + "${chip_root}/third_party/java_deps:annotation", ] data_deps = [ diff --git a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java index 62ed67132871d1..7004fac4e177a9 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java +++ b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java @@ -19,13 +19,13 @@ import android.bluetooth.BluetoothGatt; import android.util.Log; -import androidx.annotation.Nullable; import chip.devicecontroller.GetConnectedDeviceCallbackJni.GetConnectedDeviceCallback; import chip.devicecontroller.model.ChipAttributePath; import chip.devicecontroller.model.ChipEventPath; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import javax.annotation.Nullable; /** Controller to interact with the CHIP device. */ public class ChipDeviceController { diff --git a/src/controller/java/src/chip/devicecontroller/ControllerParams.java b/src/controller/java/src/chip/devicecontroller/ControllerParams.java index e2e429a6ad083d..c4897ef8423eef 100644 --- a/src/controller/java/src/chip/devicecontroller/ControllerParams.java +++ b/src/controller/java/src/chip/devicecontroller/ControllerParams.java @@ -1,6 +1,6 @@ package chip.devicecontroller; -import androidx.annotation.Nullable; +import javax.annotation.Nullable; /** Parameters representing initialization arguments for {@link ChipDeviceController}. */ public final class ControllerParams { diff --git a/src/controller/java/src/chip/devicecontroller/NetworkCredentials.java b/src/controller/java/src/chip/devicecontroller/NetworkCredentials.java index f45bca0d2e43c4..e2ec432bf06acb 100644 --- a/src/controller/java/src/chip/devicecontroller/NetworkCredentials.java +++ b/src/controller/java/src/chip/devicecontroller/NetworkCredentials.java @@ -19,7 +19,7 @@ import android.os.Parcel; import android.os.Parcelable; -import androidx.annotation.Nullable; +import javax.annotation.Nullable; /** Class for holding WiFi or Thread credentials, but not both. */ public class NetworkCredentials implements Parcelable { diff --git a/src/controller/java/src/chip/devicecontroller/OperationalKeyConfig.java b/src/controller/java/src/chip/devicecontroller/OperationalKeyConfig.java index dc1130c51d8566..6716b2bb502b13 100644 --- a/src/controller/java/src/chip/devicecontroller/OperationalKeyConfig.java +++ b/src/controller/java/src/chip/devicecontroller/OperationalKeyConfig.java @@ -1,6 +1,6 @@ package chip.devicecontroller; -import androidx.annotation.Nullable; +import javax.annotation.Nullable; /** Represents a set of operating credentials for a ChipDeviceController. */ public final class OperationalKeyConfig { diff --git a/src/controller/java/src/chip/devicecontroller/ReportCallbackJni.java b/src/controller/java/src/chip/devicecontroller/ReportCallbackJni.java index da2e7194da30b0..b5a002508d5add 100644 --- a/src/controller/java/src/chip/devicecontroller/ReportCallbackJni.java +++ b/src/controller/java/src/chip/devicecontroller/ReportCallbackJni.java @@ -17,7 +17,7 @@ */ package chip.devicecontroller; -import androidx.annotation.Nullable; +import javax.annotation.Nullable; /** JNI wrapper callback class for {@link ReportCallback}. */ public class ReportCallbackJni { diff --git a/src/controller/java/src/chip/devicecontroller/ReportEventCallbackJni.java b/src/controller/java/src/chip/devicecontroller/ReportEventCallbackJni.java index 6c05c09090c20b..1f786060b84d93 100644 --- a/src/controller/java/src/chip/devicecontroller/ReportEventCallbackJni.java +++ b/src/controller/java/src/chip/devicecontroller/ReportEventCallbackJni.java @@ -17,7 +17,7 @@ */ package chip.devicecontroller; -import androidx.annotation.Nullable; +import javax.annotation.Nullable; /** JNI wrapper callback class for {@link ReportCallback}. */ public class ReportEventCallbackJni { diff --git a/src/controller/java/src/chip/devicecontroller/model/ClusterState.java b/src/controller/java/src/chip/devicecontroller/model/ClusterState.java index 4ce1c1e62e1824..d31069ceac2953 100644 --- a/src/controller/java/src/chip/devicecontroller/model/ClusterState.java +++ b/src/controller/java/src/chip/devicecontroller/model/ClusterState.java @@ -17,10 +17,10 @@ */ package chip.devicecontroller.model; -import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.Map; import java.util.Optional; +import javax.annotation.Nullable; /** Class for tracking CHIP cluster state in a hierarchical manner. */ public final class ClusterState { diff --git a/src/controller/java/src/chip/devicecontroller/model/EndpointState.java b/src/controller/java/src/chip/devicecontroller/model/EndpointState.java index fe6958d63cf682..9c5181db265057 100644 --- a/src/controller/java/src/chip/devicecontroller/model/EndpointState.java +++ b/src/controller/java/src/chip/devicecontroller/model/EndpointState.java @@ -17,8 +17,8 @@ */ package chip.devicecontroller.model; -import androidx.annotation.Nullable; import java.util.Map; +import javax.annotation.Nullable; /** Class for tracking CHIP endpoint state in a hierarchical manner. */ public final class EndpointState { diff --git a/src/controller/java/src/chip/devicecontroller/model/NodeState.java b/src/controller/java/src/chip/devicecontroller/model/NodeState.java index 1dab3ebc0ea3b6..7e84997085bc00 100644 --- a/src/controller/java/src/chip/devicecontroller/model/NodeState.java +++ b/src/controller/java/src/chip/devicecontroller/model/NodeState.java @@ -17,10 +17,10 @@ */ package chip.devicecontroller.model; -import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import javax.annotation.Nullable; /** Class for tracking CHIP node state in a hierarchical manner. */ public final class NodeState { diff --git a/src/controller/java/templates/ChipClusters-java.zapt b/src/controller/java/templates/ChipClusters-java.zapt index 43dcb4a9a209b5..6337aafbddc2c5 100644 --- a/src/controller/java/templates/ChipClusters-java.zapt +++ b/src/controller/java/templates/ChipClusters-java.zapt @@ -3,7 +3,7 @@ package chip.devicecontroller; -import androidx.annotation.Nullable; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; diff --git a/src/controller/java/templates/ChipEventStructs-java.zapt b/src/controller/java/templates/ChipEventStructs-java.zapt index 63f20476386cc7..90b82b818a3ce1 100644 --- a/src/controller/java/templates/ChipEventStructs-java.zapt +++ b/src/controller/java/templates/ChipEventStructs-java.zapt @@ -2,7 +2,7 @@ package chip.devicecontroller; {{#if (chip_has_client_clusters)}} -import androidx.annotation.Nullable; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.Optional; diff --git a/src/controller/java/templates/ChipStructs-java.zapt b/src/controller/java/templates/ChipStructs-java.zapt index c7121821f4f5bd..12ce7baf3a3a72 100644 --- a/src/controller/java/templates/ChipStructs-java.zapt +++ b/src/controller/java/templates/ChipStructs-java.zapt @@ -2,7 +2,7 @@ package chip.devicecontroller; {{#if (chip_has_client_clusters)}} -import androidx.annotation.Nullable; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.Optional; diff --git a/src/controller/java/templates/ClusterInfo-java.zapt b/src/controller/java/templates/ClusterInfo-java.zapt index 622bc2998275f8..9521aca1198481 100644 --- a/src/controller/java/templates/ClusterInfo-java.zapt +++ b/src/controller/java/templates/ClusterInfo-java.zapt @@ -3,14 +3,14 @@ package chip.devicecontroller; -import androidx.annotation.Nullable; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; -import androidx.annotation.Nullable; +import javax.annotation.Nullable; import chip.clusterinfo.ClusterInfo; import chip.clusterinfo.InteractionInfo; import chip.clusterinfo.CommandParameterInfo; diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java b/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java index bb39d141a53239..2e2cdc863599b4 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java @@ -19,10 +19,10 @@ package chip.devicecontroller; -import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import javax.annotation.Nullable; public class ChipClusters { diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ChipEventStructs.java b/src/controller/java/zap-generated/chip/devicecontroller/ChipEventStructs.java index 21ebe48212f1a1..c3d450db99436f 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ChipEventStructs.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ChipEventStructs.java @@ -18,10 +18,10 @@ // THIS FILE IS GENERATED BY ZAP package chip.devicecontroller; -import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.Optional; +import javax.annotation.Nullable; public class ChipEventStructs { public static class AccessControlClusterAccessControlEntryChangedEvent { diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ChipStructs.java b/src/controller/java/zap-generated/chip/devicecontroller/ChipStructs.java index 84c26000b20b7b..eb9c76ab151f4b 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ChipStructs.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ChipStructs.java @@ -18,10 +18,10 @@ // THIS FILE IS GENERATED BY ZAP package chip.devicecontroller; -import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.Optional; +import javax.annotation.Nullable; public class ChipStructs { public static class ScenesClusterAttributeValuePair { diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ClusterInfoMapping.java b/src/controller/java/zap-generated/chip/devicecontroller/ClusterInfoMapping.java index 83d0ff677419bd..f1614c42ad0653 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ClusterInfoMapping.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ClusterInfoMapping.java @@ -19,7 +19,6 @@ package chip.devicecontroller; -import androidx.annotation.Nullable; import chip.clusterinfo.ClusterCommandCallback; import chip.clusterinfo.ClusterInfo; import chip.clusterinfo.CommandParameterInfo; @@ -33,6 +32,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import javax.annotation.Nullable; public class ClusterInfoMapping { diff --git a/third_party/java_deps/.gitignore b/third_party/java_deps/.gitignore new file mode 100644 index 00000000000000..d4f588edfef5a3 --- /dev/null +++ b/third_party/java_deps/.gitignore @@ -0,0 +1 @@ +artifacts/ diff --git a/third_party/java_deps/BUILD.gn b/third_party/java_deps/BUILD.gn new file mode 100644 index 00000000000000..330783e23af0a9 --- /dev/null +++ b/third_party/java_deps/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 2022 Project CHIP Authors +# +# Licensed 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. + +# === This BUILD file is auto-generated, modify the GnBuildGenerator task instead of editing this file manually. === + +import("//build_overrides/chip.gni") +import("${chip_root}/build/chip/java/rules.gni") + +java_prebuilt("annotation") { + jar_path = "artifacts/jsr305-3.0.2.jar" +} diff --git a/third_party/java_deps/set_up_java_deps.sh b/third_party/java_deps/set_up_java_deps.sh new file mode 100755 index 00000000000000..ce6dc81f4e29d5 --- /dev/null +++ b/third_party/java_deps/set_up_java_deps.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# +# Copyright (c) 2022 Project CHIP Authors +# +# Licensed 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. +# + +mkdir third_party/java_deps/artifacts +curl --fail --location --silent --show-error https://repo1.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar -o third_party/java_deps/artifacts/jsr305-3.0.2.jar