use of org.sonar.api.config.Settings in project sonarqube by SonarSource.
the class ExclusionFiltersTest method match_exclusion_by_absolute_path.
@Test
public void match_exclusion_by_absolute_path() throws IOException {
File excludedFile = new File(moduleBaseDir.toString(), "src/main/java/org/bar/Bar.java");
Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "src/main/java/**/*");
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "file:" + excludedFile.getAbsolutePath());
ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
filter.prepare();
IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/org/bar/Foo.java");
assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isTrue();
indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/org/bar/Bar.java");
assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isFalse();
}
use of org.sonar.api.config.Settings in project sonarqube by SonarSource.
the class InputFileBuilderTest method setUp.
@Before
public void setUp() throws IOException {
baseDir = temp.newFolder().toPath();
DefaultInputModule module = new DefaultInputModule(ProjectDefinition.create().setKey("module1").setBaseDir(baseDir.toFile()), 0);
PathResolver pathResolver = new PathResolver();
LanguageDetection langDetection = mock(LanguageDetection.class);
MetadataGenerator metadataGenerator = mock(MetadataGenerator.class);
BatchIdGenerator idGenerator = new BatchIdGenerator();
Settings settings = new MapSettings();
builder = new InputFileBuilder(module, pathResolver, langDetection, metadataGenerator, idGenerator, settings);
}
use of org.sonar.api.config.Settings in project sonarqube by SonarSource.
the class LanguageDetectionTest method solve_conflict_using_filepattern.
@Test
public void solve_conflict_using_filepattern() throws Exception {
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml")));
Settings settings = new MapSettings();
settings.setProperty("sonar.lang.patterns.xml", "xml/**");
settings.setProperty("sonar.lang.patterns.web", "web/**");
LanguageDetection detection = new LanguageDetection(settings, languages);
assertThat(detection.language(newIndexedFile("xml/abc.xhtml"))).isEqualTo("xml");
assertThat(detection.language(newIndexedFile("web/abc.xhtml"))).isEqualTo("web");
}
use of org.sonar.api.config.Settings in project sonarqube by SonarSource.
the class LanguageDetectionTest method fail_if_invalid_language.
@Test
public void fail_if_invalid_language() {
thrown.expect(MessageException.class);
thrown.expectMessage("You must install a plugin that supports the language 'unknown'");
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php")));
Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "unknown");
new LanguageDetection(settings, languages);
}
use of org.sonar.api.config.Settings in project sonarqube by SonarSource.
the class LanguageDetectionTest method fail_if_conflicting_filepattern.
@Test
public void fail_if_conflicting_filepattern() throws Exception {
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap"), new MockLanguage("cobol", "cobol")));
Settings settings = new MapSettings();
settings.setProperty("sonar.lang.patterns.abap", "*.abap,*.txt");
settings.setProperty("sonar.lang.patterns.cobol", "*.cobol,*.txt");
LanguageDetection detection = new LanguageDetection(settings, languages);
assertThat(detection.language(newIndexedFile("abc.abap"))).isEqualTo("abap");
assertThat(detection.language(newIndexedFile("abc.cobol"))).isEqualTo("cobol");
try {
detection.language(newIndexedFile("abc.txt"));
fail();
} catch (MessageException e) {
assertThat(e.getMessage()).contains("Language of file 'abc.txt' can not be decided as the file matches patterns of both ").contains("sonar.lang.patterns.abap : *.abap,*.txt").contains("sonar.lang.patterns.cobol : *.cobol,*.txt");
}
}
Aggregations