blob: 07b46c6b9b6923ba243fcc2b9bd394d660a912f0 [file] [log] [blame]
#!/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
'''