[Gradle, JS] Change byArgument on byArgumentOrNull

#KT-38485 fixed
This commit is contained in:
Ilya Goncharov
2020-04-22 12:14:20 +03:00
parent 47c27726b9
commit 8e282e8aad
4 changed files with 11 additions and 17 deletions
@@ -13,7 +13,7 @@ enum class KotlinJsCompilerType {
companion object { companion object {
const val jsCompilerProperty = "kotlin.js.compiler" const val jsCompilerProperty = "kotlin.js.compiler"
fun byArgument(argument: String): KotlinJsCompilerType? = fun byArgumentOrNull(argument: String): KotlinJsCompilerType? =
values().firstOrNull { it.name.equals(argument, ignoreCase = true) } values().firstOrNull { it.name.equals(argument, ignoreCase = true) }
} }
} }
@@ -166,7 +166,7 @@ open class KotlinJsProjectExtension :
compiler: String, compiler: String,
body: KotlinJsTargetDsl.() -> Unit = { } body: KotlinJsTargetDsl.() -> Unit = { }
): KotlinJsTargetDsl = js( ): KotlinJsTargetDsl = js(
KotlinJsCompilerType.byArgument(compiler) KotlinJsCompilerType.byArgumentOrNull(compiler)
?: throw IllegalArgumentException( ?: throw IllegalArgumentException(
"Unable to find $compiler setting. Use [${KotlinJsCompilerType.values().toList().joinToString()}]" "Unable to find $compiler setting. Use [${KotlinJsCompilerType.values().toList().joinToString()}]"
), ),
@@ -1,3 +1,8 @@
/*
* 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.dsl package org.jetbrains.kotlin.gradle.dsl
import groovy.lang.Closure import groovy.lang.Closure
@@ -26,7 +31,7 @@ interface KotlinTargetContainerWithJsPresetFunctions :
configure: KotlinJsTargetDsl.() -> Unit = { } configure: KotlinJsTargetDsl.() -> Unit = { }
) = js( ) = js(
name = name, name = name,
compiler = KotlinJsCompilerType.byArgument(compiler) compiler = KotlinJsCompilerType.byArgumentOrNull(compiler)
?: throw IllegalArgumentException( ?: throw IllegalArgumentException(
"Unable to find $compiler setting. Use [${KotlinJsCompilerType.values().toList().joinToString()}]" "Unable to find $compiler setting. Use [${KotlinJsCompilerType.values().toList().joinToString()}]"
), ),
@@ -1,17 +1,6 @@
/* /*
* Copyright 2010-2016 JetBrains s.r.o. * 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.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.jetbrains.kotlin.gradle.plugin package org.jetbrains.kotlin.gradle.plugin
@@ -206,7 +195,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
* Use Kotlin/JS backend compiler type * Use Kotlin/JS backend compiler type
*/ */
val jsCompiler: KotlinJsCompilerType val jsCompiler: KotlinJsCompilerType
get() = property(jsCompilerProperty)?.let { KotlinJsCompilerType.byArgument(it) } ?: KotlinJsCompilerType.LEGACY get() = property(jsCompilerProperty)?.let { KotlinJsCompilerType.byArgumentOrNull(it) } ?: KotlinJsCompilerType.LEGACY
private fun propertyWithDeprecatedVariant(propName: String, deprecatedPropName: String): String? { private fun propertyWithDeprecatedVariant(propName: String, deprecatedPropName: String): String? {
val deprecatedProperty = property(deprecatedPropName) val deprecatedProperty = property(deprecatedPropName)