Skip to content

Commit 6711b83

Browse files
authored
fix(gradle): Correct Configuration Filtering Logic (IDETECT-4853) (#1570)
1 parent 05424f4 commit 6711b83

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/main/resources/init-script-gradle.ftl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import org.gradle.api.Task
88
import org.gradle.api.execution.TaskExecutionListener
99
import org.gradle.api.tasks.TaskState
1010

11-
Set<String> projectNameExcludeFilter = convertStringToSet('${excludedProjectNames}')
12-
Set<String> projectNameIncludeFilter = convertStringToSet('${includedProjectNames}')
13-
Set<String> projectPathExcludeFilter = convertStringToSet('${excludedProjectPaths}')
14-
Set<String> projectPathIncludeFilter = convertStringToSet('${includedProjectPaths}')
11+
Set<String> projectNameExcludeFilter = convertStringToSet('${excludedProjectNames?replace("\\", "\\\\")?replace("\'", "\\\'")}')
12+
Set<String> projectNameIncludeFilter = convertStringToSet('${includedProjectNames?replace("\\", "\\\\")?replace("\'", "\\\'")}')
13+
Set<String> projectPathExcludeFilter = convertStringToSet('${excludedProjectPaths?replace("\\", "\\\\")?replace("\'", "\\\'")}')
14+
Set<String> projectPathIncludeFilter = convertStringToSet('${includedProjectPaths?replace("\\", "\\\\")?replace("\'", "\\\'")}')
1515
Boolean rootOnly = Boolean.parseBoolean("${rootOnlyOption}")
1616

1717
gradle.allprojects {
@@ -47,9 +47,11 @@ gradle.allprojects {
4747
def projectVersion = currentProject.version.toString()
4848
def projectParent = currentProject.parent ? currentProject.parent.toString() : "none"
4949

50-
// Prepare configuration names
50+
// Prepare configuration names (handles single quotes issues )
5151
def configurationNames = getFilteredConfigurationNames(currentProject,
52-
'${excludedConfigurationNames}', '${includedConfigurationNames}')
52+
'${excludedConfigurationNames?replace("\\", "\\\\")?replace("\'", "\\\'")}',
53+
'${includedConfigurationNames?replace("\\", "\\\\")?replace("\'", "\\\'")}'
54+
)
5355

5456
def selectedConfigs = []
5557
configurationNames.each { name ->
@@ -64,11 +66,14 @@ gradle.allprojects {
6466
}
6567
}
6668

67-
// Check if the project should be included in results
68-
def shouldIncludeProject = (rootOnly && isRootProject) ||
69+
// Check if the project should be included based on project-level filters
70+
def projectMatchesFilters = (rootOnly && isRootProject) ||
6971
(!rootOnly && shouldInclude(projectNameExcludeFilter, projectNameIncludeFilter, projectName) &&
7072
shouldInclude(projectPathExcludeFilter, projectPathIncludeFilter, projectPath))
7173

74+
// A project is only included if it matches project filters AND has configurations that match config filters.
75+
def shouldIncludeProject = projectMatchesFilters && !selectedConfigs.isEmpty()
76+
7277
// Capture output file path during configuration
7378
def projectFilePathConfig = computeProjectFilePath(projectPath, extractionDir, rootProject)
7479

0 commit comments

Comments
 (0)