use of org.sonarlint.intellij.core.SonarLintFacade 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.core.SonarLintFacade 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 "";
}
}
use of org.sonarlint.intellij.core.SonarLintFacade in project sonarlint-intellij by SonarSource.
the class SonarLintSubmitter method filterAndgetByModule.
private Map<Module, Collection<VirtualFile>> filterAndgetByModule(Collection<VirtualFile> files, boolean checkExclusions) throws InvalidBindingException {
HashMultimap<Module, VirtualFile> filesByModule = HashMultimap.create();
SonarLintFacade sonarLintFacade = projectBindingManager.getFacade();
for (VirtualFile file : files) {
Module m = utils.findModuleForFile(file, myProject);
if (checkExclusions) {
LocalFileExclusions.Result result = localFileExclusions.checkExclusions(file, m);
if (result.isExcluded()) {
if (result.excludeReason() != null) {
logExclusion(file, "excluded: " + result.excludeReason());
}
continue;
}
} else {
if (!localFileExclusions.canAnalyze(file, m)) {
logExclusion(file, "can't be analyzed. Skipping it.");
continue;
}
}
filesByModule.put(m, file);
}
// Apply server file exclusions. This is an expensive operation, so we call the core only once per module.
if (checkExclusions) {
// Note: iterating over a copy of keys, because removal of last value removes the key,
// resulting in ConcurrentModificationException
List<Module> modules = new ArrayList<>(filesByModule.keySet());
for (Module module : modules) {
VirtualFileTestPredicate testPredicate = SonarLintUtils.get(module, VirtualFileTestPredicate.class);
Collection<VirtualFile> excluded = sonarLintFacade.getExcluded(filesByModule.get(module), testPredicate);
for (VirtualFile f : excluded) {
logExclusion(f, "not automatically analyzed due to exclusions configured in the SonarQube Server");
}
filesByModule.get(module).removeAll(excluded);
}
}
return filesByModule.asMap();
}
Aggregations