Adding Checkstyle daemon

Lazily instaniate a checkstyle daemon for the first checkstyle job.
Then, each subsequent checkstyle target uses the daemon.

The daemon is terminated when the parent buck or buckd exits.

Change-Id: I4dbea957f20a3f77048dd25d960b7faa1eafef37
diff --git a/tools/build/conf/BUCK b/tools/build/conf/BUCK
index 35f9b85..3b9516c 100644
--- a/tools/build/conf/BUCK
+++ b/tools/build/conf/BUCK
@@ -1,22 +1,68 @@
 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)"/>'
-       '</module>' )
-cmd = "sed 's#<module name=\"Checker\">#<module name=\"Checker\">%s#' %s > $OUT" % ( xml, checkstyle_source )
-
-genrule(
+export_file (
   name = 'checkstyle-xml',
-  srcs = [ checkstyle_source ],
-  out = 'checkstyle.xml',
-  bash = cmd,
-  visibility = [ 'PUBLIC' ]
+  src = checkstyle_source,
+  visibility = [ 'PUBLIC' ],
 )
 
-#FIXME location suppression.xml does not trigger this rule
-export_file(
+export_file (
   name = 'suppressions-xml',
   src = suppression_source,
-  visibility = [ 'PUBLIC' ]
+  visibility = [ 'PUBLIC' ],
 )
+
+export_file (
+  name = 'start-checkstyle',
+  visibility = [ 'PUBLIC' ],
+)
+
+COMPILE = [
+  '//lib:guava',
+  '//lib:checkstyle',
+]
+
+RUN = [
+  '//lib:commons-logging',
+  '//lib:commons-beanutils',
+  '//lib:commons-lang3',
+  '//lib:commons-collections',
+  '//lib:antlr',
+]
+
+java_library (
+  name = 'checkstyle',
+  srcs = glob([ 'src/main/java/**/*.java' ]),
+  deps = COMPILE,
+)
+
+java_binary (
+  name = 'checkstyle-jar',
+  deps = [ ':checkstyle' ] + RUN,
+  main_class = 'org.onosproject.checkstyle.Main',
+  blacklist = [ 'META-INF/.*' ],
+  visibility = [ 'PUBLIC' ],
+)
+
+# cmd = '#!/bin/bash\n'
+# cmd += '$1 &>/dev/null < /dev/null &'
+#
+# genrule(
+#   name = 'checkstyle-sh',
+#   bash = "echo '%s' > $OUT && chmod +x $OUT" % cmd,
+#   out = 'checkstyle.sh',
+# )
+#
+# sh_test(
+#   name = 'checkstyle-runner',
+#   test = ':checkstyle-sh',
+#   args = [
+#   '$(exe :checkstyle-jar)',
+#   '$(location //lib:checkstyle)',
+#   '$(location //tools/build/conf:checkstyle-xml)',
+#   '`mktemp /tmp/%s-checkstyle-XXXXXX`',
+#   ],
+#   labels = [ 'checkstyle' ],
+#   visibility = [ 'PUBLIC' ],
+# )
\ No newline at end of file