From eecb37ed1483da705ce56086c8787b182b443cdd Mon Sep 17 00:00:00 2001 From: Evgeny Naumenko Date: Sun, 26 May 2024 19:34:41 +0300 Subject: [PATCH] #309 delay configuration defaults --- .../jk1/license/LicenseReportExtension.groovy | 3 +- .../jk1/license/reader/ProjectReader.groovy | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/groovy/com/github/jk1/license/LicenseReportExtension.groovy b/src/main/groovy/com/github/jk1/license/LicenseReportExtension.groovy index 0472801f..b8efe03d 100644 --- a/src/main/groovy/com/github/jk1/license/LicenseReportExtension.groovy +++ b/src/main/groovy/com/github/jk1/license/LicenseReportExtension.groovy @@ -47,8 +47,7 @@ class LicenseReportExtension { outputDir = "${project.buildDir}/reports/dependency-license" projects = [project] + project.subprojects renderers = new SimpleHtmlReportRenderer() - configurations = - project.getPlugins().hasPlugin('com.android.application') ? ['releaseRuntimeClasspath'] : ['runtimeClasspath'] + configurations = null excludeOwnGroup = true excludeBoms = false // false - for backwards compatibility excludeGroups = [] diff --git a/src/main/groovy/com/github/jk1/license/reader/ProjectReader.groovy b/src/main/groovy/com/github/jk1/license/reader/ProjectReader.groovy index b7969f9f..6f675131 100644 --- a/src/main/groovy/com/github/jk1/license/reader/ProjectReader.groovy +++ b/src/main/groovy/com/github/jk1/license/reader/ProjectReader.groovy @@ -27,11 +27,14 @@ import org.gradle.api.logging.Logging class ProjectReader { private Logger LOGGER = Logging.getLogger(ReportTask.class) - private LicenseReportExtension config + private Project[] projects + private String[] configurations + private ConfigurationReader configurationReader ProjectReader(LicenseReportExtension config) { - this.config = config + this.projects = config.projects + this.configurations = config.configurations this.configurationReader = new ConfigurationReader(config, new CachedModuleReader(config)) } @@ -39,10 +42,9 @@ class ProjectReader { ProjectData data = new ProjectData() data.project = project - Project[] projectsToScan = config.projects - LOGGER.info("Configured projects: ${projectsToScan.join(',')}") + LOGGER.info("Configured projects: ${projects.join(',')}") - List readConfigurations = projectsToScan.collect { subProject -> + List readConfigurations = projects.collect { subProject -> Set configurationsToScan = findConfigurationsToScan(subProject) configurationsToScan.addAll(getAllExtendedConfigurations(configurationsToScan)) @@ -56,13 +58,17 @@ class ProjectReader { return data } - public Set findConfigurationsToScan(Project project) { + private Set findConfigurationsToScan(Project project) { Set toScan - if (config.configurations.length == 0) { - LOGGER.info("No configuration defined. Use all resolvable configurations.") + if (configurations == null) { + LOGGER.info("No configurations defined, falling back to the default ones") + configurations = project.getPlugins().hasPlugin('com.android.application') ? ['releaseRuntimeClasspath'] : ['runtimeClasspath'] + } + if (configurations.length == 0) { + LOGGER.info("Using all resolvable configurations") toScan = findResolvableConfigurations(project) } else { - toScan = findConfiguredConfigurations(project, config) + toScan = findConfiguredConfigurations(project) Set unresolvable = findUnresolvable(toScan) if (unresolvable) { throw new UnresolvableConfigurationException("Unable to resolve configurations: $unresolvable") @@ -75,7 +81,7 @@ class ProjectReader { project.configurations.findAll { config -> isResolvable(config) } } - public static Set getAllExtendedConfigurations(Collection configurationsToScan) { + private static Set getAllExtendedConfigurations(Collection configurationsToScan) { configurationsToScan.collect { it.extendsFrom }.flatten().findAll { config -> isResolvable(config) }.toSet() } @@ -86,8 +92,8 @@ class ProjectReader { } } - static Set findConfiguredConfigurations(Project project, LicenseReportExtension extension) { - project.configurations.findAll { config -> config.name in extension.configurations } + private Set findConfiguredConfigurations(Project project) { + project.configurations.findAll { config -> config.name in configurations } } private static Set findUnresolvable(Set toScan) {