use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonar-web by SonarSource.
the class TestHelper method scan.
public static WebSourceCode scan(File file, DefaultNodeVisitor visitor) {
FileReader fileReader;
try {
fileReader = new FileReader(file);
} catch (FileNotFoundException e) {
throw Throwables.propagate(e);
}
WebSourceCode result = new WebSourceCode(new DefaultInputFile("key", file.getPath()).setLanguage(WebConstants.LANGUAGE_KEY).setType(InputFile.Type.MAIN).setModuleBaseDir(new File(".").toPath()));
HtmlAstScanner walker = new HtmlAstScanner(ImmutableList.of(new PageCountLines(), new ComplexityVisitor()));
walker.addVisitor(visitor);
walker.scan(new PageLexer().parse(fileReader), result, Charsets.UTF_8);
return result;
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonar-java by SonarSource.
the class JavaSquidSensorTest method createContext.
private static SensorContextTester createContext(InputFile.Type onType) throws IOException {
SensorContextTester context = SensorContextTester.create(new File("src/test/java/").getAbsoluteFile());
DefaultFileSystem fs = context.fileSystem();
String effectiveKey = "org/sonar/plugins/java/JavaSquidSensorTest.java";
File file = new File(fs.baseDir(), effectiveKey);
DefaultInputFile inputFile = new TestInputFileBuilder("", effectiveKey).setLanguage("java").setModuleBaseDir(fs.baseDirPath()).setType(onType).initMetadata(new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8)).setCharset(StandardCharsets.UTF_8).build();
fs.add(inputFile);
return context;
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonar-java by SonarSource.
the class JavaSquidSensorTest method createParseErrorContext.
private SensorContextTester createParseErrorContext() throws IOException {
File file = new File("src/test/files/ParseError.java");
SensorContextTester context = SensorContextTester.create(file.getParentFile().getAbsoluteFile());
DefaultInputFile defaultFile = new TestInputFileBuilder(file.getParentFile().getPath(), file.getName()).setLanguage("java").initMetadata(new String(Files.readAllBytes(file.getAbsoluteFile().toPath()), StandardCharsets.UTF_8)).setCharset(StandardCharsets.UTF_8).build();
context.fileSystem().add(defaultFile);
return context;
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonar-java by SonarSource.
the class XmlFileSensorTest method test_no_issues_but_xml_file_still_published.
@Test
public void test_no_issues_but_xml_file_still_published() throws Exception {
SensorContextTester context = SensorContextTester.create(new File("src/test/files/maven2/").getAbsoluteFile());
DefaultFileSystem fs = context.fileSystem();
final File file = new File("src/test/files/maven2/pom.xml");
DefaultInputFile inputFile = new TestInputFileBuilder("", "pom.xml").setModuleBaseDir(fs.baseDirPath()).setPublish(false).build();
fs.add(inputFile);
SonarComponents sonarComponents = createSonarComponentsMock(fs, file);
XmlFileSensor sensor = new XmlFileSensor(sonarComponents, fs);
assertThat(inputFile.isPublished()).isFalse();
sensor.execute(context);
assertThat(inputFile.isPublished()).isTrue();
verify(sonarComponents, never()).reportIssue(Mockito.argThat(argument -> file.getAbsolutePath().equals(argument.getFile().getAbsolutePath())));
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonar-java by SonarSource.
the class JavaAstScannerTest method comments.
@Test
public void comments() {
File file = new File("src/test/files/metrics/Comments.java");
DefaultInputFile resource = new TestInputFileBuilder("", "src/test/files/metrics/Comments.java").build();
fs.add(resource);
NoSonarFilter noSonarFilter = mock(NoSonarFilter.class);
JavaAstScanner.scanSingleFileForTests(file, new VisitorsBridge(new Measurer(fs, context, noSonarFilter)));
verify(noSonarFilter).noSonarInFile(resource, ImmutableSet.of(15));
}
Aggregations