|
37 | 37 | import org.sonarsource.scanner.lib.internal.MessageException; |
38 | 38 | import org.sonarsource.scanner.lib.internal.SuccessfulBootstrap; |
39 | 39 | import org.sonarsource.scanner.lib.internal.cache.FileCache; |
| 40 | +import org.sonarsource.scanner.lib.internal.endpoint.ScannerEndpoint; |
| 41 | +import org.sonarsource.scanner.lib.internal.endpoint.ScannerEndpointResolver; |
40 | 42 | import org.sonarsource.scanner.lib.internal.facade.forked.NewScannerEngineFacade; |
41 | 43 | import org.sonarsource.scanner.lib.internal.facade.forked.ScannerEngineLauncherFactory; |
42 | 44 | import org.sonarsource.scanner.lib.internal.facade.inprocess.InProcessScannerEngineFacade; |
@@ -77,8 +79,7 @@ public class ScannerEngineBootstrapper { |
77 | 79 |
|
78 | 80 | private static final Logger LOG = LoggerFactory.getLogger(ScannerEngineBootstrapper.class); |
79 | 81 |
|
80 | | - private static final String SONARCLOUD_HOST = "https://sonarcloud.io"; |
81 | | - private static final String SONARCLOUD_REST_API = "https://api.sonarcloud.io"; |
| 82 | + |
82 | 83 | static final String SQ_VERSION_NEW_BOOTSTRAPPING = "10.6"; |
83 | 84 | static final String SQ_VERSION_TOKEN_AUTHENTICATION = "10.0"; |
84 | 85 |
|
@@ -125,37 +126,38 @@ public ScannerEngineBootstrapResult bootstrap() { |
125 | 126 | if (LOG.isDebugEnabled()) { |
126 | 127 | LOG.debug("Scanner max available memory: {}", FileUtils.byteCountToDisplaySize(Runtime.getRuntime().maxMemory())); |
127 | 128 | } |
128 | | - initBootstrapDefaultValues(); |
| 129 | + var endpoint = ScannerEndpointResolver.resolveEndpoint(bootstrapProperties); |
| 130 | + initBootstrapDefaultValues(endpoint); |
129 | 131 | var immutableProperties = Map.copyOf(bootstrapProperties); |
130 | 132 | var sonarUserHome = resolveSonarUserHome(immutableProperties); |
131 | 133 | var httpConfig = new HttpConfig(immutableProperties, sonarUserHome, system); |
132 | | - var isSonarCloud = isSonarCloud(immutableProperties); |
| 134 | + var isSonarQubeCloud = endpoint.isSonarQubeCloud(); |
133 | 135 | var isSimulation = immutableProperties.containsKey(InternalProperties.SCANNER_DUMP_TO_FILE); |
134 | 136 | var fileCache = FileCache.create(sonarUserHome); |
135 | 137 |
|
136 | 138 | if (isSimulation) { |
137 | 139 | var serverVersion = immutableProperties.getOrDefault(InternalProperties.SCANNER_VERSION_SIMULATION, "9.9"); |
138 | | - return new SuccessfulBootstrap(new SimulationScannerEngineFacade(immutableProperties, isSonarCloud, serverVersion)); |
| 140 | + return new SuccessfulBootstrap(new SimulationScannerEngineFacade(immutableProperties, isSonarQubeCloud, serverVersion)); |
139 | 141 | } |
140 | 142 |
|
141 | 143 | // No HTTP call should be made before this point |
142 | 144 | try { |
143 | 145 | scannerHttpClient.init(httpConfig); |
144 | 146 |
|
145 | | - var serverVersion = !isSonarCloud ? getServerVersion(scannerHttpClient) : null; |
| 147 | + var serverVersion = !isSonarQubeCloud ? getServerVersion(scannerHttpClient) : null; |
146 | 148 |
|
147 | | - if (!isSonarCloud && VersionUtils.isAtLeastIgnoringQualifier(serverVersion, SQ_VERSION_TOKEN_AUTHENTICATION) && Objects.nonNull(httpConfig.getLogin())) { |
| 149 | + if (!isSonarQubeCloud && VersionUtils.isAtLeastIgnoringQualifier(serverVersion, SQ_VERSION_TOKEN_AUTHENTICATION) && Objects.nonNull(httpConfig.getLogin())) { |
148 | 150 | LOG.warn("Use of '{}' property has been deprecated in favor of '{}' (or the env variable alternative '{}'). Please use the latter when passing a token.", SONAR_LOGIN, |
149 | 151 | SONAR_TOKEN, TOKEN_ENV_VARIABLE); |
150 | 152 | } |
151 | 153 |
|
152 | 154 | ScannerEngineFacade scannerFacade; |
153 | | - if (isSonarCloud || VersionUtils.isAtLeastIgnoringQualifier(serverVersion, SQ_VERSION_NEW_BOOTSTRAPPING)) { |
| 155 | + if (isSonarQubeCloud || VersionUtils.isAtLeastIgnoringQualifier(serverVersion, SQ_VERSION_NEW_BOOTSTRAPPING)) { |
154 | 156 | var launcher = scannerEngineLauncherFactory.createLauncher(scannerHttpClient, fileCache, immutableProperties); |
155 | 157 |
|
156 | 158 | var adaptedProperties = adaptSslPropertiesToScannerProperties(immutableProperties, httpConfig); |
157 | 159 |
|
158 | | - scannerFacade = new NewScannerEngineFacade(adaptedProperties, launcher, isSonarCloud, serverVersion); |
| 160 | + scannerFacade = new NewScannerEngineFacade(adaptedProperties, launcher, isSonarQubeCloud, serverVersion); |
159 | 161 | } else { |
160 | 162 | var launcher = launcherFactory.createLauncher(scannerHttpClient, fileCache); |
161 | 163 | var adaptedProperties = adaptDeprecatedPropertiesForInProcessBootstrapping(immutableProperties, httpConfig); |
@@ -201,7 +203,7 @@ private static void logWithStacktraceOnlyIfDebug(String message, Throwable t) { |
201 | 203 | } |
202 | 204 |
|
203 | 205 | private static void logServerType(ScannerEngineFacade engine) { |
204 | | - if (engine.isSonarCloud()) { |
| 206 | + if (engine.isSonarQubeCloud()) { |
205 | 207 | LOG.info("Communicating with SonarQube Cloud"); |
206 | 208 | } else { |
207 | 209 | LOG.info("Communicating with {} {}", engine.getServerLabel(), engine.getServerVersion()); |
@@ -295,10 +297,9 @@ private static String formatMessage(Exception e) { |
295 | 297 | return e.getMessage(); |
296 | 298 | } |
297 | 299 |
|
298 | | - private void initBootstrapDefaultValues() { |
299 | | - setBootstrapPropertyIfNotAlreadySet(ScannerProperties.HOST_URL, getSonarCloudUrl()); |
300 | | - setBootstrapPropertyIfNotAlreadySet(ScannerProperties.API_BASE_URL, |
301 | | - isSonarCloud(bootstrapProperties) ? SONARCLOUD_REST_API : (StringUtils.removeEnd(bootstrapProperties.get(ScannerProperties.HOST_URL), "/") + "/api/v2")); |
| 300 | + private void initBootstrapDefaultValues(ScannerEndpoint endpoint) { |
| 301 | + setBootstrapPropertyIfNotAlreadySet(ScannerProperties.HOST_URL, endpoint.getWebEndpoint()); |
| 302 | + setBootstrapPropertyIfNotAlreadySet(ScannerProperties.API_BASE_URL, endpoint.getApiEndpoint()); |
302 | 303 | if (!bootstrapProperties.containsKey(SCANNER_OS)) { |
303 | 304 | setBootstrapProperty(SCANNER_OS, new OsResolver(system, new Paths2()).getOs().name().toLowerCase(Locale.ENGLISH)); |
304 | 305 | } |
@@ -328,14 +329,6 @@ static Map<String, String> adaptSslPropertiesToScannerProperties(Map<String, Str |
328 | 329 | return Map.copyOf(result); |
329 | 330 | } |
330 | 331 |
|
331 | | - private String getSonarCloudUrl() { |
332 | | - return bootstrapProperties.getOrDefault(ScannerProperties.SONARCLOUD_URL, SONARCLOUD_HOST); |
333 | | - } |
334 | | - |
335 | | - private boolean isSonarCloud(Map<String, String> properties) { |
336 | | - return getSonarCloudUrl().equals(properties.get(ScannerProperties.HOST_URL)); |
337 | | - } |
338 | | - |
339 | 332 | private void setBootstrapPropertyIfNotAlreadySet(String key, @Nullable String value) { |
340 | 333 | if (!bootstrapProperties.containsKey(key) && value != null) { |
341 | 334 | setBootstrapProperty(key, value); |
|
0 commit comments