use of org.sonarlint.eclipse.core.resource.ISonarLintFile in project sonarlint-eclipse by SonarSource.
the class AsyncServerMarkerUpdaterJob method updateMarkers.
private void updateMarkers(IProgressMonitor monitor) {
for (var entry : issuesPerResource.entrySet()) {
var issuable = entry.getKey();
if (issuable instanceof ISonarLintFile) {
var documentOrNull = docPerFile.get(issuable);
final IDocument documentNotNull;
if (documentOrNull == null) {
documentNotNull = ((ISonarLintFile) issuable).getDocument();
} else {
documentNotNull = documentOrNull;
}
var markerRule = ResourcesPlugin.getWorkspace().getRuleFactory().markerRule(issuable.getResource());
try {
getJobManager().beginRule(markerRule, monitor);
SonarLintMarkerUpdater.updateMarkersWithServerSideData(issuable, documentNotNull, entry.getValue(), triggerType);
} finally {
getJobManager().endRule(markerRule);
}
}
}
}
use of org.sonarlint.eclipse.core.resource.ISonarLintFile in project sonarlint-eclipse by SonarSource.
the class EclipseInputFile method initFromFS.
private synchronized void initFromFS(ISonarLintFile file, Path temporaryDirectory) {
IFileStore fileStore;
try {
fileStore = EFS.getStore(file.getResource().getLocationURI());
var localFile = fileStore.toLocalFile(EFS.NONE, null);
if (localFile == null) {
// For analyzers to properly work we should ensure the temporary file has a "correct" name, and not a generated one
localFile = new File(temporaryDirectory.toFile(), file.getProjectRelativePath());
Files.createDirectories(localFile.getParentFile().toPath());
fileStore.copy(EFS.getStore(localFile.toURI()), EFS.OVERWRITE, null);
}
filePath = localFile.toPath().toAbsolutePath();
} catch (Exception e) {
throw new IllegalStateException("Unable to find path for file " + file, e);
}
}
use of org.sonarlint.eclipse.core.resource.ISonarLintFile in project sonarlint-eclipse by SonarSource.
the class AbstractAnalyzeProjectJob method doRun.
@Override
protected IStatus doRun(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
var startTime = System.currentTimeMillis();
SonarLintLogger.get().debug("Trigger: " + triggerType.name());
Path analysisWorkDir = null;
try {
var excludedFiles = new ArrayList<ISonarLintFile>();
var filesToAnalyze = new ArrayList<FileWithDocument>();
var exclusionsChecker = new FileExclusionsChecker(getProject());
files.forEach(fWithDoc -> {
var file = fWithDoc.getFile();
if (exclusionsChecker.isExcluded(file, true) || isScmIgnored(file)) {
excludedFiles.add(file);
} else {
filesToAnalyze.add(fWithDoc);
}
});
Map<ISonarLintFile, IDocument> filesToAnalyzeMap = filesToAnalyze.stream().collect(HashMap::new, (m, fWithDoc) -> m.put(fWithDoc.getFile(), fWithDoc.getDocument()), HashMap::putAll);
SonarLintLogger.get().debug("Clear markers on " + excludedFiles.size() + " excluded files");
ResourcesPlugin.getWorkspace().run(m -> {
excludedFiles.forEach(SonarLintMarkerUpdater::clearMarkers);
if (shouldClearReport) {
SonarLintMarkerUpdater.deleteAllMarkersFromReport();
}
}, monitor);
if (filesToAnalyze.isEmpty()) {
return Status.OK_STATUS;
}
// Analyze
SonarLintLogger.get().info(this.getName() + "...");
// Configure
var mergedExtraProps = new LinkedHashMap<String, String>();
var usedDeprecatedConfigurators = configureDeprecated(getProject(), filesToAnalyzeMap.keySet(), mergedExtraProps, monitor);
analysisWorkDir = Files.createTempDirectory(getProject().getWorkingDir(), "sonarlint");
var inputFiles = buildInputFiles(analysisWorkDir, filesToAnalyzeMap);
var usedConfigurators = configure(getProject(), inputFiles, mergedExtraProps, analysisWorkDir, monitor);
extraProps.forEach(sonarProperty -> mergedExtraProps.put(sonarProperty.getName(), sonarProperty.getValue()));
if (!inputFiles.isEmpty()) {
runAnalysisAndUpdateMarkers(filesToAnalyzeMap, monitor, mergedExtraProps, inputFiles, analysisWorkDir);
}
analysisCompleted(usedDeprecatedConfigurators, usedConfigurators, mergedExtraProps, monitor);
SonarLintCorePlugin.getAnalysisListenerManager().notifyListeners();
SonarLintLogger.get().debug(String.format("Done in %d ms", System.currentTimeMillis() - startTime));
} catch (CanceledException e) {
return Status.CANCEL_STATUS;
} catch (Exception e) {
SonarLintLogger.get().error("Error during execution of SonarLint analysis", e);
return new Status(IStatus.WARNING, SonarLintCorePlugin.PLUGIN_ID, "Error when executing SonarLint analysis", e);
} finally {
if (analysisWorkDir != null) {
try {
FileUtils.deleteRecursively(analysisWorkDir);
} catch (Exception e) {
SonarLintLogger.get().debug("Unable to delete temp directory: " + analysisWorkDir, e);
}
}
}
return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
}
use of org.sonarlint.eclipse.core.resource.ISonarLintFile in project sonarlint-eclipse by SonarSource.
the class AnalyzeChangedFilesJob method runInWorkspace.
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
var global = SubMonitor.convert(monitor, 100);
try {
global.setTaskName("Collect changed file(s) list");
SonarLintMarkerUpdater.deleteAllMarkersFromReport();
var collectChangedFiles = collectChangedFiles(projects, global.newChild(20));
if (collectChangedFiles.isEmpty()) {
SonarLintLogger.get().info("No changed files found");
return Status.OK_STATUS;
}
var changedFilesPerProject = collectChangedFiles.stream().collect(Collectors.groupingBy(ISonarLintFile::getProject));
long fileCount = changedFilesPerProject.values().stream().flatMap(Collection::stream).count();
SonarLintLogger.get().info("Analyzing " + fileCount + " changed file(s) in " + changedFilesPerProject.size() + " project(s)");
global.setTaskName("Analysis");
var analysisMonitor = SubMonitor.convert(global.newChild(80), changedFilesPerProject.size());
for (var entry : changedFilesPerProject.entrySet()) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
var project = entry.getKey();
if (!project.isOpen()) {
analysisMonitor.worked(1);
continue;
}
global.setTaskName("Analyzing project " + project.getName());
var filesToAnalyze = entry.getValue().stream().map(f -> new FileWithDocument(f, null)).collect(Collectors.toList());
var req = new AnalyzeProjectRequest(project, filesToAnalyze, TriggerType.MANUAL_CHANGESET);
var job = AbstractAnalyzeProjectJob.create(req);
var subMonitor = analysisMonitor.newChild(1);
job.run(subMonitor);
subMonitor.done();
}
} catch (Exception e) {
SonarLintLogger.get().error(UNABLE_TO_ANALYZE_CHANGED_FILES, e);
return new Status(Status.ERROR, SonarLintCorePlugin.PLUGIN_ID, UNABLE_TO_ANALYZE_CHANGED_FILES, e);
}
return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
}
use of org.sonarlint.eclipse.core.resource.ISonarLintFile in project sonarlint-eclipse by SonarSource.
the class ConnectedEngineFacade method updateProjectStorage.
@Override
public void updateProjectStorage(String projectKey, @Nullable String branchName, IProgressMonitor monitor) {
doWithEngine(engine -> {
engine.updateProject(createEndpointParams(), buildClientWithProxyAndCredentials(), projectKey, true, branchName, new WrappedProgressMonitor(monitor, "Update configuration from server '" + getId() + "' for project '" + projectKey + "'"));
getBoundProjects(projectKey).forEach(p -> {
var projectBinding = engine.calculatePathPrefixes(projectKey, p.files().stream().map(ISonarLintFile::getProjectRelativePath).collect(toList()));
var idePathPrefix = projectBinding.idePathPrefix();
var sqPathPrefix = projectBinding.sqPathPrefix();
SonarLintLogger.get().debug("Detected prefixes for " + p.getName() + ":\n IDE prefix: " + idePathPrefix + "\n Server side prefix: " + sqPathPrefix);
SonarLintProjectConfiguration config = SonarLintCorePlugin.loadConfig(p);
config.setProjectBinding(new EclipseProjectBinding(getId(), projectKey, sqPathPrefix, idePathPrefix));
SonarLintCorePlugin.saveConfig(p, config);
});
});
// Some prefix/suffix might have been changed
notifyAllListenersStateChanged();
}
Aggregations