load("//:java_grpc_library.bzl", "java_grpc_library")

# Mirrors the dependencies included in the artifact on Maven Central for usage
# with maven_install's override_targets. Purposefully does not export any
# symbols, as it should only be used as a dep for pre-compiled binaries on
# Maven Central.
java_library(
    name = "xds_maven",
    visibility = ["//visibility:public"],
    runtime_deps = [
        ":orca",
        ":xds",
    ],
)

java_library(
    name = "xds",
    srcs = glob(
        [
            "src/main/java/**/*.java",
            "third_party/zero-allocation-hashing/main/java/**/*.java",
        ],
        exclude = ["src/main/java/io/grpc/xds/orca/**"],
    ),
    resources = glob([
        "src/main/resources/**",
    ]),
    visibility = ["//visibility:public"],
    deps = [
        ":envoy_service_discovery_v2_java_grpc",
        ":envoy_service_discovery_v3_java_grpc",
        ":envoy_service_load_stats_v2_java_grpc",
        ":envoy_service_load_stats_v3_java_grpc",
        ":envoy_service_status_v3_java_grpc",
        ":xds_protos_java",
        "//:auto_value_annotations",
        "//alts",
        "//api",
        "//context",
        "//core:internal",
        "//core:util",
        "//netty",
        "//stub",
        "@com_google_code_findbugs_jsr305//jar",
        "@com_google_code_gson_gson//jar",
        "@com_google_errorprone_error_prone_annotations//jar",
        "@com_google_googleapis//google/rpc:rpc_java_proto",
        "@com_google_guava_guava//jar",
        "@com_google_protobuf//:protobuf_java",
        "@com_google_protobuf//:protobuf_java_util",
        "@com_google_re2j_re2j//jar",
        "@io_netty_netty_buffer//jar",
        "@io_netty_netty_codec//jar",
        "@io_netty_netty_common//jar",
        "@io_netty_netty_handler//jar",
        "@io_netty_netty_transport//jar",
    ],
)

java_proto_library(
    name = "xds_protos_java",
    deps = [
        "@com_github_cncf_udpa//udpa/type/v1:pkg",
        "@com_github_cncf_xds//xds/data/orca/v3:pkg",
        "@com_github_cncf_xds//xds/service/orca/v3:pkg",
        "@com_github_cncf_xds//xds/type/v3:pkg",
        "@envoy_api//envoy/admin/v3:pkg",
        "@envoy_api//envoy/api/v2:pkg",
        "@envoy_api//envoy/api/v2/core:pkg",
        "@envoy_api//envoy/api/v2/endpoint:pkg",
        "@envoy_api//envoy/config/cluster/aggregate/v2alpha:pkg",
        "@envoy_api//envoy/config/cluster/v3:pkg",
        "@envoy_api//envoy/config/core/v3:pkg",
        "@envoy_api//envoy/config/endpoint/v3:pkg",
        "@envoy_api//envoy/config/filter/http/fault/v2:pkg",
        "@envoy_api//envoy/config/filter/http/router/v2:pkg",
        "@envoy_api//envoy/config/filter/network/http_connection_manager/v2:pkg",
        "@envoy_api//envoy/config/listener/v3:pkg",
        "@envoy_api//envoy/config/rbac/v3:pkg",
        "@envoy_api//envoy/config/route/v3:pkg",
        "@envoy_api//envoy/extensions/clusters/aggregate/v3:pkg",
        "@envoy_api//envoy/extensions/filters/common/fault/v3:pkg",
        "@envoy_api//envoy/extensions/filters/http/fault/v3:pkg",
        "@envoy_api//envoy/extensions/filters/http/rbac/v3:pkg",
        "@envoy_api//envoy/extensions/filters/http/router/v3:pkg",
        "@envoy_api//envoy/extensions/filters/network/http_connection_manager/v3:pkg",
        "@envoy_api//envoy/extensions/load_balancing_policies/least_request/v3:pkg",
        "@envoy_api//envoy/extensions/load_balancing_policies/ring_hash/v3:pkg",
        "@envoy_api//envoy/extensions/load_balancing_policies/round_robin/v3:pkg",
        "@envoy_api//envoy/extensions/load_balancing_policies/wrr_locality/v3:pkg",
        "@envoy_api//envoy/extensions/transport_sockets/tls/v3:pkg",
        "@envoy_api//envoy/service/discovery/v2:pkg",
        "@envoy_api//envoy/service/discovery/v3:pkg",
        "@envoy_api//envoy/service/load_stats/v2:pkg",
        "@envoy_api//envoy/service/load_stats/v3:pkg",
        "@envoy_api//envoy/service/status/v3:pkg",
        "@envoy_api//envoy/type/matcher/v3:pkg",
        "@envoy_api//envoy/type/v3:pkg",
    ],
)

java_grpc_library(
    name = "envoy_service_discovery_v2_java_grpc",
    srcs = ["@envoy_api//envoy/service/discovery/v2:pkg"],
    deps = [":xds_protos_java"],
)

java_grpc_library(
    name = "envoy_service_discovery_v3_java_grpc",
    srcs = ["@envoy_api//envoy/service/discovery/v3:pkg"],
    deps = [":xds_protos_java"],
)

java_grpc_library(
    name = "envoy_service_load_stats_v2_java_grpc",
    srcs = ["@envoy_api//envoy/service/load_stats/v2:pkg"],
    deps = [":xds_protos_java"],
)

java_grpc_library(
    name = "envoy_service_load_stats_v3_java_grpc",
    srcs = ["@envoy_api//envoy/service/load_stats/v3:pkg"],
    deps = [":xds_protos_java"],
)

java_grpc_library(
    name = "envoy_service_status_v3_java_grpc",
    srcs = ["@envoy_api//envoy/service/status/v3:pkg"],
    deps = [":xds_protos_java"],
)

java_library(
    name = "orca",
    srcs = glob([
        "src/main/java/io/grpc/xds/orca/*.java",
    ]),
    visibility = ["//visibility:public"],
    deps = [
        ":orca_protos_java",
        ":xds_service_orca_v3_java_grpc",
        "//api",
        "//context",
        "//core:internal",
        "//core:util",
        "//protobuf",
        "//services:metrics",
        "//services:metrics_internal",
        "//stub",
        "@com_google_code_findbugs_jsr305//jar",
        "@com_google_guava_guava//jar",
        "@com_google_protobuf//:protobuf_java_util",
    ],
)

java_proto_library(
    name = "orca_protos_java",
    deps = [
        "@com_github_cncf_xds//xds/data/orca/v3:pkg",
        "@com_github_cncf_xds//xds/service/orca/v3:pkg",
    ],
)

java_grpc_library(
    name = "xds_service_orca_v3_java_grpc",
    srcs = ["@com_github_cncf_xds//xds/service/orca/v3:pkg"],
    deps = [":orca_protos_java"],
)
