Skip to content

Commit 29ce17c

Browse files
committed
SCANJLIB-208 Support new bootstrapping mechanism
1 parent 856dcd4 commit 29ce17c

58 files changed

Lines changed: 2182 additions & 484 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ qa_task:
7070
env:
7171
matrix:
7272
- QA_CATEGORY: RELEASE
73-
- QA_CATEGORY: DEV
73+
- QA_CATEGORY: LATEST_RELEASE
7474
JAVA_VERSION:
7575
- LATEST_RELEASE
7676
GITHUB_TOKEN: VAULT[development/github/token/licenses-ro token]

batch-interface/src/main/java/org/sonarsource/scanner/lib/internal/batch/IsolatedLauncher.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,4 @@
2323

2424
public interface IsolatedLauncher {
2525
void execute(Map<String, String> properties, LogOutput logOutput);
26-
27-
String getVersion();
28-
2926
}

batch/src/main/java/org/sonarsource/scanner/lib/internal/batch/BatchIsolatedLauncher.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
*/
2020
package org.sonarsource.scanner.lib.internal.batch;
2121

22-
import java.io.BufferedReader;
23-
import java.io.IOException;
24-
import java.io.InputStream;
25-
import java.io.InputStreamReader;
26-
import java.nio.charset.StandardCharsets;
2722
import java.util.Map;
2823

