use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class InputComponentStoreTest method should_add_input_file.
@Test
public void should_add_input_file() throws Exception {
InputComponentStore cache = new InputComponentStore(new PathResolver());
String rootModuleKey = "struts";
File rootBaseDir = temp.newFolder();
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootModuleKey, rootBaseDir);
cache.put(rootModule);
String subModuleKey = "struts-core";
DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(subModuleKey, temp.newFolder());
rootModule.definition().addSubProject(subModule.definition());
cache.put(subModule);
DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java").setModuleBaseDir(rootBaseDir.toPath()).setPublish(true).build();
cache.put(fooFile);
cache.put(new TestInputFileBuilder(subModuleKey, "src/main/java/Bar.java").setLanguage("bla").setPublish(false).setType(Type.MAIN).setStatus(Status.ADDED).setLines(2).setCharset(StandardCharsets.UTF_8).setModuleBaseDir(temp.newFolder().toPath()).build());
DefaultInputFile loadedFile = (DefaultInputFile) cache.getFile(subModuleKey, "src/main/java/Bar.java");
assertThat(loadedFile.relativePath()).isEqualTo("src/main/java/Bar.java");
assertThat(loadedFile.charset()).isEqualTo(StandardCharsets.UTF_8);
assertThat(cache.filesByModule(rootModuleKey)).hasSize(1);
assertThat(cache.filesByModule(subModuleKey)).hasSize(1);
assertThat(cache.allFiles()).hasSize(2);
for (InputPath inputPath : cache.allFiles()) {
assertThat(inputPath.relativePath()).startsWith("src/main/java/");
}
List<InputFile> toPublish = new LinkedList<>();
cache.allFilesToPublish().forEach(toPublish::add);
assertThat(toPublish).containsExactly(fooFile);
cache.remove(fooFile);
assertThat(cache.allFiles()).hasSize(1);
cache.removeModule(rootModuleKey);
assertThat(cache.filesByModule(rootModuleKey)).hasSize(0);
assertThat(cache.filesByModule(subModuleKey)).hasSize(1);
assertThat(cache.allFiles()).hasSize(1);
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class DefaultSymbolizableTest method should_update_cache_when_done.
@Test
public void should_update_cache_when_done() {
DefaultSensorStorage sensorStorage = mock(DefaultSensorStorage.class);
DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.php").initMetadata(Strings.repeat("azerty\n", 20)).build();
DefaultSymbolizable symbolPerspective = new DefaultSymbolizable(inputFile, sensorStorage, mock(AnalysisMode.class));
Symbolizable.SymbolTableBuilder symbolTableBuilder = symbolPerspective.newSymbolTableBuilder();
Symbol firstSymbol = symbolTableBuilder.newSymbol(4, 8);
symbolTableBuilder.newReference(firstSymbol, 12);
symbolTableBuilder.newReference(firstSymbol, 70);
Symbol otherSymbol = symbolTableBuilder.newSymbol(25, 33);
symbolTableBuilder.newReference(otherSymbol, 44);
symbolTableBuilder.newReference(otherSymbol, 60);
symbolTableBuilder.newReference(otherSymbol, 108);
Symbolizable.SymbolTable symbolTable = symbolTableBuilder.build();
symbolPerspective.setSymbolTable(symbolTable);
ArgumentCaptor<DefaultSymbolTable> argCaptor = ArgumentCaptor.forClass(DefaultSymbolTable.class);
verify(sensorStorage).store(argCaptor.capture());
// Map<Symbol, Set<TextRange>>
assertThat(argCaptor.getValue().getReferencesBySymbol().keySet()).hasSize(2);
}
Aggregations