use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonar-web by SonarSource.
the class TestHelper method scan.
public static HtmlSourceCode scan(File file, DefaultNodeVisitor visitor) {
FileReader fileReader;
try {
fileReader = new FileReader(file);
} catch (FileNotFoundException e) {
throw new IllegalStateException(e);
}
HtmlSourceCode result = new HtmlSourceCode(new TestInputFileBuilder("key", file.getPath()).setLanguage(HtmlConstants.LANGUAGE_KEY).setType(InputFile.Type.MAIN).setModuleBaseDir(new File(".").toPath()).setCharset(StandardCharsets.UTF_8).build());
HtmlAstScanner walker = new HtmlAstScanner(Arrays.asList(new PageCountLines(), new ComplexityVisitor()));
walker.addVisitor(visitor);
walker.scan(new PageLexer().parse(fileReader), result);
return result;
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class SourcePublisherTest method prepare.
@Before
public void prepare() throws IOException {
File baseDir = temp.newFolder();
sourceFile = new File(baseDir, "src/Foo.php");
String moduleKey = "foo";
inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setLines(5).setModuleBaseDir(baseDir.toPath()).setCharset(StandardCharsets.ISO_8859_1).build();
DefaultInputProject rootProject = TestInputFileBuilder.newDefaultInputProject(moduleKey, baseDir);
InputComponentStore componentStore = new InputComponentStore(mock(BranchConfiguration.class), mock(SonarRuntime.class));
componentStore.put(moduleKey, inputFile);
publisher = new SourcePublisher(componentStore);
File outputDir = temp.newFolder();
writer = new ScannerReportWriter(outputDir);
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class ComponentsPublisherTest method publish_unchanged_components_even_in_prs.
@Test
public void publish_unchanged_components_even_in_prs() throws IOException {
when(branchConfiguration.isPullRequest()).thenReturn(true);
ProjectInfo projectInfo = mock(ProjectInfo.class);
when(projectInfo.getAnalysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
Path baseDir = temp.newFolder().toPath();
ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo").setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0").setName("Root project").setDescription("Root description").setBaseDir(baseDir.toFile()).setWorkDir(temp.newFolder());
DefaultInputProject project = new DefaultInputProject(rootDef, 1);
InputComponentStore store = new InputComponentStore(branchConfiguration, sonarRuntime);
DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.java", 5).setLines(2).setPublish(true).setStatus(InputFile.Status.ADDED).build();
store.put("foo", file);
DefaultInputFile file2 = new TestInputFileBuilder("foo", "src2/Foo2.java", 6).setPublish(true).setStatus(InputFile.Status.SAME).setLines(2).build();
store.put("foo", file2);
ComponentsPublisher publisher = new ComponentsPublisher(project, store);
publisher.publish(writer);
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 5)).isTrue();
// do not skip, needed for computing overall coverage
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 6)).isTrue();
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class GenericTestExecutionReportParserTest method file_without_language_should_be_skipped.
@Test
public void file_without_language_should_be_skipped() throws Exception {
String filePath = "src/main/java/com/example/EmptyClass.java";
DefaultInputFile file = new TestInputFileBuilder(context.module().key(), filePath).setLanguage(null).setType(InputFile.Type.TEST).initMetadata("1\n2\n3\n4\n5\n6").build();
addFileToFs(file);
GenericTestExecutionReportParser parser = parseReportFile("unittest.xml");
assertThat(parser.numberOfMatchedFiles()).isZero();
assertThat(parser.numberOfUnknownFiles()).isEqualTo(2);
assertThat(parser.firstUnknownFiles()).hasSize(2);
assertThat(logs.logs()).contains("Skipping file 'src/main/java/com/example/EmptyClass.java' in the generic test execution report because it doesn't have a known language");
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class SvnBlameCommandTest method shouldNotFailIfFileContainsLocalModification.
@Test
public void shouldNotFailIfFileContainsLocalModification() throws Exception {
File repoDir = unzip("repo-svn.zip");
String scmUrl = "file:///" + unixPath(new File(repoDir, "repo-svn"));
File baseDir = new File(checkout(scmUrl), "dummy-svn");
when(fs.baseDir()).thenReturn(baseDir);
DefaultInputFile inputFile = new TestInputFileBuilder("foo", DUMMY_JAVA).setLines(28).setModuleBaseDir(baseDir.toPath()).build();
Files.write(baseDir.toPath().resolve(DUMMY_JAVA), "\n//foo".getBytes(), StandardOpenOption.APPEND);
BlameOutput blameResult = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(singletonList(inputFile));
newSvnBlameCommand().blame(input, blameResult);
verifyNoInteractions(blameResult);
}
Aggregations