Skip to content

Commit

Permalink
#309 fix task caching for androind builds, removed non-cacheable task
Browse files Browse the repository at this point in the history
  • Loading branch information
jk1 committed May 26, 2024
1 parent 135292c commit 6fbd80e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.github.jk1.license

import com.github.jk1.license.task.CacheableReportTask
import com.github.jk1.license.task.CheckLicensePreparationTask
import com.github.jk1.license.task.CheckLicenseTask
import com.github.jk1.license.task.ReportTask
Expand All @@ -35,8 +34,7 @@ class LicenseReportPlugin implements Plugin<Project> {
def extension = project.extensions.create('licenseReport', LicenseReportExtension, project)

def preparationTask = project.tasks.register("checkLicensePreparation", CheckLicensePreparationTask)
def taskClass = project.getPlugins().hasPlugin('com.android.application') ? ReportTask : CacheableReportTask
def generateLicenseReportTask = project.tasks.register('generateLicenseReport', taskClass) {
def generateLicenseReportTask = project.tasks.register('generateLicenseReport', ReportTask) {
it.shouldRunAfter(preparationTask)
it.config = extension
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ProjectReader {
return data
}

private Set<Configuration> findConfigurationsToScan(Project project) {
public Set<Configuration> findConfigurationsToScan(Project project) {
Set<Configuration> toScan
if (config.configurations.length == 0) {
LOGGER.info("No configuration defined. Use all resolvable configurations.")
Expand All @@ -75,7 +75,7 @@ class ProjectReader {
project.configurations.findAll { config -> isResolvable(config) }
}

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

Expand Down

This file was deleted.

13 changes: 13 additions & 0 deletions src/main/groovy/com/github/jk1/license/task/ReportTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import com.github.jk1.license.LicenseReportExtension
import com.github.jk1.license.ProjectData
import com.github.jk1.license.reader.ProjectReader
import org.gradle.api.DefaultTask
import org.gradle.api.file.FileCollection
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
import org.gradle.api.tasks.*

@CacheableTask
class ReportTask extends DefaultTask {

private Logger LOGGER = Logging.getLogger(ReportTask.class)
Expand All @@ -41,6 +43,17 @@ class ReportTask extends DefaultTask {
return new File(config.absoluteOutputDir)
}

@Input
String[] getClasspath() {
def reader = new ProjectReader(config)
// take configurations' shallow snapshot but don't revolve them
def deps = getConfig().projects
.collectMany { reader.findConfigurationsToScan(it) }
.collectMany { it.allDependencies }
.collect { it.name + it.group + it.version}
deps
}

@TaskAction
void generateReport() {
LOGGER.info("Processing dependencies for project ${getProject().name}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ abstract class AbstractGradleRunnerFunctionalSpec extends Specification {
.withProjectDir(testProjectDir)
.withArguments(args + additionalArguments)
.withPluginClasspath(pluginClasspath)
.withDebug(true)
.forwardOutput()
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ class ReportTaskCachingSpec extends Specification {
private BuildResult runBuildWith(String... params) {
return GradleRunner.create()
.withPluginClasspath()
.forwardOutput()
.withProjectDir(testProjectDir)
.withArguments(params)
.withDebug(true)
.forwardOutput()
.build()
}

Expand Down

0 comments on commit 6fbd80e

Please sign in to comment.