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