Skip to content

Commit 64ea95d

Browse files
SCANGRADLE-252 ".github" folder should not be added to "sonar.sources" if the user explicitly overrides this property
1 parent d0a49bd commit 64ea95d

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ private void computeDefaultProperties(Project project, Map<String, Object> prope
130130
}
131131

132132
if (isRootProject(project)) {
133+
addGithubFolder(project, rawProperties);
133134
addKotlinBuildScriptsToSources(project, rawProperties);
134135
}
135136

@@ -147,7 +148,6 @@ private void computeDefaultProperties(Project project, Map<String, Object> prope
147148
rawProperties.putIfAbsent("sonar.moduleKey", projectKey + project.getPath());
148149
}
149150

150-
addGithubFolder(project, rawProperties);
151151
convertProperties(rawProperties, prefix, properties);
152152

153153
List<Project> enabledChildProjects = project.getChildProjects().values().stream()

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,19 +1111,30 @@ class SonarQubePluginTest extends Specification {
11111111
project.pluginManager.apply(GroovyPlugin)
11121112
11131113
project.sourceSets.main.groovy.srcDirs = ["src"]
1114-
project.compileJava.options.encoding = 'ISO-8859-1'
11151114
1116-
def testResultsDir = new File(project.buildDir, "test-results/test")
1117-
testResultsDir.mkdirs()
1118-
new File(testResultsDir, 'TEST-.xml').createNewFile()
1115+
when:
1116+
def properties = project.tasks.sonar.properties.get()
1117+
1118+
then:
1119+
properties["sonar.sources"] == (new File(project.projectDir, "src") as String) + "," + (new File(project.projectDir, ".github") as String)
1120+
}
1121+
1122+
def ".github folder is not added if the user overrides sonar.sources"() {
1123+
def rootProject = ProjectBuilder.builder().withName("root").build()
1124+
def project = ProjectBuilder.builder().withName("parent").withParent(rootProject).withProjectDir(new File("src/test/projects/github-is-a-folder")).build()
1125+
1126+
project.pluginManager.apply(SonarQubePlugin)
1127+
project.pluginManager.apply(GroovyPlugin)
1128+
project.sonar.properties {
1129+
property "sonar.sources", "src"
1130+
}
1131+
project.sourceSets.main.groovy.srcDirs = ["src"]
11191132
11201133
when:
11211134
def properties = project.tasks.sonar.properties.get()
11221135
11231136
then:
1124-
properties["sonar.sources"].contains(new File(project.projectDir, "src") as String)
1125-
properties["sonar.sources"].contains(new File(project.projectDir, ".github") as String)
1126-
properties["sonar.sourceEncoding"] == "ISO-8859-1"
1137+
properties["sonar.sources"] == "src"
11271138
}
11281139
11291140
def ".github is present but is a file so not added to sources"() {

0 commit comments

Comments
 (0)