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 | """ |
Thomas Vachuska | 24d4f6d | 2018-10-19 11:25:04 -0700 | [diff] [blame] | 172 | Implementation of the rule to generate cfgdef files from java class source |
| 173 | """ |
| 174 | |
| 175 | def _cfgdef_impl(ctx): |
| 176 | output_jar = ctx.outputs.cfgdef_jar.path |
| 177 | |
Thomas Vachuska | 24d4f6d | 2018-10-19 11:25:04 -0700 | [diff] [blame] | 178 | arguments = [ |
| 179 | output_jar, |
Thomas Vachuska | 24d4f6d | 2018-10-19 11:25:04 -0700 | [diff] [blame] | 180 | ] |
| 181 | |
Thomas Vachuska | bef430b | 2018-10-22 10:55:47 -0700 | [diff] [blame] | 182 | for src in ctx.files.srcs: |
| 183 | arguments.append(src.path) |
| 184 | |
Thomas Vachuska | 24d4f6d | 2018-10-19 11:25:04 -0700 | [diff] [blame] | 185 | ctx.actions.run( |
| 186 | inputs = ctx.files.srcs, |
| 187 | outputs = [ctx.outputs.cfgdef_jar], |
| 188 | arguments = arguments, |
| 189 | progress_message = "Running cfgdef generator on: %s" % ctx.attr.name, |
| 190 | executable = ctx.executable._cfgdef_generator_exe, |
| 191 | ) |
| 192 | |
| 193 | """ |
| 194 | Rule definition to call cfgdef generator to create the *.cfgdef files from java sources |
| 195 | """ |
| 196 | _cfgdef = rule( |
| 197 | attrs = { |
| 198 | "srcs": attr.label_list(allow_files = True), |
| 199 | "_cfgdef_generator_exe": attr.label( |
| 200 | executable = True, |
| 201 | cfg = "host", |
| 202 | allow_files = True, |
| 203 | default = Label("//tools/build/cfgdef:cfgdef_generator"), |
| 204 | ), |
| 205 | "cfgdef_jar": attr.output(), |
| 206 | }, |
| 207 | fragments = ["java"], |
| 208 | implementation = _cfgdef_impl, |
| 209 | ) |
| 210 | |
| 211 | """ |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 212 | Implementation of the rule to call swagger generator to create the registrator java class source |
| 213 | """ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 214 | |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 215 | def _swagger_java_impl(ctx): |
| 216 | api_title = ctx.attr.api_title |
| 217 | api_version = ctx.attr.api_version |
| 218 | api_description = ctx.attr.api_description |
| 219 | api_package = ctx.attr.api_package |
| 220 | web_context = ctx.attr.web_context |
| 221 | |
| 222 | output_java = ctx.outputs.swagger_java.path |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 223 | output_dir = output_java[:output_java.find("generated-sources")] |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 224 | |
| 225 | package_name = ctx.attr.package_name |
| 226 | |
| 227 | srcs_arg = "" |
| 228 | resources_arg = "" |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 229 | |
| 230 | for file in ctx.files.srcs: |
| 231 | srcs_arg += file.path + "," |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 232 | |
| 233 | for resource in resources_arg: |
| 234 | resources_arg += resource.path + "," |
| 235 | |
| 236 | # call swagger generator to make the swagger JSON and java files |
| 237 | arguments = [ |
| 238 | srcs_arg, |
| 239 | resources_arg, |
| 240 | "", |
| 241 | package_name + "/src/main/resources", |
| 242 | output_dir, |
| 243 | output_dir, |
| 244 | web_context, |
| 245 | api_title, |
| 246 | api_version, |
| 247 | api_package, |
| 248 | api_description, |
| 249 | ] |
| 250 | |
| 251 | ctx.actions.run( |
| 252 | inputs = ctx.files.srcs, |
| 253 | outputs = [ctx.outputs.swagger_java], |
| 254 | arguments = arguments, |
| 255 | progress_message = "Running swagger generator on: %s" % ctx.attr.name, |
| 256 | executable = ctx.executable._swagger_generator_exe, |
| 257 | ) |
| 258 | |
| 259 | """ |
| 260 | Implementation of the rule to call swagger generator for swagger.json file |
| 261 | """ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 262 | |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 263 | def _swagger_json_impl(ctx): |
| 264 | api_title = ctx.attr.api_title |
| 265 | api_version = ctx.attr.api_version |
| 266 | api_description = ctx.attr.api_description |
| 267 | api_package = ctx.attr.api_package |
| 268 | web_context = ctx.attr.web_context |
| 269 | |
| 270 | output_json = ctx.outputs.swagger_json.path |
| 271 | output_dir = output_json[:output_json.find("swagger.json")] |
| 272 | |
| 273 | package_name = ctx.attr.package_name |
| 274 | |
| 275 | srcs_arg = "" |
| 276 | resources_arg = "" |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 277 | |
| 278 | for file in ctx.files.srcs: |
| 279 | srcs_arg += file.path + "," |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 280 | |
| 281 | for resource in resources_arg: |
| 282 | resources_arg += resource.path + "," |
| 283 | |
| 284 | # call swagger generator to make the swagger JSON and java files |
| 285 | arguments = [ |
| 286 | srcs_arg, |
| 287 | resources_arg, |
| 288 | "", |
| 289 | package_name + "/src/main/resources", |
| 290 | output_dir, |
| 291 | output_dir, |
| 292 | web_context, |
| 293 | api_title, |
| 294 | api_version, |
| 295 | api_package, |
| 296 | api_description, |
| 297 | ] |
| 298 | |
| 299 | ctx.actions.run( |
| 300 | inputs = ctx.files.srcs, |
| 301 | outputs = [ctx.outputs.swagger_json], |
| 302 | arguments = arguments, |
| 303 | progress_message = "Running swagger generator on: %s" % ctx.attr.name, |
| 304 | executable = ctx.executable._swagger_generator_exe, |
| 305 | ) |
| 306 | |
| 307 | """ |
| 308 | Rule definition to call swagger generator to create the registrator java class source |
| 309 | """ |
| 310 | _swagger_java = rule( |
| 311 | attrs = { |
| 312 | "srcs": attr.label_list(allow_files = True), |
| 313 | "package_name": attr.string(), |
| 314 | "api_title": attr.string(), |
| 315 | "api_version": attr.string(), |
| 316 | "api_description": attr.string(), |
| 317 | "api_package": attr.string(), |
| 318 | "web_context": attr.string(), |
| 319 | "_swagger_generator_exe": attr.label( |
| 320 | executable = True, |
| 321 | cfg = "host", |
| 322 | allow_files = True, |
Thomas Vachuska | 22ea612 | 2018-10-24 12:28:59 -0700 | [diff] [blame] | 323 | default = Label("//tools/build/swagger:swagger_generator"), |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 324 | ), |
| 325 | "swagger_java": attr.output(), |
| 326 | }, |
| 327 | fragments = ["java"], |
| 328 | implementation = _swagger_java_impl, |
| 329 | ) |
| 330 | |
| 331 | """ |
| 332 | Rule definition to call swagger generator to create the swagger JSON |
| 333 | """ |
| 334 | _swagger_json = rule( |
| 335 | attrs = { |
| 336 | "srcs": attr.label_list(allow_files = True), |
| 337 | "package_name": attr.string(), |
| 338 | "api_title": attr.string(), |
| 339 | "api_version": attr.string(), |
| 340 | "api_description": attr.string(), |
| 341 | "api_package": attr.string(), |
| 342 | "web_context": attr.string(), |
| 343 | "_swagger_generator_exe": attr.label( |
| 344 | executable = True, |
| 345 | cfg = "host", |
| 346 | allow_files = True, |
Thomas Vachuska | 22ea612 | 2018-10-24 12:28:59 -0700 | [diff] [blame] | 347 | default = Label("//tools/build/swagger:swagger_generator"), |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 348 | ), |
| 349 | "swagger_json": attr.output(), |
| 350 | }, |
| 351 | fragments = ["java"], |
| 352 | implementation = _swagger_json_impl, |
| 353 | ) |
| 354 | |
| 355 | """ |
| 356 | Converts a jar file to an OSGI compatible jar file. |
| 357 | |
| 358 | Args: |
| 359 | name: name of the rule to create the OSGI jar file - required |
| 360 | jar: jar file to convert - required target |
| 361 | deps: dependencies needed by the jar file - required list of targets |
| 362 | version: Version of the generated jar file. Optional, defaults to the current ONOS version |
| 363 | group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject' |
| 364 | import_packages: OSGI import list. Optional, comma separated list, defaults to "*" |
| 365 | visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to private |
| 366 | """ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 367 | |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 368 | def wrapped_osgi_jar( |
| 369 | name, |
| 370 | jar, |
| 371 | deps, |
| 372 | version = ONOS_VERSION, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 373 | group = "org.onosproject", |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 374 | import_packages = "*", |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 375 | visibility = ["//visibility:private"]): |
| 376 | _bnd( |
| 377 | name = name, |
| 378 | source = jar, |
| 379 | deps = deps, |
| 380 | version = version, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 381 | group = group, |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 382 | visibility = visibility, |
| 383 | import_packages = import_packages, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 384 | web_xml = None, |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 385 | ) |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 386 | |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 387 | """ |
| 388 | Creates an OSGI jar and test jar file from a set of source and test files. |
| 389 | See osgi_jar() for a description of shared parameters. |
| 390 | Args: |
| 391 | test_srcs: Test source file(s) to compile. Optional list of targets, defaults to src/test/java/**/*.java |
| 392 | test_deps: Dependencies for the test jar. Optional list of targets, defaults to a common set of dependencies |
| 393 | test_resources: Resources to include in the test jar. Optional list of targets, defaults to src/test/resources/** |
| 394 | exclude_tests: Tests that should not be run. Useful for excluding things like test files without any @Test methods. |
| 395 | Optional ist of targets, defaults to [] |
| 396 | """ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 397 | |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 398 | def osgi_jar_with_tests( |
| 399 | name = None, |
| 400 | deps = None, |
| 401 | test_deps = None, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 402 | group = "org.onosproject", |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 403 | srcs = None, |
| 404 | resources_root = None, |
| 405 | resources = None, |
Thomas Vachuska | f8c8cb9 | 2018-07-11 17:12:43 -0700 | [diff] [blame] | 406 | resource_jars = [], |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 407 | include_resources = {}, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 408 | test_srcs = None, |
| 409 | exclude_tests = None, |
Thomas Vachuska | a79bf6e | 2018-08-07 11:24:40 -0700 | [diff] [blame] | 410 | medium_tests = [], |
| 411 | large_tests = [], |
| 412 | enormous_tests = [], |
| 413 | flaky_tests = [], |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 414 | test_resources = None, |
| 415 | visibility = ["//visibility:public"], |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 416 | version = ONOS_VERSION, |
Thomas Vachuska | 5b9ff6a | 2018-07-13 11:00:50 -0700 | [diff] [blame] | 417 | suppress_errorprone = False, |
Ray Milkey | 134d292 | 2018-07-15 15:24:01 -0700 | [diff] [blame] | 418 | suppress_checkstyle = False, |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 419 | suppress_javadocs = False, |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 420 | web_context = None, |
| 421 | api_title = "", |
| 422 | api_version = "", |
| 423 | api_description = "", |
| 424 | api_package = "", |
Jian Li | 4ad8687 | 2018-08-05 03:34:35 +0900 | [diff] [blame] | 425 | import_packages = None, |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 426 | bundle_classpath = "", |
| 427 | karaf_command_packages = []): |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 428 | if name == None: |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 429 | name = _auto_name() |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 430 | if srcs == None: |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 431 | srcs = _all_java_sources() |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 432 | if resources == None: |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 433 | resources = _all_resources(resources_root) |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 434 | if test_srcs == None: |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 435 | test_srcs = _all_java_test_sources() |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 436 | if test_resources == None: |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 437 | test_resources = _all_test_resources() |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 438 | if exclude_tests == None: |
| 439 | exclude_tests = [] |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 440 | if deps == None: |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 441 | deps = COMPILE |
| 442 | if test_deps == None: |
| 443 | test_deps = TEST |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 444 | if import_packages == None: |
| 445 | import_packages = "*" |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 446 | tests_name = name + "-tests" |
| 447 | tests_jar_deps = list(depset(deps + test_deps)) + [name] |
| 448 | all_test_deps = tests_jar_deps + [tests_name] |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 449 | web_xml = _webapp() |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 450 | |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 451 | native_srcs = srcs |
| 452 | native_resources = resources |
Thomas Vachuska | 24d4f6d | 2018-10-19 11:25:04 -0700 | [diff] [blame] | 453 | |
Thomas Vachuska | 24d4f6d | 2018-10-19 11:25:04 -0700 | [diff] [blame] | 454 | if web_context != None and api_title != "" and len(resources) != 0: |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 455 | # generate Swagger files if needed |
| 456 | _swagger_java( |
| 457 | name = name + "_swagger_java", |
| 458 | srcs = srcs + resources, |
| 459 | package_name = native.package_name(), |
| 460 | api_title = api_title, |
| 461 | api_version = api_version, |
| 462 | api_description = api_description, |
| 463 | web_context = web_context, |
| 464 | api_package = api_package, |
| 465 | swagger_java = ("src/main/resources/apidoc/generated-sources/" + |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 466 | api_package.replace(".", "/") + |
| 467 | "/ApiDocRegistrator.java").replace("//", "/"), |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 468 | ) |
| 469 | _swagger_json( |
| 470 | name = name + "_swagger_json", |
| 471 | srcs = srcs + resources, |
| 472 | package_name = native.package_name(), |
| 473 | api_title = api_title, |
| 474 | api_version = api_version, |
| 475 | api_description = api_description, |
| 476 | web_context = web_context, |
| 477 | api_package = api_package, |
| 478 | swagger_json = "src/main/resources/apidoc/swagger.json", |
| 479 | ) |
| 480 | native_resources = [] |
| 481 | for r in resources: |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 482 | if not "definitions" in r: |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 483 | native_resources.append(r) |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 484 | native_srcs = srcs + [name + "_swagger_java"] |
| 485 | native_resources.append(name + "_swagger_json") |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 486 | |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 487 | javacopts = ["-XepDisableAllChecks"] if suppress_errorprone else [] |
Thomas Vachuska | 5b9ff6a | 2018-07-13 11:00:50 -0700 | [diff] [blame] | 488 | |
Thomas Vachuska | bef430b | 2018-10-22 10:55:47 -0700 | [diff] [blame] | 489 | _cfgdef( |
| 490 | name = name + "_cfgdef_jar", |
| 491 | srcs = native_srcs, |
| 492 | visibility = visibility, |
| 493 | cfgdef_jar = name + "_cfgdef.jar", |
| 494 | ) |
| 495 | |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 496 | # compile the Java code |
Thomas Vachuska | f8c8cb9 | 2018-07-11 17:12:43 -0700 | [diff] [blame] | 497 | if len(resource_jars) > 0: |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 498 | native.java_library( |
| 499 | name = name + "-native", |
| 500 | srcs = native_srcs, |
Thomas Vachuska | bef430b | 2018-10-22 10:55:47 -0700 | [diff] [blame] | 501 | resource_jars = resource_jars + [name + "_cfgdef_jar"], |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 502 | deps = deps, |
| 503 | visibility = visibility, |
| 504 | javacopts = javacopts, |
| 505 | ) |
Thomas Vachuska | f8c8cb9 | 2018-07-11 17:12:43 -0700 | [diff] [blame] | 506 | else: |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 507 | native.java_library( |
| 508 | name = name + "-native", |
| 509 | srcs = native_srcs, |
Thomas Vachuska | bef430b | 2018-10-22 10:55:47 -0700 | [diff] [blame] | 510 | resource_jars = [name + "_cfgdef_jar"], |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 511 | resources = native_resources, |
| 512 | deps = deps, |
| 513 | visibility = visibility, |
| 514 | javacopts = javacopts, |
| 515 | ) |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 516 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 517 | karaf_command_packages_string = ",".join(karaf_command_packages) |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 518 | _bnd( |
Ray Milkey | 25b785a | 2018-06-12 09:59:14 -0700 | [diff] [blame] | 519 | name = name, |
| 520 | source = name + "-native", |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 521 | deps = deps, |
| 522 | version = version, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 523 | group = group, |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 524 | visibility = visibility, |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 525 | import_packages = import_packages, |
Jian Li | 4ad8687 | 2018-08-05 03:34:35 +0900 | [diff] [blame] | 526 | bundle_classpath = bundle_classpath, |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 527 | web_context = web_context, |
| 528 | web_xml = web_xml, |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 529 | include_resources = _include_resources_to_string(include_resources), |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 530 | karaf_commands = karaf_command_packages_string, |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 531 | ) |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 532 | |
Thomas Vachuska | ac9e524 | 2018-07-19 16:15:39 -0700 | [diff] [blame] | 533 | # rule for generating pom file for publishing |
| 534 | pom_file(name = name + "-pom", artifact = name, deps = deps, visibility = visibility) |
| 535 | |
| 536 | # rule for building source jar |
Thomas Vachuska | 50ac098 | 2018-07-19 10:17:37 -0700 | [diff] [blame] | 537 | if not suppress_javadocs: |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 538 | java_sources(name = name + "-sources", srcs = srcs, visibility = visibility) |
Thomas Vachuska | 50ac098 | 2018-07-19 10:17:37 -0700 | [diff] [blame] | 539 | |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 540 | # rule for building javadocs |
| 541 | if not suppress_javadocs: |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 542 | javadoc(name = name + "-javadoc", deps = deps, srcs = srcs, visibility = visibility) |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 543 | |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 544 | if test_srcs != []: |
| 545 | native.java_library( |
| 546 | name = tests_name, |
| 547 | srcs = test_srcs, |
| 548 | resources = test_resources, |
| 549 | deps = tests_jar_deps, |
| 550 | visibility = visibility, |
| 551 | ) |
Ray Milkey | 7dac7da | 2017-08-01 16:56:05 -0700 | [diff] [blame] | 552 | |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 553 | generate_test_rules( |
| 554 | name = name + "-tests-gen", |
| 555 | test_files = test_srcs, |
| 556 | exclude_tests = exclude_tests, |
Thomas Vachuska | a79bf6e | 2018-08-07 11:24:40 -0700 | [diff] [blame] | 557 | medium_tests = medium_tests, |
| 558 | large_tests = large_tests, |
| 559 | enormous_tests = enormous_tests, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 560 | deps = all_test_deps, |
| 561 | ) |
| 562 | |
Ray Milkey | 134d292 | 2018-07-15 15:24:01 -0700 | [diff] [blame] | 563 | if not suppress_checkstyle: |
| 564 | checkstyle_test( |
| 565 | name = name + "_checkstyle_test", |
| 566 | srcs = srcs, |
| 567 | ) |
Ray Milkey | b64fe82 | 2018-08-30 09:18:16 -0700 | [diff] [blame] | 568 | if test_srcs != []: |
| 569 | checkstyle_test( |
| 570 | name = name + "_checkstyle_tests_test", |
| 571 | srcs = test_srcs, |
| 572 | ) |
Ray Milkey | b7949e7 | 2018-06-19 18:31:02 -0700 | [diff] [blame] | 573 | |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 574 | """ |
| 575 | Creates an OSGI jar file from a set of source files. |
| 576 | |
| 577 | Args: |
| 578 | name: Name of the rule to generate. Optional, defaults to a name based on the location in the source tree. |
| 579 | For example apps/mcast/app becomes onos-apps-mcast-app |
| 580 | deps: Dependencies of the generated jar file. Expressed as a list of targets |
| 581 | import_packages: OSGI import list. Optional, comma separated list, defaults to "*" |
Jian Li | 4ad8687 | 2018-08-05 03:34:35 +0900 | [diff] [blame] | 582 | 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] | 583 | group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject' |
| 584 | srcs: Source file(s) to compile. Optional list of targets, defaults to src/main/java/**/*.java |
| 585 | resources_root: Relative path to the root of the tree of resources for this jar. Optional, defaults to src/main/resources |
| 586 | resources: Resources to include in the jar file. Optional list of targets, defaults to all files beneath resources_root |
| 587 | visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to public |
| 588 | 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] | 589 | suppress_errorprone: If true, don't run ErrorProne tests. Default is false |
| 590 | suppress_checkstyle: If true, don't run checkstyle tests. Default is false |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 591 | web_context: Web context for a WAB file if needed. Only needed if the jar file provides a REST API. Optional string |
| 592 | api_title: Swagger API title. Optional string, only used if the jar file provides a REST API and has swagger annotations |
| 593 | api_version: Swagger API version. Optional string, only used if the jar file provides a REST API and has swagger annotations |
| 594 | api_description: Swagger API description. Optional string, only used if the jar file provides a REST API and has swagger annotations |
| 595 | api_package: Swagger API package name. Optional string, only used if the jar file provides a REST API and has swagger annotations |
| 596 | """ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 597 | |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 598 | def osgi_jar( |
| 599 | name = None, |
| 600 | deps = None, |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 601 | import_packages = None, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 602 | group = "org.onosproject", |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 603 | srcs = None, |
| 604 | resources_root = None, |
| 605 | resources = None, |
Thomas Vachuska | f8c8cb9 | 2018-07-11 17:12:43 -0700 | [diff] [blame] | 606 | resource_jars = [], |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 607 | include_resources = {}, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 608 | visibility = ["//visibility:public"], |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 609 | version = ONOS_VERSION, |
Thomas Vachuska | 5b9ff6a | 2018-07-13 11:00:50 -0700 | [diff] [blame] | 610 | suppress_errorprone = False, |
Ray Milkey | 134d292 | 2018-07-15 15:24:01 -0700 | [diff] [blame] | 611 | suppress_checkstyle = False, |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 612 | suppress_javadocs = False, |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 613 | web_context = None, |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 614 | api_title = "", |
| 615 | api_version = "", |
| 616 | api_description = "", |
Jian Li | 4ad8687 | 2018-08-05 03:34:35 +0900 | [diff] [blame] | 617 | api_package = "", |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 618 | bundle_classpath = "", |
| 619 | karaf_command_packages = []): |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 620 | if srcs == None: |
Ray Milkey | 32ea35c | 2018-06-06 15:28:07 -0700 | [diff] [blame] | 621 | srcs = _all_java_sources() |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 622 | if deps == None: |
| 623 | deps = COMPILE |
| 624 | |
| 625 | osgi_jar_with_tests( |
| 626 | name = name, |
| 627 | deps = deps, |
| 628 | test_deps = [], |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 629 | group = group, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 630 | srcs = srcs, |
| 631 | resources = resources, |
| 632 | resources_root = resources_root, |
Thomas Vachuska | f8c8cb9 | 2018-07-11 17:12:43 -0700 | [diff] [blame] | 633 | resource_jars = resource_jars, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 634 | test_srcs = [], |
| 635 | exclude_tests = [], |
| 636 | test_resources = [], |
| 637 | visibility = visibility, |
Thomas Vachuska | 5b9ff6a | 2018-07-13 11:00:50 -0700 | [diff] [blame] | 638 | suppress_errorprone = suppress_errorprone, |
Ray Milkey | 134d292 | 2018-07-15 15:24:01 -0700 | [diff] [blame] | 639 | suppress_checkstyle = suppress_checkstyle, |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 640 | suppress_javadocs = suppress_javadocs, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 641 | version = version, |
Ray Milkey | 12ae6ca | 2018-06-11 15:34:30 -0700 | [diff] [blame] | 642 | import_packages = import_packages, |
Ray Milkey | 275af2c | 2018-06-15 13:05:08 -0700 | [diff] [blame] | 643 | api_title = api_title, |
| 644 | api_version = api_version, |
| 645 | api_description = api_description, |
| 646 | api_package = api_package, |
Ray Milkey | 25747d8 | 2018-06-13 14:12:51 -0700 | [diff] [blame] | 647 | web_context = web_context, |
Jian Li | 4ad8687 | 2018-08-05 03:34:35 +0900 | [diff] [blame] | 648 | bundle_classpath = bundle_classpath, |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 649 | karaf_command_packages = karaf_command_packages, |
Ray Milkey | 0bcdfd1 | 2018-05-23 14:07:19 -0700 | [diff] [blame] | 650 | ) |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 651 | |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 652 | """ |
| 653 | Creates an OSGI jar file from a set of protobuf and gRPC libraries. |
| 654 | |
| 655 | Args: |
| 656 | name: Name of the rule to generate. Optional, defaults to a name based on the location in the source tree. |
| 657 | For example apps/mcast/app becomes onos-apps-mcast-app |
| 658 | proto_libs: (required) list of proto_library targets which generated Java classes will be included to this OSGi |
| 659 | jar. It is important that all the given targets reference to a single proto source files, for example |
| 660 | only the first 2 rules are good: |
| 661 | |
| 662 | proto_library( |
| 663 | name = "foo_proto", |
| 664 | srcs = ["foo.proto"], |
| 665 | ) |
| 666 | |
| 667 | proto_library( |
| 668 | name = "bar_proto", |
| 669 | srcs = ["bar.proto"], |
| 670 | ) |
| 671 | |
| 672 | # THIS WILL NOT WORK |
| 673 | proto_library( |
| 674 | name = "foo_and_bar_proto", |
| 675 | srcs = ["foo.proto", "bar.proto"], |
| 676 | ) |
| 677 | |
| 678 | grpc_proto_lib: (optional) proto_library target that contains the schema of a gRPC service. If not passed, |
| 679 | the produced jar will NOT have any gRPC stub classes. |
| 680 | deps: Dependencies of the generated jar file. Expressed as a list of targets |
| 681 | group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject' |
| 682 | visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to public |
| 683 | version: Version of the generated jar file. Optional, defaults to the current ONOS version |
| 684 | """ |
| 685 | |
| 686 | def osgi_proto_jar( |
| 687 | proto_libs, |
| 688 | grpc_proto_lib = None, |
| 689 | name = None, |
| 690 | deps = [], |
| 691 | group = "org.onosproject", |
| 692 | visibility = ["//visibility:public"], |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 693 | version = ONOS_VERSION, |
| 694 | karaf_command_packages = []): |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 695 | if name == None: |
| 696 | name = _auto_name() |
| 697 | native.java_proto_library( |
| 698 | name = name + "-java-proto", |
| 699 | deps = proto_libs, |
| 700 | ) |
| 701 | java_sources_alt( |
| 702 | name = name + "-proto-srcjar", |
| 703 | srcs = [":%s-java-proto" % name], |
| 704 | ) |
| 705 | osgi_srcs = [ |
| 706 | ":%s-proto-srcjar" % name, |
| 707 | ] |
| 708 | base_deps = [ |
| 709 | "@com_google_protobuf//:protobuf_java", |
| 710 | ] |
| 711 | if grpc_proto_lib != None: |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 712 | java_grpc_library( |
| 713 | name = name + "-java-grpc", |
| 714 | srcs = [grpc_proto_lib], |
| 715 | deps = [":%s-java-proto" % name], |
| 716 | ) |
| 717 | osgi_srcs.append( |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 718 | ":%s-java-grpc__do_not_reference__srcjar" % name, |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 719 | ) |
| 720 | base_deps.extend([ |
| 721 | "@com_google_guava_guava//jar", |
| 722 | "@io_grpc_grpc_java//core", |
| 723 | "@io_grpc_grpc_java//stub", |
| 724 | "@io_grpc_grpc_java//protobuf", |
| 725 | ]) |
| 726 | osgi_jar( |
| 727 | name = name, |
| 728 | srcs = osgi_srcs, |
| 729 | deps = base_deps + deps, |
| 730 | group = group, |
| 731 | visibility = visibility, |
| 732 | version = version, |
| 733 | suppress_errorprone = True, |
| 734 | suppress_checkstyle = True, |
| 735 | suppress_javadocs = True, |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 736 | karaf_command_packages = karaf_command_packages, |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 737 | ) |