Skip to content

Commit

Permalink
fixed issue by introducing sonar project key in BuildConfig and setti…
Browse files Browse the repository at this point in the history
…ng based on args (#54)

Co-authored-by: Naresh Nagarajan <[email protected]>
  • Loading branch information
nareshgnT and Naresh Nagarajan authored Aug 24, 2020
1 parent 413a615 commit a29dc64
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 6 additions & 1 deletion flow/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,11 @@ def main():
attachment_color=attachment_color, slack_url=slack_url)
metrics.write_metric(task, args.action)
elif task == 'sonar':
if 'sonar_project_key' in args and args.sonar_project_key is not None:
BuildConfig.sonar_project_key = args.sonar_project_key
else:
BuildConfig.sonar_project_key = BuildConfig.project_name
sonar = SonarQube()

sonar.scan_code()
metrics.write_metric(task, args.action)
elif task == 'artifactory':
Expand Down Expand Up @@ -344,6 +347,8 @@ def load_task_parsers(subparsers):
sonar_parser.add_argument('-v', '--version', help='(optional) If manually versioning, this is passed in by the '
'user. Note: versionStrategy in buildConfig should be set to '
'"manual"')
sonar_parser.add_argument('-pk', '--sonar-project-key', help='(optional) If passed then this value is used for sonar.projectKey and sonar.projectName '
'otherwise buildConfig projectInfo.name is used.')

cfdeploy_parser = subparsers.add_parser("cf", help="Cloud Foundry Deploy task",
formatter_class=RawTextHelpFormatter)
Expand Down
1 change: 1 addition & 0 deletions flow/buildconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class BuildConfig:
artifact_extension = None
artifact_extensions = None
push_location = 'fordeployment'
sonar_project_key = None

def __init__(self, args):
method = '__init__'
Expand Down
8 changes: 4 additions & 4 deletions flow/staticqualityanalysis/sonar/sonarmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ def _submit_scan(self):
custom_sonar_file = self.config.json_config['sonar']['propertiesFile']

if sonar_user is not None and sonar_pwd is not None:
sonar_cmd = 'java -Dsonar.projectKey="' + self.config.project_name + '" -Dsonar.projectName="' + self.config.project_name + '" -Dsonar.projectVersion="' + self.config.version_number + '" -Dsonar.login=$SONAR_USER -Dsonar.password=$SONAR_PWD -Dproject.settings="' + custom_sonar_file + '" -Dproject.home="$PWD" -jar $SONAR_HOME/' + sonar_runner_executable + ' -e -X'
sonar_cmd = 'java -Dsonar.projectKey="' + self.config.sonar_project_key + '" -Dsonar.projectName="' + self.config.sonar_project_key + '" -Dsonar.projectVersion="' + self.config.version_number + '" -Dsonar.login=$SONAR_USER -Dsonar.password=$SONAR_PWD -Dproject.settings="' + custom_sonar_file + '" -Dproject.home="$PWD" -jar $SONAR_HOME/' + sonar_runner_executable + ' -e -X'
else:
sonar_cmd = 'java -Dsonar.projectKey="' + self.config.project_name + '" -Dsonar.projectName="' + self.config.project_name + '" -Dsonar.projectVersion="' + self.config.version_number + '" -Dproject.settings="' + custom_sonar_file + '" -Dproject.home="$PWD" -jar $SONAR_HOME/' + sonar_runner_executable + ' -e -X'
sonar_cmd = 'java -Dsonar.projectKey="' + self.config.sonar_project_key + '" -Dsonar.projectName="' + self.config.sonar_project_key + '" -Dsonar.projectVersion="' + self.config.version_number + '" -Dproject.settings="' + custom_sonar_file + '" -Dproject.home="$PWD" -jar $SONAR_HOME/' + sonar_runner_executable + ' -e -X'
commons.print_msg(SonarQube.clazz, method, sonar_cmd)
else:
if sonar_user is not None and sonar_pwd is not None:
sonar_cmd = 'java -Dsonar.projectKey="' + self.config.project_name + '" -Dsonar.projectName="' + self.config.project_name + '" -Dsonar.projectVersion="' + self.config.version_number + '" -Dsonar.login=$SONAR_USER -Dsonar.password=$SONAR_PWD -Dproject.home="$PWD" -jar $SONAR_HOME/' + sonar_runner_executable + ' -e -X'
sonar_cmd = 'java -Dsonar.projectKey="' + self.config.sonar_project_key + '" -Dsonar.projectName="' + self.config.sonar_project_key + '" -Dsonar.projectVersion="' + self.config.version_number + '" -Dsonar.login=$SONAR_USER -Dsonar.password=$SONAR_PWD -Dproject.home="$PWD" -jar $SONAR_HOME/' + sonar_runner_executable + ' -e -X'
else:
sonar_cmd = 'java -Dsonar.projectKey="' + self.config.project_name + '" -Dsonar.projectName="' + self.config.project_name + '" -Dsonar.projectVersion="' + self.config.version_number + '" -Dproject.home="$PWD" -jar $SONAR_HOME/' + sonar_runner_executable + ' -e -X'
sonar_cmd = 'java -Dsonar.projectKey="' + self.config.sonar_project_key + '" -Dsonar.projectName="' + self.config.sonar_project_key + '" -Dsonar.projectVersion="' + self.config.version_number + '" -Dproject.home="$PWD" -jar $SONAR_HOME/' + sonar_runner_executable + ' -e -X'
commons.print_msg(SonarQube.clazz, method, sonar_cmd)

p = subprocess.Popen(sonar_cmd.split(), shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Expand Down

0 comments on commit a29dc64

Please sign in to comment.