Permalink
Browse files

Adding sonar properties generation script

Change-Id: Ibdf39fce77775ffcf5e849f3fa7b128a5308f9fe
  • Loading branch information...
1 parent 5fdf5bf commit 8c7b12814d77730ee8cf34514c62d00f8ea191b9 @bocon13 bocon13 committed with tomikazi Nov 6, 2016
Showing with 60 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +59 −0 tools/build/onos-sonar-properties
View
@@ -26,3 +26,4 @@ web/gui/src/test/_karma/node_modules
web/gui/src/main/webapp/node_modules/
npm-debug.log
+sonar-project.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
+ '''

0 comments on commit 8c7b128

Please sign in to comment.