Brian O'Connor | b86c920 | 2016-04-05 20:15:04 -0700 | [diff] [blame] | 1 | import random |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 2 | |
| 3 | DEBUG_ARG='JAVA_TOOL_OPTIONS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=y"' |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame] | 4 | FORCE_INSTALL=True |
| 5 | NONE='NONE' |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 6 | |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 7 | SRC = 'src/main/java/**/' |
| 8 | TEST = 'src/test/java/**/' |
Brian O'Connor | 0f6677d | 2016-04-06 23:26:51 -0700 | [diff] [blame] | 9 | RESOURCES_ROOT = 'src/main/resources/' |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 10 | TEST_RESOURCES_ROOT = 'src/test/resources/' |
| 11 | |
Ray Milkey | 171b89a | 2016-07-28 15:22:26 -0700 | [diff] [blame] | 12 | include_defs('//onos.defs') |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 13 | |
| 14 | def _get_name(): |
| 15 | base_path = get_base_path() |
| 16 | return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | 40a3fbd | 2016-06-08 13:54:46 -0700 | [diff] [blame] | 18 | def checkstyle( |
| 19 | name, |
| 20 | srcs = None, |
| 21 | jar_target = None, |
| 22 | ): |
| 23 | |
| 24 | if srcs and jar_target: |
| 25 | base = get_base_path() |
| 26 | files = '%s\n%s\n' % (name, base) + '\n'.join(['%s/%s' % (base, s) for s in srcs]) |
| 27 | |
| 28 | genrule( |
| 29 | name = name + '-checkstyle-files', |
| 30 | bash = "echo '%s' > $OUT" % files, |
| 31 | srcs = srcs, |
| 32 | out = 'checkstyle-files.txt', |
| 33 | ) |
| 34 | |
| 35 | sh_test( |
| 36 | name = name + '-checkstyle', |
Thomas Vachuska | 275d2e8 | 2016-07-14 17:41:34 -0700 | [diff] [blame] | 37 | test = '//tools/build/conf:start-buck-daemon', |
Brian O'Connor | 40a3fbd | 2016-06-08 13:54:46 -0700 | [diff] [blame] | 38 | deps = [ jar_target ], |
| 39 | args = [ |
Thomas Vachuska | 275d2e8 | 2016-07-14 17:41:34 -0700 | [diff] [blame] | 40 | '$(location //tools/build/conf:buck-daemon-jar)', |
| 41 | 'checkstyle', |
Brian O'Connor | 40a3fbd | 2016-06-08 13:54:46 -0700 | [diff] [blame] | 42 | '$(location :' + name + '-checkstyle-files)', |
| 43 | '$(location //tools/build/conf:checkstyle-xml)', |
| 44 | '$(location //tools/build/conf:suppressions-xml)', |
| 45 | ], |
| 46 | test_rule_timeout_ms = 20000, |
| 47 | labels = [ 'checkstyle' ], |
| 48 | ) |
Brian O'Connor | 40a3fbd | 2016-06-08 13:54:46 -0700 | [diff] [blame] | 49 | |
Ray Milkey | c340e28 | 2016-06-30 14:45:42 -0700 | [diff] [blame] | 50 | def java_doc( |
| 51 | name, |
| 52 | title, |
| 53 | pkgs, |
| 54 | paths, |
| 55 | srcs = [], |
| 56 | deps = [], |
| 57 | visibility = [], |
| 58 | do_it_wrong = False, |
| 59 | ): |
| 60 | if do_it_wrong: |
| 61 | sourcepath = paths |
| 62 | else: |
| 63 | sourcepath = ['$SRCDIR/' + n for n in paths] |
Ray Milkey | 2a74983 | 2016-08-02 15:22:20 -0700 | [diff] [blame] | 64 | |
| 65 | if len(srcs) != 0: |
Ray Milkey | c340e28 | 2016-06-30 14:45:42 -0700 | [diff] [blame] | 66 | cmd = ' '.join([ |
Ray Milkey | 2a74983 | 2016-08-02 15:22:20 -0700 | [diff] [blame] | 67 | 'while ! test -f .buckconfig; do cd ..; done;', |
| 68 | 'javadoc', |
| 69 | '-tag onos.rsModel:a:"onos model"', |
| 70 | '-quiet', |
| 71 | '-protected', |
| 72 | '-encoding UTF-8', |
| 73 | '-charset UTF-8', |
| 74 | '-notimestamp', |
| 75 | '-windowtitle "' + title + '"', |
| 76 | '-link http://docs.oracle.com/javase/8/docs/api', |
| 77 | '-subpackages ', |
| 78 | ':'.join(pkgs), |
| 79 | '-sourcepath ', |
| 80 | ':'.join(sourcepath), |
| 81 | ' -classpath ', |
| 82 | ':'.join(['$(classpath %s)' % n for n in deps]), |
| 83 | '-d $TMP', |
| 84 | ]) + ';jar cf $OUT -C $TMP .' |
| 85 | |
| 86 | genrule( |
| 87 | name = name, |
| 88 | cmd = cmd, |
| 89 | srcs = srcs, |
| 90 | out = name + '.jar', |
| 91 | visibility = visibility, |
Ray Milkey | c340e28 | 2016-06-30 14:45:42 -0700 | [diff] [blame] | 92 | ) |
| 93 | |
| 94 | |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 95 | def osgi_jar( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 96 | name = None, |
| 97 | srcs = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 98 | group_id = ONOS_GROUP_ID, |
| 99 | version = ONOS_VERSION, |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 100 | deps = [], |
| 101 | visibility = ['PUBLIC'], |
| 102 | license = 'NONE', |
| 103 | description = '', |
| 104 | debug = False, |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame] | 105 | import_packages = '*', |
Yuta HIGUCHI | f05db40 | 2016-08-12 18:36:33 -0700 | [diff] [blame] | 106 | dynamicimport_packages = '', |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame] | 107 | export_packages = '*', |
Ray Milkey | 2a74983 | 2016-08-02 15:22:20 -0700 | [diff] [blame] | 108 | package_name_root = 'org.onosproject', |
Brian O'Connor | 79b7067 | 2016-10-20 13:44:52 -0700 | [diff] [blame] | 109 | include_resources = {}, |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame] | 110 | web_context = NONE, |
Brian O'Connor | 79b7067 | 2016-10-20 13:44:52 -0700 | [diff] [blame] | 111 | api_title = None, |
Brian O'Connor | e8468b5 | 2016-07-25 13:42:36 -0700 | [diff] [blame] | 112 | api_version = NONE, |
| 113 | api_package = NONE, |
| 114 | api_description = NONE, |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 115 | resources = NONE, |
Brian O'Connor | 0f6677d | 2016-04-06 23:26:51 -0700 | [diff] [blame] | 116 | resources_root = None, |
Brian O'Connor | ee67495 | 2016-09-13 16:31:45 -0700 | [diff] [blame] | 117 | tests = None, |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 118 | **kwargs |
| 119 | ): |
| 120 | |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 121 | # if name and _get_name() != name: |
| 122 | # print _get_name(), '!=', name |
| 123 | if name is None: |
| 124 | name = _get_name() |
| 125 | |
| 126 | if srcs is None: |
| 127 | srcs = glob([SRC + '/*.java']) |
| 128 | |
| 129 | if resources == NONE and resources_root is not None: |
| 130 | resources = glob([resources_root + '**']) |
| 131 | elif resources == NONE: |
| 132 | resources = glob([RESOURCES_ROOT + '**']) |
| 133 | |
| 134 | if resources and not resources_root: |
| 135 | resources_root = RESOURCES_ROOT |
| 136 | |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 137 | mvn_coords = group_id + ':' + name + ':' + version |
| 138 | |
Brian O'Connor | e8468b5 | 2016-07-25 13:42:36 -0700 | [diff] [blame] | 139 | onos_jar( |
Brian O'Connor | ee67495 | 2016-09-13 16:31:45 -0700 | [diff] [blame] | 140 | name = name, |
| 141 | srcs = srcs + glob(['src/main/webapp/**']), |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 142 | deps = deps, |
Brian O'Connor | ee67495 | 2016-09-13 16:31:45 -0700 | [diff] [blame] | 143 | visibility = visibility, |
Brian O'Connor | 0f6677d | 2016-04-06 23:26:51 -0700 | [diff] [blame] | 144 | resources = resources, |
| 145 | resources_root = resources_root, |
Brian O'Connor | ee67495 | 2016-09-13 16:31:45 -0700 | [diff] [blame] | 146 | bundle_name = name, |
| 147 | group_id = group_id, |
| 148 | bundle_version = version, |
| 149 | bundle_license = license, |
| 150 | bundle_description = description, |
| 151 | import_packages = import_packages, |
| 152 | export_packages = export_packages, |
| 153 | include_resources = include_resources, |
| 154 | dynamicimport_packages = dynamicimport_packages, |
Brian O'Connor | e8468b5 | 2016-07-25 13:42:36 -0700 | [diff] [blame] | 155 | web_context = web_context, |
| 156 | api_title = api_title, |
| 157 | api_version = api_version, |
| 158 | api_package = api_package, |
| 159 | api_description = api_description, |
Brian O'Connor | ee67495 | 2016-09-13 16:31:45 -0700 | [diff] [blame] | 160 | tests = tests, |
| 161 | maven_coords = mvn_coords, |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 162 | **kwargs |
| 163 | ) |
| 164 | |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 165 | ### Checkstyle |
Brian O'Connor | 40a3fbd | 2016-06-08 13:54:46 -0700 | [diff] [blame] | 166 | checkstyle( |
Brian O'Connor | be95f68 | 2016-05-18 15:40:19 -0700 | [diff] [blame] | 167 | name = name + '-checkstyle-files', |
Brian O'Connor | 4847ea3 | 2016-04-29 16:33:06 -0700 | [diff] [blame] | 168 | srcs = srcs, |
Brian O'Connor | ee67495 | 2016-09-13 16:31:45 -0700 | [diff] [blame] | 169 | jar_target = ':'+ name, |
Brian O'Connor | 40a3fbd | 2016-06-08 13:54:46 -0700 | [diff] [blame] | 170 | ) |
Brian O'Connor | b3cc604 | 2016-04-25 11:55:51 -0700 | [diff] [blame] | 171 | |
Ray Milkey | c340e28 | 2016-06-30 14:45:42 -0700 | [diff] [blame] | 172 | java_doc( |
| 173 | name = name + '-javadoc', |
| 174 | title = 'Java Docs', |
Ray Milkey | 2a74983 | 2016-08-02 15:22:20 -0700 | [diff] [blame] | 175 | pkgs = [ package_name_root ], |
Ray Milkey | c340e28 | 2016-06-30 14:45:42 -0700 | [diff] [blame] | 176 | paths = [ 'src/main/java' ], |
| 177 | srcs = srcs, |
| 178 | deps = deps, |
| 179 | visibility = visibility, |
| 180 | do_it_wrong = False, |
| 181 | ) |
| 182 | |
Brian O'Connor | b3cc604 | 2016-04-25 11:55:51 -0700 | [diff] [blame] | 183 | # TODO add project config for intellij |
| 184 | # project_config( |
Brian O'Connor | ee67495 | 2016-09-13 16:31:45 -0700 | [diff] [blame] | 185 | # src_target = ':' + name, |
Brian O'Connor | b3cc604 | 2016-04-25 11:55:51 -0700 | [diff] [blame] | 186 | # src_roots = [ 'src/main/java' ], |
| 187 | # test_target = ':' + name + '-tests', |
| 188 | # test_roots = [ 'src/test/java' ], |
| 189 | # ) |
| 190 | |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 191 | ### .m2 Install |
Brian O'Connor | b86c920 | 2016-04-05 20:15:04 -0700 | [diff] [blame] | 192 | mvn_cmd = ' '.join(( 'mvn install:install-file', |
| 193 | '-Dfile=$(location :%s)' % name, |
| 194 | '-DgroupId=%s' % group_id, |
| 195 | '-DartifactId=%s' % name, |
| 196 | '-Dversion=%s' % version, |
| 197 | '-Dpackaging=jar' )) |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame] | 198 | cmd = mvn_cmd + ' > $OUT' |
| 199 | if FORCE_INSTALL: |
| 200 | # Add a random number to the command to force this rule to run. |
| 201 | # TODO We should make this configurable from CLI, perhaps with a flag. |
| 202 | cmd = 'FOO=%s ' % random.random() + cmd |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 203 | genrule( |
| 204 | name = name + '-install', |
Brian O'Connor | b86c920 | 2016-04-05 20:15:04 -0700 | [diff] [blame] | 205 | bash = cmd, |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 206 | out = 'install.log', |
| 207 | visibility = visibility, |
| 208 | ) |
| 209 | |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 210 | def osgi_jar_with_tests( |
| 211 | name = None, |
| 212 | deps = [], |
Brian O'Connor | ee67495 | 2016-09-13 16:31:45 -0700 | [diff] [blame] | 213 | group_id = ONOS_GROUP_ID, |
| 214 | version = ONOS_VERSION, |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 215 | test_srcs = None, |
| 216 | test_deps = [ '//lib:TEST' ], |
| 217 | test_resources = None, |
| 218 | test_resources_root = None, |
| 219 | visibility = [ 'PUBLIC' ], |
| 220 | **kwargs |
| 221 | ): |
| 222 | |
| 223 | if name is None: |
| 224 | name = _get_name() |
| 225 | |
| 226 | osgi_jar(name = name, |
| 227 | deps = deps, |
Brian O'Connor | ee67495 | 2016-09-13 16:31:45 -0700 | [diff] [blame] | 228 | group_id = group_id, |
| 229 | version = version, |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 230 | visibility = visibility, |
Brian O'Connor | ee67495 | 2016-09-13 16:31:45 -0700 | [diff] [blame] | 231 | tests = [':' + name + '-tests'], |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 232 | **kwargs) |
Brian O'Connor | 0f6677d | 2016-04-06 23:26:51 -0700 | [diff] [blame] | 233 | |
| 234 | if test_resources and not test_resources_root: |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 235 | test_resources_root = TEST_RESOURCES_ROOT |
| 236 | if test_resources_root and not test_resources: |
| 237 | test_resources = glob([test_resources_root + '**']) |
| 238 | if not test_resources and not test_resources_root: |
| 239 | test_resources = glob([TEST_RESOURCES_ROOT + '**']) |
| 240 | if test_resources: |
| 241 | test_resources_root = TEST_RESOURCES_ROOT |
Brian O'Connor | 0f6677d | 2016-04-06 23:26:51 -0700 | [diff] [blame] | 242 | |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 243 | if test_srcs is None: |
| 244 | test_srcs = glob([TEST + '/*.java']) |
| 245 | |
Brian O'Connor | ee67495 | 2016-09-13 16:31:45 -0700 | [diff] [blame] | 246 | mvn_coords = group_id + ':' + name + ':jar:tests:' + version |
| 247 | |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 248 | java_test( |
| 249 | name = name + '-tests', |
| 250 | srcs = test_srcs, |
| 251 | deps = deps + |
| 252 | test_deps + |
Brian O'Connor | ee67495 | 2016-09-13 16:31:45 -0700 | [diff] [blame] | 253 | [':' + name + '#non-osgi'], |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 254 | resources = test_resources, |
| 255 | resources_root = test_resources_root, |
Brian O'Connor | ee67495 | 2016-09-13 16:31:45 -0700 | [diff] [blame] | 256 | maven_coords = mvn_coords, |
| 257 | visibility = visibility, |
Brian O'Connor | be95f68 | 2016-05-18 15:40:19 -0700 | [diff] [blame] | 258 | ) |
| 259 | |
Brian O'Connor | 40a3fbd | 2016-06-08 13:54:46 -0700 | [diff] [blame] | 260 | checkstyle( |
| 261 | name = name + '-tests', |
| 262 | srcs = test_srcs, |
| 263 | jar_target = ':' + name + '-tests', |
| 264 | ) |