Skip to content

Commit 1ac7e0f

Browse files
SCANPY-179 There should be a parameter to configure the heap size (#215)
1 parent f3c29ba commit 1ac7e0f

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

CLI_ARGS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
| `--sonar-scanner-internal-dump-to-file`, `-Dsonar.scanner.internal.dumpToFile` | Filename where the input to the scanner engine will be dumped. Useful for debugging |
7474
| `--sonar-scanner-internal-sq-version`, `-Dsonar.scanner.internal.sqVersion` | Emulate the result of the call to get SQ server version. Useful for debugging with --sonar-scanner-internal-dump-to-file |
7575
| `--sonar-scanner-java-exe-path`, `-Dsonar.scanner.javaExePath` | If defined, the scanner engine will be run with this JRE |
76+
| `--sonar-scanner-java-heap-size`, `--java-heap-size`, `-Dsonar.scanner.javaHeapSize` | Arguments specifies the heap size provided to the JVM when running the scanner |
7677
| `--sonar-scanner-java-opts`, `-Dsonar.scanner.javaOpts` | Arguments provided to the JVM when running the scanner |
7778
| `--sonar-scanner-keystore-password`, `-Dsonar.scanner.keystorePassword` | Password to access the keystore |
7879
| `--sonar-scanner-keystore-path`, `-Dsonar.scanner.keystorePath` | Path to the keystore containing the client certificates used by the scanner. By default, <sonar.userHome>/ssl/keystore.p12 |

src/pysonar_scanner/configuration/cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ def __create_parser(cls):
179179
type=str,
180180
help="Arguments provided to the JVM when running the scanner",
181181
)
182+
parser.add_argument(
183+
"--sonar-scanner-java-heap-size",
184+
"--java-heap-size",
185+
"-Dsonar.scanner.javaHeapSize",
186+
type=str,
187+
help="Arguments specifies the heap size provided to the JVM when running the scanner",
188+
)
182189

183190
parser.add_argument(
184191
"--sonar-scanner-internal-dump-to-file",

src/pysonar_scanner/configuration/properties.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
SONAR_SCANNER_PROXY_PASSWORD: Key = "sonar.scanner.proxyPassword"
5757
SONAR_SCANNER_METADATA_FILEPATH: Key = "sonar.scanner.metadataFilePath"
5858
SONAR_SCANNER_JAVA_OPTS: Key = "sonar.scanner.javaOpts"
59+
SONAR_SCANNER_JAVA_HEAP_SIZE: Key = "sonar.scanner.javaHeapSize"
5960
SONAR_PROJECT_BASE_DIR: Key = "sonar.projectBaseDir"
6061
SONAR_PROJECT_KEY: Key = "sonar.projectKey"
6162
SONAR_PROJECT_NAME: Key = "sonar.projectName"
@@ -299,6 +300,11 @@ def env_variable_name(self) -> str:
299300
default_value=None,
300301
cli_getter=lambda args: args.sonar_scanner_java_opts
301302
),
303+
Property(
304+
name=SONAR_SCANNER_JAVA_HEAP_SIZE,
305+
default_value=None,
306+
cli_getter=lambda args: args.sonar_scanner_java_heap_size
307+
),
302308
Property(
303309
name=SONAR_SCANNER_METADATA_FILEPATH,
304310
default_value=None,

tests/unit/test_configuration_cli.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
SONAR_SCANNER_INTERNAL_SQ_VERSION,
3939
SONAR_SCANNER_JAVA_EXE_PATH,
4040
SONAR_SCANNER_JAVA_OPTS,
41+
SONAR_SCANNER_JAVA_HEAP_SIZE,
4142
SONAR_SCANNER_KEYSTORE_PASSWORD,
4243
SONAR_SCANNER_KEYSTORE_PATH,
4344
SONAR_SCANNER_OS,
@@ -125,6 +126,7 @@
125126
SONAR_SCANNER_SKIP_JRE_PROVISIONING: True,
126127
SONAR_SCANNER_JAVA_EXE_PATH: "mySonarScannerJavaExePath",
127128
SONAR_SCANNER_JAVA_OPTS: "mySonarScannerJavaOpts",
129+
SONAR_SCANNER_JAVA_HEAP_SIZE: "8000Mb",
128130
SONAR_SCANNER_METADATA_FILEPATH: "myMetadataFilepath",
129131
SONAR_REGION: "us",
130132
SONAR_ORGANIZATION: "mySonarOrganization",
@@ -181,8 +183,16 @@ def test_minimal_cli_args(self):
181183

182184
def test_alternative_cli_args(self):
183185
alternatives = [
184-
["-t", "myToken", "-v", "--project-key", "myProjectKey"],
185-
["--sonar-token", "myToken", "--sonar-verbose", "--sonar-project-key", "myProjectKey"],
186+
["-t", "myToken", "-v", "--project-key", "myProjectKey", "--sonar-scanner-java-heap-size", "8000Mb"],
187+
[
188+
"--sonar-token",
189+
"myToken",
190+
"--sonar-verbose",
191+
"--sonar-project-key",
192+
"myProjectKey",
193+
"--java-heap-size",
194+
"8000Mb",
195+
],
186196
]
187197
for alternative in alternatives:
188198
with patch("sys.argv", ["myscript.py", *alternative]), patch("sys.stderr", new=StringIO()):
@@ -191,6 +201,7 @@ def test_alternative_cli_args(self):
191201
SONAR_TOKEN: "myToken",
192202
SONAR_VERBOSE: True,
193203
SONAR_PROJECT_KEY: "myProjectKey",
204+
SONAR_SCANNER_JAVA_HEAP_SIZE: "8000Mb",
194205
}
195206
self.assertDictEqual(configuration, expected_configuration)
196207

