2020import json
2121import logging
2222import pathlib
23- from dataclasses import dataclass
2423import shlex
25- from subprocess import Popen , PIPE
24+ from dataclasses import dataclass
25+ from subprocess import PIPE , Popen
2626from threading import Thread
2727from typing import IO , Any , Callable , Optional
2828
2929from pysonar_scanner .api import EngineInfo , SonarQubeApi
3030from pysonar_scanner .cache import Cache , CacheFile
31- from pysonar_scanner .configuration .properties import SONAR_SCANNER_JAVA_OPTS
31+ from pysonar_scanner .configuration .properties import (
32+ SONAR_SCANNER_JAVA_OPTS ,
33+ SONAR_SCANNER_OPTS ,
34+ )
3235from pysonar_scanner .exceptions import ChecksumException
3336from pysonar_scanner .jre import JREResolvedPath
3437
@@ -97,7 +100,9 @@ def __log_output(self, stream: IO[bytes]):
97100 log_line = parse_log_line (decoded_line )
98101 self .log_line_listener (log_line )
99102
100- def __process_output (self , output_thread : Thread , error_thread : Thread , process : Popen ) -> int :
103+ def __process_output (
104+ self , output_thread : Thread , error_thread : Thread , process : Popen
105+ ) -> int :
101106 output_thread .start ()
102107 error_thread .start ()
103108 process .wait ()
@@ -117,7 +122,9 @@ def provision(self) -> pathlib.Path:
117122 if scanner_file is not None :
118123 return scanner_file .filepath
119124 # Retry once in case the checksum failed due to the scanner engine being updated between getting the checksum and downloading the jar
120- logging .warning ("Something went wrong while downloading the scanner engine. Retrying..." )
125+ logging .warning (
126+ "Something went wrong while downloading the scanner engine. Retrying..."
127+ )
121128 scanner_file = self .__download_and_verify ()
122129 if scanner_file is not None :
123130 return scanner_file .filepath
@@ -132,7 +139,9 @@ def __download_and_verify(self) -> Optional[CacheFile]:
132139 self .__download_scanner_engine (cache_file , engine_info )
133140 return cache_file if cache_file .is_valid () else None
134141
135- def __download_scanner_engine (self , cache_file : CacheFile , engine_info : EngineInfo ) -> None :
142+ def __download_scanner_engine (
143+ self , cache_file : CacheFile , engine_info : EngineInfo
144+ ) -> None :
136145 with cache_file .open (mode = "wb" ) as f :
137146 if engine_info .download_url is not None :
138147 self .api .download_file_from_url (engine_info .download_url , f )
@@ -148,6 +157,7 @@ def __init__(self, jre_path: JREResolvedPath, scanner_engine_path: pathlib.Path)
148157 def run (self , config : dict [str , Any ]):
149158 # Extract Java options if present; they must influence the JVM invocation, not the scanner engine itself
150159 java_opts = config .get (SONAR_SCANNER_JAVA_OPTS )
160+ java_opts = config .get (SONAR_SCANNER_OPTS ) if not java_opts else java_opts
151161
152162 cmd = self .__build_command (self .jre_path , self .scanner_engine_path , java_opts )
153163 logging .debug (f"Command: { cmd } " )
@@ -173,7 +183,11 @@ def __build_command(
173183
174184 def __config_to_json (self , config : dict [str , Any ]) -> str :
175185 # SONAR_SCANNER_JAVA_OPTS are properties that shouldn't be passed to the engine, only to the JVM
176- scanner_properties = [{"key" : k , "value" : v } for k , v in config .items () if k != SONAR_SCANNER_JAVA_OPTS ]
186+ scanner_properties = [
187+ {"key" : k , "value" : v }
188+ for k , v in config .items ()
189+ if k != SONAR_SCANNER_JAVA_OPTS and k != SONAR_SCANNER_OPTS
190+ ]
177191 return json .dumps ({"scannerProperties" : scanner_properties })
178192
179193 def __decompose_java_opts (self , java_opts : str ) -> list [str ]:
0 commit comments