Skip to content

Commit d5e8698

Browse files
authored
JS-751 Fix SQ issues (#5438)
1 parent 61fa6d5 commit d5e8698

6 files changed

Lines changed: 31 additions & 43 deletions

File tree

sonar-plugin/bridge/src/main/java/org/sonar/plugins/javascript/bridge/AstProtoUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import com.google.protobuf.CodedInputStream;
2020
import com.google.protobuf.InvalidProtocolBufferException;
21-
import java.io.FileInputStream;
22-
import java.io.FileNotFoundException;
2321
import java.io.IOException;
2422
import java.util.Base64;
2523
import org.slf4j.Logger;

sonar-plugin/bridge/src/main/java/org/sonar/plugins/javascript/bridge/BridgeServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
@ScannerSide
3737
@SonarLintSide(lifespan = INSTANCE)
3838
public interface BridgeServer extends Startable {
39-
void startServerLazily(BridgeServerConfig context) throws IOException, InterruptedException;
39+
void startServerLazily(BridgeServerConfig context) throws IOException;
4040

4141
void initLinter(
4242
List<EslintRule> rules,

sonar-plugin/bridge/src/main/java/org/sonar/plugins/javascript/bridge/BridgeServerImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ private static Map<String, String> getEnv() {
309309
}
310310

311311
@Override
312-
public void startServerLazily(BridgeServerConfig serverConfig)
313-
throws IOException, InterruptedException {
312+
public void startServerLazily(BridgeServerConfig serverConfig) throws IOException {
314313
if (status == Status.FAILED) {
315314
if (shouldRestartFailedServer()) {
316315
// Reset the status, which will cause the server to retry deployment

sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/HtmlSensor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.sonar.plugins.javascript.analysis;
1818

1919
import java.io.IOException;
20-
import java.util.ArrayList;
2120
import java.util.List;
2221
import java.util.concurrent.TimeUnit;
2322
import java.util.stream.StreamSupport;

sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/JsTsSensor.java

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected void analyzeFiles(List<InputFile> inputFiles) throws IOException {
147147
}
148148
}
149149

150-
class AnalyzeProjectHandler implements WebSocketMessageHandler {
150+
class AnalyzeProjectHandler implements WebSocketMessageHandler<ProjectAnalysisRequest> {
151151

152152
private final JsTsContext<?> context;
153153
private final Map<String, List<ExternalIssue>> externalIssues;
@@ -231,42 +231,35 @@ public CompletableFuture<Void> getFuture() {
231231
@Override
232232
public void handleMessage(JsonObject jsonObject) {
233233
var messageType = jsonObject.get("messageType").getAsString();
234-
switch (messageType) {
235-
case "fileResult":
236-
var filePath = jsonObject.get("filename").getAsString();
237-
var response = BridgeServer.AnalysisResponse.fromDTO(
238-
GSON.fromJson(jsonObject, BridgeServer.AnalysisResponseDTO.class)
239-
);
240-
var file = fileToInputFile.get(filePath);
241-
var cacheStrategy = fileToCacheStrategy.get(filePath);
242-
var issues = analysisProcessor.processResponse(context, checks, file, response);
243-
var dedupedIssues = ExternalIssueRepository.deduplicateIssues(
244-
externalIssues.get(filePath),
245-
issues
234+
if ("fileResult".equals(messageType)) {
235+
var filePath = jsonObject.get("filename").getAsString();
236+
var response = BridgeServer.AnalysisResponse.fromDTO(
237+
GSON.fromJson(jsonObject, BridgeServer.AnalysisResponseDTO.class)
238+
);
239+
var file = fileToInputFile.get(filePath);
240+
var cacheStrategy = fileToCacheStrategy.get(filePath);
241+
var issues = analysisProcessor.processResponse(context, checks, file, response);
242+
var dedupedIssues = ExternalIssueRepository.deduplicateIssues(
243+
externalIssues.get(filePath),
244+
issues
245+
);
246+
if (!dedupedIssues.isEmpty()) {
247+
ExternalIssueRepository.saveESLintIssues(context.getSensorContext(), dedupedIssues);
248+
}
249+
externalIssues.remove(filePath);
250+
try {
251+
cacheStrategy.writeAnalysisToCache(
252+
CacheAnalysis.fromResponse(response.ucfgPaths(), response.cpdTokens(), response.ast()),
253+
file
246254
);
247-
if (!dedupedIssues.isEmpty()) {
248-
ExternalIssueRepository.saveESLintIssues(context.getSensorContext(), dedupedIssues);
249-
}
250-
externalIssues.remove(filePath);
251-
try {
252-
cacheStrategy.writeAnalysisToCache(
253-
CacheAnalysis.fromResponse(
254-
response.ucfgPaths(),
255-
response.cpdTokens(),
256-
response.ast()
257-
),
258-
file
259-
);
260-
} catch (IOException e) {
261-
handle.completeExceptionally(new IllegalStateException(e));
262-
}
263-
acceptAstResponse(response.ast(), file);
264-
break;
265-
case "meta":
266-
var meta = GSON.fromJson(jsonObject, BridgeServer.ProjectAnalysisMetaResponse.class);
267-
meta.warnings().forEach(analysisWarnings::addUnique);
268-
handle.complete(null);
269-
break;
255+
} catch (IOException e) {
256+
handle.completeExceptionally(new IllegalStateException(e));
257+
}
258+
acceptAstResponse(response.ast(), file);
259+
} else if ("meta".equals(messageType)) {
260+
var meta = GSON.fromJson(jsonObject, BridgeServer.ProjectAnalysisMetaResponse.class);
261+
meta.warnings().forEach(analysisWarnings::addUnique);
262+
handle.complete(null);
270263
}
271264
}
272265

sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/YamlSensor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.sonar.plugins.javascript.CancellationException;
3535
import org.sonar.plugins.javascript.analysis.cache.CacheAnalysis;
3636
import org.sonar.plugins.javascript.analysis.cache.CacheStrategies;
37-
import org.sonar.plugins.javascript.bridge.AnalysisWarningsWrapper;
3837
import org.sonar.plugins.javascript.bridge.BridgeServer;
3938
import org.sonar.plugins.javascript.bridge.BridgeServer.JsAnalysisRequest;
4039
import org.sonar.plugins.javascript.utils.ProgressReport;

0 commit comments

Comments
 (0)