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));
}
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();
}
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();
}
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);
}
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();
}
Aggregations