Search in sources :

Example 1 with ScannerMediumTester

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

the class FileSystemMediumTest method publishFilesWithIssues.

@Test
public void publishFilesWithIssues() throws IOException {
    ScannerMediumTester tester2 = ScannerMediumTester.builder().registerPlugin("xoo", new XooPlugin()).addDefaultQProfile("xoo", "Sonar Way").addRules(new XooRulesDefinition()).addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo").build();
    tester2.start();
    builder = createBuilder();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile, "Sample xoo\ncontent");
    TaskResult result = tester2.newTask().properties(builder.put("sonar.sources", "src").build()).start();
    DefaultInputFile file = (DefaultInputFile) result.inputFile("src/sample.xoo");
    InputDir dir = result.inputDir("src");
    assertThat(file.publish()).isTrue();
    assertThat(result.getReportComponent(dir.key())).isNotNull();
    assertThat(result.getReportComponent(file.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) InputDir(org.sonar.api.batch.fs.InputDir) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 2 with ScannerMediumTester

use of org.sonar.scanner.mediumtest.ScannerMediumTester 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 3 with ScannerMediumTester

use of org.sonar.scanner.mediumtest.ScannerMediumTester 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)3 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)3 ScannerMediumTester (org.sonar.scanner.mediumtest.ScannerMediumTester)3 TaskResult (org.sonar.scanner.mediumtest.TaskResult)3 XooPlugin (org.sonar.xoo.XooPlugin)3 XooRulesDefinition (org.sonar.xoo.rule.XooRulesDefinition)3 File (java.io.File)2 InputDir (org.sonar.api.batch.fs.InputDir)2 InputFile (org.sonar.api.batch.fs.InputFile)2 Path (java.nio.file.Path)1 LogOutputRecorder (org.sonar.scanner.mediumtest.LogOutputRecorder)1