[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 }
|
||||
).get()
|
||||
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
||||
it.destinationDirectory = distribution.directory
|
||||
it._destinationDirectory = distribution.directory
|
||||
|
||||
commonWebpackConfigurations.forEach { configure ->
|
||||
it.configure()
|
||||
|
||||
+1
-1
@@ -195,7 +195,7 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
|
||||
it.compilation = compilation
|
||||
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
||||
it.destinationDirectory = distribution.directory
|
||||
it._destinationDirectory = distribution.directory
|
||||
|
||||
when (kind) {
|
||||
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.testing.internal.reportsDir
|
||||
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 javax.inject.Inject
|
||||
|
||||
@@ -51,14 +53,17 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
||||
@Input
|
||||
var mode: Mode = Mode.DEVELOPMENT
|
||||
|
||||
private var _entry: File? = null
|
||||
|
||||
@get:PathSensitive(PathSensitivity.ABSOLUTE)
|
||||
@get:InputFile
|
||||
var entry: File? = null
|
||||
get() = field ?: compilation.compileKotlinTask.outputFile
|
||||
var entry: File by property(::_entry) {
|
||||
compilation.compileKotlinTask.outputFile
|
||||
}
|
||||
|
||||
init {
|
||||
onlyIf {
|
||||
entry!!.exists()
|
||||
entry.exists()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,22 +89,29 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
||||
@get:Internal
|
||||
@Deprecated("use destinationDirectory instead", ReplaceWith("destinationDirectory"))
|
||||
val outputPath: File
|
||||
get() = destinationDirectory!!
|
||||
get() = destinationDirectory
|
||||
|
||||
private val baseConventions: BasePluginConvention?
|
||||
get() = project.convention.plugins["base"] as BasePluginConvention?
|
||||
|
||||
@get:Internal
|
||||
var destinationDirectory: File? = null
|
||||
get() = field ?: project.buildDir.resolve(baseConventions!!.distsDirName)
|
||||
internal var _destinationDirectory: File? = null
|
||||
|
||||
@get:Internal
|
||||
var outputFileName: String? = null
|
||||
get() = field ?: (baseConventions?.archivesBaseName + ".js")
|
||||
val destinationDirectory: File by provider(::_destinationDirectory) {
|
||||
project.buildDir.resolve(baseConventions!!.distsDirName)
|
||||
}
|
||||
|
||||
private var _outputFileName: String? = null
|
||||
|
||||
@get:Internal
|
||||
var outputFileName: String by property(::_outputFileName) {
|
||||
baseConventions?.archivesBaseName + ".js"
|
||||
}
|
||||
|
||||
@get:OutputFile
|
||||
open val outputFile: File
|
||||
get() = destinationDirectory!!.resolve(outputFileName!!)
|
||||
get() = destinationDirectory.resolve(outputFileName)
|
||||
|
||||
open val configDirectory: File?
|
||||
@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
|
||||
|
||||
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
|
||||
@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