[Gradle, JS] Non-nullable properties in KotlinWebpack with delegate
#KT-37582 fixed
This commit is contained in:
+1
-1
@@ -169,7 +169,7 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
compilation.developmentLinkTask.map { it.outputFile }
|
compilation.developmentLinkTask.map { it.outputFile }
|
||||||
).get()
|
).get()
|
||||||
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
||||||
it.destinationDirectory = distribution.directory
|
it._destinationDirectory = distribution.directory
|
||||||
|
|
||||||
commonWebpackConfigurations.forEach { configure ->
|
commonWebpackConfigurations.forEach { configure ->
|
||||||
it.configure()
|
it.configure()
|
||||||
|
|||||||
+1
-1
@@ -195,7 +195,7 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
|
|
||||||
it.compilation = compilation
|
it.compilation = compilation
|
||||||
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
||||||
it.destinationDirectory = distribution.directory
|
it._destinationDirectory = distribution.directory
|
||||||
|
|
||||||
when (kind) {
|
when (kind) {
|
||||||
BuildVariantKind.PRODUCTION -> {
|
BuildVariantKind.PRODUCTION -> {
|
||||||
|
|||||||
+22
-10
@@ -23,6 +23,8 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
|||||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.Mode
|
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.Mode
|
||||||
import org.jetbrains.kotlin.gradle.testing.internal.reportsDir
|
import org.jetbrains.kotlin.gradle.testing.internal.reportsDir
|
||||||
import org.jetbrains.kotlin.gradle.utils.injected
|
import org.jetbrains.kotlin.gradle.utils.injected
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.property
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.provider
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -51,14 +53,17 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
|||||||
@Input
|
@Input
|
||||||
var mode: Mode = Mode.DEVELOPMENT
|
var mode: Mode = Mode.DEVELOPMENT
|
||||||
|
|
||||||
|
private var _entry: File? = null
|
||||||
|
|
||||||
@get:PathSensitive(PathSensitivity.ABSOLUTE)
|
@get:PathSensitive(PathSensitivity.ABSOLUTE)
|
||||||
@get:InputFile
|
@get:InputFile
|
||||||
var entry: File? = null
|
var entry: File by property(::_entry) {
|
||||||
get() = field ?: compilation.compileKotlinTask.outputFile
|
compilation.compileKotlinTask.outputFile
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
onlyIf {
|
onlyIf {
|
||||||
entry!!.exists()
|
entry.exists()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,22 +89,29 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
|||||||
@get:Internal
|
@get:Internal
|
||||||
@Deprecated("use destinationDirectory instead", ReplaceWith("destinationDirectory"))
|
@Deprecated("use destinationDirectory instead", ReplaceWith("destinationDirectory"))
|
||||||
val outputPath: File
|
val outputPath: File
|
||||||
get() = destinationDirectory!!
|
get() = destinationDirectory
|
||||||
|
|
||||||
private val baseConventions: BasePluginConvention?
|
private val baseConventions: BasePluginConvention?
|
||||||
get() = project.convention.plugins["base"] as BasePluginConvention?
|
get() = project.convention.plugins["base"] as BasePluginConvention?
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
var destinationDirectory: File? = null
|
internal var _destinationDirectory: File? = null
|
||||||
get() = field ?: project.buildDir.resolve(baseConventions!!.distsDirName)
|
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
var outputFileName: String? = null
|
val destinationDirectory: File by provider(::_destinationDirectory) {
|
||||||
get() = field ?: (baseConventions?.archivesBaseName + ".js")
|
project.buildDir.resolve(baseConventions!!.distsDirName)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var _outputFileName: String? = null
|
||||||
|
|
||||||
|
@get:Internal
|
||||||
|
var outputFileName: String by property(::_outputFileName) {
|
||||||
|
baseConventions?.archivesBaseName + ".js"
|
||||||
|
}
|
||||||
|
|
||||||
@get:OutputFile
|
@get:OutputFile
|
||||||
open val outputFile: File
|
open val outputFile: File
|
||||||
get() = destinationDirectory!!.resolve(outputFileName!!)
|
get() = destinationDirectory.resolve(outputFileName)
|
||||||
|
|
||||||
open val configDirectory: File?
|
open val configDirectory: File?
|
||||||
@Optional @InputDirectory get() = project.projectDir.resolve("webpack.config.d").takeIf { it.isDirectory }
|
@Optional @InputDirectory get() = project.projectDir.resolve("webpack.config.d").takeIf { it.isDirectory }
|
||||||
@@ -108,7 +120,7 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
|||||||
var report: Boolean = false
|
var report: Boolean = false
|
||||||
|
|
||||||
open val reportDir: File
|
open val reportDir: File
|
||||||
@OutputDirectory get() = project.reportsDir.resolve("webpack").resolve(entry!!.nameWithoutExtension)
|
@OutputDirectory get() = project.reportsDir.resolve("webpack").resolve(entry.nameWithoutExtension)
|
||||||
|
|
||||||
open val evaluatedConfigFile: File
|
open val evaluatedConfigFile: File
|
||||||
@OutputFile get() = reportDir.resolve("webpack.config.evaluated.js")
|
@OutputFile get() = reportDir.resolve("webpack.config.evaluated.js")
|
||||||
|
|||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.utils
|
||||||
|
|
||||||
|
import kotlin.reflect.KMutableProperty
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
open class ProviderDelegate<out T : Any>(
|
||||||
|
protected open val backing: KProperty<T?>,
|
||||||
|
private val defaultValueProvider: () -> T
|
||||||
|
) {
|
||||||
|
operator fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||||
|
return backing.getter.call() ?: defaultValueProvider()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PropertyDelegate<T : Any>(
|
||||||
|
override val backing: KMutableProperty<T?>,
|
||||||
|
defaultValueProvider: () -> T
|
||||||
|
) : ProviderDelegate<T>(backing, defaultValueProvider) {
|
||||||
|
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
||||||
|
backing.setter.call(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : Any> provider(
|
||||||
|
backing: KProperty<T?>,
|
||||||
|
defaultValueProvider: () -> T
|
||||||
|
): ProviderDelegate<T> = ProviderDelegate(backing, defaultValueProvider)
|
||||||
|
|
||||||
|
fun <T : Any> property(
|
||||||
|
backing: KMutableProperty<T?>,
|
||||||
|
defaultValueProvider: () -> T
|
||||||
|
): PropertyDelegate<T> = PropertyDelegate(backing, defaultValueProvider)
|
||||||
Reference in New Issue
Block a user