use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonarlint-core by SonarSource.
the class StandaloneTest method globalExtension.
@Test
public void globalExtension() throws Exception {
ClientInputFile inputFile = prepareInputFile("foo.glob", "foo", false);
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), issue -> issues.add(issue), null, null);
assertThat(issues).extracting("ruleKey", "inputFile.path", "message").containsOnly(tuple("global:inc", inputFile.getPath(), "Issue number 0"));
issues.clear();
sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), issue -> issues.add(issue), null, null);
assertThat(issues).extracting("ruleKey", "inputFile.path", "message").containsOnly(tuple("global:inc", inputFile.getPath(), "Issue number 1"));
}
use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonarlint-core by SonarSource.
the class SonarLintLanguageServer method analyze.
private void analyze(URI uri, String content) {
Map<URI, PublishDiagnosticsParams> files = new HashMap<>();
files.put(uri, newPublishDiagnostics(uri));
Path baseDir = workspaceRoot != null ? Paths.get(workspaceRoot) : Paths.get(uri).getParent();
Objects.requireNonNull(baseDir);
Objects.requireNonNull(engine);
StandaloneAnalysisConfiguration configuration = new StandaloneAnalysisConfiguration(baseDir, baseDir.resolve(".sonarlint"), Arrays.asList(new DefaultClientInputFile(baseDir, uri, content, userSettings.testFilePattern, languageIdPerFileURI.get(uri))), userSettings.analyzerProperties);
debug("Analysis triggered on " + uri + " with configuration: \n" + configuration.toString());
long start = System.currentTimeMillis();
AnalysisResults analysisResults = engine.analyze(configuration, issue -> {
ClientInputFile inputFile = issue.getInputFile();
if (inputFile != null) {
URI uri1 = inputFile.getClientObject();
PublishDiagnosticsParams publish = files.computeIfAbsent(uri1, SonarLintLanguageServer::newPublishDiagnostics);
convert(issue).ifPresent(publish.getDiagnostics()::add);
}
}, logOutput, null);
telemetry.analysisDoneOnSingleFile(StringUtils.substringAfterLast(uri.toString(), "."), (int) (System.currentTimeMillis() - start));
// Ignore files with parsing error
analysisResults.failedAnalysisFiles().stream().map(ClientInputFile::getClientObject).forEach(files::remove);
files.values().forEach(client::publishDiagnostics);
}
use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonarlint-core by SonarSource.
the class StandaloneSonarLintImpl method analyze.
@Override
public void analyze(AnalysisReq requestConfig, StreamObserver<Issue> response) {
if (engine == null) {
response.onError(new IllegalStateException("Not registered"));
return;
}
try {
List<ClientInputFile> files = new LinkedList<>();
List<InputFile> requestFiles = requestConfig.getFileList();
Path baseDir = Paths.get(requestConfig.getBaseDir());
for (InputFile f : requestFiles) {
files.add(new DefaultClientInputFile(baseDir, Paths.get(f.getPath()), f.getIsTest(), Charset.forName(f.getCharset()), f.getUserObject(), trimToNull(f.getLanguage())));
}
StandaloneAnalysisConfiguration config = new StandaloneAnalysisConfiguration(baseDir, Paths.get(requestConfig.getWorkDir()), files, requestConfig.getPropertiesMap());
logOutput.log("Analysis configuration:\n" + config.toString(), Level.DEBUG);
engine.analyze(config, new ProxyIssueListener(response), logOutput, null);
response.onCompleted();
} catch (Exception e) {
LOGGER.error("Error analyzing", e);
response.onError(e);
}
}
use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTest method simplePython.
@Test
public void simplePython() throws Exception {
ClientInputFile inputFile = prepareInputFile("foo.py", "def my_function(name):\n" + " print \"Hello\"\n" + " print \"world!\" # NOSONAR\n" + "\n", false);
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), issue -> issues.add(issue), null, null);
assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path").containsOnly(tuple("python:PrintStatementUsage", 2, inputFile.getPath()));
}
use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTest method simpleJavaWithBytecode.
@Test
public void simpleJavaWithBytecode() throws Exception {
ClientInputFile inputFile = TestUtils.createInputFile(new File("src/test/projects/java-with-bytecode/src/Foo.java").getAbsoluteFile().toPath(), "src/Foo.java", false);
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of("sonar.java.binaries", new File("src/test/projects/java-with-bytecode/bin").getAbsolutePath())), issue -> issues.add(issue), null, null);
assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path").containsOnly(tuple("squid:S106", 5, inputFile.getPath()), tuple("squid:S1220", null, inputFile.getPath()), tuple("squid:UnusedPrivateMethod", 8, inputFile.getPath()), tuple("squid:S1186", 8, inputFile.getPath()));
}
Aggregations