blob: 7df0ec835355caf53cc5f57b5acd7dbbd3f96b67 [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 Milkey472d8392018-05-23 17:06:51 -070089
Ray Milkey25b785a2018-06-12 09:59:14 -070090 if cp:
91 cp += ":"
92 cp += file.path
93 inputDependencies = inputDependencies + [file]
Ray Milkey7dac7da2017-08-01 16:56:05 -070094
Ray Milkey0bcdfd12018-05-23 14:07:19 -070095 # extract the class files for use by bnd
Ray Milkey3275ae82018-05-29 15:35:36 -070096 classes = ctx.actions.declare_file("classes" + ctx.label.name.replace("/", "-"))
Ray Milkey0bcdfd12018-05-23 14:07:19 -070097 classesPath = classes.path
98 jarCommand = "mkdir -p %s && cp %s %s && cd %s && jar xf *.jar" % (classesPath, jar, classesPath, classesPath)
99 ctx.actions.run_shell(
100 inputs = inputDependencies,
101 outputs = [classes],
102 command = jarCommand,
103 progress_message = "Expanding jar file: %s" % jar,
104 )
105 inputDependencies += [classes]
Ray Milkey25747d82018-06-13 14:12:51 -0700106 web_xml_root_path = ""
107 if len(web_xml) != 0:
108 web_xml_root = web_xml[0].files.to_list()[0]
109 inputDependencies += [web_xml_root]
110 web_xml_root_path = web_xml_root.path.replace("WEB-INF/web.xml", "")
Ray Milkey7dac7da2017-08-01 16:56:05 -0700111
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700112 # call bnd to make the OSGI jar file
113 arguments = [
114 jar,
115 output,
116 cp,
117 name,
118 group,
119 version,
120 license,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700121 import_packages,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700122 exportPackages,
Ray Milkey6b3775a2018-06-28 11:18:44 -0700123 include_resources,
Ray Milkey25747d82018-06-13 14:12:51 -0700124 web_context,
125 web_xml_root_path,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700126 dynamicimportPackages,
127 classesPath,
Jian Li4ad86872018-08-05 03:34:35 +0900128 bundle_classpath,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700129 ]
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700130
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700131 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 Milkey7dac7da2017-08-01 16:56:05 -0700138
Ray Milkey25b785a2018-06-12 09:59:14 -0700139 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 Milkey15053f02018-06-13 10:00:45 -0700144 providers = [deps_provider],
Ray Milkey25b785a2018-06-12 09:59:14 -0700145 )
146
Ray Milkey275af2c2018-06-15 13:05:08 -0700147"""
148 Rule definition for calling bnd to make an OSGi jar file.
149"""
Ray Milkey32ea35c2018-06-06 15:28:07 -0700150_bnd = rule(
Ray Milkey7dac7da2017-08-01 16:56:05 -0700151 attrs = {
152 "deps": attr.label_list(),
153 "version": attr.string(),
Ray Milkey275af2c2018-06-15 13:05:08 -0700154 "group": attr.string(),
Ray Milkey3275ae82018-05-29 15:35:36 -0700155 "source": attr.label(),
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700156 "import_packages": attr.string(),
Jian Li4ad86872018-08-05 03:34:35 +0900157 "bundle_classpath": attr.string(),
Ray Milkey25747d82018-06-13 14:12:51 -0700158 "web_context": attr.string(),
159 "web_xml": attr.label_list(allow_files = True),
Ray Milkey6b3775a2018-06-28 11:18:44 -0700160 "include_resources": attr.string(),
Ray Milkey7dac7da2017-08-01 16:56:05 -0700161 "_bnd_exe": attr.label(
162 executable = True,
163 cfg = "host",
164 allow_files = True,
165 default = Label("//utils/osgiwrap:osgi-jar"),
166 ),
167 },
168 fragments = ["java"],
169 outputs = {
170 "osgi_jar": "lib%{name}.jar",
171 },
172 implementation = _bnd_impl,
173)
174
Ray Milkey275af2c2018-06-15 13:05:08 -0700175"""
176 Implementation of the rule to call swagger generator to create the registrator java class source
177"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700178
Ray Milkey275af2c2018-06-15 13:05:08 -0700179def _swagger_java_impl(ctx):
180 api_title = ctx.attr.api_title
181 api_version = ctx.attr.api_version
182 api_description = ctx.attr.api_description
183 api_package = ctx.attr.api_package
184 web_context = ctx.attr.web_context
185
186 output_java = ctx.outputs.swagger_java.path
Ray Milkey6b3775a2018-06-28 11:18:44 -0700187 output_dir = output_java[:output_java.find("generated-sources")]
Ray Milkey275af2c2018-06-15 13:05:08 -0700188
189 package_name = ctx.attr.package_name
190
191 srcs_arg = ""
192 resources_arg = ""
193 input_dependencies = []
194
195 for file in ctx.files.srcs:
196 srcs_arg += file.path + ","
197 input_dependencies.append(file)
198
199 for resource in resources_arg:
200 resources_arg += resource.path + ","
201
202 # call swagger generator to make the swagger JSON and java files
203 arguments = [
204 srcs_arg,
205 resources_arg,
206 "",
207 package_name + "/src/main/resources",
208 output_dir,
209 output_dir,
210 web_context,
211 api_title,
212 api_version,
213 api_package,
214 api_description,
215 ]
216
217 ctx.actions.run(
218 inputs = ctx.files.srcs,
219 outputs = [ctx.outputs.swagger_java],
220 arguments = arguments,
221 progress_message = "Running swagger generator on: %s" % ctx.attr.name,
222 executable = ctx.executable._swagger_generator_exe,
223 )
224
225"""
226Implementation of the rule to call swagger generator for swagger.json file
227"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700228
Ray Milkey275af2c2018-06-15 13:05:08 -0700229def _swagger_json_impl(ctx):
230 api_title = ctx.attr.api_title
231 api_version = ctx.attr.api_version
232 api_description = ctx.attr.api_description
233 api_package = ctx.attr.api_package
234 web_context = ctx.attr.web_context
235
236 output_json = ctx.outputs.swagger_json.path
237 output_dir = output_json[:output_json.find("swagger.json")]
238
239 package_name = ctx.attr.package_name
240
241 srcs_arg = ""
242 resources_arg = ""
243 input_dependencies = []
244
245 for file in ctx.files.srcs:
246 srcs_arg += file.path + ","
247 input_dependencies.append(file)
248
249 for resource in resources_arg:
250 resources_arg += resource.path + ","
251
252 # call swagger generator to make the swagger JSON and java files
253 arguments = [
254 srcs_arg,
255 resources_arg,
256 "",
257 package_name + "/src/main/resources",
258 output_dir,
259 output_dir,
260 web_context,
261 api_title,
262 api_version,
263 api_package,
264 api_description,
265 ]
266
267 ctx.actions.run(
268 inputs = ctx.files.srcs,
269 outputs = [ctx.outputs.swagger_json],
270 arguments = arguments,
271 progress_message = "Running swagger generator on: %s" % ctx.attr.name,
272 executable = ctx.executable._swagger_generator_exe,
273 )
274
275"""
276 Rule definition to call swagger generator to create the registrator java class source
277"""
278_swagger_java = rule(
279 attrs = {
280 "srcs": attr.label_list(allow_files = True),
281 "package_name": attr.string(),
282 "api_title": attr.string(),
283 "api_version": attr.string(),
284 "api_description": attr.string(),
285 "api_package": attr.string(),
286 "web_context": attr.string(),
287 "_swagger_generator_exe": attr.label(
288 executable = True,
289 cfg = "host",
290 allow_files = True,
291 default = Label("//tools/build/buck-plugin:swagger_generator"),
292 ),
293 "swagger_java": attr.output(),
294 },
295 fragments = ["java"],
296 implementation = _swagger_java_impl,
297)
298
299"""
300 Rule definition to call swagger generator to create the swagger JSON
301"""
302_swagger_json = rule(
303 attrs = {
304 "srcs": attr.label_list(allow_files = True),
305 "package_name": attr.string(),
306 "api_title": attr.string(),
307 "api_version": attr.string(),
308 "api_description": attr.string(),
309 "api_package": attr.string(),
310 "web_context": attr.string(),
311 "_swagger_generator_exe": attr.label(
312 executable = True,
313 cfg = "host",
314 allow_files = True,
315 default = Label("//tools/build/buck-plugin:swagger_generator"),
316 ),
317 "swagger_json": attr.output(),
318 },
319 fragments = ["java"],
320 implementation = _swagger_json_impl,
321)
322
323"""
324 Converts a jar file to an OSGI compatible jar file.
325
326 Args:
327 name: name of the rule to create the OSGI jar file - required
328 jar: jar file to convert - required target
329 deps: dependencies needed by the jar file - required list of targets
330 version: Version of the generated jar file. Optional, defaults to the current ONOS version
331 group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject'
332 import_packages: OSGI import list. Optional, comma separated list, defaults to "*"
333 visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to private
334"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700335
Ray Milkey25747d82018-06-13 14:12:51 -0700336def wrapped_osgi_jar(
337 name,
338 jar,
339 deps,
340 version = ONOS_VERSION,
Ray Milkey275af2c2018-06-15 13:05:08 -0700341 group = "org.onosproject",
Ray Milkey25747d82018-06-13 14:12:51 -0700342 import_packages = "*",
Ray Milkey25747d82018-06-13 14:12:51 -0700343 visibility = ["//visibility:private"]):
344 _bnd(
345 name = name,
346 source = jar,
347 deps = deps,
348 version = version,
Ray Milkey275af2c2018-06-15 13:05:08 -0700349 group = group,
Ray Milkey25747d82018-06-13 14:12:51 -0700350 visibility = visibility,
351 import_packages = import_packages,
Ray Milkey275af2c2018-06-15 13:05:08 -0700352 web_xml = None,
Ray Milkey25747d82018-06-13 14:12:51 -0700353 )
Ray Milkey7dac7da2017-08-01 16:56:05 -0700354
Ray Milkey275af2c2018-06-15 13:05:08 -0700355"""
356 Creates an OSGI jar and test jar file from a set of source and test files.
357 See osgi_jar() for a description of shared parameters.
358 Args:
359 test_srcs: Test source file(s) to compile. Optional list of targets, defaults to src/test/java/**/*.java
360 test_deps: Dependencies for the test jar. Optional list of targets, defaults to a common set of dependencies
361 test_resources: Resources to include in the test jar. Optional list of targets, defaults to src/test/resources/**
362 exclude_tests: Tests that should not be run. Useful for excluding things like test files without any @Test methods.
363 Optional ist of targets, defaults to []
364"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700365
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700366def osgi_jar_with_tests(
367 name = None,
368 deps = None,
369 test_deps = None,
Ray Milkey275af2c2018-06-15 13:05:08 -0700370 group = "org.onosproject",
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700371 srcs = None,
372 resources_root = None,
373 resources = None,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700374 resource_jars = [],
Ray Milkey6b3775a2018-06-28 11:18:44 -0700375 include_resources = {},
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700376 test_srcs = None,
377 exclude_tests = None,
Thomas Vachuskaa79bf6e2018-08-07 11:24:40 -0700378 medium_tests = [],
379 large_tests = [],
380 enormous_tests = [],
381 flaky_tests = [],
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700382 test_resources = None,
383 visibility = ["//visibility:public"],
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700384 version = ONOS_VERSION,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700385 suppress_errorprone = False,
Ray Milkey134d2922018-07-15 15:24:01 -0700386 suppress_checkstyle = False,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700387 suppress_javadocs = False,
Ray Milkey25747d82018-06-13 14:12:51 -0700388 web_context = None,
389 api_title = "",
390 api_version = "",
391 api_description = "",
392 api_package = "",
Jian Li4ad86872018-08-05 03:34:35 +0900393 import_packages = None,
394 bundle_classpath = ""):
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700395 if name == None:
396 name = "onos-" + native.package_name().replace("/", "-")
Ray Milkey7dac7da2017-08-01 16:56:05 -0700397 if srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700398 srcs = _all_java_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700399 if resources == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700400 resources = _all_resources(resources_root)
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700401 if test_srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700402 test_srcs = _all_java_test_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700403 if test_resources == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700404 test_resources = _all_test_resources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700405 if exclude_tests == None:
406 exclude_tests = []
Ray Milkey7dac7da2017-08-01 16:56:05 -0700407 if deps == None:
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700408 deps = COMPILE
409 if test_deps == None:
410 test_deps = TEST
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700411 if import_packages == None:
412 import_packages = "*"
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700413 tests_name = name + "-tests"
414 tests_jar_deps = list(depset(deps + test_deps)) + [name]
415 all_test_deps = tests_jar_deps + [tests_name]
Ray Milkey25747d82018-06-13 14:12:51 -0700416 web_xml = _webapp()
Ray Milkey7dac7da2017-08-01 16:56:05 -0700417
Ray Milkey275af2c2018-06-15 13:05:08 -0700418 native_srcs = srcs
419 native_resources = resources
Ray Milkey6b3775a2018-06-28 11:18:44 -0700420 if web_context != None and api_title != "" and len(resources) != 0:
Ray Milkey275af2c2018-06-15 13:05:08 -0700421 # generate Swagger files if needed
422 _swagger_java(
423 name = name + "_swagger_java",
424 srcs = srcs + resources,
425 package_name = native.package_name(),
426 api_title = api_title,
427 api_version = api_version,
428 api_description = api_description,
429 web_context = web_context,
430 api_package = api_package,
431 swagger_java = ("src/main/resources/apidoc/generated-sources/" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700432 api_package.replace(".", "/") +
433 "/ApiDocRegistrator.java").replace("//", "/"),
Ray Milkey275af2c2018-06-15 13:05:08 -0700434 )
435 _swagger_json(
436 name = name + "_swagger_json",
437 srcs = srcs + resources,
438 package_name = native.package_name(),
439 api_title = api_title,
440 api_version = api_version,
441 api_description = api_description,
442 web_context = web_context,
443 api_package = api_package,
444 swagger_json = "src/main/resources/apidoc/swagger.json",
445 )
446 native_resources = []
447 for r in resources:
Ray Milkey6b3775a2018-06-28 11:18:44 -0700448 if not "definitions" in r:
Ray Milkey275af2c2018-06-15 13:05:08 -0700449 native_resources.append(r)
Ray Milkey6b3775a2018-06-28 11:18:44 -0700450 native_srcs = srcs + [name + "_swagger_java"]
451 native_resources.append(name + "_swagger_json")
Ray Milkey275af2c2018-06-15 13:05:08 -0700452
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700453 javacopts = [ "-XepDisableAllChecks" ] if suppress_errorprone else []
454
Ray Milkey25747d82018-06-13 14:12:51 -0700455 # compile the Java code
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700456 if len(resource_jars) > 0:
457 native.java_library(name = name + "-native", srcs = native_srcs, resource_jars = resource_jars,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700458 deps = deps, visibility = visibility, javacopts = javacopts)
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700459 else:
460 native.java_library(name = name + "-native", srcs = native_srcs, resources = native_resources,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700461 deps = deps, visibility = visibility, javacopts = javacopts)
Ray Milkey25747d82018-06-13 14:12:51 -0700462
Ray Milkey32ea35c2018-06-06 15:28:07 -0700463 _bnd(
Ray Milkey25b785a2018-06-12 09:59:14 -0700464 name = name,
465 source = name + "-native",
Ray Milkey32ea35c2018-06-06 15:28:07 -0700466 deps = deps,
467 version = version,
Ray Milkey275af2c2018-06-15 13:05:08 -0700468 group = group,
Ray Milkey32ea35c2018-06-06 15:28:07 -0700469 visibility = visibility,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700470 import_packages = import_packages,
Jian Li4ad86872018-08-05 03:34:35 +0900471 bundle_classpath = bundle_classpath,
Ray Milkey25747d82018-06-13 14:12:51 -0700472 web_context = web_context,
473 web_xml = web_xml,
Ray Milkey6b3775a2018-06-28 11:18:44 -0700474 include_resources = _include_resources_to_string(include_resources),
Ray Milkey32ea35c2018-06-06 15:28:07 -0700475 )
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700476
Thomas Vachuskaac9e5242018-07-19 16:15:39 -0700477 # rule for generating pom file for publishing
478 pom_file(name = name + "-pom", artifact = name, deps = deps, visibility = visibility)
479
480 # rule for building source jar
Thomas Vachuska50ac0982018-07-19 10:17:37 -0700481 if not suppress_javadocs:
482 java_sources(name = name + "-sources", srcs = srcs, visibility = visibility)
483
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700484 # rule for building javadocs
485 if not suppress_javadocs:
Ray Milkey7f46b1f2018-07-24 19:01:58 -0700486 javadoc(name = name + "-javadoc", deps = deps, srcs = srcs, visibility = visibility)
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700487
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700488 if test_srcs != []:
489 native.java_library(
490 name = tests_name,
491 srcs = test_srcs,
492 resources = test_resources,
493 deps = tests_jar_deps,
494 visibility = visibility,
495 )
Ray Milkey7dac7da2017-08-01 16:56:05 -0700496
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700497 generate_test_rules(
498 name = name + "-tests-gen",
499 test_files = test_srcs,
500 exclude_tests = exclude_tests,
Thomas Vachuskaa79bf6e2018-08-07 11:24:40 -0700501 medium_tests = medium_tests,
502 large_tests = large_tests,
503 enormous_tests = enormous_tests,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700504 deps = all_test_deps,
505 )
506
Ray Milkey134d2922018-07-15 15:24:01 -0700507 if not suppress_checkstyle:
508 checkstyle_test(
509 name = name + "_checkstyle_test",
510 srcs = srcs,
511 )
Ray Milkeyb7949e72018-06-19 18:31:02 -0700512
Ray Milkey275af2c2018-06-15 13:05:08 -0700513"""
514 Creates an OSGI jar file from a set of source files.
515
516 Args:
517 name: Name of the rule to generate. Optional, defaults to a name based on the location in the source tree.
518 For example apps/mcast/app becomes onos-apps-mcast-app
519 deps: Dependencies of the generated jar file. Expressed as a list of targets
520 import_packages: OSGI import list. Optional, comma separated list, defaults to "*"
Jian Li4ad86872018-08-05 03:34:35 +0900521 bundle_classpath: intended for including dependencies in our bundle, so that our bundle can be deployed standalone
Ray Milkey275af2c2018-06-15 13:05:08 -0700522 group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject'
523 srcs: Source file(s) to compile. Optional list of targets, defaults to src/main/java/**/*.java
524 resources_root: Relative path to the root of the tree of resources for this jar. Optional, defaults to src/main/resources
525 resources: Resources to include in the jar file. Optional list of targets, defaults to all files beneath resources_root
526 visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to public
527 version: Version of the generated jar file. Optional, defaults to the current ONOS version
Ray Milkey134d2922018-07-15 15:24:01 -0700528 suppress_errorprone: If true, don't run ErrorProne tests. Default is false
529 suppress_checkstyle: If true, don't run checkstyle tests. Default is false
Ray Milkey275af2c2018-06-15 13:05:08 -0700530 web_context: Web context for a WAB file if needed. Only needed if the jar file provides a REST API. Optional string
531 api_title: Swagger API title. Optional string, only used if the jar file provides a REST API and has swagger annotations
532 api_version: Swagger API version. Optional string, only used if the jar file provides a REST API and has swagger annotations
533 api_description: Swagger API description. Optional string, only used if the jar file provides a REST API and has swagger annotations
534 api_package: Swagger API package name. Optional string, only used if the jar file provides a REST API and has swagger annotations
535"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700536
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700537def osgi_jar(
538 name = None,
539 deps = None,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700540 import_packages = None,
Ray Milkey275af2c2018-06-15 13:05:08 -0700541 group = "org.onosproject",
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700542 srcs = None,
543 resources_root = None,
544 resources = None,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700545 resource_jars = [],
Ray Milkey6b3775a2018-06-28 11:18:44 -0700546 include_resources = {},
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700547 visibility = ["//visibility:public"],
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700548 version = ONOS_VERSION,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700549 suppress_errorprone = False,
Ray Milkey134d2922018-07-15 15:24:01 -0700550 suppress_checkstyle = False,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700551 suppress_javadocs = False,
Ray Milkey25747d82018-06-13 14:12:51 -0700552 web_context = None,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700553 api_title = "",
554 api_version = "",
555 api_description = "",
Jian Li4ad86872018-08-05 03:34:35 +0900556 api_package = "",
557 bundle_classpath = ""):
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700558 if srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700559 srcs = _all_java_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700560 if deps == None:
561 deps = COMPILE
562
563 osgi_jar_with_tests(
564 name = name,
565 deps = deps,
566 test_deps = [],
Ray Milkey275af2c2018-06-15 13:05:08 -0700567 group = group,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700568 srcs = srcs,
569 resources = resources,
570 resources_root = resources_root,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700571 resource_jars = resource_jars,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700572 test_srcs = [],
573 exclude_tests = [],
574 test_resources = [],
575 visibility = visibility,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700576 suppress_errorprone = suppress_errorprone,
Ray Milkey134d2922018-07-15 15:24:01 -0700577 suppress_checkstyle = suppress_checkstyle,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700578 suppress_javadocs = suppress_javadocs,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700579 version = version,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700580 import_packages = import_packages,
Ray Milkey275af2c2018-06-15 13:05:08 -0700581 api_title = api_title,
582 api_version = api_version,
583 api_description = api_description,
584 api_package = api_package,
Ray Milkey25747d82018-06-13 14:12:51 -0700585 web_context = web_context,
Jian Li4ad86872018-08-05 03:34:35 +0900586 bundle_classpath = bundle_classpath,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700587 )