blob: 5ba5e9100c31da4534096982c91605fdea9a91f5 [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 Vachuska50ac0982018-07-19 10:17:37 -070021load("//tools/build/bazel:java_sources.bzl", "java_sources")
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -070022load("//tools/build/bazel:javadoc.bzl", "javadoc")
Ray Milkey7dac7da2017-08-01 16:56:05 -070023
Ray Milkey32ea35c2018-06-06 15:28:07 -070024def _all_java_sources():
Ray Milkey0bcdfd12018-05-23 14:07:19 -070025 return native.glob(["src/main/java/**/*.java"])
Ray Milkey7dac7da2017-08-01 16:56:05 -070026
Ray Milkey32ea35c2018-06-06 15:28:07 -070027def _all_java_test_sources():
Ray Milkey0bcdfd12018-05-23 14:07:19 -070028 return native.glob(["src/test/java/**/*.java"])
Ray Milkey7dac7da2017-08-01 16:56:05 -070029
Ray Milkey32ea35c2018-06-06 15:28:07 -070030def _all_test_resources():
Ray Milkey0bcdfd12018-05-23 14:07:19 -070031 return native.glob(["src/test/resources/**"])
Ray Milkey7dac7da2017-08-01 16:56:05 -070032
Ray Milkey32ea35c2018-06-06 15:28:07 -070033def _all_resources(resources_root):
Ray Milkey0bcdfd12018-05-23 14:07:19 -070034 if resources_root == None:
35 return native.glob(["src/main/resources/**"])
36 else:
37 return native.glob([resources_root + "**"])
Ray Milkey7dac7da2017-08-01 16:56:05 -070038
Ray Milkey25747d82018-06-13 14:12:51 -070039def _webapp():
Ray Milkey6b3775a2018-06-28 11:18:44 -070040 return native.glob(["src/main/webapp/WEB-INF/web.xml"])
41
42def _include_resources_to_string(include_resources):
43 result = ""
44 for (path, filename) in include_resources.items():
45 result += (path + "=" + filename)
46 return result
Ray Milkey25747d82018-06-13 14:12:51 -070047
Ray Milkey275af2c2018-06-15 13:05:08 -070048"""
49 Implementation of the rule to call bnd to make an OSGI jar file
50"""
Ray Milkey6b3775a2018-06-28 11:18:44 -070051
Ray Milkey7dac7da2017-08-01 16:56:05 -070052def _bnd_impl(ctx):
Ray Milkey3275ae82018-05-29 15:35:36 -070053 if (len(ctx.files.source) == 1):
54 input_file = ctx.files.source[0]
55 else:
56 # this is a list of inputs. The one we want is the last one
57 # in the list that isn't a source jar
58 for file in reversed(ctx.files.source):
59 if ("-src" in file.path):
60 continue
61 else:
62 input_file = file
63 break
64
65 jar = input_file.path
Ray Milkey0bcdfd12018-05-23 14:07:19 -070066 output = ctx.outputs.osgi_jar.path
Thomas Vachuska8e022a92018-07-10 14:47:38 -070067 name = ctx.attr.name
Ray Milkey275af2c2018-06-15 13:05:08 -070068 group = ctx.attr.group
Ray Milkey0bcdfd12018-05-23 14:07:19 -070069 version = ctx.attr.version
70 license = ""
Ray Milkey12ae6ca2018-06-11 15:34:30 -070071 import_packages = ctx.attr.import_packages
Ray Milkey0bcdfd12018-05-23 14:07:19 -070072 exportPackages = "*"
Ray Milkey6b3775a2018-06-28 11:18:44 -070073 include_resources = ctx.attr.include_resources
Ray Milkey25747d82018-06-13 14:12:51 -070074 web_context = ctx.attr.web_context
75 if web_context == None or web_context == "":
76 web_context = "NONE"
77 web_xml = ctx.attr.web_xml
Ray Milkey0bcdfd12018-05-23 14:07:19 -070078 dynamicimportPackages = ""
Ray Milkey3275ae82018-05-29 15:35:36 -070079 cp = ""
Ray Milkey7dac7da2017-08-01 16:56:05 -070080
Ray Milkey3275ae82018-05-29 15:35:36 -070081 inputDependencies = [input_file]
Ray Milkey7dac7da2017-08-01 16:56:05 -070082
Ray Milkey0bcdfd12018-05-23 14:07:19 -070083 # determine the dependencies and build the class path
84 for dep in ctx.attr.deps:
Ray Milkey25b785a2018-06-12 09:59:14 -070085 if java_common.provider in dep:
86 file = dep.files.to_list()[0]
Ray Milkey472d8392018-05-23 17:06:51 -070087
Ray Milkey25b785a2018-06-12 09:59:14 -070088 if cp:
89 cp += ":"
90 cp += file.path
91 inputDependencies = inputDependencies + [file]
Ray Milkey7dac7da2017-08-01 16:56:05 -070092
Ray Milkey0bcdfd12018-05-23 14:07:19 -070093 # extract the class files for use by bnd
Ray Milkey3275ae82018-05-29 15:35:36 -070094 classes = ctx.actions.declare_file("classes" + ctx.label.name.replace("/", "-"))
Ray Milkey0bcdfd12018-05-23 14:07:19 -070095 classesPath = classes.path
96 jarCommand = "mkdir -p %s && cp %s %s && cd %s && jar xf *.jar" % (classesPath, jar, classesPath, classesPath)
97 ctx.actions.run_shell(
98 inputs = inputDependencies,
99 outputs = [classes],
100 command = jarCommand,
101 progress_message = "Expanding jar file: %s" % jar,
102 )
103 inputDependencies += [classes]
Ray Milkey25747d82018-06-13 14:12:51 -0700104 web_xml_root_path = ""
105 if len(web_xml) != 0:
106 web_xml_root = web_xml[0].files.to_list()[0]
107 inputDependencies += [web_xml_root]
108 web_xml_root_path = web_xml_root.path.replace("WEB-INF/web.xml", "")
Ray Milkey7dac7da2017-08-01 16:56:05 -0700109
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700110 # call bnd to make the OSGI jar file
111 arguments = [
112 jar,
113 output,
114 cp,
115 name,
116 group,
117 version,
118 license,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700119 import_packages,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700120 exportPackages,
Ray Milkey6b3775a2018-06-28 11:18:44 -0700121 include_resources,
Ray Milkey25747d82018-06-13 14:12:51 -0700122 web_context,
123 web_xml_root_path,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700124 dynamicimportPackages,
125 classesPath,
126 ]
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700127
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700128 ctx.actions.run(
129 inputs = inputDependencies,
130 outputs = [ctx.outputs.osgi_jar],
131 arguments = arguments,
132 progress_message = "Running bnd wrapper on: %s" % ctx.attr.name,
133 executable = ctx.executable._bnd_exe,
134 )
Ray Milkey7dac7da2017-08-01 16:56:05 -0700135
Ray Milkey25b785a2018-06-12 09:59:14 -0700136 deps = []
137 if java_common.provider in ctx.attr.source:
138 deps.append(ctx.attr.source[java_common.provider])
139 deps_provider = java_common.merge(deps)
140 return struct(
Ray Milkey15053f02018-06-13 10:00:45 -0700141 providers = [deps_provider],
Ray Milkey25b785a2018-06-12 09:59:14 -0700142 )
143
Ray Milkey275af2c2018-06-15 13:05:08 -0700144"""
145 Rule definition for calling bnd to make an OSGi jar file.
146"""
Ray Milkey32ea35c2018-06-06 15:28:07 -0700147_bnd = rule(
Ray Milkey7dac7da2017-08-01 16:56:05 -0700148 attrs = {
149 "deps": attr.label_list(),
150 "version": attr.string(),
Ray Milkey275af2c2018-06-15 13:05:08 -0700151 "group": attr.string(),
Ray Milkey3275ae82018-05-29 15:35:36 -0700152 "source": attr.label(),
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700153 "import_packages": attr.string(),
Ray Milkey25747d82018-06-13 14:12:51 -0700154 "web_context": attr.string(),
155 "web_xml": attr.label_list(allow_files = True),
Ray Milkey6b3775a2018-06-28 11:18:44 -0700156 "include_resources": attr.string(),
Ray Milkey7dac7da2017-08-01 16:56:05 -0700157 "_bnd_exe": attr.label(
158 executable = True,
159 cfg = "host",
160 allow_files = True,
161 default = Label("//utils/osgiwrap:osgi-jar"),
162 ),
163 },
164 fragments = ["java"],
165 outputs = {
166 "osgi_jar": "lib%{name}.jar",
167 },
168 implementation = _bnd_impl,
169)
170
Ray Milkey275af2c2018-06-15 13:05:08 -0700171"""
172 Implementation of the rule to call swagger generator to create the registrator java class source
173"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700174
Ray Milkey275af2c2018-06-15 13:05:08 -0700175def _swagger_java_impl(ctx):
176 api_title = ctx.attr.api_title
177 api_version = ctx.attr.api_version
178 api_description = ctx.attr.api_description
179 api_package = ctx.attr.api_package
180 web_context = ctx.attr.web_context
181
182 output_java = ctx.outputs.swagger_java.path
Ray Milkey6b3775a2018-06-28 11:18:44 -0700183 output_dir = output_java[:output_java.find("generated-sources")]
Ray Milkey275af2c2018-06-15 13:05:08 -0700184
185 package_name = ctx.attr.package_name
186
187 srcs_arg = ""
188 resources_arg = ""
189 input_dependencies = []
190
191 for file in ctx.files.srcs:
192 srcs_arg += file.path + ","
193 input_dependencies.append(file)
194
195 for resource in resources_arg:
196 resources_arg += resource.path + ","
197
198 # call swagger generator to make the swagger JSON and java files
199 arguments = [
200 srcs_arg,
201 resources_arg,
202 "",
203 package_name + "/src/main/resources",
204 output_dir,
205 output_dir,
206 web_context,
207 api_title,
208 api_version,
209 api_package,
210 api_description,
211 ]
212
213 ctx.actions.run(
214 inputs = ctx.files.srcs,
215 outputs = [ctx.outputs.swagger_java],
216 arguments = arguments,
217 progress_message = "Running swagger generator on: %s" % ctx.attr.name,
218 executable = ctx.executable._swagger_generator_exe,
219 )
220
221"""
222Implementation of the rule to call swagger generator for swagger.json file
223"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700224
Ray Milkey275af2c2018-06-15 13:05:08 -0700225def _swagger_json_impl(ctx):
226 api_title = ctx.attr.api_title
227 api_version = ctx.attr.api_version
228 api_description = ctx.attr.api_description
229 api_package = ctx.attr.api_package
230 web_context = ctx.attr.web_context
231
232 output_json = ctx.outputs.swagger_json.path
233 output_dir = output_json[:output_json.find("swagger.json")]
234
235 package_name = ctx.attr.package_name
236
237 srcs_arg = ""
238 resources_arg = ""
239 input_dependencies = []
240
241 for file in ctx.files.srcs:
242 srcs_arg += file.path + ","
243 input_dependencies.append(file)
244
245 for resource in resources_arg:
246 resources_arg += resource.path + ","
247
248 # call swagger generator to make the swagger JSON and java files
249 arguments = [
250 srcs_arg,
251 resources_arg,
252 "",
253 package_name + "/src/main/resources",
254 output_dir,
255 output_dir,
256 web_context,
257 api_title,
258 api_version,
259 api_package,
260 api_description,
261 ]
262
263 ctx.actions.run(
264 inputs = ctx.files.srcs,
265 outputs = [ctx.outputs.swagger_json],
266 arguments = arguments,
267 progress_message = "Running swagger generator on: %s" % ctx.attr.name,
268 executable = ctx.executable._swagger_generator_exe,
269 )
270
271"""
272 Rule definition to call swagger generator to create the registrator java class source
273"""
274_swagger_java = rule(
275 attrs = {
276 "srcs": attr.label_list(allow_files = True),
277 "package_name": attr.string(),
278 "api_title": attr.string(),
279 "api_version": attr.string(),
280 "api_description": attr.string(),
281 "api_package": attr.string(),
282 "web_context": attr.string(),
283 "_swagger_generator_exe": attr.label(
284 executable = True,
285 cfg = "host",
286 allow_files = True,
287 default = Label("//tools/build/buck-plugin:swagger_generator"),
288 ),
289 "swagger_java": attr.output(),
290 },
291 fragments = ["java"],
292 implementation = _swagger_java_impl,
293)
294
295"""
296 Rule definition to call swagger generator to create the swagger JSON
297"""
298_swagger_json = rule(
299 attrs = {
300 "srcs": attr.label_list(allow_files = True),
301 "package_name": attr.string(),
302 "api_title": attr.string(),
303 "api_version": attr.string(),
304 "api_description": attr.string(),
305 "api_package": attr.string(),
306 "web_context": attr.string(),
307 "_swagger_generator_exe": attr.label(
308 executable = True,
309 cfg = "host",
310 allow_files = True,
311 default = Label("//tools/build/buck-plugin:swagger_generator"),
312 ),
313 "swagger_json": attr.output(),
314 },
315 fragments = ["java"],
316 implementation = _swagger_json_impl,
317)
318
319"""
320 Converts a jar file to an OSGI compatible jar file.
321
322 Args:
323 name: name of the rule to create the OSGI jar file - required
324 jar: jar file to convert - required target
325 deps: dependencies needed by the jar file - required list of targets
326 version: Version of the generated jar file. Optional, defaults to the current ONOS version
327 group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject'
328 import_packages: OSGI import list. Optional, comma separated list, defaults to "*"
329 visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to private
330"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700331
Ray Milkey25747d82018-06-13 14:12:51 -0700332def wrapped_osgi_jar(
333 name,
334 jar,
335 deps,
336 version = ONOS_VERSION,
Ray Milkey275af2c2018-06-15 13:05:08 -0700337 group = "org.onosproject",
Ray Milkey25747d82018-06-13 14:12:51 -0700338 import_packages = "*",
Ray Milkey25747d82018-06-13 14:12:51 -0700339 visibility = ["//visibility:private"]):
340 _bnd(
341 name = name,
342 source = jar,
343 deps = deps,
344 version = version,
Ray Milkey275af2c2018-06-15 13:05:08 -0700345 group = group,
Ray Milkey25747d82018-06-13 14:12:51 -0700346 visibility = visibility,
347 import_packages = import_packages,
Ray Milkey275af2c2018-06-15 13:05:08 -0700348 web_xml = None,
Ray Milkey25747d82018-06-13 14:12:51 -0700349 )
Ray Milkey7dac7da2017-08-01 16:56:05 -0700350
Ray Milkey275af2c2018-06-15 13:05:08 -0700351"""
352 Creates an OSGI jar and test jar file from a set of source and test files.
353 See osgi_jar() for a description of shared parameters.
354 Args:
355 test_srcs: Test source file(s) to compile. Optional list of targets, defaults to src/test/java/**/*.java
356 test_deps: Dependencies for the test jar. Optional list of targets, defaults to a common set of dependencies
357 test_resources: Resources to include in the test jar. Optional list of targets, defaults to src/test/resources/**
358 exclude_tests: Tests that should not be run. Useful for excluding things like test files without any @Test methods.
359 Optional ist of targets, defaults to []
360"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700361
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700362def osgi_jar_with_tests(
363 name = None,
364 deps = None,
365 test_deps = None,
Ray Milkey275af2c2018-06-15 13:05:08 -0700366 group = "org.onosproject",
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700367 srcs = None,
368 resources_root = None,
369 resources = None,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700370 resource_jars = [],
Ray Milkey6b3775a2018-06-28 11:18:44 -0700371 include_resources = {},
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700372 test_srcs = None,
373 exclude_tests = None,
374 test_resources = None,
375 visibility = ["//visibility:public"],
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700376 version = ONOS_VERSION,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700377 suppress_errorprone = False,
Ray Milkey134d2922018-07-15 15:24:01 -0700378 suppress_checkstyle = False,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700379 suppress_javadocs = False,
Ray Milkey25747d82018-06-13 14:12:51 -0700380 web_context = None,
381 api_title = "",
382 api_version = "",
383 api_description = "",
384 api_package = "",
Ray Milkey15053f02018-06-13 10:00:45 -0700385 import_packages = None):
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700386 if name == None:
387 name = "onos-" + native.package_name().replace("/", "-")
Ray Milkey7dac7da2017-08-01 16:56:05 -0700388 if srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700389 srcs = _all_java_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700390 if resources == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700391 resources = _all_resources(resources_root)
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700392 if test_srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700393 test_srcs = _all_java_test_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700394 if test_resources == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700395 test_resources = _all_test_resources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700396 if exclude_tests == None:
397 exclude_tests = []
Ray Milkey7dac7da2017-08-01 16:56:05 -0700398 if deps == None:
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700399 deps = COMPILE
400 if test_deps == None:
401 test_deps = TEST
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700402 if import_packages == None:
403 import_packages = "*"
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700404 tests_name = name + "-tests"
405 tests_jar_deps = list(depset(deps + test_deps)) + [name]
406 all_test_deps = tests_jar_deps + [tests_name]
Ray Milkey25747d82018-06-13 14:12:51 -0700407 web_xml = _webapp()
Ray Milkey7dac7da2017-08-01 16:56:05 -0700408
Ray Milkey275af2c2018-06-15 13:05:08 -0700409 native_srcs = srcs
410 native_resources = resources
Ray Milkey6b3775a2018-06-28 11:18:44 -0700411 if web_context != None and api_title != "" and len(resources) != 0:
Ray Milkey275af2c2018-06-15 13:05:08 -0700412 # generate Swagger files if needed
413 _swagger_java(
414 name = name + "_swagger_java",
415 srcs = srcs + resources,
416 package_name = native.package_name(),
417 api_title = api_title,
418 api_version = api_version,
419 api_description = api_description,
420 web_context = web_context,
421 api_package = api_package,
422 swagger_java = ("src/main/resources/apidoc/generated-sources/" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700423 api_package.replace(".", "/") +
424 "/ApiDocRegistrator.java").replace("//", "/"),
Ray Milkey275af2c2018-06-15 13:05:08 -0700425 )
426 _swagger_json(
427 name = name + "_swagger_json",
428 srcs = srcs + resources,
429 package_name = native.package_name(),
430 api_title = api_title,
431 api_version = api_version,
432 api_description = api_description,
433 web_context = web_context,
434 api_package = api_package,
435 swagger_json = "src/main/resources/apidoc/swagger.json",
436 )
437 native_resources = []
438 for r in resources:
Ray Milkey6b3775a2018-06-28 11:18:44 -0700439 if not "definitions" in r:
Ray Milkey275af2c2018-06-15 13:05:08 -0700440 native_resources.append(r)
Ray Milkey6b3775a2018-06-28 11:18:44 -0700441 native_srcs = srcs + [name + "_swagger_java"]
442 native_resources.append(name + "_swagger_json")
Ray Milkey275af2c2018-06-15 13:05:08 -0700443
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700444 javacopts = [ "-XepDisableAllChecks" ] if suppress_errorprone else []
445
Ray Milkey25747d82018-06-13 14:12:51 -0700446 # compile the Java code
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700447 if len(resource_jars) > 0:
448 native.java_library(name = name + "-native", srcs = native_srcs, resource_jars = resource_jars,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700449 deps = deps, visibility = visibility, javacopts = javacopts)
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700450 else:
451 native.java_library(name = name + "-native", srcs = native_srcs, resources = native_resources,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700452 deps = deps, visibility = visibility, javacopts = javacopts)
Ray Milkey25747d82018-06-13 14:12:51 -0700453
Ray Milkey32ea35c2018-06-06 15:28:07 -0700454 _bnd(
Ray Milkey25b785a2018-06-12 09:59:14 -0700455 name = name,
456 source = name + "-native",
Ray Milkey32ea35c2018-06-06 15:28:07 -0700457 deps = deps,
458 version = version,
Ray Milkey275af2c2018-06-15 13:05:08 -0700459 group = group,
Ray Milkey32ea35c2018-06-06 15:28:07 -0700460 visibility = visibility,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700461 import_packages = import_packages,
Ray Milkey25747d82018-06-13 14:12:51 -0700462 web_context = web_context,
463 web_xml = web_xml,
Ray Milkey6b3775a2018-06-28 11:18:44 -0700464 include_resources = _include_resources_to_string(include_resources),
Ray Milkey32ea35c2018-06-06 15:28:07 -0700465 )
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700466
Thomas Vachuska50ac0982018-07-19 10:17:37 -0700467 # rule for building source jars
468 if not suppress_javadocs:
469 java_sources(name = name + "-sources", srcs = srcs, visibility = visibility)
470
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700471 # rule for building javadocs
472 if not suppress_javadocs:
473 javadoc(name = name + "-javadocs", deps = deps, srcs = srcs, visibility = visibility)
474
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700475 if test_srcs != []:
476 native.java_library(
477 name = tests_name,
478 srcs = test_srcs,
479 resources = test_resources,
480 deps = tests_jar_deps,
481 visibility = visibility,
482 )
Ray Milkey7dac7da2017-08-01 16:56:05 -0700483
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700484 generate_test_rules(
485 name = name + "-tests-gen",
486 test_files = test_srcs,
487 exclude_tests = exclude_tests,
488 deps = all_test_deps,
489 )
490
Ray Milkey134d2922018-07-15 15:24:01 -0700491 if not suppress_checkstyle:
492 checkstyle_test(
493 name = name + "_checkstyle_test",
494 srcs = srcs,
495 )
Ray Milkeyb7949e72018-06-19 18:31:02 -0700496
Ray Milkey275af2c2018-06-15 13:05:08 -0700497"""
498 Creates an OSGI jar file from a set of source files.
499
500 Args:
501 name: Name of the rule to generate. Optional, defaults to a name based on the location in the source tree.
502 For example apps/mcast/app becomes onos-apps-mcast-app
503 deps: Dependencies of the generated jar file. Expressed as a list of targets
504 import_packages: OSGI import list. Optional, comma separated list, defaults to "*"
505 group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject'
506 srcs: Source file(s) to compile. Optional list of targets, defaults to src/main/java/**/*.java
507 resources_root: Relative path to the root of the tree of resources for this jar. Optional, defaults to src/main/resources
508 resources: Resources to include in the jar file. Optional list of targets, defaults to all files beneath resources_root
509 visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to public
510 version: Version of the generated jar file. Optional, defaults to the current ONOS version
Ray Milkey134d2922018-07-15 15:24:01 -0700511 suppress_errorprone: If true, don't run ErrorProne tests. Default is false
512 suppress_checkstyle: If true, don't run checkstyle tests. Default is false
Ray Milkey275af2c2018-06-15 13:05:08 -0700513 web_context: Web context for a WAB file if needed. Only needed if the jar file provides a REST API. Optional string
514 api_title: Swagger API title. Optional string, only used if the jar file provides a REST API and has swagger annotations
515 api_version: Swagger API version. Optional string, only used if the jar file provides a REST API and has swagger annotations
516 api_description: Swagger API description. Optional string, only used if the jar file provides a REST API and has swagger annotations
517 api_package: Swagger API package name. Optional string, only used if the jar file provides a REST API and has swagger annotations
518"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700519
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700520def osgi_jar(
521 name = None,
522 deps = None,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700523 import_packages = None,
Ray Milkey275af2c2018-06-15 13:05:08 -0700524 group = "org.onosproject",
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700525 srcs = None,
526 resources_root = None,
527 resources = None,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700528 resource_jars = [],
Ray Milkey6b3775a2018-06-28 11:18:44 -0700529 include_resources = {},
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700530 visibility = ["//visibility:public"],
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700531 version = ONOS_VERSION,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700532 suppress_errorprone = False,
Ray Milkey134d2922018-07-15 15:24:01 -0700533 suppress_checkstyle = False,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700534 suppress_javadocs = False,
Ray Milkey25747d82018-06-13 14:12:51 -0700535 web_context = None,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700536 api_title = "",
537 api_version = "",
538 api_description = "",
Ray Milkey15053f02018-06-13 10:00:45 -0700539 api_package = ""):
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700540 if srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700541 srcs = _all_java_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700542 if deps == None:
543 deps = COMPILE
544
545 osgi_jar_with_tests(
546 name = name,
547 deps = deps,
548 test_deps = [],
Ray Milkey275af2c2018-06-15 13:05:08 -0700549 group = group,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700550 srcs = srcs,
551 resources = resources,
552 resources_root = resources_root,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700553 resource_jars = resource_jars,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700554 test_srcs = [],
555 exclude_tests = [],
556 test_resources = [],
557 visibility = visibility,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700558 suppress_errorprone = suppress_errorprone,
Ray Milkey134d2922018-07-15 15:24:01 -0700559 suppress_checkstyle = suppress_checkstyle,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700560 suppress_javadocs = suppress_javadocs,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700561 version = version,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700562 import_packages = import_packages,
Ray Milkey275af2c2018-06-15 13:05:08 -0700563 api_title = api_title,
564 api_version = api_version,
565 api_description = api_description,
566 api_package = api_package,
Ray Milkey25747d82018-06-13 14:12:51 -0700567 web_context = web_context,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700568 )