Ray Milkey | 3275ae8 | 2018-05-29 15:35:36 -0700 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | """ |
| 16 | |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 17 | load("//tools/build/bazel:generate_workspace.bzl", "COMPILE", "TEST") |
| 18 | load("//tools/build/bazel:variables.bzl", "ONOS_VERSION") |
| 19 | load("//tools/build/bazel:generate_test_rules.bzl", "generate_test_rules") |
Ray Milkey | b7949e7 | 2018-06-19 18:31:02 -0700 | [diff] [blame] | 20 | load("//tools/build/bazel:checkstyle.bzl", "checkstyle_test") |
Thomas Vachuska | ac9e524 | 2018-07-19 16:15:39 -0700 | [diff] [blame] | 21 | load("//tools/build/bazel:pom_file.bzl", "pom_file") |
Thomas Vachuska | 50ac098 | 2018-07-19 10:17:37 -0700 | [diff] [blame] | 22 | load("//tools/build/bazel:java_sources.bzl", "java_sources") |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 23 | load("//tools/build/bazel:java_sources.bzl", "java_sources_alt") |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 24 | load("//tools/build/bazel:javadoc.bzl", "javadoc") |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 25 | load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library") |
| 26 | |
| 27 | def _auto_name(): |
| 28 | return "onos-" + native.package_name().replace("/", "-") |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 29 | |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 30 | def _all_java_sources(): |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 31 | return native.glob(["src/main/java/**/*.java"]) |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 32 | |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 33 | def _all_java_test_sources(): |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 34 | return native.glob(["src/test/java/**/*.java"]) |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 35 | |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 36 | def _all_test_resources(): |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 37 | return native.glob(["src/test/resources/**"]) |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 38 | |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 39 | def _all_resources(resources_root): |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 40 | if resources_root == None: |
| 41 | return native.glob(["src/main/resources/**"]) |
| 42 | else: |
| 43 | return native.glob([resources_root + "**"]) |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 44 | |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 45 | def _webapp(): |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 46 | return native.glob(["src/main/webapp/WEB-INF/web.xml"]) |
| 47 | |
| 48 | def _include_resources_to_string(include_resources): |
| 49 | result = "" |
| 50 | for (path, filename) in include_resources.items(): |
| 51 | result += (path + "=" + filename) |
| 52 | return result |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 53 | |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 54 | """ |
| 55 | Implementation of the rule to call bnd to make an OSGI jar file |
| 56 | """ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 57 | |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 58 | def _bnd_impl(ctx): |
Ray Milkey | 3275ae8 | 2018-05-29 15:35:36 -0700 | [diff] [blame] | 59 | if (len(ctx.files.source) == 1): |
| 60 | input_file = ctx.files.source[0] |
| 61 | else: |
| 62 | # this is a list of inputs. The one we want is the last one |
| 63 | # in the list that isn't a source jar |
| 64 | for file in reversed(ctx.files.source): |
| 65 | if ("-src" in file.path): |
| 66 | continue |
| 67 | else: |
| 68 | input_file = file |
| 69 | break |
| 70 | |
| 71 | jar = input_file.path |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 72 | output = ctx.outputs.osgi_jar.path |
Thomas Vachuska | 8e022a9 | 2018-07-10 14:47:38 -0700 | [diff] [blame] | 73 | name = ctx.attr.name |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 74 | group = ctx.attr.group |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 75 | version = ctx.attr.version |
| 76 | license = "" |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 77 | import_packages = ctx.attr.import_packages |
Jian Li | 4ad8687 | 2018-08-05 03:34:35 +0900 | [diff] [blame] | 78 | bundle_classpath = ctx.attr.bundle_classpath |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 79 | exportPackages = "*" |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 80 | include_resources = ctx.attr.include_resources |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 81 | web_context = ctx.attr.web_context |
| 82 | if web_context == None or web_context == "": |
| 83 | web_context = "NONE" |
| 84 | web_xml = ctx.attr.web_xml |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 85 | dynamicimportPackages = "" |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 86 | karaf_commands = ctx.attr.karaf_commands |
Ray Milkey | 3275ae8 | 2018-05-29 15:35:36 -0700 | [diff] [blame] | 87 | cp = "" |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 88 | |
Ray Milkey | 3275ae8 | 2018-05-29 15:35:36 -0700 | [diff] [blame] | 89 | inputDependencies = [input_file] |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 90 | |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 91 | # determine the dependencies and build the class path |
| 92 | for dep in ctx.attr.deps: |
Ray Milkey | 25b785a | 2018-06-12 09:59:14 -0700 | [diff] [blame] | 93 | if java_common.provider in dep: |
| 94 | file = dep.files.to_list()[0] |
Ray Milkey | 25b785a | 2018-06-12 09:59:14 -0700 | [diff] [blame] | 95 | if cp: |
| 96 | cp += ":" |
| 97 | cp += file.path |
| 98 | inputDependencies = inputDependencies + [file] |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 99 | |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 100 | web_xml_root_path = "" |
| 101 | if len(web_xml) != 0: |
| 102 | web_xml_root = web_xml[0].files.to_list()[0] |
| 103 | inputDependencies += [web_xml_root] |
| 104 | web_xml_root_path = web_xml_root.path.replace("WEB-INF/web.xml", "") |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 105 | |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 106 | # call bnd to make the OSGI jar file |
| 107 | arguments = [ |
| 108 | jar, |
| 109 | output, |
| 110 | cp, |
| 111 | name, |
| 112 | group, |
| 113 | version, |
| 114 | license, |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 115 | import_packages, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 116 | exportPackages, |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 117 | include_resources, |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 118 | web_context, |
| 119 | web_xml_root_path, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 120 | dynamicimportPackages, |
Thomas Vachuska | e443694 | 2018-08-07 19:27:10 -0700 | [diff] [blame] | 121 | "classes", |
Jian Li | 4ad8687 | 2018-08-05 03:34:35 +0900 | [diff] [blame] | 122 | bundle_classpath, |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 123 | karaf_commands, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 124 | ] |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 125 | |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 126 | ctx.actions.run( |
| 127 | inputs = inputDependencies, |
| 128 | outputs = [ctx.outputs.osgi_jar], |
| 129 | arguments = arguments, |
| 130 | progress_message = "Running bnd wrapper on: %s" % ctx.attr.name, |
| 131 | executable = ctx.executable._bnd_exe, |
| 132 | ) |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 133 | |
Ray Milkey | 25b785a | 2018-06-12 09:59:14 -0700 | [diff] [blame] | 134 | deps = [] |
| 135 | if java_common.provider in ctx.attr.source: |
| 136 | deps.append(ctx.attr.source[java_common.provider]) |
| 137 | deps_provider = java_common.merge(deps) |
| 138 | return struct( |
Ray Milkey | 15053f0 | 2018-06-13 10:00:45 -0700 | [diff] [blame] | 139 | providers = [deps_provider], |
Ray Milkey | 25b785a | 2018-06-12 09:59:14 -0700 | [diff] [blame] | 140 | ) |
| 141 | |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 142 | """ |
| 143 | Rule definition for calling bnd to make an OSGi jar file. |
| 144 | """ |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 145 | _bnd = rule( |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 146 | attrs = { |
| 147 | "deps": attr.label_list(), |
| 148 | "version": attr.string(), |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 149 | "group": attr.string(), |
Ray Milkey | 3275ae8 | 2018-05-29 15:35:36 -0700 | [diff] [blame] | 150 | "source": attr.label(), |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 151 | "import_packages": attr.string(), |
Jian Li | 4ad8687 | 2018-08-05 03:34:35 +0900 | [diff] [blame] | 152 | "bundle_classpath": attr.string(), |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 153 | "web_context": attr.string(), |
| 154 | "web_xml": attr.label_list(allow_files = True), |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 155 | "include_resources": attr.string(), |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 156 | "karaf_commands": attr.string(), |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 157 | "_bnd_exe": attr.label( |
| 158 | executable = True, |
| 159 | cfg = "host", |
| 160 | allow_files = True, |
| 161 | default = Label("//utils/osgiwrap:osgi-jar"), |
| 162 | ), |
| 163 | }, |
| 164 | fragments = ["java"], |
| 165 | outputs = { |
| 166 | "osgi_jar": "lib%{name}.jar", |
| 167 | }, |
| 168 | implementation = _bnd_impl, |
| 169 | ) |
| 170 | |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 171 | """ |
| 172 | Implementation of the rule to call swagger generator to create the registrator java class source |
| 173 | """ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 174 | |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 175 | def _swagger_java_impl(ctx): |
| 176 | api_title = ctx.attr.api_title |
| 177 | api_version = ctx.attr.api_version |
| 178 | api_description = ctx.attr.api_description |
| 179 | api_package = ctx.attr.api_package |
| 180 | web_context = ctx.attr.web_context |
| 181 | |
| 182 | output_java = ctx.outputs.swagger_java.path |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 183 | output_dir = output_java[:output_java.find("generated-sources")] |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 184 | |
| 185 | package_name = ctx.attr.package_name |
| 186 | |
| 187 | srcs_arg = "" |
| 188 | resources_arg = "" |
| 189 | input_dependencies = [] |
| 190 | |
| 191 | for file in ctx.files.srcs: |
| 192 | srcs_arg += file.path + "," |
| 193 | input_dependencies.append(file) |
| 194 | |
| 195 | for resource in resources_arg: |
| 196 | resources_arg += resource.path + "," |
| 197 | |
| 198 | # call swagger generator to make the swagger JSON and java files |
| 199 | arguments = [ |
| 200 | srcs_arg, |
| 201 | resources_arg, |
| 202 | "", |
| 203 | package_name + "/src/main/resources", |
| 204 | output_dir, |
| 205 | output_dir, |
| 206 | web_context, |
| 207 | api_title, |
| 208 | api_version, |
| 209 | api_package, |
| 210 | api_description, |
| 211 | ] |
| 212 | |
| 213 | ctx.actions.run( |
| 214 | inputs = ctx.files.srcs, |
| 215 | outputs = [ctx.outputs.swagger_java], |
| 216 | arguments = arguments, |
| 217 | progress_message = "Running swagger generator on: %s" % ctx.attr.name, |
| 218 | executable = ctx.executable._swagger_generator_exe, |
| 219 | ) |
| 220 | |
| 221 | """ |
| 222 | Implementation of the rule to call swagger generator for swagger.json file |
| 223 | """ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 224 | |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 225 | def _swagger_json_impl(ctx): |
| 226 | api_title = ctx.attr.api_title |
| 227 | api_version = ctx.attr.api_version |
| 228 | api_description = ctx.attr.api_description |
| 229 | api_package = ctx.attr.api_package |
| 230 | web_context = ctx.attr.web_context |
| 231 | |
| 232 | output_json = ctx.outputs.swagger_json.path |
| 233 | output_dir = output_json[:output_json.find("swagger.json")] |
| 234 | |
| 235 | package_name = ctx.attr.package_name |
| 236 | |
| 237 | srcs_arg = "" |
| 238 | resources_arg = "" |
| 239 | input_dependencies = [] |
| 240 | |
| 241 | for file in ctx.files.srcs: |
| 242 | srcs_arg += file.path + "," |
| 243 | input_dependencies.append(file) |
| 244 | |
| 245 | for resource in resources_arg: |
| 246 | resources_arg += resource.path + "," |
| 247 | |
| 248 | # call swagger generator to make the swagger JSON and java files |
| 249 | arguments = [ |
| 250 | srcs_arg, |
| 251 | resources_arg, |
| 252 | "", |
| 253 | package_name + "/src/main/resources", |
| 254 | output_dir, |
| 255 | output_dir, |
| 256 | web_context, |
| 257 | api_title, |
| 258 | api_version, |
| 259 | api_package, |
| 260 | api_description, |
| 261 | ] |
| 262 | |
| 263 | ctx.actions.run( |
| 264 | inputs = ctx.files.srcs, |
| 265 | outputs = [ctx.outputs.swagger_json], |
| 266 | arguments = arguments, |
| 267 | progress_message = "Running swagger generator on: %s" % ctx.attr.name, |
| 268 | executable = ctx.executable._swagger_generator_exe, |
| 269 | ) |
| 270 | |
| 271 | """ |
| 272 | Rule definition to call swagger generator to create the registrator java class source |
| 273 | """ |
| 274 | _swagger_java = rule( |
| 275 | attrs = { |
| 276 | "srcs": attr.label_list(allow_files = True), |
| 277 | "package_name": attr.string(), |
| 278 | "api_title": attr.string(), |
| 279 | "api_version": attr.string(), |
| 280 | "api_description": attr.string(), |
| 281 | "api_package": attr.string(), |
| 282 | "web_context": attr.string(), |
| 283 | "_swagger_generator_exe": attr.label( |
| 284 | executable = True, |
| 285 | cfg = "host", |
| 286 | allow_files = True, |
| 287 | default = Label("//tools/build/buck-plugin:swagger_generator"), |
| 288 | ), |
| 289 | "swagger_java": attr.output(), |
| 290 | }, |
| 291 | fragments = ["java"], |
| 292 | implementation = _swagger_java_impl, |
| 293 | ) |
| 294 | |
| 295 | """ |
| 296 | Rule definition to call swagger generator to create the swagger JSON |
| 297 | """ |
| 298 | _swagger_json = rule( |
| 299 | attrs = { |
| 300 | "srcs": attr.label_list(allow_files = True), |
| 301 | "package_name": attr.string(), |
| 302 | "api_title": attr.string(), |
| 303 | "api_version": attr.string(), |
| 304 | "api_description": attr.string(), |
| 305 | "api_package": attr.string(), |
| 306 | "web_context": attr.string(), |
| 307 | "_swagger_generator_exe": attr.label( |
| 308 | executable = True, |
| 309 | cfg = "host", |
| 310 | allow_files = True, |
| 311 | default = Label("//tools/build/buck-plugin:swagger_generator"), |
| 312 | ), |
| 313 | "swagger_json": attr.output(), |
| 314 | }, |
| 315 | fragments = ["java"], |
| 316 | implementation = _swagger_json_impl, |
| 317 | ) |
| 318 | |
| 319 | """ |
| 320 | Converts a jar file to an OSGI compatible jar file. |
| 321 | |
| 322 | Args: |
| 323 | name: name of the rule to create the OSGI jar file - required |
| 324 | jar: jar file to convert - required target |
| 325 | deps: dependencies needed by the jar file - required list of targets |
| 326 | version: Version of the generated jar file. Optional, defaults to the current ONOS version |
| 327 | group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject' |
| 328 | import_packages: OSGI import list. Optional, comma separated list, defaults to "*" |
| 329 | visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to private |
| 330 | """ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 331 | |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 332 | def wrapped_osgi_jar( |
| 333 | name, |
| 334 | jar, |
| 335 | deps, |
| 336 | version = ONOS_VERSION, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 337 | group = "org.onosproject", |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 338 | import_packages = "*", |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 339 | visibility = ["//visibility:private"]): |
| 340 | _bnd( |
| 341 | name = name, |
| 342 | source = jar, |
| 343 | deps = deps, |
| 344 | version = version, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 345 | group = group, |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 346 | visibility = visibility, |
| 347 | import_packages = import_packages, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 348 | web_xml = None, |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 349 | ) |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 350 | |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 351 | """ |
| 352 | Creates an OSGI jar and test jar file from a set of source and test files. |
| 353 | See osgi_jar() for a description of shared parameters. |
| 354 | Args: |
| 355 | test_srcs: Test source file(s) to compile. Optional list of targets, defaults to src/test/java/**/*.java |
| 356 | test_deps: Dependencies for the test jar. Optional list of targets, defaults to a common set of dependencies |
| 357 | test_resources: Resources to include in the test jar. Optional list of targets, defaults to src/test/resources/** |
| 358 | exclude_tests: Tests that should not be run. Useful for excluding things like test files without any @Test methods. |
| 359 | Optional ist of targets, defaults to [] |
| 360 | """ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 361 | |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 362 | def osgi_jar_with_tests( |
| 363 | name = None, |
| 364 | deps = None, |
| 365 | test_deps = None, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 366 | group = "org.onosproject", |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 367 | srcs = None, |
| 368 | resources_root = None, |
| 369 | resources = None, |
Thomas Vachuska | f8c8cb9 | 2018-07-11 17:12:43 -0700 | [diff] [blame] | 370 | resource_jars = [], |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 371 | include_resources = {}, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 372 | test_srcs = None, |
| 373 | exclude_tests = None, |
Thomas Vachuska | a79bf6e | 2018-08-07 11:24:40 -0700 | [diff] [blame] | 374 | medium_tests = [], |
| 375 | large_tests = [], |
| 376 | enormous_tests = [], |
| 377 | flaky_tests = [], |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 378 | test_resources = None, |
| 379 | visibility = ["//visibility:public"], |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 380 | version = ONOS_VERSION, |
Thomas Vachuska | 5b9ff6a | 2018-07-13 11:00:50 -0700 | [diff] [blame] | 381 | suppress_errorprone = False, |
Ray Milkey | 134d292 | 2018-07-15 15:24:01 -0700 | [diff] [blame] | 382 | suppress_checkstyle = False, |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 383 | suppress_javadocs = False, |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 384 | web_context = None, |
| 385 | api_title = "", |
| 386 | api_version = "", |
| 387 | api_description = "", |
| 388 | api_package = "", |
Jian Li | 4ad8687 | 2018-08-05 03:34:35 +0900 | [diff] [blame] | 389 | import_packages = None, |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 390 | bundle_classpath = "", |
| 391 | karaf_command_packages = []): |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 392 | if name == None: |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 393 | name = _auto_name() |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 394 | if srcs == None: |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 395 | srcs = _all_java_sources() |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 396 | if resources == None: |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 397 | resources = _all_resources(resources_root) |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 398 | if test_srcs == None: |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 399 | test_srcs = _all_java_test_sources() |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 400 | if test_resources == None: |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 401 | test_resources = _all_test_resources() |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 402 | if exclude_tests == None: |
| 403 | exclude_tests = [] |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 404 | if deps == None: |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 405 | deps = COMPILE |
| 406 | if test_deps == None: |
| 407 | test_deps = TEST |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 408 | if import_packages == None: |
| 409 | import_packages = "*" |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 410 | tests_name = name + "-tests" |
| 411 | tests_jar_deps = list(depset(deps + test_deps)) + [name] |
| 412 | all_test_deps = tests_jar_deps + [tests_name] |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 413 | web_xml = _webapp() |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 414 | |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 415 | native_srcs = srcs |
| 416 | native_resources = resources |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 417 | if web_context != None and api_title != "" and len(resources) != 0 and 1 == 0: |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 418 | # generate Swagger files if needed |
| 419 | _swagger_java( |
| 420 | name = name + "_swagger_java", |
| 421 | srcs = srcs + resources, |
| 422 | package_name = native.package_name(), |
| 423 | api_title = api_title, |
| 424 | api_version = api_version, |
| 425 | api_description = api_description, |
| 426 | web_context = web_context, |
| 427 | api_package = api_package, |
| 428 | swagger_java = ("src/main/resources/apidoc/generated-sources/" + |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 429 | api_package.replace(".", "/") + |
| 430 | "/ApiDocRegistrator.java").replace("//", "/"), |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 431 | ) |
| 432 | _swagger_json( |
| 433 | name = name + "_swagger_json", |
| 434 | srcs = srcs + resources, |
| 435 | package_name = native.package_name(), |
| 436 | api_title = api_title, |
| 437 | api_version = api_version, |
| 438 | api_description = api_description, |
| 439 | web_context = web_context, |
| 440 | api_package = api_package, |
| 441 | swagger_json = "src/main/resources/apidoc/swagger.json", |
| 442 | ) |
| 443 | native_resources = [] |
| 444 | for r in resources: |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 445 | if not "definitions" in r: |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 446 | native_resources.append(r) |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 447 | native_srcs = srcs + [name + "_swagger_java"] |
| 448 | native_resources.append(name + "_swagger_json") |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 449 | |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 450 | javacopts = ["-XepDisableAllChecks"] if suppress_errorprone else [] |
Thomas Vachuska | 5b9ff6a | 2018-07-13 11:00:50 -0700 | [diff] [blame] | 451 | |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 452 | # compile the Java code |
Thomas Vachuska | f8c8cb9 | 2018-07-11 17:12:43 -0700 | [diff] [blame] | 453 | if len(resource_jars) > 0: |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 454 | native.java_library( |
| 455 | name = name + "-native", |
| 456 | srcs = native_srcs, |
| 457 | resource_jars = resource_jars, |
| 458 | deps = deps, |
| 459 | visibility = visibility, |
| 460 | javacopts = javacopts, |
| 461 | ) |
Thomas Vachuska | f8c8cb9 | 2018-07-11 17:12:43 -0700 | [diff] [blame] | 462 | else: |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 463 | native.java_library( |
| 464 | name = name + "-native", |
| 465 | srcs = native_srcs, |
| 466 | resources = native_resources, |
| 467 | deps = deps, |
| 468 | visibility = visibility, |
| 469 | javacopts = javacopts, |
| 470 | ) |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 471 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 472 | karaf_command_packages_string = ",".join(karaf_command_packages) |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 473 | _bnd( |
Ray Milkey | 25b785a | 2018-06-12 09:59:14 -0700 | [diff] [blame] | 474 | name = name, |
| 475 | source = name + "-native", |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 476 | deps = deps, |
| 477 | version = version, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 478 | group = group, |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 479 | visibility = visibility, |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 480 | import_packages = import_packages, |
Jian Li | 4ad8687 | 2018-08-05 03:34:35 +0900 | [diff] [blame] | 481 | bundle_classpath = bundle_classpath, |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 482 | web_context = web_context, |
| 483 | web_xml = web_xml, |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 484 | include_resources = _include_resources_to_string(include_resources), |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 485 | karaf_commands = karaf_command_packages_string, |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 486 | ) |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 487 | |
Thomas Vachuska | ac9e524 | 2018-07-19 16:15:39 -0700 | [diff] [blame] | 488 | # rule for generating pom file for publishing |
| 489 | pom_file(name = name + "-pom", artifact = name, deps = deps, visibility = visibility) |
| 490 | |
| 491 | # rule for building source jar |
Thomas Vachuska | 50ac098 | 2018-07-19 10:17:37 -0700 | [diff] [blame] | 492 | if not suppress_javadocs: |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 493 | java_sources(name = name + "-sources", srcs = srcs, visibility = visibility) |
Thomas Vachuska | 50ac098 | 2018-07-19 10:17:37 -0700 | [diff] [blame] | 494 | |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 495 | # rule for building javadocs |
| 496 | if not suppress_javadocs: |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 497 | javadoc(name = name + "-javadoc", deps = deps, srcs = srcs, visibility = visibility) |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 498 | |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 499 | if test_srcs != []: |
| 500 | native.java_library( |
| 501 | name = tests_name, |
| 502 | srcs = test_srcs, |
| 503 | resources = test_resources, |
| 504 | deps = tests_jar_deps, |
| 505 | visibility = visibility, |
| 506 | ) |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 507 | |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 508 | generate_test_rules( |
| 509 | name = name + "-tests-gen", |
| 510 | test_files = test_srcs, |
| 511 | exclude_tests = exclude_tests, |
Thomas Vachuska | a79bf6e | 2018-08-07 11:24:40 -0700 | [diff] [blame] | 512 | medium_tests = medium_tests, |
| 513 | large_tests = large_tests, |
| 514 | enormous_tests = enormous_tests, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 515 | deps = all_test_deps, |
| 516 | ) |
| 517 | |
Ray Milkey | 134d292 | 2018-07-15 15:24:01 -0700 | [diff] [blame] | 518 | if not suppress_checkstyle: |
| 519 | checkstyle_test( |
| 520 | name = name + "_checkstyle_test", |
| 521 | srcs = srcs, |
| 522 | ) |
Ray Milkey | b64fe82 | 2018-08-30 09:18:16 -0700 | [diff] [blame] | 523 | if test_srcs != []: |
| 524 | checkstyle_test( |
| 525 | name = name + "_checkstyle_tests_test", |
| 526 | srcs = test_srcs, |
| 527 | ) |
Ray Milkey | b7949e7 | 2018-06-19 18:31:02 -0700 | [diff] [blame] | 528 | |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 529 | """ |
| 530 | Creates an OSGI jar file from a set of source files. |
| 531 | |
| 532 | Args: |
| 533 | name: Name of the rule to generate. Optional, defaults to a name based on the location in the source tree. |
| 534 | For example apps/mcast/app becomes onos-apps-mcast-app |
| 535 | deps: Dependencies of the generated jar file. Expressed as a list of targets |
| 536 | import_packages: OSGI import list. Optional, comma separated list, defaults to "*" |
Jian Li | 4ad8687 | 2018-08-05 03:34:35 +0900 | [diff] [blame] | 537 | bundle_classpath: intended for including dependencies in our bundle, so that our bundle can be deployed standalone |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 538 | group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject' |
| 539 | srcs: Source file(s) to compile. Optional list of targets, defaults to src/main/java/**/*.java |
| 540 | resources_root: Relative path to the root of the tree of resources for this jar. Optional, defaults to src/main/resources |
| 541 | resources: Resources to include in the jar file. Optional list of targets, defaults to all files beneath resources_root |
| 542 | visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to public |
| 543 | version: Version of the generated jar file. Optional, defaults to the current ONOS version |
Ray Milkey | 134d292 | 2018-07-15 15:24:01 -0700 | [diff] [blame] | 544 | suppress_errorprone: If true, don't run ErrorProne tests. Default is false |
| 545 | suppress_checkstyle: If true, don't run checkstyle tests. Default is false |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 546 | web_context: Web context for a WAB file if needed. Only needed if the jar file provides a REST API. Optional string |
| 547 | api_title: Swagger API title. Optional string, only used if the jar file provides a REST API and has swagger annotations |
| 548 | api_version: Swagger API version. Optional string, only used if the jar file provides a REST API and has swagger annotations |
| 549 | api_description: Swagger API description. Optional string, only used if the jar file provides a REST API and has swagger annotations |
| 550 | api_package: Swagger API package name. Optional string, only used if the jar file provides a REST API and has swagger annotations |
| 551 | """ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 552 | |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 553 | def osgi_jar( |
| 554 | name = None, |
| 555 | deps = None, |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 556 | import_packages = None, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 557 | group = "org.onosproject", |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 558 | srcs = None, |
| 559 | resources_root = None, |
| 560 | resources = None, |
Thomas Vachuska | f8c8cb9 | 2018-07-11 17:12:43 -0700 | [diff] [blame] | 561 | resource_jars = [], |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 562 | include_resources = {}, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 563 | visibility = ["//visibility:public"], |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 564 | version = ONOS_VERSION, |
Thomas Vachuska | 5b9ff6a | 2018-07-13 11:00:50 -0700 | [diff] [blame] | 565 | suppress_errorprone = False, |
Ray Milkey | 134d292 | 2018-07-15 15:24:01 -0700 | [diff] [blame] | 566 | suppress_checkstyle = False, |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 567 | suppress_javadocs = False, |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 568 | web_context = None, |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 569 | api_title = "", |
| 570 | api_version = "", |
| 571 | api_description = "", |
Jian Li | 4ad8687 | 2018-08-05 03:34:35 +0900 | [diff] [blame] | 572 | api_package = "", |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 573 | bundle_classpath = "", |
| 574 | karaf_command_packages = []): |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 575 | if srcs == None: |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 576 | srcs = _all_java_sources() |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 577 | if deps == None: |
| 578 | deps = COMPILE |
| 579 | |
| 580 | osgi_jar_with_tests( |
| 581 | name = name, |
| 582 | deps = deps, |
| 583 | test_deps = [], |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 584 | group = group, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 585 | srcs = srcs, |
| 586 | resources = resources, |
| 587 | resources_root = resources_root, |
Thomas Vachuska | f8c8cb9 | 2018-07-11 17:12:43 -0700 | [diff] [blame] | 588 | resource_jars = resource_jars, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 589 | test_srcs = [], |
| 590 | exclude_tests = [], |
| 591 | test_resources = [], |
| 592 | visibility = visibility, |
Thomas Vachuska | 5b9ff6a | 2018-07-13 11:00:50 -0700 | [diff] [blame] | 593 | suppress_errorprone = suppress_errorprone, |
Ray Milkey | 134d292 | 2018-07-15 15:24:01 -0700 | [diff] [blame] | 594 | suppress_checkstyle = suppress_checkstyle, |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 595 | suppress_javadocs = suppress_javadocs, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 596 | version = version, |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 597 | import_packages = import_packages, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 598 | api_title = api_title, |
| 599 | api_version = api_version, |
| 600 | api_description = api_description, |
| 601 | api_package = api_package, |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 602 | web_context = web_context, |
Jian Li | 4ad8687 | 2018-08-05 03:34:35 +0900 | [diff] [blame] | 603 | bundle_classpath = bundle_classpath, |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 604 | karaf_command_packages = karaf_command_packages, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 605 | ) |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 606 | |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 607 | """ |
| 608 | Creates an OSGI jar file from a set of protobuf and gRPC libraries. |
| 609 | |
| 610 | Args: |
| 611 | name: Name of the rule to generate. Optional, defaults to a name based on the location in the source tree. |
| 612 | For example apps/mcast/app becomes onos-apps-mcast-app |
| 613 | proto_libs: (required) list of proto_library targets which generated Java classes will be included to this OSGi |
| 614 | jar. It is important that all the given targets reference to a single proto source files, for example |
| 615 | only the first 2 rules are good: |
| 616 | |
| 617 | proto_library( |
| 618 | name = "foo_proto", |
| 619 | srcs = ["foo.proto"], |
| 620 | ) |
| 621 | |
| 622 | proto_library( |
| 623 | name = "bar_proto", |
| 624 | srcs = ["bar.proto"], |
| 625 | ) |
| 626 | |
| 627 | # THIS WILL NOT WORK |
| 628 | proto_library( |
| 629 | name = "foo_and_bar_proto", |
| 630 | srcs = ["foo.proto", "bar.proto"], |
| 631 | ) |
| 632 | |
| 633 | grpc_proto_lib: (optional) proto_library target that contains the schema of a gRPC service. If not passed, |
| 634 | the produced jar will NOT have any gRPC stub classes. |
| 635 | deps: Dependencies of the generated jar file. Expressed as a list of targets |
| 636 | group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject' |
| 637 | visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to public |
| 638 | version: Version of the generated jar file. Optional, defaults to the current ONOS version |
| 639 | """ |
| 640 | |
| 641 | def osgi_proto_jar( |
| 642 | proto_libs, |
| 643 | grpc_proto_lib = None, |
| 644 | name = None, |
| 645 | deps = [], |
| 646 | group = "org.onosproject", |
| 647 | visibility = ["//visibility:public"], |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 648 | version = ONOS_VERSION, |
| 649 | karaf_command_packages = []): |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 650 | if name == None: |
| 651 | name = _auto_name() |
| 652 | native.java_proto_library( |
| 653 | name = name + "-java-proto", |
| 654 | deps = proto_libs, |
| 655 | ) |
| 656 | java_sources_alt( |
| 657 | name = name + "-proto-srcjar", |
| 658 | srcs = [":%s-java-proto" % name], |
| 659 | ) |
| 660 | osgi_srcs = [ |
| 661 | ":%s-proto-srcjar" % name, |
| 662 | ] |
| 663 | base_deps = [ |
| 664 | "@com_google_protobuf//:protobuf_java", |
| 665 | ] |
| 666 | if grpc_proto_lib != None: |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 667 | java_grpc_library( |
| 668 | name = name + "-java-grpc", |
| 669 | srcs = [grpc_proto_lib], |
| 670 | deps = [":%s-java-proto" % name], |
| 671 | ) |
| 672 | osgi_srcs.append( |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 673 | ":%s-java-grpc__do_not_reference__srcjar" % name, |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 674 | ) |
| 675 | base_deps.extend([ |
| 676 | "@com_google_guava_guava//jar", |
| 677 | "@io_grpc_grpc_java//core", |
| 678 | "@io_grpc_grpc_java//stub", |
| 679 | "@io_grpc_grpc_java//protobuf", |
| 680 | ]) |
| 681 | osgi_jar( |
| 682 | name = name, |
| 683 | srcs = osgi_srcs, |
| 684 | deps = base_deps + deps, |
| 685 | group = group, |
| 686 | visibility = visibility, |
| 687 | version = version, |
| 688 | suppress_errorprone = True, |
| 689 | suppress_checkstyle = True, |
| 690 | suppress_javadocs = True, |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 691 | karaf_command_packages = karaf_command_packages, |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 692 | ) |