blob: 523224c57f2caafe403593a47bee907daafd3048 [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
Ray Milkey0bcdfd12018-05-23 14:07:19 -070073 exportPackages = "*"
Ray Milkey6b3775a2018-06-28 11:18:44 -070074 include_resources = ctx.attr.include_resources
Ray Milkey25747d82018-06-13 14:12:51 -070075 web_context = ctx.attr.web_context
76 if web_context == None or web_context == "":
77 web_context = "NONE"
78 web_xml = ctx.attr.web_xml
Ray Milkey0bcdfd12018-05-23 14:07:19 -070079 dynamicimportPackages = ""
Ray Milkey3275ae82018-05-29 15:35:36 -070080 cp = ""
Ray Milkey7dac7da2017-08-01 16:56:05 -070081
Ray Milkey3275ae82018-05-29 15:35:36 -070082 inputDependencies = [input_file]
Ray Milkey7dac7da2017-08-01 16:56:05 -070083
Ray Milkey0bcdfd12018-05-23 14:07:19 -070084 # determine the dependencies and build the class path
85 for dep in ctx.attr.deps:
Ray Milkey25b785a2018-06-12 09:59:14 -070086 if java_common.provider in dep:
87 file = dep.files.to_list()[0]
Ray Milkey472d8392018-05-23 17:06:51 -070088
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 Milkey0bcdfd12018-05-23 14:07:19 -070094 # extract the class files for use by bnd
Ray Milkey3275ae82018-05-29 15:35:36 -070095 classes = ctx.actions.declare_file("classes" + ctx.label.name.replace("/", "-"))
Ray Milkey0bcdfd12018-05-23 14:07:19 -070096 classesPath = classes.path
97 jarCommand = "mkdir -p %s && cp %s %s && cd %s && jar xf *.jar" % (classesPath, jar, classesPath, classesPath)
98 ctx.actions.run_shell(
99 inputs = inputDependencies,
100 outputs = [classes],
101 command = jarCommand,
102 progress_message = "Expanding jar file: %s" % jar,
103 )
104 inputDependencies += [classes]
Ray Milkey25747d82018-06-13 14:12:51 -0700105 web_xml_root_path = ""
106 if len(web_xml) != 0:
107 web_xml_root = web_xml[0].files.to_list()[0]
108 inputDependencies += [web_xml_root]
109 web_xml_root_path = web_xml_root.path.replace("WEB-INF/web.xml", "")
Ray Milkey7dac7da2017-08-01 16:56:05 -0700110
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700111 # call bnd to make the OSGI jar file
112 arguments = [
113 jar,
114 output,
115 cp,
116 name,
117 group,
118 version,
119 license,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700120 import_packages,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700121 exportPackages,
Ray Milkey6b3775a2018-06-28 11:18:44 -0700122 include_resources,
Ray Milkey25747d82018-06-13 14:12:51 -0700123 web_context,
124 web_xml_root_path,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700125 dynamicimportPackages,
126 classesPath,
127 ]
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700128
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700129 ctx.actions.run(
130 inputs = inputDependencies,
131 outputs = [ctx.outputs.osgi_jar],
132 arguments = arguments,
133 progress_message = "Running bnd wrapper on: %s" % ctx.attr.name,
134 executable = ctx.executable._bnd_exe,
135 )
Ray Milkey7dac7da2017-08-01 16:56:05 -0700136
Ray Milkey25b785a2018-06-12 09:59:14 -0700137 deps = []
138 if java_common.provider in ctx.attr.source:
139 deps.append(ctx.attr.source[java_common.provider])
140 deps_provider = java_common.merge(deps)
141 return struct(
Ray Milkey15053f02018-06-13 10:00:45 -0700142 providers = [deps_provider],
Ray Milkey25b785a2018-06-12 09:59:14 -0700143 )
144
Ray Milkey275af2c2018-06-15 13:05:08 -0700145"""
146 Rule definition for calling bnd to make an OSGi jar file.
147"""
Ray Milkey32ea35c2018-06-06 15:28:07 -0700148_bnd = rule(
Ray Milkey7dac7da2017-08-01 16:56:05 -0700149 attrs = {
150 "deps": attr.label_list(),
151 "version": attr.string(),
Ray Milkey275af2c2018-06-15 13:05:08 -0700152 "group": attr.string(),
Ray Milkey3275ae82018-05-29 15:35:36 -0700153 "source": attr.label(),
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700154 "import_packages": attr.string(),
Ray Milkey25747d82018-06-13 14:12:51 -0700155 "web_context": attr.string(),
156 "web_xml": attr.label_list(allow_files = True),
Ray Milkey6b3775a2018-06-28 11:18:44 -0700157 "include_resources": attr.string(),
Ray Milkey7dac7da2017-08-01 16:56:05 -0700158 "_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 Milkey275af2c2018-06-15 13:05:08 -0700172"""
173 Implementation of the rule to call swagger generator to create the registrator java class source
174"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700175
Ray Milkey275af2c2018-06-15 13:05:08 -0700176def _swagger_java_impl(ctx):
177 api_title = ctx.attr.api_title
178 api_version = ctx.attr.api_version
179 api_description = ctx.attr.api_description
180 api_package = ctx.attr.api_package
181 web_context = ctx.attr.web_context
182
183 output_java = ctx.outputs.swagger_java.path
Ray Milkey6b3775a2018-06-28 11:18:44 -0700184 output_dir = output_java[:output_java.find("generated-sources")]
Ray Milkey275af2c2018-06-15 13:05:08 -0700185
186 package_name = ctx.attr.package_name
187
188 srcs_arg = ""
189 resources_arg = ""
190 input_dependencies = []
191
192 for file in ctx.files.srcs:
193 srcs_arg += file.path + ","
194 input_dependencies.append(file)
195
196 for resource in resources_arg:
197 resources_arg += resource.path + ","
198
199 # call swagger generator to make the swagger JSON and java files
200 arguments = [
201 srcs_arg,
202 resources_arg,
203 "",
204 package_name + "/src/main/resources",
205 output_dir,
206 output_dir,
207 web_context,
208 api_title,
209 api_version,
210 api_package,
211 api_description,
212 ]
213
214 ctx.actions.run(
215 inputs = ctx.files.srcs,
216 outputs = [ctx.outputs.swagger_java],
217 arguments = arguments,
218 progress_message = "Running swagger generator on: %s" % ctx.attr.name,
219 executable = ctx.executable._swagger_generator_exe,
220 )
221
222"""
223Implementation of the rule to call swagger generator for swagger.json file
224"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700225
Ray Milkey275af2c2018-06-15 13:05:08 -0700226def _swagger_json_impl(ctx):
227 api_title = ctx.attr.api_title
228 api_version = ctx.attr.api_version
229 api_description = ctx.attr.api_description
230 api_package = ctx.attr.api_package
231 web_context = ctx.attr.web_context
232
233 output_json = ctx.outputs.swagger_json.path
234 output_dir = output_json[:output_json.find("swagger.json")]
235
236 package_name = ctx.attr.package_name
237
238 srcs_arg = ""
239 resources_arg = ""
240 input_dependencies = []
241
242 for file in ctx.files.srcs:
243 srcs_arg += file.path + ","
244 input_dependencies.append(file)
245
246 for resource in resources_arg:
247 resources_arg += resource.path + ","
248
249 # call swagger generator to make the swagger JSON and java files
250 arguments = [
251 srcs_arg,
252 resources_arg,
253 "",
254 package_name + "/src/main/resources",
255 output_dir,
256 output_dir,
257 web_context,
258 api_title,
259 api_version,
260 api_package,
261 api_description,
262 ]
263
264 ctx.actions.run(
265 inputs = ctx.files.srcs,
266 outputs = [ctx.outputs.swagger_json],
267 arguments = arguments,
268 progress_message = "Running swagger generator on: %s" % ctx.attr.name,
269 executable = ctx.executable._swagger_generator_exe,
270 )
271
272"""
273 Rule definition to call swagger generator to create the registrator java class source
274"""
275_swagger_java = rule(
276 attrs = {
277 "srcs": attr.label_list(allow_files = True),
278 "package_name": attr.string(),
279 "api_title": attr.string(),
280 "api_version": attr.string(),
281 "api_description": attr.string(),
282 "api_package": attr.string(),
283 "web_context": attr.string(),
284 "_swagger_generator_exe": attr.label(
285 executable = True,
286 cfg = "host",
287 allow_files = True,
288 default = Label("//tools/build/buck-plugin:swagger_generator"),
289 ),
290 "swagger_java": attr.output(),
291 },
292 fragments = ["java"],
293 implementation = _swagger_java_impl,
294)
295
296"""
297 Rule definition to call swagger generator to create the swagger JSON
298"""
299_swagger_json = rule(
300 attrs = {
301 "srcs": attr.label_list(allow_files = True),
302 "package_name": attr.string(),
303 "api_title": attr.string(),
304 "api_version": attr.string(),
305 "api_description": attr.string(),
306 "api_package": attr.string(),
307 "web_context": attr.string(),
308 "_swagger_generator_exe": attr.label(
309 executable = True,
310 cfg = "host",
311 allow_files = True,
312 default = Label("//tools/build/buck-plugin:swagger_generator"),
313 ),
314 "swagger_json": attr.output(),
315 },
316 fragments = ["java"],
317 implementation = _swagger_json_impl,
318)
319
320"""
321 Converts a jar file to an OSGI compatible jar file.
322
323 Args:
324 name: name of the rule to create the OSGI jar file - required
325 jar: jar file to convert - required target
326 deps: dependencies needed by the jar file - required list of targets
327 version: Version of the generated jar file. Optional, defaults to the current ONOS version
328 group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject'
329 import_packages: OSGI import list. Optional, comma separated list, defaults to "*"
330 visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to private
331"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700332
Ray Milkey25747d82018-06-13 14:12:51 -0700333def wrapped_osgi_jar(
334 name,
335 jar,
336 deps,
337 version = ONOS_VERSION,
Ray Milkey275af2c2018-06-15 13:05:08 -0700338 group = "org.onosproject",
Ray Milkey25747d82018-06-13 14:12:51 -0700339 import_packages = "*",
Ray Milkey25747d82018-06-13 14:12:51 -0700340 visibility = ["//visibility:private"]):
341 _bnd(
342 name = name,
343 source = jar,
344 deps = deps,
345 version = version,
Ray Milkey275af2c2018-06-15 13:05:08 -0700346 group = group,
Ray Milkey25747d82018-06-13 14:12:51 -0700347 visibility = visibility,
348 import_packages = import_packages,
Ray Milkey275af2c2018-06-15 13:05:08 -0700349 web_xml = None,
Ray Milkey25747d82018-06-13 14:12:51 -0700350 )
Ray Milkey7dac7da2017-08-01 16:56:05 -0700351
Ray Milkey275af2c2018-06-15 13:05:08 -0700352"""
353 Creates an OSGI jar and test jar file from a set of source and test files.
354 See osgi_jar() for a description of shared parameters.
355 Args:
356 test_srcs: Test source file(s) to compile. Optional list of targets, defaults to src/test/java/**/*.java
357 test_deps: Dependencies for the test jar. Optional list of targets, defaults to a common set of dependencies
358 test_resources: Resources to include in the test jar. Optional list of targets, defaults to src/test/resources/**
359 exclude_tests: Tests that should not be run. Useful for excluding things like test files without any @Test methods.
360 Optional ist of targets, defaults to []
361"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700362
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700363def osgi_jar_with_tests(
364 name = None,
365 deps = None,
366 test_deps = None,
Ray Milkey275af2c2018-06-15 13:05:08 -0700367 group = "org.onosproject",
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700368 srcs = None,
369 resources_root = None,
370 resources = None,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700371 resource_jars = [],
Ray Milkey6b3775a2018-06-28 11:18:44 -0700372 include_resources = {},
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700373 test_srcs = None,
374 exclude_tests = None,
375 test_resources = None,
376 visibility = ["//visibility:public"],
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700377 version = ONOS_VERSION,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700378 suppress_errorprone = False,
Ray Milkey134d2922018-07-15 15:24:01 -0700379 suppress_checkstyle = False,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700380 suppress_javadocs = False,
Ray Milkey25747d82018-06-13 14:12:51 -0700381 web_context = None,
382 api_title = "",
383 api_version = "",
384 api_description = "",
385 api_package = "",
Ray Milkey15053f02018-06-13 10:00:45 -0700386 import_packages = None):
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700387 if name == None:
388 name = "onos-" + native.package_name().replace("/", "-")
Ray Milkey7dac7da2017-08-01 16:56:05 -0700389 if srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700390 srcs = _all_java_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700391 if resources == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700392 resources = _all_resources(resources_root)
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700393 if test_srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700394 test_srcs = _all_java_test_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700395 if test_resources == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700396 test_resources = _all_test_resources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700397 if exclude_tests == None:
398 exclude_tests = []
Ray Milkey7dac7da2017-08-01 16:56:05 -0700399 if deps == None:
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700400 deps = COMPILE
401 if test_deps == None:
402 test_deps = TEST
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700403 if import_packages == None:
404 import_packages = "*"
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700405 tests_name = name + "-tests"
406 tests_jar_deps = list(depset(deps + test_deps)) + [name]
407 all_test_deps = tests_jar_deps + [tests_name]
Ray Milkey25747d82018-06-13 14:12:51 -0700408 web_xml = _webapp()
Ray Milkey7dac7da2017-08-01 16:56:05 -0700409
Ray Milkey275af2c2018-06-15 13:05:08 -0700410 native_srcs = srcs
411 native_resources = resources
Ray Milkey6b3775a2018-06-28 11:18:44 -0700412 if web_context != None and api_title != "" and len(resources) != 0:
Ray Milkey275af2c2018-06-15 13:05:08 -0700413 # generate Swagger files if needed
414 _swagger_java(
415 name = name + "_swagger_java",
416 srcs = srcs + resources,
417 package_name = native.package_name(),
418 api_title = api_title,
419 api_version = api_version,
420 api_description = api_description,
421 web_context = web_context,
422 api_package = api_package,
423 swagger_java = ("src/main/resources/apidoc/generated-sources/" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700424 api_package.replace(".", "/") +
425 "/ApiDocRegistrator.java").replace("//", "/"),
Ray Milkey275af2c2018-06-15 13:05:08 -0700426 )
427 _swagger_json(
428 name = name + "_swagger_json",
429 srcs = srcs + resources,
430 package_name = native.package_name(),
431 api_title = api_title,
432 api_version = api_version,
433 api_description = api_description,
434 web_context = web_context,
435 api_package = api_package,
436 swagger_json = "src/main/resources/apidoc/swagger.json",
437 )
438 native_resources = []
439 for r in resources:
Ray Milkey6b3775a2018-06-28 11:18:44 -0700440 if not "definitions" in r:
Ray Milkey275af2c2018-06-15 13:05:08 -0700441 native_resources.append(r)
Ray Milkey6b3775a2018-06-28 11:18:44 -0700442 native_srcs = srcs + [name + "_swagger_java"]
443 native_resources.append(name + "_swagger_json")
Ray Milkey275af2c2018-06-15 13:05:08 -0700444
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700445 javacopts = [ "-XepDisableAllChecks" ] if suppress_errorprone else []
446
Ray Milkey25747d82018-06-13 14:12:51 -0700447 # compile the Java code
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700448 if len(resource_jars) > 0:
449 native.java_library(name = name + "-native", srcs = native_srcs, resource_jars = resource_jars,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700450 deps = deps, visibility = visibility, javacopts = javacopts)
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700451 else:
452 native.java_library(name = name + "-native", srcs = native_srcs, resources = native_resources,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700453 deps = deps, visibility = visibility, javacopts = javacopts)
Ray Milkey25747d82018-06-13 14:12:51 -0700454
Ray Milkey32ea35c2018-06-06 15:28:07 -0700455 _bnd(
Ray Milkey25b785a2018-06-12 09:59:14 -0700456 name = name,
457 source = name + "-native",
Ray Milkey32ea35c2018-06-06 15:28:07 -0700458 deps = deps,
459 version = version,
Ray Milkey275af2c2018-06-15 13:05:08 -0700460 group = group,
Ray Milkey32ea35c2018-06-06 15:28:07 -0700461 visibility = visibility,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700462 import_packages = import_packages,
Ray Milkey25747d82018-06-13 14:12:51 -0700463 web_context = web_context,
464 web_xml = web_xml,
Ray Milkey6b3775a2018-06-28 11:18:44 -0700465 include_resources = _include_resources_to_string(include_resources),
Ray Milkey32ea35c2018-06-06 15:28:07 -0700466 )
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700467
Thomas Vachuskaac9e5242018-07-19 16:15:39 -0700468 # rule for generating pom file for publishing
469 pom_file(name = name + "-pom", artifact = name, deps = deps, visibility = visibility)
470
471 # rule for building source jar
Thomas Vachuska50ac0982018-07-19 10:17:37 -0700472 if not suppress_javadocs:
473 java_sources(name = name + "-sources", srcs = srcs, visibility = visibility)
474
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700475 # rule for building javadocs
476 if not suppress_javadocs:
477 javadoc(name = name + "-javadocs", deps = deps, srcs = srcs, visibility = visibility)
478
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700479 if test_srcs != []:
480 native.java_library(
481 name = tests_name,
482 srcs = test_srcs,
483 resources = test_resources,
484 deps = tests_jar_deps,
485 visibility = visibility,
486 )
Ray Milkey7dac7da2017-08-01 16:56:05 -0700487
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700488 generate_test_rules(
489 name = name + "-tests-gen",
490 test_files = test_srcs,
491 exclude_tests = exclude_tests,
492 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 "*"
509 group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject'
510 srcs: Source file(s) to compile. Optional list of targets, defaults to src/main/java/**/*.java
511 resources_root: Relative path to the root of the tree of resources for this jar. Optional, defaults to src/main/resources
512 resources: Resources to include in the jar file. Optional list of targets, defaults to all files beneath resources_root
513 visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to public
514 version: Version of the generated jar file. Optional, defaults to the current ONOS version
Ray Milkey134d2922018-07-15 15:24:01 -0700515 suppress_errorprone: If true, don't run ErrorProne tests. Default is false
516 suppress_checkstyle: If true, don't run checkstyle tests. Default is false
Ray Milkey275af2c2018-06-15 13:05:08 -0700517 web_context: Web context for a WAB file if needed. Only needed if the jar file provides a REST API. Optional string
518 api_title: Swagger API title. Optional string, only used if the jar file provides a REST API and has swagger annotations
519 api_version: Swagger API version. Optional string, only used if the jar file provides a REST API and has swagger annotations
520 api_description: Swagger API description. Optional string, only used if the jar file provides a REST API and has swagger annotations
521 api_package: Swagger API package name. Optional string, only used if the jar file provides a REST API and has swagger annotations
522"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700523
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700524def osgi_jar(
525 name = None,
526 deps = None,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700527 import_packages = None,
Ray Milkey275af2c2018-06-15 13:05:08 -0700528 group = "org.onosproject",
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700529 srcs = None,
530 resources_root = None,
531 resources = None,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700532 resource_jars = [],
Ray Milkey6b3775a2018-06-28 11:18:44 -0700533 include_resources = {},
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700534 visibility = ["//visibility:public"],
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700535 version = ONOS_VERSION,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700536 suppress_errorprone = False,
Ray Milkey134d2922018-07-15 15:24:01 -0700537 suppress_checkstyle = False,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700538 suppress_javadocs = False,
Ray Milkey25747d82018-06-13 14:12:51 -0700539 web_context = None,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700540 api_title = "",
541 api_version = "",
542 api_description = "",
Ray Milkey15053f02018-06-13 10:00:45 -0700543 api_package = ""):
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700544 if srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700545 srcs = _all_java_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700546 if deps == None:
547 deps = COMPILE
548
549 osgi_jar_with_tests(
550 name = name,
551 deps = deps,
552 test_deps = [],
Ray Milkey275af2c2018-06-15 13:05:08 -0700553 group = group,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700554 srcs = srcs,
555 resources = resources,
556 resources_root = resources_root,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700557 resource_jars = resource_jars,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700558 test_srcs = [],
559 exclude_tests = [],
560 test_resources = [],
561 visibility = visibility,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700562 suppress_errorprone = suppress_errorprone,
Ray Milkey134d2922018-07-15 15:24:01 -0700563 suppress_checkstyle = suppress_checkstyle,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700564 suppress_javadocs = suppress_javadocs,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700565 version = version,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700566 import_packages = import_packages,
Ray Milkey275af2c2018-06-15 13:05:08 -0700567 api_title = api_title,
568 api_version = api_version,
569 api_description = api_description,
570 api_package = api_package,
Ray Milkey25747d82018-06-13 14:12:51 -0700571 web_context = web_context,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700572 )