Skip to content

Commit

Permalink
#309 delay configuration defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
jk1 committed May 26, 2024
1 parent 8d11f3d commit eecb37e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
30 changes: 18 additions & 12 deletions src/main/groovy/com/github/jk1/license/reader/ProjectReader.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@ 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))
}

ProjectData read(Project project) {
ProjectData data = new ProjectData()
data.project = project

Project[] projectsToScan = config.projects
LOGGER.info("Configured projects: ${projectsToScan.join(',')}")
LOGGER.info("Configured projects: ${projects.join(',')}")

List<ConfigurationData> readConfigurations = projectsToScan.collect { subProject ->
List<ConfigurationData> readConfigurations = projects.collect { subProject ->
Set<Configuration> configurationsToScan = findConfigurationsToScan(subProject)

configurationsToScan.addAll(getAllExtendedConfigurations(configurationsToScan))
Expand All @@ -56,13 +58,17 @@ class ProjectReader {
return data
}

public Set<Configuration> findConfigurationsToScan(Project project) {
private Set<Configuration> findConfigurationsToScan(Project project) {
Set<Configuration> 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<Configuration> unresolvable = findUnresolvable(toScan)
if (unresolvable) {
throw new UnresolvableConfigurationException("Unable to resolve configurations: $unresolvable")
Expand All @@ -75,7 +81,7 @@ class ProjectReader {
project.configurations.findAll { config -> isResolvable(config) }
}

public static Set<Configuration> getAllExtendedConfigurations(Collection<Configuration> configurationsToScan) {
private static Set<Configuration> getAllExtendedConfigurations(Collection<Configuration> configurationsToScan) {
configurationsToScan.collect { it.extendsFrom }.flatten().findAll { config -> isResolvable(config) }.toSet()
}

Expand All @@ -86,8 +92,8 @@ class ProjectReader {
}
}

static Set<Configuration> findConfiguredConfigurations(Project project, LicenseReportExtension extension) {
project.configurations.findAll { config -> config.name in extension.configurations }
private Set<Configuration> findConfiguredConfigurations(Project project) {
project.configurations.findAll { config -> config.name in configurations }
}

private static Set<Configuration> findUnresolvable(Set<Configuration> toScan) {
Expand Down

0 comments on commit eecb37e

Please sign in to comment.