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 | |
| 7 | def osgi_jar( |
| 8 | name, |
| 9 | srcs, |
| 10 | group_id = 'org.onosproject', |
| 11 | version = '1.6.0-SNAPSHOT', |
| 12 | deps = [], |
| 13 | visibility = ['PUBLIC'], |
| 14 | license = 'NONE', |
| 15 | description = '', |
| 16 | debug = False, |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame^] | 17 | import_packages = '*', |
| 18 | export_packages = '*', |
| 19 | include_resources = NONE, |
| 20 | web_context = NONE, |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 21 | **kwargs |
| 22 | ): |
| 23 | |
| 24 | bare_jar_name = name + '-jar' |
| 25 | osgi_jar_name = name + '-osgi' |
| 26 | mvn_coords = group_id + ':' + name + ':' + version |
| 27 | |
| 28 | java_library( |
| 29 | name = bare_jar_name, |
| 30 | srcs = srcs, |
| 31 | deps = deps, |
Ray Milkey | 7c25182 | 2016-04-06 17:38:25 -0700 | [diff] [blame] | 32 | visibility = ['PUBLIC'], |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 33 | **kwargs |
| 34 | ) |
| 35 | |
| 36 | cp = ':'.join(['$(classpath %s)' % c for c in deps]) |
| 37 | |
| 38 | args = ( '$(location :%s)' % bare_jar_name, #input jar |
| 39 | '$OUT', #output jar |
| 40 | cp, #classpath |
| 41 | name, #bundle name |
| 42 | group_id, #group id |
| 43 | version, #version |
| 44 | license, #license url |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame^] | 45 | "'%s'" % import_packages, #packages to import |
| 46 | "'%s'" % export_packages, #packages to export |
| 47 | include_resources, #custom includes to classpath |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 48 | web_context, #web context (REST API only) |
| 49 | description, #description |
| 50 | ) |
| 51 | |
| 52 | #TODO stage_jar is a horrendous hack |
| 53 | stage_jar = 'pushd $SRCDIR; mkdir bin; cd bin; jar xf $(location :%s); ls; popd; ' % bare_jar_name |
| 54 | wrap_jar = '$(exe //utils/osgiwrap:osgi-jar) ' + ' '.join(args) |
| 55 | bash = stage_jar + wrap_jar |
| 56 | if debug: |
| 57 | bash = stage_jar + DEBUG_ARG + ' ' + wrap_jar |
| 58 | print bash |
| 59 | # TODO this is a hack to add checkstyle as dependency before generating jar |
| 60 | bash = 'ls $(location :' + name + '-checkstyle) > /dev/null; ' + bash |
| 61 | |
| 62 | genrule( |
| 63 | name = osgi_jar_name, |
| 64 | bash = bash, |
| 65 | out = name + '.jar', |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame^] | 66 | srcs = glob(['src/main/webapp/**']), |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 67 | visibility = [], #intentially, not visible |
| 68 | ) |
| 69 | |
| 70 | # TODO we really should shade the jar with maven flavor |
| 71 | prebuilt_jar( |
| 72 | name = name, |
| 73 | maven_coords = mvn_coords, |
| 74 | binary_jar = ':' + osgi_jar_name, |
| 75 | visibility = visibility, |
| 76 | ) |
| 77 | |
| 78 | |
| 79 | |
| 80 | ### Checkstyle |
| 81 | chk_cmd = ' '.join(( 'java -jar $(location //lib:checkstyle)', |
| 82 | '-o $OUT', |
| 83 | '-c $(location //tools/build/conf:checkstyle-xml)', |
| 84 | ' '.join(srcs) )) |
| 85 | error_cmd = '(touch $OUT; cat $OUT | grep "^\[ERROR\]"; exit 1)' |
| 86 | cmd = ' || '.join((chk_cmd, error_cmd)) |
| 87 | genrule( |
| 88 | name = name + '-checkstyle', |
| 89 | bash = cmd, |
| 90 | srcs = srcs, |
| 91 | out = 'checkstyle.log', |
| 92 | ) |
| 93 | |
| 94 | ### .m2 Install |
Brian O'Connor | b86c920 | 2016-04-05 20:15:04 -0700 | [diff] [blame] | 95 | mvn_cmd = ' '.join(( 'mvn install:install-file', |
| 96 | '-Dfile=$(location :%s)' % name, |
| 97 | '-DgroupId=%s' % group_id, |
| 98 | '-DartifactId=%s' % name, |
| 99 | '-Dversion=%s' % version, |
| 100 | '-Dpackaging=jar' )) |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame^] | 101 | cmd = mvn_cmd + ' > $OUT' |
| 102 | if FORCE_INSTALL: |
| 103 | # Add a random number to the command to force this rule to run. |
| 104 | # TODO We should make this configurable from CLI, perhaps with a flag. |
| 105 | cmd = 'FOO=%s ' % random.random() + cmd |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 106 | genrule( |
| 107 | name = name + '-install', |
Brian O'Connor | b86c920 | 2016-04-05 20:15:04 -0700 | [diff] [blame] | 108 | bash = cmd, |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 109 | out = 'install.log', |
| 110 | visibility = visibility, |
| 111 | ) |
| 112 | |
| 113 | def onos_app( |
| 114 | name, |
| 115 | **kwargs): |
| 116 | |
| 117 | osgi_jar( |
| 118 | name = name, |
| 119 | **kwargs |
| 120 | ) |
| 121 | |