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