[Gradle, JS] Fix node.js repository declaration

^KT-47557 fixed
This commit is contained in:
Ilya Goncharov
2021-07-01 10:34:52 +03:00
committed by Space
parent f05110f99b
commit e0c1f50f03
3 changed files with 27 additions and 25 deletions
@@ -11,7 +11,8 @@ data class NodeJsEnv(
val platformName: String,
val architectureName: String,
val ivyDependency: String
val ivyDependency: String,
val downloadBaseUrl: String
) {
val isWindows: Boolean
get() = platformName == "win"
@@ -110,7 +110,8 @@ open class NodeJsRootExtension(@Transient val rootProject: Project) : Configurat
nodeExecutable = getExecutable("node", nodeCommand, "exe"),
platformName = platform,
architectureName = architecture,
ivyDependency = getIvyDependency()
ivyDependency = getIvyDependency(),
downloadBaseUrl = nodeDownloadBaseUrl
)
}
@@ -28,6 +28,9 @@ abstract class NodeJsSetupTask : DefaultTask() {
val ivyDependency: String
@Input get() = env.ivyDependency
val downloadBaseUrl: String
@Input get() = env.downloadBaseUrl
val destination: File
@OutputDirectory get() = env.nodeDir
@@ -41,30 +44,27 @@ abstract class NodeJsSetupTask : DefaultTask() {
@Suppress("unused") // as it called by Gradle before task execution and used to resolve artifact
@get:Classpath
val nodeJsDist: File
get() {
@Suppress("UnstableApiUsage", "DEPRECATION")
val repo = project.repositories.ivy { repo ->
repo.name = "Node Distributions at ${settings.nodeDownloadBaseUrl}"
repo.url = URI(settings.nodeDownloadBaseUrl)
val nodeJsDist: File by lazy {
val repo = project.repositories.ivy { repo ->
repo.name = "Node Distributions at ${downloadBaseUrl}"
repo.url = URI(downloadBaseUrl)
repo.patternLayout {
it.artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]")
it.ivy("v[revision]/ivy.xml")
}
repo.metadataSources { it.artifact() }
repo.content { it.includeModule("org.nodejs", "node") }
repo.patternLayout {
it.artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]")
}
val startDownloadTime = System.currentTimeMillis()
val dist = _nodeJsDist
val downloadDuration = System.currentTimeMillis() - startDownloadTime
if (downloadDuration > 0) {
KotlinBuildStatsService.getInstance()
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration)
}
project.repositories.remove(repo)
return dist
repo.metadataSources { it.artifact() }
repo.content { it.includeModule("org.nodejs", "node") }
}
val startDownloadTime = System.currentTimeMillis()
val dist = _nodeJsDist
val downloadDuration = System.currentTimeMillis() - startDownloadTime
if (downloadDuration > 0) {
KotlinBuildStatsService.getInstance()
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration)
}
project.repositories.remove(repo)
dist
}
init {
@Suppress("LeakingThis")
@@ -76,9 +76,9 @@ abstract class NodeJsSetupTask : DefaultTask() {
@Suppress("unused")
@TaskAction
fun exec() {
logger.kotlinInfo("Using node distribution from '$_nodeJsDist'")
logger.kotlinInfo("Using node distribution from '$nodeJsDist'")
unpackNodeArchive(_nodeJsDist, destination.parentFile) // parent because archive contains name already
unpackNodeArchive(nodeJsDist, destination.parentFile) // parent because archive contains name already
if (!env.isWindows) {
File(env.nodeExecutable).setExecutable(true)