blob: ee4b17d31f6fb736bf71b8b8fab5f24396e59c84 [file] [log] [blame]
Brian O'Connorb86c9202016-04-05 20:15:04 -07001import random
Brian O'Connor42c38cf2016-04-05 17:05:57 -07002
3DEBUG_ARG='JAVA_TOOL_OPTIONS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=y"'
4
5def osgi_jar(
6 name,
7 srcs,
8 group_id = 'org.onosproject',
9 version = '1.6.0-SNAPSHOT',
10 deps = [],
11 visibility = ['PUBLIC'],
12 license = 'NONE',
13 description = '',
14 debug = False,
15 web_context = 'NONE',
16 **kwargs
17 ):
18
19 bare_jar_name = name + '-jar'
20 osgi_jar_name = name + '-osgi'
21 mvn_coords = group_id + ':' + name + ':' + version
22
23 java_library(
24 name = bare_jar_name,
25 srcs = srcs,
26 deps = deps,
Ray Milkey7c251822016-04-06 17:38:25 -070027 visibility = ['PUBLIC'],
Brian O'Connor42c38cf2016-04-05 17:05:57 -070028 **kwargs
29 )
30
31 cp = ':'.join(['$(classpath %s)' % c for c in deps])
32
33 args = ( '$(location :%s)' % bare_jar_name, #input jar
34 '$OUT', #output jar
35 cp, #classpath
36 name, #bundle name
37 group_id, #group id
38 version, #version
39 license, #license url
40 web_context, #web context (REST API only)
41 description, #description
42 )
43
44 #TODO stage_jar is a horrendous hack
45 stage_jar = 'pushd $SRCDIR; mkdir bin; cd bin; jar xf $(location :%s); ls; popd; ' % bare_jar_name
46 wrap_jar = '$(exe //utils/osgiwrap:osgi-jar) ' + ' '.join(args)
47 bash = stage_jar + wrap_jar
48 if debug:
49 bash = stage_jar + DEBUG_ARG + ' ' + wrap_jar
50 print bash
51 # TODO this is a hack to add checkstyle as dependency before generating jar
52 bash = 'ls $(location :' + name + '-checkstyle) > /dev/null; ' + bash
53
54 genrule(
55 name = osgi_jar_name,
56 bash = bash,
57 out = name + '.jar',
58 visibility = [], #intentially, not visible
59 )
60
61 # TODO we really should shade the jar with maven flavor
62 prebuilt_jar(
63 name = name,
64 maven_coords = mvn_coords,
65 binary_jar = ':' + osgi_jar_name,
66 visibility = visibility,
67 )
68
69
70
71 ### Checkstyle
72 chk_cmd = ' '.join(( 'java -jar $(location //lib:checkstyle)',
73 '-o $OUT',
74 '-c $(location //tools/build/conf:checkstyle-xml)',
75 ' '.join(srcs) ))
76 error_cmd = '(touch $OUT; cat $OUT | grep "^\[ERROR\]"; exit 1)'
77 cmd = ' || '.join((chk_cmd, error_cmd))
78 genrule(
79 name = name + '-checkstyle',
80 bash = cmd,
81 srcs = srcs,
82 out = 'checkstyle.log',
83 )
84
85 ### .m2 Install
Brian O'Connorb86c9202016-04-05 20:15:04 -070086 mvn_cmd = ' '.join(( 'mvn install:install-file',
87 '-Dfile=$(location :%s)' % name,
88 '-DgroupId=%s' % group_id,
89 '-DartifactId=%s' % name,
90 '-Dversion=%s' % version,
91 '-Dpackaging=jar' ))
92 # TODO This rule must be run every time, adding random number as rule input.
93 # We should make this configurable, perhaps with a flag.
94 cmd = 'FOO=%s ' % random.random() + mvn_cmd + ' > $OUT'
Brian O'Connor42c38cf2016-04-05 17:05:57 -070095 genrule(
96 name = name + '-install',
Brian O'Connorb86c9202016-04-05 20:15:04 -070097 bash = cmd,
Brian O'Connor42c38cf2016-04-05 17:05:57 -070098 out = 'install.log',
99 visibility = visibility,
100 )
101
102def onos_app(
103 name,
104 **kwargs):
105
106 osgi_jar(
107 name = name,
108 **kwargs
109 )
110