Adding sonar properties generation script
Change-Id: Ibdf39fce77775ffcf5e849f3fa7b128a5308f9fe
diff --git a/.gitignore b/.gitignore
index e109650..c5329f4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,3 +26,4 @@
web/gui/src/main/webapp/node_modules/
npm-debug.log
+sonar-project.properties
diff --git a/tools/build/onos-sonar-properties b/tools/build/onos-sonar-properties
new file mode 100755
index 0000000..07b46c6
--- /dev/null
+++ b/tools/build/onos-sonar-properties
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+#
+# This script generates the Sonar project properties file from the Buck rules
+# To run sonar, run 'sonar-scanner' from $ONOS_ROOT
+#
+
+import os
+from subprocess import call, check_call, check_output
+
+# SonarQube property file name and template
+FILE_NAME = 'sonar-project.properties'
+ROOT_TEMPLATE = '''# Auto-generated properties file
+sonar.projectKey=%(key)s
+sonar.projectName=%(name)s
+sonar.projectVersion=%(version)s
+
+sonar.sources=src
+sonar.sourceEncoding=UTF-8
+sonar.language=java
+
+sonar.modules=%(modules)s
+
+'''
+
+# Change to $ONOS_ROOT
+ONOS_ROOT = os.environ[ 'ONOS_ROOT' ]
+if ONOS_ROOT:
+ os.chdir( ONOS_ROOT )
+
+# Final all onos_jar rules
+cmd = ['onos-buck', 'query', "kind('onos_jar', deps(//tools/package:onos-package))"]
+output = check_output( cmd )
+
+modules = {}
+for line in output.rstrip().split('\n'):
+ # Parse rule into path and name
+ path, name = line.split(':', 2)
+ path = path.replace('//', '', 1)
+ if path not in modules:
+ modules[path] = name
+ else:
+ print "Skipping %s" % line
+
+# Write the sonar properties file
+# FIXME pull the version from the Buck version file
+with open(FILE_NAME, 'w') as f:
+ f.write(ROOT_TEMPLATE % {
+ 'name': 'onos',
+ 'key': 'org.onosproject:onos',
+ 'version': '1.8.0-SNAPSHOT',
+ 'modules': ','.join( modules.values() )
+ })
+ for path, name in modules.iteritems():
+ f.write('%s.sonar.projectBaseDir=%s\n' % ( name, path ))
+ ''' Extra options
+ module2.sonar.projectBaseDir=Module 2
+ module2.sonar.sources=sources
+ module2.sonar.projectName=Module #2
+ '''