blob: 07b46c6b9b6923ba243fcc2b9bd394d660a912f0 [file] [log] [blame]
Brian O'Connor8c7b1282016-11-06 06:15:12 -08001#!/usr/bin/env python
2#
3# This script generates the Sonar project properties file from the Buck rules
4# To run sonar, run 'sonar-scanner' from $ONOS_ROOT
5#
6
7import os
8from subprocess import call, check_call, check_output
9
10# SonarQube property file name and template
11FILE_NAME = 'sonar-project.properties'
12ROOT_TEMPLATE = '''# Auto-generated properties file
13sonar.projectKey=%(key)s
14sonar.projectName=%(name)s
15sonar.projectVersion=%(version)s
16
17sonar.sources=src
18sonar.sourceEncoding=UTF-8
19sonar.language=java
20
21sonar.modules=%(modules)s
22
23'''
24
25# Change to $ONOS_ROOT
26ONOS_ROOT = os.environ[ 'ONOS_ROOT' ]
27if ONOS_ROOT:
28 os.chdir( ONOS_ROOT )
29
30# Final all onos_jar rules
31cmd = ['onos-buck', 'query', "kind('onos_jar', deps(//tools/package:onos-package))"]
32output = check_output( cmd )
33
34modules = {}
35for line in output.rstrip().split('\n'):
36 # Parse rule into path and name
37 path, name = line.split(':', 2)
38 path = path.replace('//', '', 1)
39 if path not in modules:
40 modules[path] = name
41 else:
42 print "Skipping %s" % line
43
44# Write the sonar properties file
45# FIXME pull the version from the Buck version file
46with open(FILE_NAME, 'w') as f:
47 f.write(ROOT_TEMPLATE % {
48 'name': 'onos',
49 'key': 'org.onosproject:onos',
50 'version': '1.8.0-SNAPSHOT',
51 'modules': ','.join( modules.values() )
52 })
53 for path, name in modules.iteritems():
54 f.write('%s.sonar.projectBaseDir=%s\n' % ( name, path ))
55 ''' Extra options
56 module2.sonar.projectBaseDir=Module 2
57 module2.sonar.sources=sources
58 module2.sonar.projectName=Module #2
59 '''