blob: ba2ed1743c9a131fdaf8ff4bdbac0a41192a6372 [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"'
Brian O'Connore5817c92016-04-06 15:41:48 -07004FORCE_INSTALL=True
5NONE='NONE'
Brian O'Connor42c38cf2016-04-05 17:05:57 -07006
7def 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'Connore5817c92016-04-06 15:41:48 -070017 import_packages = '*',
18 export_packages = '*',
19 include_resources = NONE,
20 web_context = NONE,
Brian O'Connor42c38cf2016-04-05 17:05:57 -070021 **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 Milkey7c251822016-04-06 17:38:25 -070032 visibility = ['PUBLIC'],
Brian O'Connor42c38cf2016-04-05 17:05:57 -070033 **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'Connore5817c92016-04-06 15:41:48 -070045 "'%s'" % import_packages, #packages to import
46 "'%s'" % export_packages, #packages to export
47 include_resources, #custom includes to classpath
Brian O'Connor42c38cf2016-04-05 17:05:57 -070048 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'Connore5817c92016-04-06 15:41:48 -070066 srcs = glob(['src/main/webapp/**']),
Brian O'Connor42c38cf2016-04-05 17:05:57 -070067 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'Connorb86c9202016-04-05 20:15:04 -070095 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'Connore5817c92016-04-06 15:41:48 -0700101 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'Connor42c38cf2016-04-05 17:05:57 -0700106 genrule(
107 name = name + '-install',
Brian O'Connorb86c9202016-04-05 20:15:04 -0700108 bash = cmd,
Brian O'Connor42c38cf2016-04-05 17:05:57 -0700109 out = 'install.log',
110 visibility = visibility,
111 )
112
113def onos_app(
114 name,
115 **kwargs):
116
117 osgi_jar(
118 name = name,
119 **kwargs
120 )
121