use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class ComponentKeysTest method create_effective_key.
@Test
public void create_effective_key() {
Project project = new Project(ProjectDefinition.create().setKey("my_project"));
assertThat(ComponentKeys.createEffectiveKey("my_project", project)).isEqualTo("my_project");
Directory dir = Directory.create("src/org/foo");
assertThat(ComponentKeys.createEffectiveKey("my_project", dir)).isEqualTo("my_project:src/org/foo");
InputFile file = mock(InputFile.class);
when(file.relativePath()).thenReturn("foo/Bar.php");
assertThat(ComponentKeys.createEffectiveKey("my_project", file)).isEqualTo("my_project:foo/Bar.php");
}
use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class DefaultInputFileTest method test.
@Test
public void test() throws Exception {
Path baseDir = temp.newFolder().toPath();
Metadata metadata = new Metadata(42, 42, "", new int[0], 0);
DefaultIndexedFile indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/Foo.php", InputFile.Type.TEST, 0).setLanguage("php");
DefaultInputFile inputFile = new DefaultInputFile(indexedFile, (f) -> f.setMetadata(metadata)).setStatus(InputFile.Status.ADDED).setCharset(StandardCharsets.ISO_8859_1);
assertThat(inputFile.relativePath()).isEqualTo("src/Foo.php");
assertThat(new File(inputFile.relativePath())).isRelative();
assertThat(inputFile.absolutePath()).endsWith("Foo.php");
assertThat(new File(inputFile.absolutePath())).isAbsolute();
assertThat(inputFile.language()).isEqualTo("php");
assertThat(inputFile.status()).isEqualTo(InputFile.Status.ADDED);
assertThat(inputFile.type()).isEqualTo(InputFile.Type.TEST);
assertThat(inputFile.lines()).isEqualTo(42);
assertThat(inputFile.charset()).isEqualTo(StandardCharsets.ISO_8859_1);
}
use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class FilenamePredicateTest method should_find_matching_file_in_index.
@Test
public void should_find_matching_file_in_index() throws IOException {
String filename = "some name";
InputFile inputFile = mock(InputFile.class);
when(inputFile.file()).thenReturn(newDummyFile(filename));
FileSystem.Index index = mock(FileSystem.Index.class);
when(index.getFilesByName(filename)).thenReturn(Collections.singleton(inputFile));
assertThat(new FilenamePredicate(filename).get(index)).containsOnly(inputFile);
}
use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class DefaultCpdBlockIndexer method populateIndex.
private void populateIndex(String languageKey, List<InputFile> sourceFiles, CpdMapping mapping) {
TokenizerBridge bridge = new TokenizerBridge(mapping.getTokenizer(), fs.encoding().name(), getBlockSize(languageKey));
for (InputFile inputFile : sourceFiles) {
if (!index.isIndexed(inputFile)) {
LOG.debug("Populating index from {}", inputFile.absolutePath());
String resourceEffectiveKey = ((DefaultInputFile) inputFile).key();
List<Block> blocks = bridge.chunk(resourceEffectiveKey, inputFile.file());
index.insert(inputFile, blocks);
}
}
}
use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class DefaultCpdBlockIndexer method index.
@Override
public void index(String languageKey) {
CpdMapping mapping = mappings.getMapping(languageKey);
if (mapping == null) {
LOG.debug("No CpdMapping for language {}", languageKey);
return;
}
String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS);
logExclusions(cpdExclusions);
FilePredicates p = fs.predicates();
List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(p.and(p.hasType(InputFile.Type.MAIN), p.hasLanguage(languageKey), p.doesNotMatchPathPatterns(cpdExclusions))));
if (sourceFiles.isEmpty()) {
return;
}
// Create index
populateIndex(languageKey, sourceFiles, mapping);
}
Aggregations