-
Notifications
You must be signed in to change notification settings - Fork 0
SLVS-2583 Implement cancellation #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
.../main/java/org/sonarsource/sonarlint/visualstudio/roslyn/AnalysisCancellationService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* SonarQube Ide VisualStudio Roslyn Plugin | ||
* Copyright (C) 2025-2025 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonarsource.sonarlint.visualstudio.roslyn; | ||
|
||
import org.sonar.api.Startable; | ||
import org.sonarsource.api.sonarlint.SonarLintSide; | ||
|
||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.ScheduledFuture; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@SonarLintSide(lifespan = SonarLintSide.INSTANCE) | ||
public class AnalysisCancellationService implements Startable { | ||
private final ScheduledExecutorService scheduledExecutorService; | ||
|
||
public AnalysisCancellationService() { | ||
scheduledExecutorService = Executors.newScheduledThreadPool(5); | ||
} | ||
|
||
public void registerAnalysis(AnalysisTracker analysisTracker) { | ||
AnalysisPollingRunnable task = new AnalysisPollingRunnable(analysisTracker); | ||
task.selfFuture = scheduledExecutorService.scheduleAtFixedRate(task, 100, 100, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
@Override | ||
public void start() { | ||
// do nothing, executor created in constructor | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
scheduledExecutorService.shutdownNow(); | ||
} | ||
|
||
private static class AnalysisPollingRunnable implements Runnable{ | ||
private final AnalysisTracker analysisCompletion; | ||
ScheduledFuture<?> selfFuture; | ||
|
||
public AnalysisPollingRunnable(AnalysisTracker analysisCompletion) { | ||
this.analysisCompletion = analysisCompletion; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
if (analysisCompletion.cancelIfNeeded()) { | ||
selfFuture.cancel(false); | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...n-plugin/src/main/java/org/sonarsource/sonarlint/visualstudio/roslyn/AnalysisTracker.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* SonarQube Ide VisualStudio Roslyn Plugin | ||
* Copyright (C) 2025-2025 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonarsource.sonarlint.visualstudio.roslyn; | ||
|
||
import java.io.Closeable; | ||
import java.util.UUID; | ||
|
||
public interface AnalysisTracker extends Closeable { | ||
UUID getAnalysisId(); | ||
|
||
boolean cancelIfNeeded(); | ||
} |
69 changes: 69 additions & 0 deletions
69
...ugin/src/main/java/org/sonarsource/sonarlint/visualstudio/roslyn/AnalysisTrackerImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* SonarQube Ide VisualStudio Roslyn Plugin | ||
* Copyright (C) 2025-2025 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonarsource.sonarlint.visualstudio.roslyn; | ||
|
||
import org.sonar.api.batch.sensor.SensorContext; | ||
import org.sonarsource.sonarlint.visualstudio.roslyn.http.HttpAnalysisRequestHandler; | ||
|
||
import java.util.UUID; | ||
|
||
public class AnalysisTrackerImpl implements AnalysisTracker { | ||
private final UUID analysisId; | ||
private boolean isCompleted; | ||
private SensorContext sensorContext; | ||
private final HttpAnalysisRequestHandler handler; | ||
|
||
public AnalysisTrackerImpl(SensorContext sensorContext, HttpAnalysisRequestHandler handler, AnalysisCancellationService analysisCancellationService) { | ||
this.sensorContext = sensorContext; | ||
this.handler = handler; | ||
this.analysisId = UUID.randomUUID(); | ||
analysisCancellationService.registerAnalysis(this); | ||
} | ||
|
||
@Override | ||
public UUID getAnalysisId() { | ||
return analysisId; | ||
} | ||
|
||
@Override | ||
public synchronized boolean cancelIfNeeded() { | ||
if (isCompleted) { | ||
return true; | ||
} | ||
|
||
if (sensorContext.isCancelled()) { | ||
handler.cancelAnalysis(analysisId); | ||
setCompletedState(); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public synchronized void close() { | ||
setCompletedState(); | ||
} | ||
|
||
private synchronized void setCompletedState() { | ||
isCompleted = true; | ||
sensorContext = null; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...in/src/main/java/org/sonarsource/sonarlint/visualstudio/roslyn/RemoteAnalysisService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* SonarQube Ide VisualStudio Roslyn Plugin | ||
* Copyright (C) 2025-2025 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonarsource.sonarlint.visualstudio.roslyn; | ||
|
||
import org.sonar.api.batch.rule.ActiveRule; | ||
import org.sonar.api.batch.sensor.SensorContext; | ||
import org.sonarsource.api.sonarlint.SonarLintSide; | ||
import org.sonarsource.sonarlint.visualstudio.roslyn.http.AnalyzerInfoDto; | ||
import org.sonarsource.sonarlint.visualstudio.roslyn.http.HttpAnalysisRequestHandler; | ||
import org.sonarsource.sonarlint.visualstudio.roslyn.protocol.RoslynIssue; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
@SonarLintSide | ||
public class RemoteAnalysisService { | ||
damien-urruty-sonarsource marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final AnalysisCancellationService analysisCancellationService; | ||
private final HttpAnalysisRequestHandler httpAnalysisRequestHandler; | ||
private final SensorContext sensorContext; | ||
|
||
public RemoteAnalysisService( | ||
AnalysisCancellationService analysisCancellationService, | ||
HttpAnalysisRequestHandler httpAnalysisRequestHandler, | ||
SensorContext sensorContext) { | ||
this.analysisCancellationService = analysisCancellationService; | ||
this.httpAnalysisRequestHandler = httpAnalysisRequestHandler; | ||
this.sensorContext = sensorContext; | ||
} | ||
|
||
public Collection<RoslynIssue> analyze( | ||
Collection<String> inputFiles, | ||
Collection<ActiveRule> activeRules, | ||
Map<String, String> analysisProperties, | ||
AnalyzerInfoDto analyzerInfo) { | ||
try (var tracker = new AnalysisTrackerImpl(sensorContext, httpAnalysisRequestHandler, analysisCancellationService)) { | ||
return httpAnalysisRequestHandler.analyze(inputFiles, activeRules, analysisProperties, analyzerInfo, tracker.getAnalysisId()); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
.../main/java/org/sonarsource/sonarlint/visualstudio/roslyn/http/CancellationRequestDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* SonarQube Ide VisualStudio Roslyn Plugin | ||
* Copyright (C) 2025-2025 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonarsource.sonarlint.visualstudio.roslyn.http; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
public record CancellationRequestDto(@SerializedName("AnalysisId") java.util.UUID analysisId) { | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.