|
20 | 20 | package org.sonarsource.scanner.lib; |
21 | 21 |
|
22 | 22 | import java.net.InetSocketAddress; |
| 23 | +import java.nio.file.Files; |
23 | 24 | import java.nio.file.Path; |
24 | 25 | import java.nio.file.Paths; |
25 | 26 | import java.time.temporal.ChronoUnit; |
26 | 27 | import java.util.HashMap; |
27 | 28 | import java.util.Locale; |
28 | 29 | import java.util.Map; |
29 | 30 | import java.util.Objects; |
30 | | -import javax.annotation.Nonnull; |
31 | 31 | import javax.annotation.Nullable; |
32 | 32 | import org.apache.commons.io.FileUtils; |
33 | 33 | import org.apache.commons.lang3.StringUtils; |
@@ -121,20 +121,38 @@ public ScannerEngineFacade bootstrap() { |
121 | 121 | return new SimulationScannerEngineFacade(properties, isSonarCloud, serverVersion); |
122 | 122 | } else if (isSonarCloud || VersionUtils.isAtLeastIgnoringQualifier(serverVersion, SQ_VERSION_NEW_BOOTSTRAPPING)) { |
123 | 123 | var launcher = scannerEngineLauncherFactory.createLauncher(scannerHttpClient, fileCache, properties); |
124 | | - return new NewScannerEngineFacade(properties, launcher, isSonarCloud, serverVersion); |
| 124 | + var adaptedProperties = adaptDeprecatedPropertiesForForkedBootstrapping(properties, httpConfig); |
| 125 | + return new NewScannerEngineFacade(adaptedProperties, launcher, isSonarCloud, serverVersion); |
125 | 126 | } else { |
126 | 127 | var launcher = launcherFactory.createLauncher(scannerHttpClient, fileCache); |
127 | | - var adaptedProperties = adaptDeprecatedProperties(properties, httpConfig); |
| 128 | + var adaptedProperties = adaptDeprecatedPropertiesForInProcessBootstrapping(properties, httpConfig); |
128 | 129 | return new InProcessScannerEngineFacade(adaptedProperties, launcher, false, serverVersion); |
129 | 130 | } |
130 | 131 | } |
131 | 132 |
|
| 133 | + /** |
| 134 | + * New versions of SonarQube/SonarCloud will run on a separate VM. For people who used to rely on configuring SSL |
| 135 | + * by inserting the trusted certificate in the Scanner JVM truststore, |
| 136 | + * we need to adapt the properties to read from the truststore of the scanner JVM. |
| 137 | + */ |
| 138 | + Map<String, String> adaptDeprecatedPropertiesForForkedBootstrapping(Map<String, String> properties, HttpConfig httpConfig) { |
| 139 | + var adaptedProperties = new HashMap<>(properties); |
| 140 | + if (system.getProperty("javax.net.ssl.trustStore") == null && httpConfig.getSslConfig().getTrustStore() == null) { |
| 141 | + var defaultJvmTrustStoreLocation = Paths.get(System.getProperty("java.home"), "lib", "security", "cacerts"); |
| 142 | + if (Files.isRegularFile(defaultJvmTrustStoreLocation)) { |
| 143 | + LOG.debug("Mapping default scanner JVM truststore location '{}' to new properties", defaultJvmTrustStoreLocation); |
| 144 | + adaptedProperties.put("sonar.scanner.truststorePath", defaultJvmTrustStoreLocation.toString()); |
| 145 | + adaptedProperties.put("sonar.scanner.truststorePassword", System.getProperty("javax.net.ssl.trustStorePassword", "changeit")); |
| 146 | + } |
| 147 | + } |
| 148 | + return Map.copyOf(adaptedProperties); |
| 149 | + } |
| 150 | + |
132 | 151 | /** |
133 | 152 | * Older SonarQube versions used to rely on some different properties, or even {@link System} properties. |
134 | 153 | * For backward compatibility, we adapt the new properties to the old format. |
135 | 154 | */ |
136 | | - @Nonnull |
137 | | - Map<String, String> adaptDeprecatedProperties(Map<String, String> properties, HttpConfig httpConfig) { |
| 155 | + Map<String, String> adaptDeprecatedPropertiesForInProcessBootstrapping(Map<String, String> properties, HttpConfig httpConfig) { |
138 | 156 | var adaptedProperties = new HashMap<>(properties); |
139 | 157 | if (!adaptedProperties.containsKey(HttpConfig.READ_TIMEOUT_SEC_PROPERTY)) { |
140 | 158 | adaptedProperties.put(HttpConfig.READ_TIMEOUT_SEC_PROPERTY, "" + httpConfig.getSocketTimeout().get(ChronoUnit.SECONDS)); |
|
0 commit comments