blob: 03913f4940b7375bef16250c006fc5e780fdd2aa [file] [log] [blame]
Ray Milkey3275ae82018-05-29 15:35:36 -07001"""
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 Milkey7dac7da2017-08-01 16:56:05 -070017load("//tools/build/bazel:generate_workspace.bzl", "COMPILE", "TEST")
18load("//tools/build/bazel:variables.bzl", "ONOS_VERSION")
19load("//tools/build/bazel:generate_test_rules.bzl", "generate_test_rules")
Ray Milkeyb7949e72018-06-19 18:31:02 -070020load("//tools/build/bazel:checkstyle.bzl", "checkstyle_test")
Thomas Vachuskaac9e5242018-07-19 16:15:39 -070021load("//tools/build/bazel:pom_file.bzl", "pom_file")
Thomas Vachuska50ac0982018-07-19 10:17:37 -070022load("//tools/build/bazel:java_sources.bzl", "java_sources")
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -070023load("//tools/build/bazel:javadoc.bzl", "javadoc")
Ray Milkey7dac7da2017-08-01 16:56:05 -070024
Ray Milkey32ea35c2018-06-06 15:28:07 -070025def _all_java_sources():
Ray Milkey0bcdfd12018-05-23 14:07:19 -070026 return native.glob(["src/main/java/**/*.java"])
Ray Milkey7dac7da2017-08-01 16:56:05 -070027
Ray Milkey32ea35c2018-06-06 15:28:07 -070028def _all_java_test_sources():
Ray Milkey0bcdfd12018-05-23 14:07:19 -070029 return native.glob(["src/test/java/**/*.java"])
Ray Milkey7dac7da2017-08-01 16:56:05 -070030
Ray Milkey32ea35c2018-06-06 15:28:07 -070031def _all_test_resources():
Ray Milkey0bcdfd12018-05-23 14:07:19 -070032 return native.glob(["src/test/resources/**"])
Ray Milkey7dac7da2017-08-01 16:56:05 -070033
Ray Milkey32ea35c2018-06-06 15:28:07 -070034def _all_resources(resources_root):
Ray Milkey0bcdfd12018-05-23 14:07:19 -070035 if resources_root == None:
36 return native.glob(["src/main/resources/**"])
37 else:
38 return native.glob([resources_root + "**"])
Ray Milkey7dac7da2017-08-01 16:56:05 -070039
Ray Milkey25747d82018-06-13 14:12:51 -070040def _webapp():
Ray Milkey6b3775a2018-06-28 11:18:44 -070041 return native.glob(["src/main/webapp/WEB-INF/web.xml"])
42
43def _include_resources_to_string(include_resources):
44 result = ""
45 for (path, filename) in include_resources.items():
46 result += (path + "=" + filename)
47 return result
Ray Milkey25747d82018-06-13 14:12:51 -070048
Ray Milkey275af2c2018-06-15 13:05:08 -070049"""
50 Implementation of the rule to call bnd to make an OSGI jar file
51"""
Ray Milkey6b3775a2018-06-28 11:18:44 -070052
Ray Milkey7dac7da2017-08-01 16:56:05 -070053def _bnd_impl(ctx):
Ray Milkey3275ae82018-05-29 15:35:36 -070054 if (len(ctx.files.source) == 1):
55 input_file = ctx.files.source[0]
56 else:
57 # this is a list of inputs. The one we want is the last one
58 # in the list that isn't a source jar
59 for file in reversed(ctx.files.source):
60 if ("-src" in file.path):
61 continue
62 else:
63 input_file = file
64 break
65
66 jar = input_file.path
Ray Milkey0bcdfd12018-05-23 14:07:19 -070067 output = ctx.outputs.osgi_jar.path
Thomas Vachuska8e022a92018-07-10 14:47:38 -070068 name = ctx.attr.name
Ray Milkey275af2c2018-06-15 13:05:08 -070069 group = ctx.attr.group
Ray Milkey0bcdfd12018-05-23 14:07:19 -070070 version = ctx.attr.version
71 license = ""
Ray Milkey12ae6ca2018-06-11 15:34:30 -070072 import_packages = ctx.attr.import_packages
Jian Li4ad86872018-08-05 03:34:35 +090073 bundle_classpath = ctx.attr.bundle_classpath
Ray Milkey0bcdfd12018-05-23 14:07:19 -070074 exportPackages = "*"
Ray Milkey6b3775a2018-06-28 11:18:44 -070075 include_resources = ctx.attr.include_resources
Ray Milkey25747d82018-06-13 14:12:51 -070076 web_context = ctx.attr.web_context
77 if web_context == None or web_context == "":
78 web_context = "NONE"
79 web_xml = ctx.attr.web_xml
Ray Milkey0bcdfd12018-05-23 14:07:19 -070080 dynamicimportPackages = ""
Ray Milkey3275ae82018-05-29 15:35:36 -070081 cp = ""
Ray Milkey7dac7da2017-08-01 16:56:05 -070082
Ray Milkey3275ae82018-05-29 15:35:36 -070083 inputDependencies = [input_file]
Ray Milkey7dac7da2017-08-01 16:56:05 -070084
Ray Milkey0bcdfd12018-05-23 14:07:19 -070085 # determine the dependencies and build the class path
86 for dep in ctx.attr.deps:
Ray Milkey25b785a2018-06-12 09:59:14 -070087 if java_common.provider in dep:
88 file = dep.files.to_list()[0]
Ray Milkey25b785a2018-06-12 09:59:14 -070089 if cp:
90 cp += ":"
91 cp += file.path
92 inputDependencies = inputDependencies + [file]
Ray Milkey7dac7da2017-08-01 16:56:05 -070093
Ray Milkey25747d82018-06-13 14:12:51 -070094 web_xml_root_path = ""
95 if len(web_xml) != 0:
96 web_xml_root = web_xml[0].files.to_list()[0]
97 inputDependencies += [web_xml_root]
98 web_xml_root_path = web_xml_root.path.replace("WEB-INF/web.xml", "")
Ray Milkey7dac7da2017-08-01 16:56:05 -070099
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700100 # call bnd to make the OSGI jar file
101 arguments = [
102 jar,
103 output,
104 cp,
105 name,
106 group,
107 version,
108 license,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700109 import_packages,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700110 exportPackages,
Ray Milkey6b3775a2018-06-28 11:18:44 -0700111 include_resources,
Ray Milkey25747d82018-06-13 14:12:51 -0700112 web_context,
113 web_xml_root_path,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700114 dynamicimportPackages,
Thomas Vachuskae4436942018-08-07 19:27:10 -0700115 "classes",
Jian Li4ad86872018-08-05 03:34:35 +0900116 bundle_classpath,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700117 ]
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700118
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700119 ctx.actions.run(
120 inputs = inputDependencies,
121 outputs = [ctx.outputs.osgi_jar],
122 arguments = arguments,
123 progress_message = "Running bnd wrapper on: %s" % ctx.attr.name,
124 executable = ctx.executable._bnd_exe,
125 )
Ray Milkey7dac7da2017-08-01 16:56:05 -0700126
Ray Milkey25b785a2018-06-12 09:59:14 -0700127 deps = []
128 if java_common.provider in ctx.attr.source:
129 deps.append(ctx.attr.source[java_common.provider])
130 deps_provider = java_common.merge(deps)
131 return struct(
Ray Milkey15053f02018-06-13 10:00:45 -0700132 providers = [deps_provider],
Ray Milkey25b785a2018-06-12 09:59:14 -0700133 )
134
Ray Milkey275af2c2018-06-15 13:05:08 -0700135"""
136 Rule definition for calling bnd to make an OSGi jar file.
137"""
Ray Milkey32ea35c2018-06-06 15:28:07 -0700138_bnd = rule(
Ray Milkey7dac7da2017-08-01 16:56:05 -0700139 attrs = {
140 "deps": attr.label_list(),
141 "version": attr.string(),
Ray Milkey275af2c2018-06-15 13:05:08 -0700142 "group": attr.string(),
Ray Milkey3275ae82018-05-29 15:35:36 -0700143 "source": attr.label(),
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700144 "import_packages": attr.string(),
Jian Li4ad86872018-08-05 03:34:35 +0900145 "bundle_classpath": attr.string(),
Ray Milkey25747d82018-06-13 14:12:51 -0700146 "web_context": attr.string(),
147 "web_xml": attr.label_list(allow_files = True),
Ray Milkey6b3775a2018-06-28 11:18:44 -0700148 "include_resources": attr.string(),
Ray Milkey7dac7da2017-08-01 16:56:05 -0700149 "_bnd_exe": attr.label(
150 executable = True,
151 cfg = "host",
152 allow_files = True,
153 default = Label("//utils/osgiwrap:osgi-jar"),
154 ),
155 },
156 fragments = ["java"],
157 outputs = {
158 "osgi_jar": "lib%{name}.jar",
159 },
160 implementation = _bnd_impl,
161)
162
Ray Milkey275af2c2018-06-15 13:05:08 -0700163"""
164 Implementation of the rule to call swagger generator to create the registrator java class source
165"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700166
Ray Milkey275af2c2018-06-15 13:05:08 -0700167def _swagger_java_impl(ctx):
168 api_title = ctx.attr.api_title
169 api_version = ctx.attr.api_version
170 api_description = ctx.attr.api_description
171 api_package = ctx.attr.api_package
172 web_context = ctx.attr.web_context
173
174 output_java = ctx.outputs.swagger_java.path
Ray Milkey6b3775a2018-06-28 11:18:44 -0700175 output_dir = output_java[:output_java.find("generated-sources")]
Ray Milkey275af2c2018-06-15 13:05:08 -0700176
177 package_name = ctx.attr.package_name
178
179 srcs_arg = ""
180 resources_arg = ""
181 input_dependencies = []
182
183 for file in ctx.files.srcs:
184 srcs_arg += file.path + ","
185 input_dependencies.append(file)
186
187 for resource in resources_arg:
188 resources_arg += resource.path + ","
189
190 # call swagger generator to make the swagger JSON and java files
191 arguments = [
192 srcs_arg,
193 resources_arg,
194 "",
195 package_name + "/src/main/resources",
196 output_dir,
197 output_dir,
198 web_context,
199 api_title,
200 api_version,
201 api_package,
202 api_description,
203 ]
204
205 ctx.actions.run(
206 inputs = ctx.files.srcs,
207 outputs = [ctx.outputs.swagger_java],
208 arguments = arguments,
209 progress_message = "Running swagger generator on: %s" % ctx.attr.name,
210 executable = ctx.executable._swagger_generator_exe,
211 )
212
213"""
214Implementation of the rule to call swagger generator for swagger.json file
215"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700216
Ray Milkey275af2c2018-06-15 13:05:08 -0700217def _swagger_json_impl(ctx):
218 api_title = ctx.attr.api_title
219 api_version = ctx.attr.api_version
220 api_description = ctx.attr.api_description
221 api_package = ctx.attr.api_package
222 web_context = ctx.attr.web_context
223
224 output_json = ctx.outputs.swagger_json.path
225 output_dir = output_json[:output_json.find("swagger.json")]
226
227 package_name = ctx.attr.package_name
228
229 srcs_arg = ""
230 resources_arg = ""
231 input_dependencies = []
232
233 for file in ctx.files.srcs:
234 srcs_arg += file.path + ","
235 input_dependencies.append(file)
236
237 for resource in resources_arg:
238 resources_arg += resource.path + ","
239
240 # call swagger generator to make the swagger JSON and java files
241 arguments = [
242 srcs_arg,
243 resources_arg,
244 "",
245 package_name + "/src/main/resources",
246 output_dir,
247 output_dir,
248 web_context,
249 api_title,
250 api_version,
251 api_package,
252 api_description,
253 ]
254
255 ctx.actions.run(
256 inputs = ctx.files.srcs,
257 outputs = [ctx.outputs.swagger_json],
258 arguments = arguments,
259 progress_message = "Running swagger generator on: %s" % ctx.attr.name,
260 executable = ctx.executable._swagger_generator_exe,
261 )
262
263"""
264 Rule definition to call swagger generator to create the registrator java class source
265"""
266_swagger_java = rule(
267 attrs = {
268 "srcs": attr.label_list(allow_files = True),
269 "package_name": attr.string(),
270 "api_title": attr.string(),
271 "api_version": attr.string(),
272 "api_description": attr.string(),
273 "api_package": attr.string(),
274 "web_context": attr.string(),
275 "_swagger_generator_exe": attr.label(
276 executable = True,
277 cfg = "host",
278 allow_files = True,
279 default = Label("//tools/build/buck-plugin:swagger_generator"),
280 ),
281 "swagger_java": attr.output(),
282 },
283 fragments = ["java"],
284 implementation = _swagger_java_impl,
285)
286
287"""
288 Rule definition to call swagger generator to create the swagger JSON
289"""
290_swagger_json = rule(
291 attrs = {
292 "srcs": attr.label_list(allow_files = True),
293 "package_name": attr.string(),
294 "api_title": attr.string(),
295 "api_version": attr.string(),
296 "api_description": attr.string(),
297 "api_package": attr.string(),
298 "web_context": attr.string(),
299 "_swagger_generator_exe": attr.label(
300 executable = True,
301 cfg = "host",
302 allow_files = True,
303 default = Label("//tools/build/buck-plugin:swagger_generator"),
304 ),
305 "swagger_json": attr.output(),
306 },
307 fragments = ["java"],
308 implementation = _swagger_json_impl,
309)
310
311"""
312 Converts a jar file to an OSGI compatible jar file.
313
314 Args:
315 name: name of the rule to create the OSGI jar file - required
316 jar: jar file to convert - required target
317 deps: dependencies needed by the jar file - required list of targets
318 version: Version of the generated jar file. Optional, defaults to the current ONOS version
319 group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject'
320 import_packages: OSGI import list. Optional, comma separated list, defaults to "*"
321 visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to private
322"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700323
Ray Milkey25747d82018-06-13 14:12:51 -0700324def wrapped_osgi_jar(
325 name,
326 jar,
327 deps,
328 version = ONOS_VERSION,
Ray Milkey275af2c2018-06-15 13:05:08 -0700329 group = "org.onosproject",
Ray Milkey25747d82018-06-13 14:12:51 -0700330 import_packages = "*",
Ray Milkey25747d82018-06-13 14:12:51 -0700331 visibility = ["//visibility:private"]):
332 _bnd(
333 name = name,
334 source = jar,
335 deps = deps,
336 version = version,
Ray Milkey275af2c2018-06-15 13:05:08 -0700337 group = group,
Ray Milkey25747d82018-06-13 14:12:51 -0700338 visibility = visibility,
339 import_packages = import_packages,
Ray Milkey275af2c2018-06-15 13:05:08 -0700340 web_xml = None,
Ray Milkey25747d82018-06-13 14:12:51 -0700341 )
Ray Milkey7dac7da2017-08-01 16:56:05 -0700342
Ray Milkey275af2c2018-06-15 13:05:08 -0700343"""
344 Creates an OSGI jar and test jar file from a set of source and test files.
345 See osgi_jar() for a description of shared parameters.
346 Args:
347 test_srcs: Test source file(s) to compile. Optional list of targets, defaults to src/test/java/**/*.java
348 test_deps: Dependencies for the test jar. Optional list of targets, defaults to a common set of dependencies
349 test_resources: Resources to include in the test jar. Optional list of targets, defaults to src/test/resources/**
350 exclude_tests: Tests that should not be run. Useful for excluding things like test files without any @Test methods.
351 Optional ist of targets, defaults to []
352"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700353
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700354def osgi_jar_with_tests(
355 name = None,
356 deps = None,
357 test_deps = None,
Ray Milkey275af2c2018-06-15 13:05:08 -0700358 group = "org.onosproject",
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700359 srcs = None,
360 resources_root = None,
361 resources = None,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700362 resource_jars = [],
Ray Milkey6b3775a2018-06-28 11:18:44 -0700363 include_resources = {},
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700364 test_srcs = None,
365 exclude_tests = None,
Thomas Vachuskaa79bf6e2018-08-07 11:24:40 -0700366 medium_tests = [],
367 large_tests = [],
368 enormous_tests = [],
369 flaky_tests = [],
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700370 test_resources = None,
371 visibility = ["//visibility:public"],
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700372 version = ONOS_VERSION,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700373 suppress_errorprone = False,
Ray Milkey134d2922018-07-15 15:24:01 -0700374 suppress_checkstyle = False,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700375 suppress_javadocs = False,
Ray Milkey25747d82018-06-13 14:12:51 -0700376 web_context = None,
377 api_title = "",
378 api_version = "",
379 api_description = "",
380 api_package = "",
Jian Li4ad86872018-08-05 03:34:35 +0900381 import_packages = None,
382 bundle_classpath = ""):
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700383 if name == None:
384 name = "onos-" + native.package_name().replace("/", "-")
Ray Milkey7dac7da2017-08-01 16:56:05 -0700385 if srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700386 srcs = _all_java_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700387 if resources == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700388 resources = _all_resources(resources_root)
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700389 if test_srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700390 test_srcs = _all_java_test_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700391 if test_resources == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700392 test_resources = _all_test_resources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700393 if exclude_tests == None:
394 exclude_tests = []
Ray Milkey7dac7da2017-08-01 16:56:05 -0700395 if deps == None:
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700396 deps = COMPILE
397 if test_deps == None:
398 test_deps = TEST
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700399 if import_packages == None:
400 import_packages = "*"
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700401 tests_name = name + "-tests"
402 tests_jar_deps = list(depset(deps + test_deps)) + [name]
403 all_test_deps = tests_jar_deps + [tests_name]
Ray Milkey25747d82018-06-13 14:12:51 -0700404 web_xml = _webapp()
Ray Milkey7dac7da2017-08-01 16:56:05 -0700405
Ray Milkey275af2c2018-06-15 13:05:08 -0700406 native_srcs = srcs
407 native_resources = resources
Ray Milkey6b3775a2018-06-28 11:18:44 -0700408 if web_context != None and api_title != "" and len(resources) != 0:
Ray Milkey275af2c2018-06-15 13:05:08 -0700409 # generate Swagger files if needed
410 _swagger_java(
411 name = name + "_swagger_java",
412 srcs = srcs + resources,
413 package_name = native.package_name(),
414 api_title = api_title,
415 api_version = api_version,
416 api_description = api_description,
417 web_context = web_context,
418 api_package = api_package,
419 swagger_java = ("src/main/resources/apidoc/generated-sources/" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700420 api_package.replace(".", "/") +
421 "/ApiDocRegistrator.java").replace("//", "/"),
Ray Milkey275af2c2018-06-15 13:05:08 -0700422 )
423 _swagger_json(
424 name = name + "_swagger_json",
425 srcs = srcs + resources,
426 package_name = native.package_name(),
427 api_title = api_title,
428 api_version = api_version,
429 api_description = api_description,
430 web_context = web_context,
431 api_package = api_package,
432 swagger_json = "src/main/resources/apidoc/swagger.json",
433 )
434 native_resources = []
435 for r in resources:
Ray Milkey6b3775a2018-06-28 11:18:44 -0700436 if not "definitions" in r:
Ray Milkey275af2c2018-06-15 13:05:08 -0700437 native_resources.append(r)
Ray Milkey6b3775a2018-06-28 11:18:44 -0700438 native_srcs = srcs + [name + "_swagger_java"]
439 native_resources.append(name + "_swagger_json")
Ray Milkey275af2c2018-06-15 13:05:08 -0700440
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700441 javacopts = [ "-XepDisableAllChecks" ] if suppress_errorprone else []
442
Ray Milkey25747d82018-06-13 14:12:51 -0700443 # compile the Java code
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700444 if len(resource_jars) > 0:
445 native.java_library(name = name + "-native", srcs = native_srcs, resource_jars = resource_jars,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700446 deps = deps, visibility = visibility, javacopts = javacopts)
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700447 else:
448 native.java_library(name = name + "-native", srcs = native_srcs, resources = native_resources,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700449 deps = deps, visibility = visibility, javacopts = javacopts)
Ray Milkey25747d82018-06-13 14:12:51 -0700450
Ray Milkey32ea35c2018-06-06 15:28:07 -0700451 _bnd(
Ray Milkey25b785a2018-06-12 09:59:14 -0700452 name = name,
453 source = name + "-native",
Ray Milkey32ea35c2018-06-06 15:28:07 -0700454 deps = deps,
455 version = version,
Ray Milkey275af2c2018-06-15 13:05:08 -0700456 group = group,
Ray Milkey32ea35c2018-06-06 15:28:07 -0700457 visibility = visibility,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700458 import_packages = import_packages,
Jian Li4ad86872018-08-05 03:34:35 +0900459 bundle_classpath = bundle_classpath,
Ray Milkey25747d82018-06-13 14:12:51 -0700460 web_context = web_context,
461 web_xml = web_xml,
Ray Milkey6b3775a2018-06-28 11:18:44 -0700462 include_resources = _include_resources_to_string(include_resources),
Ray Milkey32ea35c2018-06-06 15:28:07 -0700463 )
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700464
Thomas Vachuskaac9e5242018-07-19 16:15:39 -0700465 # rule for generating pom file for publishing
466 pom_file(name = name + "-pom", artifact = name, deps = deps, visibility = visibility)
467
468 # rule for building source jar
Thomas Vachuska50ac0982018-07-19 10:17:37 -0700469 if not suppress_javadocs:
470 java_sources(name = name + "-sources", srcs = srcs, visibility = visibility)
471
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700472 # rule for building javadocs
473 if not suppress_javadocs:
Ray Milkey7f46b1f2018-07-24 19:01:58 -0700474 javadoc(name = name + "-javadoc", deps = deps, srcs = srcs, visibility = visibility)
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700475
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700476 if test_srcs != []:
477 native.java_library(
478 name = tests_name,
479 srcs = test_srcs,
480 resources = test_resources,
481 deps = tests_jar_deps,
482 visibility = visibility,
483 )
Ray Milkey7dac7da2017-08-01 16:56:05 -0700484
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700485 generate_test_rules(
486 name = name + "-tests-gen",
487 test_files = test_srcs,
488 exclude_tests = exclude_tests,
Thomas Vachuskaa79bf6e2018-08-07 11:24:40 -0700489 medium_tests = medium_tests,
490 large_tests = large_tests,
491 enormous_tests = enormous_tests,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700492 deps = all_test_deps,
493 )
494
Ray Milkey134d2922018-07-15 15:24:01 -0700495 if not suppress_checkstyle:
496 checkstyle_test(
497 name = name + "_checkstyle_test",
498 srcs = srcs,
499 )
Ray Milkeyb7949e72018-06-19 18:31:02 -0700500
Ray Milkey275af2c2018-06-15 13:05:08 -0700501"""
502 Creates an OSGI jar file from a set of source files.
503
504 Args:
505 name: Name of the rule to generate. Optional, defaults to a name based on the location in the source tree.
506 For example apps/mcast/app becomes onos-apps-mcast-app
507 deps: Dependencies of the generated jar file. Expressed as a list of targets
508 import_packages: OSGI import list. Optional, comma separated list, defaults to "*"
Jian Li4ad86872018-08-05 03:34:35 +0900509 bundle_classpath: intended for including dependencies in our bundle, so that our bundle can be deployed standalone
Ray Milkey275af2c2018-06-15 13:05:08 -0700510 group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject'
511 srcs: Source file(s) to compile. Optional list of targets, defaults to src/main/java/**/*.java
512 resources_root: Relative path to the root of the tree of resources for this jar. Optional, defaults to src/main/resources
513 resources: Resources to include in the jar file. Optional list of targets, defaults to all files beneath resources_root
514 visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to public
515 version: Version of the generated jar file. Optional, defaults to the current ONOS version
Ray Milkey134d2922018-07-15 15:24:01 -0700516 suppress_errorprone: If true, don't run ErrorProne tests. Default is false
517 suppress_checkstyle: If true, don't run checkstyle tests. Default is false
Ray Milkey275af2c2018-06-15 13:05:08 -0700518 web_context: Web context for a WAB file if needed. Only needed if the jar file provides a REST API. Optional string
519 api_title: Swagger API title. Optional string, only used if the jar file provides a REST API and has swagger annotations
520 api_version: Swagger API version. Optional string, only used if the jar file provides a REST API and has swagger annotations
521 api_description: Swagger API description. Optional string, only used if the jar file provides a REST API and has swagger annotations
522 api_package: Swagger API package name. Optional string, only used if the jar file provides a REST API and has swagger annotations
523"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700524
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700525def osgi_jar(
526 name = None,
527 deps = None,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700528 import_packages = None,
Ray Milkey275af2c2018-06-15 13:05:08 -0700529 group = "org.onosproject",
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700530 srcs = None,
531 resources_root = None,
532 resources = None,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700533 resource_jars = [],
Ray Milkey6b3775a2018-06-28 11:18:44 -0700534 include_resources = {},
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700535 visibility = ["//visibility:public"],
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700536 version = ONOS_VERSION,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700537 suppress_errorprone = False,
Ray Milkey134d2922018-07-15 15:24:01 -0700538 suppress_checkstyle = False,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700539 suppress_javadocs = False,
Ray Milkey25747d82018-06-13 14:12:51 -0700540 web_context = None,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700541 api_title = "",
542 api_version = "",
543 api_description = "",
Jian Li4ad86872018-08-05 03:34:35 +0900544 api_package = "",
545 bundle_classpath = ""):
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700546 if srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700547 srcs = _all_java_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700548 if deps == None:
549 deps = COMPILE
550
551 osgi_jar_with_tests(
552 name = name,
553 deps = deps,
554 test_deps = [],
Ray Milkey275af2c2018-06-15 13:05:08 -0700555 group = group,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700556 srcs = srcs,
557 resources = resources,
558 resources_root = resources_root,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700559 resource_jars = resource_jars,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700560 test_srcs = [],
561 exclude_tests = [],
562 test_resources = [],
563 visibility = visibility,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700564 suppress_errorprone = suppress_errorprone,
Ray Milkey134d2922018-07-15 15:24:01 -0700565 suppress_checkstyle = suppress_checkstyle,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700566 suppress_javadocs = suppress_javadocs,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700567 version = version,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700568 import_packages = import_packages,
Ray Milkey275af2c2018-06-15 13:05:08 -0700569 api_title = api_title,
570 api_version = api_version,
571 api_description = api_description,
572 api_package = api_package,
Ray Milkey25747d82018-06-13 14:12:51 -0700573 web_context = web_context,
Jian Li4ad86872018-08-05 03:34:35 +0900574 bundle_classpath = bundle_classpath,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700575 )