use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonar-web by SonarSource.
the class SonarLintTest method prepareInputFile.
private ClientInputFile prepareInputFile(String relativePath, String content, final boolean isTest) throws IOException {
File file = new File(baseDir, relativePath);
FileUtils.write(file, content, StandardCharsets.UTF_8);
return createInputFile(file.toPath(), isTest);
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonar-java by SonarSource.
the class SonarLintTest method simplePom.
@Test
public void simplePom() throws Exception {
ClientInputFile inputFile = prepareInputFile("pom.xml", "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + " <modelVersion>4.0.0</modelVersion>\n" + " <groupId>org.sonarsource.java</groupId>\n" + " <artifactId>simple-project</artifactId>\n" + " <version>1.0-SNAPSHOT</version>\n" + " <packaging>jar</packaging>\n" + " <properties>" + // S3421 line 7
" <deprecated>${pom.artifactId}</deprecated>\n" + " </properties>\n" + "</project>", false);
final List<Issue> issues = new ArrayList<>();
sonarlintEngine.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Collections.singletonList(inputFile), ImmutableMap.<String, String>of()), issues::add, null, null);
assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S3421", 7, inputFile.getPath(), "MINOR"));
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonar-java by SonarSource.
the class SonarLintTest method simpleJava.
@Test
public void simpleJava() throws Exception {
ClientInputFile inputFile = prepareInputFile("Foo.java", "public class Foo {\n" + " public void foo() {\n" + " int x;\n" + " System.out.println(\"Foo\");\n" + " System.out.println(\"Foo\"); //NOSONAR\n" + " }\n" + "}", false);
final List<Issue> issues = new ArrayList<>();
StandaloneAnalysisConfiguration standaloneAnalysisConfiguration = new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Collections.singletonList(inputFile), ImmutableMap.<String, String>of());
sonarlintEngine.analyze(standaloneAnalysisConfiguration, issues::add, null, null);
assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S106", 4, inputFile.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile.getPath(), "MINOR"), tuple("squid:S1481", 3, inputFile.getPath(), "MINOR"));
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonar-java by SonarSource.
the class SonarLintTest method simpleTestFileJava.
@Test
public void simpleTestFileJava() throws Exception {
ClientInputFile inputFile = prepareInputFile("FooTest.java", "public class FooTest {\n" + " @org.junit.Test\n" + " @org.junit.Ignore\n" + // S1607(ignored test) - requires semantic
" public void testName() throws Exception {\n" + " Foo foo = new Foo();\n" + // S2970(incomplete assertions) - requires semantic
" org.assertj.core.api.Assertions.assertThat(foo.isFooActive());\n" + // S2925(thread.sleep in test)
" java.lang.Thread.sleep(Long.MAX_VALUE);" + " }\n\n" + " private static class Foo {" + " public boolean isFooActive() {" + " return false;" + " }" + " }" + "}", true);
final List<Issue> issues = new ArrayList<>();
sonarlintEngine.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Collections.singletonList(inputFile), ImmutableMap.<String, String>of()), issues::add, null, null);
assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(// tuple("squid:S2970", 6, inputFile.getPath(), "BLOCKER"),
tuple("squid:S2925", 7, inputFile.getPath(), "MAJOR"));
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonar-java by SonarSource.
the class SonarLintTest method prepareInputFile.
private ClientInputFile prepareInputFile(String relativePath, String content, final boolean isTest) throws IOException {
final File file = new File(baseDir, relativePath);
FileUtils.write(file, content, StandardCharsets.UTF_8);
return createInputFile(file.toPath(), isTest);
}
Aggregations