diff --git a/src/main/resources/init-script-gradle.ftl b/src/main/resources/init-script-gradle.ftl index 28b996fe3e..e526b625d8 100644 --- a/src/main/resources/init-script-gradle.ftl +++ b/src/main/resources/init-script-gradle.ftl @@ -8,10 +8,10 @@ import org.gradle.api.Task import org.gradle.api.execution.TaskExecutionListener import org.gradle.api.tasks.TaskState -Set projectNameExcludeFilter = convertStringToSet('${excludedProjectNames}') -Set projectNameIncludeFilter = convertStringToSet('${includedProjectNames}') -Set projectPathExcludeFilter = convertStringToSet('${excludedProjectPaths}') -Set projectPathIncludeFilter = convertStringToSet('${includedProjectPaths}') +Set projectNameExcludeFilter = convertStringToSet('${excludedProjectNames?replace("\\", "\\\\")?replace("\'", "\\\'")}') +Set projectNameIncludeFilter = convertStringToSet('${includedProjectNames?replace("\\", "\\\\")?replace("\'", "\\\'")}') +Set projectPathExcludeFilter = convertStringToSet('${excludedProjectPaths?replace("\\", "\\\\")?replace("\'", "\\\'")}') +Set projectPathIncludeFilter = convertStringToSet('${includedProjectPaths?replace("\\", "\\\\")?replace("\'", "\\\'")}') Boolean rootOnly = Boolean.parseBoolean("${rootOnlyOption}") gradle.allprojects { @@ -47,9 +47,11 @@ gradle.allprojects { def projectVersion = currentProject.version.toString() def projectParent = currentProject.parent ? currentProject.parent.toString() : "none" - // Prepare configuration names + // Prepare configuration names (handles single quotes issues ) def configurationNames = getFilteredConfigurationNames(currentProject, - '${excludedConfigurationNames}', '${includedConfigurationNames}') + '${excludedConfigurationNames?replace("\\", "\\\\")?replace("\'", "\\\'")}', + '${includedConfigurationNames?replace("\\", "\\\\")?replace("\'", "\\\'")}' + ) def selectedConfigs = [] configurationNames.each { name -> @@ -64,11 +66,14 @@ gradle.allprojects { } } - // Check if the project should be included in results - def shouldIncludeProject = (rootOnly && isRootProject) || + // Check if the project should be included based on project-level filters + def projectMatchesFilters = (rootOnly && isRootProject) || (!rootOnly && shouldInclude(projectNameExcludeFilter, projectNameIncludeFilter, projectName) && shouldInclude(projectPathExcludeFilter, projectPathIncludeFilter, projectPath)) + // A project is only included if it matches project filters AND has configurations that match config filters. + def shouldIncludeProject = projectMatchesFilters && !selectedConfigs.isEmpty() + // Capture output file path during configuration def projectFilePathConfig = computeProjectFilePath(projectPath, extractionDir, rootProject)