Search in sources :

Example 41 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class DeprecatedApiMediumTest method testIssueDetails.

@Test
public void testIssueDetails() throws IOException {
    File baseDir = temp.getRoot();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFileInRootDir = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFileInRootDir, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
    File xooFileInAnotherDir = new File(srcDir, "package/sample.xoo");
    FileUtils.write(xooFileInAnotherDir, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
    TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").build()).start();
    assertThat(result.issuesFor(result.inputFile("src/sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly(tuple("Issue created using deprecated API", 0), tuple("Issue created using deprecated API", 1));
    assertThat(result.issuesFor(result.inputFile("src/package/sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly(tuple("Issue created using deprecated API", 0), tuple("Issue created using deprecated API", 1));
    assertThat(result.issuesFor(result.inputDir("src"))).extracting("msg", "textRange.startLine").containsOnly(tuple("Issue created using deprecated API", 0));
    assertThat(result.issuesFor(result.inputDir("src/package"))).extracting("msg", "textRange.startLine").containsOnly(tuple("Issue created using deprecated API", 0));
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) Test(org.junit.Test)

Example 42 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class FileSystemMediumTest method publishDirsWithIssues.

@Test
public void publishDirsWithIssues() throws IOException {
    ScannerMediumTester tester2 = ScannerMediumTester.builder().registerPlugin("xoo", new XooPlugin()).addDefaultQProfile("xoo", "Sonar Way").addRules(new XooRulesDefinition()).addActiveRule("xoo", "OneIssuePerDirectory", null, "OneIssuePerDirectory", "MAJOR", null, "xoo").build();
    tester2.start();
    builder = ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.verbose", "true").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project");
    Path unknownRelative = Paths.get("src/unknown/file.notanalyzed");
    Path unknown = baseDir.toPath().resolve(unknownRelative);
    Files.createDirectories(unknown.getParent());
    Files.write(unknown, "dummy content".getBytes());
    Path emptyDirRelative = Paths.get("src/emptydir");
    Files.createDirectories(emptyDirRelative);
    TaskResult result = tester2.newTask().properties(builder.put("sonar.sources", "src").build()).start();
    DefaultInputFile unknownInputFile = (DefaultInputFile) result.inputFile(unknownRelative.toString());
    InputDir unknownInputDir = result.inputDir(unknownRelative.getParent().toString());
    assertThat(unknownInputFile.publish()).isFalse();
    assertThat(result.getReportComponent(unknownInputDir.key())).isNotNull();
    // no issues on empty dir
    InputDir emptyInputDir = result.inputDir(emptyDirRelative.toString());
    assertThat(emptyInputDir).isNull();
    // no issues on parent dir
    InputDir parentInputDir = result.inputDir(unknownRelative.getParent().getParent().toString());
    assertThat(parentInputDir).isNull();
    tester2.stop();
}
Also used : Path(java.nio.file.Path) XooPlugin(org.sonar.xoo.XooPlugin) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) XooRulesDefinition(org.sonar.xoo.rule.XooRulesDefinition) ScannerMediumTester(org.sonar.scanner.mediumtest.ScannerMediumTester) TaskResult(org.sonar.scanner.mediumtest.TaskResult) InputDir(org.sonar.api.batch.fs.InputDir) Test(org.junit.Test)

Example 43 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class FileSystemMediumTest method indexAnyFile.

@Test
public void indexAnyFile() throws IOException {
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile, "Sample xoo\ncontent");
    File otherFile = new File(srcDir, "sample.other");
    FileUtils.write(otherFile, "Sample other\ncontent");
    TaskResult result = tester.newTask().properties(builder.put("sonar.sources", "src").build()).start();
    assertThat(result.inputFiles()).hasSize(2);
    assertThat(result.inputFile("src/sample.other").type()).isEqualTo(InputFile.Type.MAIN);
    assertThat(result.inputFile("src/sample.other").relativePath()).isEqualTo("src/sample.other");
    assertThat(result.inputFile("src/sample.other").language()).isNull();
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 44 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class FileSystemMediumTest method scanProjectWithMixedSourcesAndTests.

/**
   * SONAR-5419
   */
@Test
public void scanProjectWithMixedSourcesAndTests() throws IOException {
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile, "Sample xoo\ncontent");
    File xooFile2 = new File(baseDir, "another.xoo");
    FileUtils.write(xooFile2, "Sample xoo 2\ncontent");
    File testDir = new File(baseDir, "test");
    testDir.mkdir();
    File xooTestFile = new File(baseDir, "sampleTest2.xoo");
    FileUtils.write(xooTestFile, "Sample test xoo\ncontent");
    File xooTestFile2 = new File(testDir, "sampleTest.xoo");
    FileUtils.write(xooTestFile2, "Sample test xoo 2\ncontent");
    TaskResult result = tester.newTask().properties(builder.put("sonar.sources", "src,another.xoo").put("sonar.tests", "test,sampleTest2.xoo").build()).start();
    assertThat(result.inputFiles()).hasSize(4);
    assertThat(result.inputDirs()).hasSize(3);
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 45 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class FileSystemMediumTest method createIssueOnAnyFile.

@Test
public void createIssueOnAnyFile() throws IOException {
    LogOutputRecorder logs = new LogOutputRecorder();
    ScannerMediumTester tester2 = ScannerMediumTester.builder().registerPlugin("xoo", new XooPlugin()).addDefaultQProfile("xoo", "Sonar Way").addRules(new XooRulesDefinition()).setLogOutput(logs).addActiveRule("xoo", "OneIssuePerUnknownFile", null, "OneIssuePerUnknownFile", "MAJOR", null, "xoo").build();
    tester2.start();
    builder = createBuilder();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.unknown");
    FileUtils.write(xooFile, "Sample xoo\ncontent");
    TaskResult result = tester2.newTask().properties(builder.put("sonar.sources", "src").build()).start();
    assertThat(logs.getAllAsString()).contains("1 file indexed");
    assertThat(logs.getAllAsString()).contains("'src/sample.unknown' indexed with language 'null'");
    assertThat(logs.getAllAsString()).contains("'src/sample.unknown' generated metadata");
    DefaultInputFile javaInputFile = (DefaultInputFile) result.inputFile("src/sample.unknown");
    assertThat(result.getReportComponent(javaInputFile.key())).isNotNull();
    tester2.stop();
}
Also used : XooPlugin(org.sonar.xoo.XooPlugin) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) XooRulesDefinition(org.sonar.xoo.rule.XooRulesDefinition) ScannerMediumTester(org.sonar.scanner.mediumtest.ScannerMediumTester) TaskResult(org.sonar.scanner.mediumtest.TaskResult) LogOutputRecorder(org.sonar.scanner.mediumtest.LogOutputRecorder) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)61 TaskResult (org.sonar.scanner.mediumtest.TaskResult)61 File (java.io.File)59 InputFile (org.sonar.api.batch.fs.InputFile)31 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)21 List (java.util.List)8 Issue (org.sonar.scanner.protocol.output.ScannerReport.Issue)7 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)6 Path (java.nio.file.Path)3 InputDir (org.sonar.api.batch.fs.InputDir)3 ScannerMediumTester (org.sonar.scanner.mediumtest.ScannerMediumTester)3 XooPlugin (org.sonar.xoo.XooPlugin)3 XooRulesDefinition (org.sonar.xoo.rule.XooRulesDefinition)3 TrackedIssue (org.sonar.scanner.issue.tracking.TrackedIssue)2 Date (java.util.Date)1 LogOutputRecorder (org.sonar.scanner.mediumtest.LogOutputRecorder)1