Skip to content

Commit

Permalink
Use javax.annotation.Nullable instead of androidx.annotation.Nullable…
Browse files Browse the repository at this point in the history
… to decouple Android dependency (#23310)

* Use JSR305 Annotations instead of Android:annotations

* Address review comments
  • Loading branch information
yufengwangca authored and pull[bot] committed Aug 4, 2023
1 parent e885999 commit 1206364
Show file tree
Hide file tree
Showing 24 changed files with 71 additions and 25 deletions.
7 changes: 1 addition & 6 deletions examples/java-matter-controller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,16 @@ 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" ]

javac_flags = [ "-Xlint:deprecation" ]
}

java_prebuilt("android") {
jar_path = "${android_sdk_root}/platforms/android-21/android.jar"
}

group("default") {
deps = [ ":java-matter-controller" ]
}
5 changes: 5 additions & 0 deletions scripts/build/builders/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions scripts/build/testdata/dry_run_android-arm64-chip-tool.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" '

Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/templates/ChipClusters-java.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/templates/ChipEventStructs-java.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/templates/ChipStructs-java.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/controller/java/templates/ClusterInfo-java.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions third_party/java_deps/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
artifacts/
22 changes: 22 additions & 0 deletions third_party/java_deps/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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"
}
20 changes: 20 additions & 0 deletions third_party/java_deps/set_up_java_deps.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1206364

Please sign in to comment.