private static final String WARNING_ALIAS_PROPERTY_USAGE = "Use of %s detected. While being taken into account, the only supported property is %s." +
" Consider updating your configuration.";
- private static final String WARNING_LEGACY_AND_ALIAS_PROPERTIES_USAGE =
- "Use of %s and %s at the same time. %s is taken into account. Consider updating your configuration";
+ private static final String WARNING_LEGACY_AND_ALIAS_PROPERTIES_USAGE = "Use of %s and %s at the same time. %s is taken into account. Consider updating your configuration";
private final AnalysisWarnings analysisWarnings;
private final String[] sourceInclusions;
protected AbstractExclusionFilters(AnalysisWarnings analysisWarnings, Function<String, String[]> configProvider) {
this.analysisWarnings = analysisWarnings;
+
this.sourceInclusions = inclusions(configProvider, CoreProperties.PROJECT_INCLUSIONS_PROPERTY);
- this.sourceExclusions = exclusions(configProvider, CoreProperties.GLOBAL_EXCLUSIONS_PROPERTY, CoreProperties.PROJECT_EXCLUSIONS_PROPERTY);
+ this.sourceExclusions = initSourceExclusions(configProvider);
+ this.testInclusions = initTestInclusions(configProvider);
+ this.testExclusions = initTestExclusions(configProvider);
+ this.mainInclusionsPattern = prepareMainInclusions(this.sourceInclusions);
+ this.mainExclusionsPattern = prepareMainExclusions(this.sourceExclusions, this.testInclusions);
+ this.testInclusionsPattern = prepareTestInclusions(this.testInclusions);
+ this.testExclusionsPattern = prepareTestExclusions(this.testExclusions);
+ }
+
+ private String[] initSourceExclusions(Function<String, String[]> configProvider) {
+ String[] projectSourceExclusion = exclusions(configProvider, CoreProperties.PROJECT_EXCLUSIONS_PROPERTY);
+ String[] globalSourceExclusion = exclusions(configProvider, CoreProperties.GLOBAL_EXCLUSIONS_PROPERTY);
+ return Stream.concat(Arrays.stream(projectSourceExclusion), Arrays.stream(globalSourceExclusion))
+ .map(String::trim)
+ .toArray(String[]::new);
+ }
+
+ private String[] initTestInclusions(Function<String, String[]> configProvider) {
String[] testInclusionsFromLegacy = inclusions(configProvider, PROJECT_TEST_INCLUSIONS_PROPERTY);
String[] testInclusionsFromAlias = inclusions(configProvider, PROJECT_TESTS_INCLUSIONS_PROPERTY);
- this.testInclusions = keepInclusionTestBetweenLegacyAndAliasProperties(testInclusionsFromLegacy, testInclusionsFromAlias);
- String[] testExclusionsFromLegacy = exclusions(configProvider, CoreProperties.GLOBAL_TEST_EXCLUSIONS_PROPERTY, PROJECT_TEST_EXCLUSIONS_PROPERTY);
- String[] testExclusionsFromAlias = exclusions(configProvider, CoreProperties.GLOBAL_TEST_EXCLUSIONS_PROPERTY, PROJECT_TESTS_EXCLUSIONS_PROPERTY);
- this.testExclusions = keepExclusionTestBetweenLegacyAndAliasProperties(testExclusionsFromLegacy, testExclusionsFromAlias);
+ return keepInclusionTestBetweenLegacyAndAliasProperties(testInclusionsFromLegacy, testInclusionsFromAlias);
+ }
- this.mainInclusionsPattern = prepareMainInclusions(sourceInclusions);
- this.mainExclusionsPattern = prepareMainExclusions(sourceExclusions, this.testInclusions);
- this.testInclusionsPattern = prepareTestInclusions(this.testInclusions);
- this.testExclusionsPattern = prepareTestExclusions(this.testExclusions);
+ private String[] initTestExclusions(Function<String, String[]> configProvider) {
+ String[] testExclusionsFromLegacy = exclusions(configProvider, CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY);
+ String[] testExclusionsFromAlias = exclusions(configProvider, CoreProperties.PROJECT_TESTS_EXCLUSIONS_PROPERTY);
+ String[] testExclusionsKept = keepExclusionTestBetweenLegacyAndAliasProperties(testExclusionsFromLegacy, testExclusionsFromAlias);
+
+ String[] testExclusionsFromGlobal = exclusions(configProvider, CoreProperties.GLOBAL_TEST_EXCLUSIONS_PROPERTY);
+ return Stream.concat(Arrays.stream(testExclusionsKept), Arrays.stream(testExclusionsFromGlobal))
+ .map(String::trim)
+ .toArray(String[]::new);
}
private String[] keepExclusionTestBetweenLegacyAndAliasProperties(String[] fromLegacyProperty, String[] fromAliasProperty) {
return fromLegacyProperty;
}
- private void logWarningForAliasUsage(String legacyProperty, String aliasProperty) {
+ private void logWarningForAliasUsage(String legacyProperty, String aliasProperty) {
logWarning(format(WARNING_ALIAS_PROPERTY_USAGE, aliasProperty, legacyProperty));
}
.toArray(String[]::new);
}
- private String[] exclusions(Function<String, String[]> configProvider, String globalExclusionsProperty, String exclusionsProperty) {
- String[] globalExclusions = configProvider.apply(globalExclusionsProperty);
- String[] exclusions = configProvider.apply(exclusionsProperty);
- return Stream.concat(Arrays.stream(globalExclusions), Arrays.stream(exclusions))
+ private String[] exclusions(Function<String, String[]> configProvider, String property) {
+ String[] exclusions = configProvider.apply(property);
+ return Arrays.stream(exclusions)
.map(StringUtils::trim)
.toArray(String[]::new);
}
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.sonar.api.CoreProperties.GLOBAL_TEST_EXCLUSIONS_PROPERTY;
import static org.sonar.api.CoreProperties.PROJECT_TESTS_EXCLUSIONS_PROPERTY;
import static org.sonar.api.CoreProperties.PROJECT_TESTS_INCLUSIONS_PROPERTY;
import static org.sonar.api.CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY;
verify(analysisWarnings).addUnique(expectedWarn);
}
+ @Test
+ public void AbstractExclusionFilters_whenUsedGlobalTestPropertyAndProjectTestLegacyProperty_shouldNotLogAliasWarning() {
+ settings.setProperty(PROJECT_TEST_EXCLUSIONS_PROPERTY, "**/*Dao.java");
+ settings.setProperty(GLOBAL_TEST_EXCLUSIONS_PROPERTY, "**/*Dao.java");
+ settings.setProperty(PROJECT_TEST_INCLUSIONS_PROPERTY, "**/*Dao.java");
+ new AbstractExclusionFilters(analysisWarnings, settings.asConfig()::getStringArray) {
+ };
+
+ assertThat(logTester.logs(Level.WARN)).isEmpty();
+ }
+
@Test
public void should_keepLegacyValue_when_legacyAndAliasPropertiesAreUsedForTestInclusions() {
settings.setProperty(PROJECT_TESTS_INCLUSIONS_PROPERTY, "**/*Dao.java");
.contains(expectedWarn);
verify(analysisWarnings).addUnique(expectedWarn);
}
-}
\ No newline at end of file
+}