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