@@ -387,6 +398,8 @@ def test_impossible_os_choice(self):
387398
"path/to/ruff/reports",
388399
"--sonar-modules",
389400
"module1,module2",
401+
"--sonar-scanner-java-heap-size",
402+
"8000Mb",
390403
],
391404
)
392405
def test_all_cli_args(self):
@@ -464,6 +477,7 @@ def test_all_cli_args(self):
464477
"-Dsonar.python.flake8.reportPaths=path/to/flake8/reports",
465478
"-Dsonar.python.ruff.reportPaths=path/to/ruff/reports",
466479
"-Dsonar.modules=module1,module2",
480+
"-Dsonar.scanner.javaHeapSize=8000Mb",
467481
],
468482
)
469483
def test_jvm_style_cli_args(self):

tests/unit/test_configuration_loader.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
SONAR_SCANNER_SKIP_JRE_PROVISIONING,
3838
SONAR_SCANNER_SOCKET_TIMEOUT,
3939
SONAR_SCANNER_TRUSTSTORE_PASSWORD,
40+
SONAR_SCANNER_JAVA_HEAP_SIZE,
4041
SONAR_EXCLUSIONS,
4142
SONAR_SOURCES,
4243
SONAR_TESTS,
@@ -277,6 +278,7 @@ def test_load_pyproject_toml_from_toml_path(self, mock_get_os, mock_get_arch):
277278
project-name = "Custom Path Project"
278279
sources = "src/main"
279280
tests= "src/test"
281+
scanner.javaHeapSize = "8000Mb"
280282
"""
281283
),
282284
)
@@ -301,6 +303,7 @@ def test_load_pyproject_toml_from_toml_path(self, mock_get_os, mock_get_arch):
301303
SONAR_SCANNER_OS: Os.LINUX.value,
302304
SONAR_SCANNER_ARCH: Arch.X64.value,
303305
TOML_PATH: "custom/path",
306+
SONAR_SCANNER_JAVA_HEAP_SIZE: "8000Mb",
304307
}
305308
self.assertDictEqual(configuration, expected_configuration)
306309

0 commit comments

Comments
 (0)