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