use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.
the class InputFileBuilder method create.
@CheckForNull
DefaultInputFile create(Path file, InputFile.Type type, Charset defaultEncoding) {
String relativePath = pathResolver.relativePath(moduleBaseDir, file);
if (relativePath == null) {
LOG.warn("File '{}' is ignored. It is not located in module basedir '{}'.", file.toAbsolutePath(), moduleBaseDir);
return null;
}
DefaultIndexedFile indexedFile = new DefaultIndexedFile(moduleKey, moduleBaseDir, relativePath, type, idGenerator.get());
String language = langDetection.language(indexedFile);
if (language == null && langDetection.forcedLanguage() != null) {
LOG.warn("File '{}' is ignored because it doens't belong to the forced langauge '{}'", file.toAbsolutePath(), langDetection.forcedLanguage());
return null;
}
indexedFile.setLanguage(language);
DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> metadataGenerator.setMetadata(f, defaultEncoding));
if (language != null) {
inputFile.setPublish(true);
}
return inputFile;
}
use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.
the class ExclusionFiltersTest method match_inclusion.
@Test
public void match_inclusion() throws IOException {
Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java");
ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
filter.prepare();
IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java");
assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isTrue();
indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/Foo.java");
assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isFalse();
}
use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.
the class DefaultInputFileTest method test_equals_and_hashcode.
@Test
public void test_equals_and_hashcode() {
DefaultInputFile f1 = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class));
DefaultInputFile f1a = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class));
DefaultInputFile f2 = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), "src/Bar.php", null), (f) -> mock(Metadata.class));
assertThat(f1).isEqualTo(f1).isEqualTo(f1a).isNotEqualTo(f2);
assertThat(f1.equals("foo")).isFalse();
assertThat(f1.equals(null)).isFalse();
assertThat(f1).hasSameHashCodeAs(f1).hasSameHashCodeAs(f1a);
}
use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.
the class DefaultInputFileTest method prepare.
@Before
public void prepare() throws IOException {
baseDir = temp.newFolder().toPath();
sensorStrategy = new SensorStrategy();
indexedFile = new DefaultIndexedFile(baseDir.resolve(PROJECT_RELATIVE_PATH), "ABCDE", PROJECT_RELATIVE_PATH, MODULE_RELATIVE_PATH, InputFile.Type.TEST, "php", 0, sensorStrategy);
}
use of org.sonar.api.batch.fs.internal.DefaultIndexedFile in project sonarqube by SonarSource.
the class DefaultInputFileTest method test_toString.
@Test
public void test_toString() {
DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class));
assertThat(file.toString()).isEqualTo(MODULE_RELATIVE_PATH);
}
Aggregations