use of org.sonarlint.intellij.exception.InvalidBindingException in project sonarlint-intellij by SonarSource.
the class SonarLintAnalyzer method analyzeModule.
public AnalysisResults analyzeModule(Module module, Collection<VirtualFile> filesToAnalyze, IssueListener listener, ProgressMonitor progressMonitor) {
// Configure plugin properties. Nothing might be done if there is no configurator available for the extensions loaded in runtime.
Map<String, String> pluginProps = new HashMap<>();
AnalysisConfigurator[] analysisConfigurators = AnalysisConfigurator.EP_NAME.getExtensions();
if (analysisConfigurators.length > 0) {
for (AnalysisConfigurator config : analysisConfigurators) {
console.debug("Configuring analysis with " + config.getClass().getName());
pluginProps.putAll(config.configure(module));
}
} else {
console.info("No analysis configurator found");
}
// configure files
VirtualFileTestPredicate testPredicate = SonarLintUtils.get(module, VirtualFileTestPredicate.class);
List<ClientInputFile> inputFiles = getInputFiles(module, testPredicate, filesToAnalyze);
// Analyze
long start = System.currentTimeMillis();
try {
SonarLintFacade facade = projectBindingManager.getFacade(true);
String what;
if (filesToAnalyze.size() == 1) {
what = "'" + filesToAnalyze.iterator().next().getName() + "'";
} else {
what = Integer.toString(filesToAnalyze.size()) + " files";
}
console.info("Analysing " + what + "...");
if (facade.requiresSavingFiles()) {
console.debug("Saving files");
LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed(), "Should not be in a read action (risk of dead lock)");
ApplicationManager.getApplication().invokeAndWait(() -> SonarLintUtils.saveFiles(filesToAnalyze), ModalityState.defaultModalityState());
}
AnalysisResults result = facade.startAnalysis(inputFiles, listener, pluginProps, progressMonitor);
console.debug("Done in " + (System.currentTimeMillis() - start) + "ms\n");
if (filesToAnalyze.size() == 1) {
telemetry.analysisDoneOnSingleFile(filesToAnalyze.iterator().next().getExtension(), (int) (System.currentTimeMillis() - start));
} else {
telemetry.analysisDoneOnMultipleFiles();
}
return result;
} catch (InvalidBindingException e) {
// should not happen, as analysis should not have been submitted in this case.
throw new IllegalStateException(e);
}
}
use of org.sonarlint.intellij.exception.InvalidBindingException in project sonarlint-intellij by SonarSource.
the class ServerIssueUpdater method fetchAndMatchServerIssues.
public void fetchAndMatchServerIssues(Collection<VirtualFile> virtualFiles, ProgressIndicator indicator, boolean waitForCompletion) {
if (!projectSettings.isBindingEnabled()) {
// not in connected mode
return;
}
try {
SonarQubeServer server = projectBindingManager.getSonarQubeServer();
ConnectedSonarLintEngine engine = projectBindingManager.getConnectedEngine();
String moduleKey = projectSettings.getProjectKey();
boolean downloadAll = virtualFiles.size() >= FETCH_ALL_ISSUES_THRESHOLD;
String msg;
if (downloadAll) {
msg = "Fetching all server issues";
} else {
msg = "Fetching server issues";
}
if (waitForCompletion) {
msg += " (waiting for results)";
}
console.debug(msg);
indicator.setText(msg);
// submit tasks
List<Future<Void>> updateTasks = fetchAndMatchServerIssues(virtualFiles, server, engine, moduleKey, downloadAll);
if (waitForCompletion) {
waitForTasks(updateTasks);
}
} catch (InvalidBindingException e) {
// ignore, do nothing
}
}
use of org.sonarlint.intellij.exception.InvalidBindingException in project sonarlint-intellij by SonarSource.
the class SonarLintEngineManager method checkConnectedEngineStatus.
private static void checkConnectedEngineStatus(ConnectedSonarLintEngine engine, SonarLintProjectNotifications notifications, String serverId, String projectKey) throws InvalidBindingException {
// Check if engine's global storage is OK
ConnectedSonarLintEngine.State state = engine.getState();
if (state != ConnectedSonarLintEngine.State.UPDATED) {
if (state != ConnectedSonarLintEngine.State.NEED_UPDATE) {
notifications.notifyServerNotUpdated();
} else if (state != ConnectedSonarLintEngine.State.NEVER_UPDATED) {
notifications.notifyServerStorageNeedsUpdate(serverId);
}
throw new InvalidBindingException("Server is not updated: " + serverId);
}
// Check if module's storage is OK. Global storage was updated and all project's binding that were open too,
// but we might have now opened a new project with a different binding.
ModuleStorageStatus moduleStorageStatus = engine.getModuleStorageStatus(projectKey);
if (moduleStorageStatus == null) {
notifications.notifyModuleInvalid();
throw new InvalidBindingException("Project is bound to a module that doesn't exist: " + projectKey);
} else if (moduleStorageStatus.isStale()) {
notifications.notifyModuleStale();
throw new InvalidBindingException("Stale module's storage: " + projectKey);
}
}
use of org.sonarlint.intellij.exception.InvalidBindingException in project sonarlint-intellij by SonarSource.
the class SonarQubeEventNotifications method register.
private void register(SonarLintProjectSettings settings) {
unregister();
if (settings.isBindingEnabled()) {
SonarQubeServer server;
try {
server = bindingManager.getSonarQubeServer();
} catch (InvalidBindingException e) {
// do nothing
return;
}
if (server.enableNotifications()) {
NotificationConfiguration config = createConfiguration(settings, server);
SonarQubeNotifications.get().register(config);
}
}
}
use of org.sonarlint.intellij.exception.InvalidBindingException in project sonarlint-intellij by SonarSource.
the class SonarLinkHandler method getDescription.
@Nullable
@Override
public String getDescription(@NotNull String refSuffix, @NotNull Editor editor) {
Project project = editor.getProject();
if (project == null || project.isDisposed()) {
return null;
}
ProjectBindingManager projectBindingManager = SonarLintUtils.get(project, ProjectBindingManager.class);
try {
SonarLintFacade sonarlint = projectBindingManager.getFacade();
String description = sonarlint.getDescription(refSuffix);
String name = sonarlint.getRuleName(refSuffix);
return transform(refSuffix, name, description);
} catch (InvalidBindingException e) {
return "";
}
}
Aggregations