Skip to content

Commit c65f41b

Browse files
SCANGRADLE-342 apply properties overridden by user after filter automatically generated properties (#425)
1 parent 55813e8 commit c65f41b

2 files changed

Lines changed: 84 additions & 1 deletion

File tree

src/main/java/org/sonarqube/gradle/SonarTask.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,11 @@ private static List<PropertyInfo> parsePropertiesWithNames(Map<String, String> p
397397
* @return filtered comma-delimited list of paths
398398
*/
399399
private static String filterPaths(String value, Predicate<Path> filter) {
400+
// some of the analyzer accept and expand path containing wildcards
401+
// we must not filter them
402+
Set<String> wildcardsToken = Set.of("*", "?", "${");
400403
return Arrays.stream(value.split(","))
401-
.filter(p -> filter.test(Path.of(p)))
404+
.filter(p -> wildcardsToken.stream().anyMatch(p::contains) || filter.test(Path.of(p)))
402405
.collect(Collectors.joining(","));
403406
}
404407

src/test/groovy/org/sonarqube/gradle/FunctionalTests.groovy

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,5 +850,85 @@ class FunctionalTests extends Specification {
850850
private Path projectDir(String project) {
851851
return Path.of(this.class.getResource("/projects/"+project).toURI());
852852
}
853+
854+
// some analyzer accept and expand path containing wildcards, they must not be removed
855+
def "path containing wildcards are not removed"() {
856+
given:
857+
var sonarSourcesProperty = "property 'sonar.sources', '$mainSources'"
858+
var sonarTestsProperty = "property 'sonar.tests', '$testSource'"
859+
var sonarJavaJdkHomeProperty = "property 'sonar.java.jdkHome', '$javaJdkHome'"
860+
var sonarJavaBinariesProperty = "property 'sonar.java.binaries', '$javaBinaries'"
861+
var sonarJavaLibrariesProperty = "property 'sonar.java.libraries', '$javaLibraries'"
862+
var sonarJavaTestBinariesProperty = "property 'sonar.java.test.binaries', '$javaTestBinaries'"
863+
var sonarJavaTestLibrariesProperty = "property 'sonar.java.test.libraries', '$javaTestLibraries'"
864+
var sonarLibrariesProperty = "property 'sonar.libraries', '$libraries'"
865+
var sonarGroovyBinariesProperty = "property 'sonar.groovy.binaries', '$groovyBinaries'"
866+
var sonarKotlinGradleProjectRootProperty = "property 'sonar.kotlin.gradle.project.root', '$kotlinGradleProjectRoot'"
867+
var sonarJunitReportPathsProperty = "property 'sonar.junit.reportPaths', '$junitReportPaths'"
868+
var sonarJunitReportsPathProperty = "property 'sonar.junit.reportsPath', '$junitReportsPath'"
869+
var sonarSurefireReportsPathProperty = "property 'sonar.surefire.reportsPath', '$surefireReportsPath'"
870+
var sonarJacocoXmlReportPathsProperty = "property 'sonar.coverage.jacoco.xmlReportPaths', '$jacocoXmlReportPaths'"
871+
var sonarAndroidLintReportPathsProperty = "property 'sonar.android.lint.reportPaths', '$androidLintReportPaths'"
872+
settingsFile << "rootProject.name = 'java-task-toolchains'"
873+
buildFile << """
874+
plugins {
875+
id 'java'
876+
id 'org.sonarqube'
877+
}
878+
879+
sonar {
880+
properties {
881+
$sonarSourcesProperty
882+
$sonarTestsProperty
883+
$sonarJavaJdkHomeProperty
884+
$sonarJavaBinariesProperty
885+
$sonarJavaLibrariesProperty
886+
$sonarJavaTestBinariesProperty
887+
$sonarJavaTestLibrariesProperty
888+
$sonarLibrariesProperty
889+
$sonarGroovyBinariesProperty
890+
$sonarKotlinGradleProjectRootProperty
891+
$sonarJunitReportPathsProperty
892+
$sonarJunitReportsPathProperty
893+
$sonarSurefireReportsPathProperty
894+
$sonarJacocoXmlReportPathsProperty
895+
$sonarAndroidLintReportPathsProperty
896+
}
897+
}
898+
"""
899+
900+
when:
901+
def result = GradleRunner.create()
902+
.withProjectDir(projectDir.toFile())
903+
.forwardOutput()
904+
.withArguments('sonar', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath(), "--stacktrace")
905+
.withPluginClasspath()
906+
.build()
907+
908+
then:
909+
result.task(":sonar").outcome == SUCCESS
910+
911+
def props = new Properties()
912+
props.load(outFile.newDataInputStream())
913+
props."sonar.java.jdkHome" == javaJdkHome
914+
props."sonar.java.binaries" == javaBinaries
915+
props."sonar.java.libraries" == javaLibraries
916+
props."sonar.java.test.binaries" == javaTestBinaries
917+
props."sonar.java.test.libraries" == javaTestLibraries
918+
props."sonar.libraries" == libraries
919+
props."sonar.groovy.binaries" == groovyBinaries
920+
props."sonar.kotlin.gradle.project.root" == kotlinGradleProjectRoot
921+
props."sonar.junit.reportPaths" == junitReportPaths
922+
props."sonar.junit.reportsPath" == junitReportsPath
923+
props."sonar.surefire.reportsPath" == surefireReportsPath
924+
props."sonar.coverage.jacoco.xmlReportPaths" == jacocoXmlReportPaths
925+
props."sonar.android.lint.reportPaths" == androidLintReportPaths
926+
927+
where:
928+
// first test path that do not exists
929+
// second test wildcard values and invalid values
930+
mainSources | testSource | javaJdkHome | javaBinaries | javaLibraries | javaTestBinaries | javaTestLibraries | libraries | groovyBinaries | kotlinGradleProjectRoot | junitReportPaths | junitReportsPath | surefireReportsPath | jacocoXmlReportPaths | androidLintReportPaths
931+
"source/*/" | "**/tests" | "jdkH?/" | "*?.*.*/" | "*?.*.*/" | "*?.*.*/,**/?" | "*?.*.*/" | "*?.*.*/" | "*?.*.*/" | "*?.*.*/" | "*?.*.*/" | "*?.*.*/" | "*?.*.*/" | "*?.*.*/" | "*?.*.*/"
932+
}
853933
}
854934

0 commit comments

Comments
 (0)