[Gradle, JS] Use injected services of fs
This commit is contained in:
committed by
TeamCityServer
parent
e2adf9793c
commit
da1bdf87cb
+3
-1
@@ -18,9 +18,11 @@ abstract class NodeJsSetupTask : DefaultTask() {
|
|||||||
@Transient
|
@Transient
|
||||||
private val settings = NodeJsRootPlugin.apply(project.rootProject)
|
private val settings = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
private val env by lazy { settings.requireConfigured() }
|
private val env by lazy { settings.requireConfigured() }
|
||||||
private val archiveOperations = ArchiveOperationsCompat(project)
|
|
||||||
private val shouldDownload = settings.download
|
private val shouldDownload = settings.download
|
||||||
|
|
||||||
|
private val archiveOperations = ArchiveOperationsCompat(project)
|
||||||
|
|
||||||
@get:Inject
|
@get:Inject
|
||||||
internal open val fs: FileSystemOperations
|
internal open val fs: FileSystemOperations
|
||||||
get() = error("Should be injected")
|
get() = error("Should be injected")
|
||||||
|
|||||||
+16
-3
@@ -7,25 +7,32 @@ package org.jetbrains.kotlin.gradle.targets.js.yarn
|
|||||||
|
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.artifacts.Configuration
|
import org.gradle.api.artifacts.Configuration
|
||||||
|
import org.gradle.api.file.FileSystemOperations
|
||||||
import org.gradle.api.provider.Provider
|
import org.gradle.api.provider.Provider
|
||||||
import org.gradle.api.tasks.*
|
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.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
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@CacheableTask
|
@CacheableTask
|
||||||
open class YarnSetupTask : DefaultTask() {
|
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 shouldDownload = settings.download
|
||||||
|
|
||||||
private val archiveOperations = ArchiveOperationsCompat(project)
|
private val archiveOperations = ArchiveOperationsCompat(project)
|
||||||
|
|
||||||
|
@get:Inject
|
||||||
|
internal open val fs: FileSystemOperations
|
||||||
|
get() = error("Should be injected")
|
||||||
|
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
val downloadUrl
|
val downloadUrl
|
||||||
@Input get() = env.downloadUrl
|
@Input get() = env.downloadUrl
|
||||||
@@ -73,6 +80,12 @@ open class YarnSetupTask : DefaultTask() {
|
|||||||
dist
|
dist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
onlyIf {
|
||||||
|
shouldDownload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun setup() {
|
fun setup() {
|
||||||
logger.kotlinInfo("Using yarn distribution from '$yarnDist'")
|
logger.kotlinInfo("Using yarn distribution from '$yarnDist'")
|
||||||
@@ -82,7 +95,7 @@ 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")
|
||||||
fileSystemOperations.copy {
|
fs.copy {
|
||||||
it.from(archiveOperations.tarTree(archive))
|
it.from(archiveOperations.tarTree(archive))
|
||||||
it.into(destination)
|
it.into(destination)
|
||||||
it.includeEmptyDirs = false
|
it.includeEmptyDirs = false
|
||||||
|
|||||||
Reference in New Issue
Block a user