@Override public IContentProposal[] getProposals(String contents, int position) { if (!server.isStorageUpdated()) { parentPage.setMessage( "Please refresh project list from server first", IMessageProvider.INFORMATION); return new IContentProposal[0]; } List<IContentProposal> list = new ArrayList<>(); try { List<RemoteModule> modules = getModuleIndex().search(contents); for (RemoteModule m : modules) { RemoteSonarProject prj = new RemoteSonarProject(server.getId(), m.getKey(), m.getName()); list.add(new ContentProposal(prj.asString(), m.getName(), prj.getDescription())); } } catch (Exception e) { SonarLintCorePlugin.getDefault() .debug("Unable to search modules from server " + server.getId(), e); } if (!list.isEmpty()) { parentPage.setMessage("", IMessageProvider.NONE); return list.toArray(new IContentProposal[list.size()]); } else { parentPage.setMessage("No results", IMessageProvider.INFORMATION); return new IContentProposal[0]; } }
public CProjectConfigurator() { this( new BuildWrapperJsonFactory(), CCorePlugin.getDefault(), CoreModel::isTranslationUnit, SonarLintCorePlugin.getDefault(), new FilePathResolver()); }
@Override protected IStatus run(SonarRunnerFacade runner, final IProgressMonitor monitor) { // Configure Properties properties = configureAnalysis(monitor, extraProps); // Analyze Collection<File> tmpToDelete = new ArrayList<>(); try { if (request.getOnlyOnFiles() != null) { IProject project = request.getProject(); final File baseDir = project.getLocation().toFile(); handleLinkedFiles(tmpToDelete, baseDir); } run(request.getProject(), properties, runner, monitor); analysisCompleted(properties, monitor); } catch (Exception e) { SonarLintCorePlugin.getDefault() .error("Error during execution of SonarLint analysis" + System.lineSeparator(), e); return new Status( Status.WARNING, SonarLintCorePlugin.PLUGIN_ID, "Error when executing SonarLint analysis", e); } finally { for (File f : tmpToDelete) { try { f.delete(); } catch (Exception e) { SonarLintCorePlugin.getDefault() .error("Unable to delete temporary file" + System.lineSeparator(), e); } } } if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
private void handleLinkedFiles(Collection<File> tmpToDelete, final File baseDir) { // Handle linked files for (IFile file : request.getOnlyOnFiles()) { if (file.isLinked()) { File tmp = new File(baseDir, file.getProjectRelativePath().toString()); SonarLintCorePlugin.getDefault() .debug( file.getName() + " is a linked resource. Will create a temporary copy" + System.lineSeparator()); try { Files.copy(file.getContents(), tmp.toPath()); tmpToDelete.add(tmp); } catch (IOException | CoreException e) { SonarLintCorePlugin.getDefault() .error( "Unable to create temporary copy for linked resource" + System.lineSeparator(), e); } } } }
private void loadProperties() { sonarProperties = new ArrayList<SonarLintProperty>(); if (isGlobal()) { String props = getPreferenceStore().getString(PreferencesUtils.PREF_EXTRA_ARGS); try { String[] keyValuePairs = StringUtils.split(props, "\n\r"); for (String keyValuePair : keyValuePairs) { String[] keyValue = StringUtils.split(keyValuePair, "="); sonarProperties.add(new SonarLintProperty(keyValue[0], keyValue[1])); } } catch (Exception e) { SonarLintCorePlugin.getDefault() .error("Error while loading SonarQube properties" + props, e); } } else { sonarProperties.addAll(getSonarProject().getExtraProperties()); } }
public void run( IProject project, final Properties props, final SonarRunnerFacade runner, final IProgressMonitor monitor) { if (SonarLintCorePlugin.getDefault().isDebugEnabled()) { SonarLintCorePlugin.getDefault() .info("Start sonar-runner with args:\n" + propsToString(props) + System.lineSeparator()); } Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread th, Throwable ex) { SonarLintCorePlugin.getDefault() .error("Error during analysis" + System.lineSeparator(), ex); } }; Thread t = new Thread("SonarLint analysis") { @Override public void run() { runner.startAnalysis( props, new IssueListener() { @Override public void handle(Issue issue) { IResource r = ResourceUtils.findResource(request.getProject(), issue.getComponentKey()); if (request.getOnlyOnFiles() == null || request.getOnlyOnFiles().contains(r)) { try { SonarMarker.create(r, issue); } catch (CoreException e) { SonarLintCorePlugin.getDefault().error(e.getMessage(), e); } } } }); } }; t.setDaemon(true); t.setUncaughtExceptionHandler(h); t.start(); while (t.isAlive()) { if (monitor.isCanceled()) { t.interrupt(); try { t.join(5000); } catch (InterruptedException e) { // just quit } if (t.isAlive()) { SonarLintCorePlugin.getDefault().error("Unable to properly terminate SonarLint analysis"); } break; } try { Thread.sleep(100); } catch (InterruptedException e) { // Here we don't care } } }