Brian O'Connor

Updating checkstyle rule in onos.bucklet

Change-Id: I16422bf02b55572d82d9463cb87c678545b79793
......@@ -68,7 +68,7 @@ def osgi_jar(
**kwargs
)
cp = ':'.join(['$(classpath %s)' % c for c in deps])
cp = ':'.join(['$(classpath %s)' % c for c in deps]) if deps else '""'
args = ( '$(location :%s)' % bare_jar_name, #input jar
'$OUT', #output jar
......@@ -110,29 +110,32 @@ def osgi_jar(
### Checkstyle
if srcs:
chk_cmd = '#!/bin/sh\n'
base = get_base_path()
chk_cmd += ' '.join(( 'java -jar $(location //lib:checkstyle)',
'-c $(location //tools/build/conf:checkstyle-xml)',
' '.join(['%s/%s' % (base, s) for s in srcs]) ))
chk_cmd += ' | grep -E "^[^: ]*:\d+:\d+: error:"'
chk_cmd += ' | sed "s#^.*%s/#%s:#g"\n' % (base, name)
chk_cmd += 'test ${PIPESTATUS[0]} -eq 0\n' # status of java command
genrule(
name = name + '-checkstyle-sh',
bash = "echo '%s' > $OUT && chmod +x $OUT" % chk_cmd,
srcs = srcs,
out = 'checkstyle.sh',
)
sh_test(
name = name + '-checkstyle',
test = ':' + name + '-checkstyle-sh',
deps = [ ':'+ bare_jar_name ],
labels = [ 'checkstyle' ],
)
chk_cmd = '#!/bin/sh\n'
# FIXME hack to add dependency on suppressions-xml in the checkstyle rule
chk_cmd += 'FOO="$(location //tools/build/conf:suppressions-xml)"\n'
base = get_base_path()
chk_cmd += ' '.join(( 'java -jar $(location //lib:checkstyle)',
'-c $(location //tools/build/conf:checkstyle-xml)',
' '.join(['%s/%s' % (base, s) for s in srcs]) ))
chk_cmd += ' | grep -E "^[^: ]*:\d+:\d+: error:"'
chk_cmd += ' | sed "s#^.*%s/#%s:#g"\n' % (base, name)
chk_cmd += 'test ${PIPESTATUS[0]} -eq 0\n' # status of java command
genrule(
name = name + '-checkstyle-sh',
bash = "echo '%s' > $OUT && chmod +x $OUT" % chk_cmd,
srcs = srcs,
out = 'checkstyle.sh',
)
sh_test(
name = name + '-checkstyle',
test = ':' + name + '-checkstyle-sh',
deps = [ ':'+ bare_jar_name ],
labels = [ 'checkstyle' ],
)
else:
print 'Not generating checkstyle rule for %s because there are no sources.' % name
print 'Not generating checkstyle rule for %s because there are no sources.' % name
# TODO add project config for intellij
# project_config(
......
......@@ -2,7 +2,7 @@ checkstyle_source = 'src/main/resources/onos/checkstyle.xml'
suppression_source = 'src/main/resources/onos/suppressions.xml'
xml = ('<module name="SuppressionFilter">'
'<property name="file" value="$(location :suppressions.xml)"/>'
'<property name="file" value="$(location :suppressions-xml)"/>'
'</module>' )
cmd = "sed 's#<module name=\"Checker\">#<module name=\"Checker\">%s#' %s > $OUT" % ( xml, checkstyle_source )
......@@ -16,6 +16,7 @@ genrule(
#FIXME location suppression.xml does not trigger this rule
export_file(
name = 'suppressions.xml',
name = 'suppressions-xml',
src = suppression_source,
visibility = [ 'PUBLIC' ]
)
......