Search in sources :

Example 1 with XooRulesDefinition

use of org.sonar.xoo.rule.XooRulesDefinition in project sonarqube by SonarSource.

the class ScanOnlyChangedTest method prepare.

@Before
public void prepare() throws IOException {
    String filePath = "xources/hello/HelloJava.xoo";
    String md5sum = DigestUtils.md5Hex(FileUtils.readFileToString(new File(Resources.getResource("mediumtest/xoo/sample/" + filePath).getPath())));
    tester = ScannerMediumTester.builder().bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)).registerPlugin("xoo", new XooPlugin()).addDefaultQProfile("xoo", "Sonar Way").addRules(new XooRulesDefinition()).addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", null, "xoo").addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo").addActiveRule("xoo", "OneIssuePerModule", null, "OneIssuePerModule", "MAJOR", null, "xoo").addFileData("sample", filePath, new FileData(md5sum, null)).setPreviousAnalysisDate(new Date()).mockServerIssue(ServerIssue.newBuilder().setKey("xyz").setModuleKey("sample").setMsg("One issue per Line copied").setPath("xources/hello/HelloJava.xoo").setRuleRepository("xoo").setRuleKey("OneIssuePerLine").setLine(1).setSeverity(Severity.MAJOR).setCreationDate(date("14/03/2004")).setChecksum(DigestUtils.md5Hex("packagehello;")).setStatus("OPEN").build()).mockServerIssue(ServerIssue.newBuilder().setKey("resolved-on-project").setModuleKey("sample").setRuleRepository("xoo").setRuleKey("OneIssuePerModule").setSeverity(Severity.CRITICAL).setCreationDate(date("14/03/2004")).setStatus("OPEN").build()).build();
    tester.start();
}
Also used : XooPlugin(org.sonar.xoo.XooPlugin) XooRulesDefinition(org.sonar.xoo.rule.XooRulesDefinition) File(java.io.File) FileData(org.sonar.scanner.repository.FileData) Date(java.util.Date) Before(org.junit.Before)

Example 2 with XooRulesDefinition

use of org.sonar.xoo.rule.XooRulesDefinition 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 3 with XooRulesDefinition

use of org.sonar.xoo.rule.XooRulesDefinition 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 4 with XooRulesDefinition

use of org.sonar.xoo.rule.XooRulesDefinition 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

XooPlugin (org.sonar.xoo.XooPlugin)4 XooRulesDefinition (org.sonar.xoo.rule.XooRulesDefinition)4 File (java.io.File)3 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 InputDir (org.sonar.api.batch.fs.InputDir)2 InputFile (org.sonar.api.batch.fs.InputFile)2 Path (java.nio.file.Path)1 Date (java.util.Date)1 Before (org.junit.Before)1 LogOutputRecorder (org.sonar.scanner.mediumtest.LogOutputRecorder)1 FileData (org.sonar.scanner.repository.FileData)1