use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class JSONReportTest method before.
@Before
public void before() throws Exception {
moduleHierarchy = mock(InputModuleHierarchy.class);
userRepository = mock(UserRepositoryLoader.class);
File projectBaseDir = temp.newFolder();
fs = new DefaultFileSystem(projectBaseDir.toPath());
SIMPLE_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+02:00"));
when(server.getVersion()).thenReturn("3.6");
InputComponentStore inputComponentStore = new InputComponentStore(new PathResolver());
DefaultComponentTree inputComponentTree = new DefaultComponentTree();
DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create().setBaseDir(projectBaseDir).setKey("struts"), 1);
inputComponentStore.put(rootModule);
DefaultInputModule moduleA = new DefaultInputModule("struts-core");
inputComponentTree.index(moduleA, rootModule);
DefaultInputModule moduleB = new DefaultInputModule("struts-ui");
inputComponentTree.index(moduleB, rootModule);
DefaultInputDir inputDir = new DefaultInputDir("struts", "src/main/java/org/apache/struts", TestInputFileBuilder.nextBatchId()).setModuleBaseDir(projectBaseDir.toPath());
DefaultInputFile inputFile = new TestInputFileBuilder("struts", "src/main/java/org/apache/struts/Action.java").setModuleBaseDir(projectBaseDir.toPath()).build();
inputFile.setStatus(InputFile.Status.CHANGED);
inputFile.setPublish(true);
inputComponentStore.put(inputFile);
inputComponentStore.put(inputDir);
inputComponentTree.index(inputDir, rootModule);
inputComponentTree.index(inputFile, inputDir);
when(moduleHierarchy.children(rootModule)).thenReturn(Arrays.asList(moduleA, moduleB));
when(moduleHierarchy.parent(moduleA)).thenReturn(rootModule);
when(moduleHierarchy.parent(moduleB)).thenReturn(rootModule);
when(moduleHierarchy.relativePath(moduleA)).thenReturn("core");
when(moduleHierarchy.relativePath(moduleB)).thenReturn("ui");
RulesBuilder builder = new RulesBuilder();
builder.add(RuleKey.of("squid", "AvoidCycles")).setName("Avoid Cycles");
rules = builder.build();
jsonReport = new JSONReport(moduleHierarchy, settings, fs, server, rules, issueCache, rootModule, inputComponentStore, userRepository, inputComponentTree);
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class DefaultHighlightableTest method should_store_highlighting_rules.
@Test
public void should_store_highlighting_rules() {
SensorStorage sensorStorage = mock(SensorStorage.class);
DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.php").initMetadata("azerty\nbla bla").build();
DefaultHighlightable highlightablePerspective = new DefaultHighlightable(inputFile, sensorStorage, mock(AnalysisMode.class));
highlightablePerspective.newHighlighting().highlight(0, 6, "k").highlight(7, 10, "cppd").done();
ArgumentCaptor<DefaultHighlighting> argCaptor = ArgumentCaptor.forClass(DefaultHighlighting.class);
verify(sensorStorage).store(argCaptor.capture());
assertThat(argCaptor.getValue().getSyntaxHighlightingRuleSet()).hasSize(2);
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarlint-core by SonarSource.
the class AdditionalFilePredicatesTest method key.
@Test
public void key() {
FilePredicate predicate = new AdditionalFilePredicates.KeyPredicate("struts:Action.java");
DefaultInputFile inputFile = new TestInputFileBuilder("struts", "Action.java").build();
assertThat(predicate.apply(inputFile)).isTrue();
inputFile = new TestInputFileBuilder("struts", "Filter.java").build();
assertThat(predicate.apply(inputFile)).isFalse();
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonar-web by SonarSource.
the class PageCountLinesTest method testCountLinesHtmlFile.
@Test
public void testCountLinesHtmlFile() throws FileNotFoundException {
List<Node> nodeList = lexer.parse(new FileReader(TestUtils.getResource("checks/AvoidHtmlCommentCheck/document.html")));
String relativePath = "test/document.html";
WebSourceCode webSourceCode = new WebSourceCode(new DefaultInputFile("key", relativePath).setModuleBaseDir(new File(".").toPath()));
scanner.scan(nodeList, webSourceCode, Charsets.UTF_8);
assertThat(webSourceCode.getMeasure(CoreMetrics.NCLOC)).isEqualTo(8);
assertThat(webSourceCode.getDetailedLinesOfCode()).containsOnly(1, 2, 3, 4, 6, 7, 8, 9);
assertThat(webSourceCode.getMeasure(CoreMetrics.COMMENT_LINES)).isEqualTo(1);
assertThat(webSourceCode.getDetailedLinesOfComments()).containsOnly(5);
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonar-web by SonarSource.
the class PageCountLinesTest method testCountLines.
@Test
public void testCountLines() throws FileNotFoundException {
java.io.File file = TestUtils.getResource("src/main/webapp/user-properties.jsp");
List<Node> nodeList = lexer.parse(new FileReader(file));
assertThat(nodeList.size()).isGreaterThan(100);
// new File("test", "user-properties.jsp");
String relativePath = "test/user-properties.jsp";
WebSourceCode webSourceCode = new WebSourceCode(new DefaultInputFile("key", relativePath).setModuleBaseDir(new File(".").toPath()));
scanner.scan(nodeList, webSourceCode, Charsets.UTF_8);
assertThat(webSourceCode.getMeasure(CoreMetrics.NCLOC)).isEqualTo(227);
assertThat(webSourceCode.getDetailedLinesOfCode().size()).isEqualTo(224);
assertThat(webSourceCode.getMeasure(CoreMetrics.COMMENT_LINES)).isEqualTo(14);
assertThat(webSourceCode.getDetailedLinesOfComments().size()).isEqualTo(14);
}
Aggregations