[Gradle, JS] Configuration cache friendly

This commit is contained in:
Ilya Goncharov
2021-07-01 15:27:46 +03:00
committed by TeamCityServer
parent 81ac48390c
commit 065a5d98fb
@@ -12,6 +12,8 @@ import org.gradle.api.tasks.*
import org.jetbrains.kotlin.gradle.logging.kotlinInfo import org.jetbrains.kotlin.gradle.logging.kotlinInfo
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.utils.ArchiveOperationsCompat
import org.jetbrains.kotlin.gradle.utils.FileSystemOperationsCompat
import org.jetbrains.kotlin.statistics.metrics.NumericalMetrics import org.jetbrains.kotlin.statistics.metrics.NumericalMetrics
import java.io.File import java.io.File
import java.net.URI import java.net.URI
@@ -21,6 +23,8 @@ open class YarnSetupTask : DefaultTask() {
@Transient @Transient
private val settings = project.yarn private val settings = project.yarn
private val env by lazy { settings.requireConfigured() } private val env by lazy { settings.requireConfigured() }
private val fileSystemOperations = FileSystemOperationsCompat(project)
private val archiveOperations = ArchiveOperationsCompat(project)
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
val downloadUrl val downloadUrl
@@ -48,8 +52,7 @@ open class YarnSetupTask : DefaultTask() {
@Suppress("unused") // as it called by Gradle before task execution and used to resolve artifact @Suppress("unused") // as it called by Gradle before task execution and used to resolve artifact
@get:Classpath @get:Classpath
val yarnDist: File val yarnDist: File by lazy {
get() {
val repo = project.repositories.ivy { repo -> val repo = project.repositories.ivy { repo ->
repo.name = "Yarn Distributions at ${downloadUrl}" repo.name = "Yarn Distributions at ${downloadUrl}"
repo.url = URI(downloadUrl) repo.url = URI(downloadUrl)
@@ -67,7 +70,7 @@ open class YarnSetupTask : DefaultTask() {
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration) ?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration)
} }
project.repositories.remove(repo) project.repositories.remove(repo)
return dist dist
} }
@TaskAction @TaskAction
@@ -79,8 +82,8 @@ open class YarnSetupTask : DefaultTask() {
private fun extract(archive: File, destination: File) { private fun extract(archive: File, destination: File) {
val dirInTar = archive.name.removeSuffix(".tar.gz") val dirInTar = archive.name.removeSuffix(".tar.gz")
project.copy { fileSystemOperations.copy {
it.from(project.tarTree(archive)) it.from(archiveOperations.tarTree(archive))
it.into(destination) it.into(destination)
it.includeEmptyDirs = false it.includeEmptyDirs = false
it.eachFile { fileCopy -> it.eachFile { fileCopy ->