Skip to content

Commit 45897a4

Browse files
SCANMAVEN-296 Include github actions folder in the scan (#310)
1 parent 4315ce7 commit 45897a4

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

sonar-maven-plugin/src/main/java/org/sonarsource/scanner/maven/bootstrap/MavenProjectConverter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,9 @@ private List<File> mainSources(MavenProject pom) throws MojoExecutionException {
558558
.forEach(sources::add);
559559
}
560560

561+
// Add GHA folder
562+
sources.add(new File(pom.getBasedir(), ".github").getAbsolutePath());
563+
561564
return sourcePaths(pom, AnalysisProperties.PROJECT_SOURCE_DIRS, sources);
562565
}
563566

sonar-maven-plugin/src/test/java/org/sonarsource/scanner/maven/bootstrap/MavenProjectConverterTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,37 @@ void getAbsolutePathToOriginalPom_returns_the_original_pom_when_available() thro
698698
.containsOnly(originalPom.getAbsolutePath());
699699
}
700700

701+
@Test
702+
void shouldIncludeGithubActionFolder() throws Exception {
703+
File baseDir = temp.toAbsolutePath().toFile();
704+
File githubDir = new File(baseDir, ".github");
705+
githubDir.mkdirs();
706+
MavenProject project = createProject(new Properties(), "jar");
707+
708+
Map<String, String> props = projectConverter.configure(Collections.singletonList(project), project, new Properties());
709+
assertThat(props).containsEntry("sonar.projectKey", "com.foo:myProject")
710+
.containsEntry("sonar.projectName", "My Project")
711+
.containsEntry("sonar.projectVersion", "2.1");
712+
assertThat(props.get("sonar.sources").split(",")).containsExactly(
713+
new File(baseDir, "pom.xml").getAbsolutePath(),
714+
githubDir.getAbsolutePath()
715+
);
716+
}
717+
718+
@Test
719+
void shouldNotIncludeGithubActionFolderWhenNotPresent() throws Exception {
720+
File baseDir = temp.toAbsolutePath().toFile();
721+
MavenProject project = createProject(new Properties(), "jar");
722+
723+
Map<String, String> props = projectConverter.configure(Collections.singletonList(project), project, new Properties());
724+
assertThat(props).containsEntry("sonar.projectKey", "com.foo:myProject")
725+
.containsEntry("sonar.projectName", "My Project")
726+
.containsEntry("sonar.projectVersion", "2.1");
727+
assertThat(props.get("sonar.sources").split(",")).containsExactly(
728+
new File(baseDir, "pom.xml").getAbsolutePath()
729+
);
730+
}
731+
701732
private MavenProject createProject(Properties pomProps, String packaging) throws IOException {
702733
File pom = temp.resolve("pom.xml").toFile();
703734
pom.createNewFile();

0 commit comments

Comments
 (0)