blob: 03521576032517b88b87844b1f2690e2bda76262 [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,
378 test_resources = None,
379 visibility = ["//visibility:public"],
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700380 version = ONOS_VERSION,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700381 suppress_errorprone = False,
Ray Milkey134d2922018-07-15 15:24:01 -0700382 suppress_checkstyle = False,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700383 suppress_javadocs = False,
Ray Milkey25747d82018-06-13 14:12:51 -0700384 web_context = None,
385 api_title = "",
386 api_version = "",
387 api_description = "",
388 api_package = "",
Jian Li4ad86872018-08-05 03:34:35 +0900389 import_packages = None,
390 bundle_classpath = ""):
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700391 if name == None:
392 name = "onos-" + native.package_name().replace("/", "-")
Ray Milkey7dac7da2017-08-01 16:56:05 -0700393 if srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700394 srcs = _all_java_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700395 if resources == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700396 resources = _all_resources(resources_root)
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700397 if test_srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700398 test_srcs = _all_java_test_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700399 if test_resources == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700400 test_resources = _all_test_resources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700401 if exclude_tests == None:
402 exclude_tests = []
Ray Milkey7dac7da2017-08-01 16:56:05 -0700403 if deps == None:
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700404 deps = COMPILE
405 if test_deps == None:
406 test_deps = TEST
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700407 if import_packages == None:
408 import_packages = "*"
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700409 tests_name = name + "-tests"
410 tests_jar_deps = list(depset(deps + test_deps)) + [name]
411 all_test_deps = tests_jar_deps + [tests_name]
Ray Milkey25747d82018-06-13 14:12:51 -0700412 web_xml = _webapp()
Ray Milkey7dac7da2017-08-01 16:56:05 -0700413
Ray Milkey275af2c2018-06-15 13:05:08 -0700414 native_srcs = srcs
415 native_resources = resources
Ray Milkey6b3775a2018-06-28 11:18:44 -0700416 if web_context != None and api_title != "" and len(resources) != 0:
Ray Milkey275af2c2018-06-15 13:05:08 -0700417 # generate Swagger files if needed
418 _swagger_java(
419 name = name + "_swagger_java",
420 srcs = srcs + resources,
421 package_name = native.package_name(),
422 api_title = api_title,
423 api_version = api_version,
424 api_description = api_description,
425 web_context = web_context,
426 api_package = api_package,
427 swagger_java = ("src/main/resources/apidoc/generated-sources/" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700428 api_package.replace(".", "/") +
429 "/ApiDocRegistrator.java").replace("//", "/"),
Ray Milkey275af2c2018-06-15 13:05:08 -0700430 )
431 _swagger_json(
432 name = name + "_swagger_json",
433 srcs = srcs + resources,
434 package_name = native.package_name(),
435 api_title = api_title,
436 api_version = api_version,
437 api_description = api_description,
438 web_context = web_context,
439 api_package = api_package,
440 swagger_json = "src/main/resources/apidoc/swagger.json",
441 )
442 native_resources = []
443 for r in resources:
Ray Milkey6b3775a2018-06-28 11:18:44 -0700444 if not "definitions" in r:
Ray Milkey275af2c2018-06-15 13:05:08 -0700445 native_resources.append(r)
Ray Milkey6b3775a2018-06-28 11:18:44 -0700446 native_srcs = srcs + [name + "_swagger_java"]
447 native_resources.append(name + "_swagger_json")
Ray Milkey275af2c2018-06-15 13:05:08 -0700448
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700449 javacopts = [ "-XepDisableAllChecks" ] if suppress_errorprone else []
450
Ray Milkey25747d82018-06-13 14:12:51 -0700451 # compile the Java code
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700452 if len(resource_jars) > 0:
453 native.java_library(name = name + "-native", srcs = native_srcs, resource_jars = resource_jars,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700454 deps = deps, visibility = visibility, javacopts = javacopts)
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700455 else:
456 native.java_library(name = name + "-native", srcs = native_srcs, resources = native_resources,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700457 deps = deps, visibility = visibility, javacopts = javacopts)
Ray Milkey25747d82018-06-13 14:12:51 -0700458
Ray Milkey32ea35c2018-06-06 15:28:07 -0700459 _bnd(
Ray Milkey25b785a2018-06-12 09:59:14 -0700460 name = name,
461 source = name + "-native",
Ray Milkey32ea35c2018-06-06 15:28:07 -0700462 deps = deps,
463 version = version,
Ray Milkey275af2c2018-06-15 13:05:08 -0700464 group = group,
Ray Milkey32ea35c2018-06-06 15:28:07 -0700465 visibility = visibility,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700466 import_packages = import_packages,
Jian Li4ad86872018-08-05 03:34:35 +0900467 bundle_classpath = bundle_classpath,
Ray Milkey25747d82018-06-13 14:12:51 -0700468 web_context = web_context,
469 web_xml = web_xml,
Ray Milkey6b3775a2018-06-28 11:18:44 -0700470 include_resources = _include_resources_to_string(include_resources),
Ray Milkey32ea35c2018-06-06 15:28:07 -0700471 )
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700472
Thomas Vachuskaac9e5242018-07-19 16:15:39 -0700473 # rule for generating pom file for publishing
474 pom_file(name = name + "-pom", artifact = name, deps = deps, visibility = visibility)
475
476 # rule for building source jar
Thomas Vachuska50ac0982018-07-19 10:17:37 -0700477 if not suppress_javadocs:
478 java_sources(name = name + "-sources", srcs = srcs, visibility = visibility)
479
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700480 # rule for building javadocs
481 if not suppress_javadocs:
Ray Milkey7f46b1f2018-07-24 19:01:58 -0700482 javadoc(name = name + "-javadoc", deps = deps, srcs = srcs, visibility = visibility)
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700483
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700484 if test_srcs != []:
485 native.java_library(
486 name = tests_name,
487 srcs = test_srcs,
488 resources = test_resources,
489 deps = tests_jar_deps,
490 visibility = visibility,
491 )
Ray Milkey7dac7da2017-08-01 16:56:05 -0700492
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700493 generate_test_rules(
494 name = name + "-tests-gen",
495 test_files = test_srcs,
496 exclude_tests = exclude_tests,
497 deps = all_test_deps,
498 )
499
Ray Milkey134d2922018-07-15 15:24:01 -0700500 if not suppress_checkstyle:
501 checkstyle_test(
502 name = name + "_checkstyle_test",
503 srcs = srcs,
504 )
Ray Milkeyb7949e72018-06-19 18:31:02 -0700505
Ray Milkey275af2c2018-06-15 13:05:08 -0700506"""
507 Creates an OSGI jar file from a set of source files.
508
509 Args:
510 name: Name of the rule to generate. Optional, defaults to a name based on the location in the source tree.
511 For example apps/mcast/app becomes onos-apps-mcast-app
512 deps: Dependencies of the generated jar file. Expressed as a list of targets
513 import_packages: OSGI import list. Optional, comma separated list, defaults to "*"
Jian Li4ad86872018-08-05 03:34:35 +0900514 bundle_classpath: intended for including dependencies in our bundle, so that our bundle can be deployed standalone
Ray Milkey275af2c2018-06-15 13:05:08 -0700515 group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject'
516 srcs: Source file(s) to compile. Optional list of targets, defaults to src/main/java/**/*.java
517 resources_root: Relative path to the root of the tree of resources for this jar. Optional, defaults to src/main/resources
518 resources: Resources to include in the jar file. Optional list of targets, defaults to all files beneath resources_root
519 visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to public
520 version: Version of the generated jar file. Optional, defaults to the current ONOS version
Ray Milkey134d2922018-07-15 15:24:01 -0700521 suppress_errorprone: If true, don't run ErrorProne tests. Default is false
522 suppress_checkstyle: If true, don't run checkstyle tests. Default is false
Ray Milkey275af2c2018-06-15 13:05:08 -0700523 web_context: Web context for a WAB file if needed. Only needed if the jar file provides a REST API. Optional string
524 api_title: Swagger API title. Optional string, only used if the jar file provides a REST API and has swagger annotations
525 api_version: Swagger API version. Optional string, only used if the jar file provides a REST API and has swagger annotations
526 api_description: Swagger API description. Optional string, only used if the jar file provides a REST API and has swagger annotations
527 api_package: Swagger API package name. Optional string, only used if the jar file provides a REST API and has swagger annotations
528"""
Ray Milkey6b3775a2018-06-28 11:18:44 -0700529
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700530def osgi_jar(
531 name = None,
532 deps = None,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700533 import_packages = None,
Ray Milkey275af2c2018-06-15 13:05:08 -0700534 group = "org.onosproject",
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700535 srcs = None,
536 resources_root = None,
537 resources = None,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700538 resource_jars = [],
Ray Milkey6b3775a2018-06-28 11:18:44 -0700539 include_resources = {},
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700540 visibility = ["//visibility:public"],
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700541 version = ONOS_VERSION,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700542 suppress_errorprone = False,
Ray Milkey134d2922018-07-15 15:24:01 -0700543 suppress_checkstyle = False,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700544 suppress_javadocs = False,
Ray Milkey25747d82018-06-13 14:12:51 -0700545 web_context = None,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700546 api_title = "",
547 api_version = "",
548 api_description = "",
Jian Li4ad86872018-08-05 03:34:35 +0900549 api_package = "",
550 bundle_classpath = ""):
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700551 if srcs == None:
Ray Milkey32ea35c2018-06-06 15:28:07 -0700552 srcs = _all_java_sources()
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700553 if deps == None:
554 deps = COMPILE
555
556 osgi_jar_with_tests(
557 name = name,
558 deps = deps,
559 test_deps = [],
Ray Milkey275af2c2018-06-15 13:05:08 -0700560 group = group,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700561 srcs = srcs,
562 resources = resources,
563 resources_root = resources_root,
Thomas Vachuskaf8c8cb92018-07-11 17:12:43 -0700564 resource_jars = resource_jars,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700565 test_srcs = [],
566 exclude_tests = [],
567 test_resources = [],
568 visibility = visibility,
Thomas Vachuska5b9ff6a2018-07-13 11:00:50 -0700569 suppress_errorprone = suppress_errorprone,
Ray Milkey134d2922018-07-15 15:24:01 -0700570 suppress_checkstyle = suppress_checkstyle,
Thomas Vachuska0f7d7a42018-07-18 15:23:40 -0700571 suppress_javadocs = suppress_javadocs,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700572 version = version,
Ray Milkey12ae6ca2018-06-11 15:34:30 -0700573 import_packages = import_packages,
Ray Milkey275af2c2018-06-15 13:05:08 -0700574 api_title = api_title,
575 api_version = api_version,
576 api_description = api_description,
577 api_package = api_package,
Ray Milkey25747d82018-06-13 14:12:51 -0700578 web_context = web_context,
Jian Li4ad86872018-08-05 03:34:35 +0900579 bundle_classpath = bundle_classpath,
Ray Milkey0bcdfd12018-05-23 14:07:19 -0700580 )