Skip to content

Commit

Permalink
optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredsburrows committed Jan 31, 2024
1 parent 91ee1f2 commit 5d065e3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,13 @@ internal open class LicenseReportTask : DefaultTask() { // tasks can't be final

// Resolve the POM artifacts
configurationSet
.asSequence()
.filter { it.isCanBeResolved }
.map { it.resolvedConfiguration }
.map { it.lenientConfiguration }
.map { it.allModuleDependencies }
.flatMap { getResolvedArtifactsFromResolvedDependencies(it) }
.toList()
.forEach { artifact ->
val id = artifact.moduleVersion.id
val gav = "${id.group}:${id.name}:${id.version}@pom"
Expand Down Expand Up @@ -235,8 +237,8 @@ internal open class LicenseReportTask : DefaultTask() { // tasks can't be final
val module = artifact.moduleVersion.id
val project =
Model().apply {
this.groupId = module.group.orEmpty().trim()
this.artifactId = module.name.orEmpty().trim()
this.groupId = module.group.trim()
this.artifactId = module.name.trim()
this.version = model.pomVersion(mavenReader, pomFile, configurations, dependencies)
this.name = model.pomName()
this.description = model.pomDescription()
Expand All @@ -255,7 +257,7 @@ internal open class LicenseReportTask : DefaultTask() { // tasks can't be final

private fun getResolvedArtifactsFromResolvedDependencies(
resolvedDependencies: Set<ResolvedDependency>,
skipSet: MutableSet<ResolvedDependency> = hashSetOf<ResolvedDependency>(),
skipSet: MutableSet<ResolvedDependency> = hashSetOf(),
): Set<ResolvedArtifact> {
val resolvedArtifacts = hashSetOf<ResolvedArtifact>()
resolvedDependencies.forEach { resolvedDependency ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@ import org.gradle.api.Project
import org.gradle.api.reporting.ReportingExtension

/** Returns true if plugin exists in project. */
internal fun Project.hasPlugin(list: List<String>): Boolean {
return list.find { plugins.hasPlugin(it) } != null
}
internal fun Project.hasPlugin(list: List<String>): Boolean = list.any { plugins.hasPlugin(it) }

/** Configure common configuration for both Java and Android tasks. */
internal fun Project.configureCommon(task: LicenseReportTask) {
task.buildFile = buildFile
val reportingExtension = extensions.getByType(ReportingExtension::class.java)
val licenseExtension = extensions.getByType(LicenseReportExtension::class.java)

// Customizing internal task options
task.outputDir = extensions.getByType(ReportingExtension::class.java).file("licenses")
task.apply {
buildFile = this@configureCommon.buildFile
outputDir = reportingExtension.file("licenses")

// Customizing internal task options from extension
val extension = extensions.getByType(LicenseReportExtension::class.java)
task.generateCsvReport = extension.generateCsvReport
task.generateHtmlReport = extension.generateHtmlReport
task.generateJsonReport = extension.generateJsonReport
task.generateTextReport = extension.generateTextReport
task.copyCsvReportToAssets = extension.copyCsvReportToAssets
task.copyHtmlReportToAssets = extension.copyHtmlReportToAssets
task.copyJsonReportToAssets = extension.copyJsonReportToAssets
task.copyTextReportToAssets = extension.copyTextReportToAssets
task.useVariantSpecificAssetDirs = extension.useVariantSpecificAssetDirs
task.ignoredPatterns = extension.ignoredPatterns
generateCsvReport = licenseExtension.generateCsvReport
generateHtmlReport = licenseExtension.generateHtmlReport
generateJsonReport = licenseExtension.generateJsonReport
generateTextReport = licenseExtension.generateTextReport
copyCsvReportToAssets = licenseExtension.copyCsvReportToAssets
copyHtmlReportToAssets = licenseExtension.copyHtmlReportToAssets
copyJsonReportToAssets = licenseExtension.copyJsonReportToAssets
copyTextReportToAssets = licenseExtension.copyTextReportToAssets
useVariantSpecificAssetDirs = licenseExtension.useVariantSpecificAssetDirs
ignoredPatterns = licenseExtension.ignoredPatterns
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@ private fun Project.configureVariant(

// Custom for Android tasks
val sourceSetName = if (it.useVariantSpecificAssetDirs) variant.name else "main"
it.assetDirs =
baseExtension
.sourceSets
.getByName(sourceSetName)
.assets
.srcDirs
.toList()
it.assetDirs = baseExtension.sourceSets.findByName(sourceSetName)?.assets?.srcDirs?.toList() ?: emptyList()
it.variantName = variant.name
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ internal fun Project.isJavaProject(): Boolean {
)
}

/**
* Configure for Java projects.
*
* All of these plugins will apply the JavaPlugin(relies on JavaBasePlugin).
*/
/** Configure for Java projects. */
internal fun Project.configureJavaProject() {
tasks.register("licenseReport", LicenseReportTask::class.java) {
// Apply common task configuration first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ final class LicensePluginSpec extends Specification {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder()
private int compileSdkVersion = 34
private String agpVersion = "3.6.4"
private List<File> pluginClasspath
private String classpathString
private File buildFile
Expand Down Expand Up @@ -206,7 +205,6 @@ final class LicensePluginSpec extends Specification {
}
dependencies {
classpath "com.android.tools.build:gradle:$agpVersion"
classpath files($classpathString)
}
}
Expand All @@ -233,7 +231,6 @@ final class LicensePluginSpec extends Specification {
}
dependencies {
classpath "com.android.tools.build:gradle:$agpVersion"
classpath files($classpathString)
}
}
Expand Down

0 comments on commit 5d065e3

Please sign in to comment.