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