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