20
20
import json
21
21
import logging
22
22
import pathlib
23
- from dataclasses import dataclass
24
23
import shlex
25
- from subprocess import Popen , PIPE
24
+ from dataclasses import dataclass
25
+ from subprocess import PIPE , Popen
26
26
from threading import Thread
27
27
from typing import IO , Any , Callable , Optional
28
28
29
29
from pysonar_scanner .api import EngineInfo , SonarQubeApi
30
30
from 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
+ )
32
35
from pysonar_scanner .exceptions import ChecksumException
33
36
from pysonar_scanner .jre import JREResolvedPath
34
37
@@ -97,7 +100,9 @@ def __log_output(self, stream: IO[bytes]):
97
100
log_line = parse_log_line (decoded_line )
98
101
self .log_line_listener (log_line )
99
102
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 :
101
106
output_thread .start ()
102
107
error_thread .start ()
103
108
process .wait ()
@@ -117,7 +122,9 @@ def provision(self) -> pathlib.Path:
117
122
if scanner_file is not None :
118
123
return scanner_file .filepath
119
124
# 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
+ )
121
128
scanner_file = self .__download_and_verify ()
122
129
if scanner_file is not None :
123
130
return scanner_file .filepath
@@ -132,7 +139,9 @@ def __download_and_verify(self) -> Optional[CacheFile]:
132
139
self .__download_scanner_engine (cache_file , engine_info )
133
140
return cache_file if cache_file .is_valid () else None
134
141
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 :
136
145
with cache_file .open (mode = "wb" ) as f :
137
146
if engine_info .download_url is not None :
138
147
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)
148
157
def run (self , config : dict [str , Any ]):
149
158
# Extract Java options if present; they must influence the JVM invocation, not the scanner engine itself
150
159
java_opts = config .get (SONAR_SCANNER_JAVA_OPTS )
160
+ java_opts = config .get (SONAR_SCANNER_OPTS ) if not java_opts else java_opts
151
161
152
162
cmd = self .__build_command (self .jre_path , self .scanner_engine_path , java_opts )
153
163
logging .debug (f"Command: { cmd } " )
@@ -173,7 +183,11 @@ def __build_command(
173
183
174
184
def __config_to_json (self , config : dict [str , Any ]) -> str :
175
185
# 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
+ ]
177
191
return json .dumps ({"scannerProperties" : scanner_properties })
178
192
179
193
def __decompose_java_opts (self , java_opts : str ) -> list [str ]:
0 commit comments