2924
/**
@@ -45,17 +40,4 @@ public BatchIsolatedLauncher(BatchFactory factory) {
4540
public void execute(Map<String, String> properties, LogOutput logOutput) {
4641
factory.createBatch(properties, logOutput).execute();
4742
}
48-
49-
@Override
50-
public String getVersion() {
51-
InputStream is = this.getClass().getClassLoader().getResourceAsStream("sq-version.txt");
52-
if (is == null) {
53-
return null;
54-
}
55-
try (BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
56-
return br.readLine();
57-
} catch (IOException e) {
58-
return null;
59-
}
60-
}
6143
}

its/it-simple-scanner/src/main/java/com/sonar/scanner/lib/it/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void main(String[] args) {
5050

5151
private static void runProject(Map<String, String> props, LogOutput logOutput) throws Exception {
5252

53-
try (var scannerEngine = new ScannerEngineBootstrapper("Simple Scanner", "1.0", logOutput)
53+
try (var scannerEngine = ScannerEngineBootstrapper.create("Simple Scanner", "1.0", logOutput)
5454
.addBootstrapProperties(props)
5555
.bootstrap()) {
5656
scannerEngine.analyze(props);

its/it-tests/src/test/java/com/sonar/scanner/lib/it/ProxyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void simple_analysis_with_proxy_auth() throws Exception {
209209

210210
BuildResult buildResult = scanner.executeSimpleProject(project("js-sample"), ORCHESTRATOR.getServer().getUrl(), params, Map.of());
211211
assertThat(buildResult.getLastStatus()).isEqualTo(1);
212-
assertThat(buildResult.getLogs()).contains("Status returned by url", "is not valid: [407]");
212+
assertThat(buildResult.getLogs()).contains("Error status returned by url", ": 407");
213213
assertThat(seenByProxy).isEmpty();
214214

215215
params.put("http.proxyUser", PROXY_USER);

its/it-tests/src/test/java/com/sonar/scanner/lib/it/SSLTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void simple_analysis_with_server_and_without_client_certificate_is_failin
212212
assertThat(buildResult.getLastStatus()).isEqualTo(1);
213213

214214
// different exception is thrown depending on the JDK version. See: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8172163
215-
String failedAnalysis = "(?s).*org\\.sonarsource\\.scanner\\.lib\\.internal\\.ScannerException: Unable to execute SonarScanner analysis.*";
215+
String failedAnalysis = "(?s).*java\\.lang\\.IllegalStateException: Failed to get server version.*";
216216
assertThat(buildResult.getLogs())
217217
.matches(p -> p.matches(failedAnalysis + "Caused by: javax\\.net\\.ssl\\.SSLException: Broken pipe \\(Write failed\\).*") ||
218218
p.matches(failedAnalysis + "Caused by: javax\\.net\\.ssl\\.SSLProtocolException: Broken pipe \\(Write failed\\).*") ||

its/it-tests/src/test/java/com/sonar/scanner/lib/it/ScannerJavaLibraryTestSuite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ScannerJavaLibraryTestSuite {
3737

3838
@ClassRule
3939
public static final OrchestratorRule ORCHESTRATOR = OrchestratorRule.builderEnv()
40-
.setSonarVersion(System.getProperty(SONAR_RUNTIME_VERSION, "LATEST_RELEASE"))
40+
.setSonarVersion(System.getProperty(SONAR_RUNTIME_VERSION, "DEV"))
4141
.useDefaultAdminCredentialsForBuilds(true)
4242
// We need to use a plugin compatible with both SonarQube DEV & SonarQube version defined in .cirrus.yml (currently SQ 7.9)
4343
.addPlugin(MavenLocation.of("org.sonarsource.javascript", "sonar-javascript-plugin", "7.4.4.15624"))

lib/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
<groupId>com.google.code.gson</groupId>
2525
<artifactId>gson</artifactId>
2626
</dependency>
27+
<dependency>
28+
<groupId>org.apache.commons</groupId>
29+
<artifactId>commons-compress</artifactId>
30+
</dependency>
2731
<dependency>
2832
<groupId>com.google.code.findbugs</groupId>
2933
<artifactId>jsr305</artifactId>
@@ -66,6 +70,11 @@
6670
<artifactId>mockito-core</artifactId>
6771
<scope>test</scope>
6872
</dependency>
73+
<dependency>
74+
<groupId>org.mockito</groupId>
75+
<artifactId>mockito-junit-jupiter</artifactId>
76+
<scope>test</scope>
77+
</dependency>
6978
<dependency>
7079
<groupId>org.assertj</groupId>
7180
<artifactId>assertj-core</artifactId>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* SonarScanner Java Library
3+
* Copyright (C) 2011-2024 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonarsource.scanner.lib;
21+
22+
import java.util.Map;
23+
import javax.annotation.Nullable;
24+
import org.sonarsource.scanner.lib.internal.IsolatedLauncherFactory;
25+
26+
public class InProcessScannerEngineFacade extends ScannerEngineFacade {
27+
private final IsolatedLauncherFactory.IsolatedLauncherAndClassloader launcherAndCl;
28+
29+
InProcessScannerEngineFacade(Map<String, String> bootstrapProperties, IsolatedLauncherFactory.IsolatedLauncherAndClassloader launcherAndCl,
30+
LogOutput logOutput, boolean isSonarCloud, @Nullable String serverVersion) {
31+
super(bootstrapProperties, logOutput, isSonarCloud, serverVersion);
32+
this.launcherAndCl = launcherAndCl;
33+
}
34+
35+
@Override
36+
void doAnalyze(Map<String, String> allProps) {
37+
launcherAndCl.getLauncher().execute(allProps, (formattedMessage, level) -> logOutput.log(formattedMessage,
38+
LogOutput.Level.valueOf(level.name())));
39+
}
40+
41+
@Override
42+
public void close() throws Exception {
43+
launcherAndCl.close();
44+
}
45+
}

lib/src/main/java/org/sonarsource/scanner/lib/LoggerAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public void error(String msg) {
5353
logOutput.log(msg, LogOutput.Level.ERROR);
5454
}
5555

56+
@Override
57+
public void trace(String msg) {
58+
logOutput.log(msg, LogOutput.Level.TRACE);
59+
}
60+
5661
@Override
5762
public void debug(String msg) {
5863
logOutput.log(msg, LogOutput.Level.DEBUG);

0 commit comments

Comments
 (0)