Refactor gradle option generation mechanism
Ensure there's a statically checked dependency on LanguageVersion and JvmTarget, so that this information is updated automatically once a new language version or a JVM target is added
This commit is contained in:
+3
-4
@@ -25,17 +25,16 @@ import java.util.List;
|
||||
public abstract class CommonCompilerArguments {
|
||||
public static final String PLUGIN_OPTION_FORMAT = "plugin:<pluginId>:<optionName>=<value>";
|
||||
|
||||
// todo: reuse LanguageVersion from frontend
|
||||
@GradleOption(defaultValue = "\"1.1\"", possibleValues = { "\"1.0\", \"1.1\"" })
|
||||
@GradleOption(DefaultValues.LanguageVersions.class)
|
||||
@Argument(value = "language-version", description = "Provide source compatibility with specified language version")
|
||||
@ValueDescription("<version>")
|
||||
public String languageVersion;
|
||||
|
||||
@GradleOption(defaultValue = "false")
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault.class)
|
||||
@Argument(value = "nowarn", description = "Generate no warnings")
|
||||
public boolean suppressWarnings;
|
||||
|
||||
@GradleOption(defaultValue = "false")
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault.class)
|
||||
@Argument(value = "verbose", description = "Enable verbose logging output")
|
||||
public boolean verbose;
|
||||
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* 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.cli.common.arguments
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.CALL
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.NO_CALL
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
|
||||
open class DefaultValues(val defaultValue: String, val possibleValues: List<String>? = null) {
|
||||
object BooleanFalseDefault : DefaultValues("false")
|
||||
|
||||
object BooleanTrueDefault : DefaultValues("true")
|
||||
|
||||
object StringNullDefault : DefaultValues("null")
|
||||
|
||||
object LanguageVersions : DefaultValues(
|
||||
"\"" + LanguageVersion.LATEST.versionString + "\"",
|
||||
LanguageVersion.values().map { "\"${it.versionString}\"" }
|
||||
)
|
||||
|
||||
object JvmTargetVersions : DefaultValues(
|
||||
"\"" + JvmTarget.DEFAULT.string + "\"",
|
||||
JvmTarget.values().map { "\"${it.string}\"" }
|
||||
)
|
||||
|
||||
object JsEcmaVersions : DefaultValues(
|
||||
"\"v5\"",
|
||||
listOf("\"v5\"")
|
||||
)
|
||||
|
||||
object JsModuleKinds : DefaultValues(
|
||||
"\"plain\"",
|
||||
listOf("\"plain\"", "\"amd\"", "\"commonjs\"", "\"umd\"")
|
||||
)
|
||||
|
||||
object JsMain : DefaultValues(
|
||||
"\"" + NO_CALL + "\"",
|
||||
listOf("\"" + CALL + "\"", "\"" + NO_CALL + "\"")
|
||||
)
|
||||
}
|
||||
+3
-2
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.common.arguments
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class GradleOption(val defaultValue: String,
|
||||
val possibleValues: Array<String> = arrayOf())
|
||||
annotation class GradleOption(val value: KClass<out DefaultValues> = DefaultValues::class)
|
||||
|
||||
+9
-9
@@ -24,12 +24,12 @@ import static org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.CA
|
||||
import static org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.NO_CALL;
|
||||
|
||||
public class K2JSCompilerArguments extends CommonCompilerArguments {
|
||||
@GradleOption(defaultValue = "null")
|
||||
@GradleOption(DefaultValues.StringNullDefault.class)
|
||||
@Argument(value = "output", description = "Output file path")
|
||||
@ValueDescription("<path>")
|
||||
public String outputFile;
|
||||
|
||||
@GradleOption(defaultValue = "true")
|
||||
@GradleOption(DefaultValues.BooleanTrueDefault.class)
|
||||
@Argument(value = "no-stdlib", description = "Don't use bundled Kotlin stdlib")
|
||||
public boolean noStdlib;
|
||||
|
||||
@@ -37,29 +37,29 @@ public class K2JSCompilerArguments extends CommonCompilerArguments {
|
||||
@ValueDescription("<path[,]>")
|
||||
public String[] libraryFiles;
|
||||
|
||||
@GradleOption(defaultValue = "false")
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault.class)
|
||||
@Argument(value = "source-map", description = "Generate source map")
|
||||
public boolean sourceMap;
|
||||
|
||||
@GradleOption(defaultValue = "true")
|
||||
@GradleOption(DefaultValues.BooleanTrueDefault.class)
|
||||
@Argument(value = "meta-info", description = "Generate metadata")
|
||||
public boolean metaInfo;
|
||||
|
||||
@GradleOption(defaultValue = "true")
|
||||
@GradleOption(DefaultValues.BooleanTrueDefault.class)
|
||||
@Argument(value = "kjsm", description = "Generate kjsm-files (for creating libraries)")
|
||||
public boolean kjsm;
|
||||
|
||||
@GradleOption(defaultValue = "\"v5\"", possibleValues = { "\"v5\"" })
|
||||
@Argument(value = "target", description = "Generate JS files for specific ECMA version)")
|
||||
@GradleOption(DefaultValues.JsEcmaVersions.class)
|
||||
@Argument(value = "target", description = "Generate JS files for specific ECMA version")
|
||||
@ValueDescription("{ v5 }")
|
||||
public String target;
|
||||
|
||||
@GradleOption(defaultValue = "\"plain\"", possibleValues = { "\"plain\"", "\"amd\"", "\"commonjs\"", "\"umd\"" })
|
||||
@GradleOption(DefaultValues.JsModuleKinds.class)
|
||||
@Argument(value = "module-kind", description = "Kind of a module generated by compiler")
|
||||
@ValueDescription("{ plain, amd, commonjs, umd }")
|
||||
public String moduleKind;
|
||||
|
||||
@GradleOption(defaultValue = "\"" + NO_CALL + "\"", possibleValues = { "\"" + CALL + "\"", "\"" + NO_CALL + "\"" })
|
||||
@GradleOption(DefaultValues.JsMain.class)
|
||||
@Nullable
|
||||
@Argument(value = "main", description = "Whether a main function should be called")
|
||||
@ValueDescription("{" + CALL + "," + NO_CALL + "}")
|
||||
|
||||
+6
-6
@@ -28,24 +28,24 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
|
||||
@ValueDescription("<path>")
|
||||
public String classpath;
|
||||
|
||||
@GradleOption(defaultValue = "false")
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault.class)
|
||||
@Argument(value = "include-runtime", description = "Include Kotlin runtime in to resulting .jar")
|
||||
public boolean includeRuntime;
|
||||
|
||||
@GradleOption(defaultValue = "null")
|
||||
@GradleOption(DefaultValues.StringNullDefault.class)
|
||||
@Argument(value = "jdk-home", description = "Path to JDK home directory to include into classpath, if differs from default JAVA_HOME")
|
||||
@ValueDescription("<path>")
|
||||
public String jdkHome;
|
||||
|
||||
@GradleOption(defaultValue = "false")
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault.class)
|
||||
@Argument(value = "no-jdk", description = "Don't include Java runtime into classpath")
|
||||
public boolean noJdk;
|
||||
|
||||
@GradleOption(defaultValue = "true")
|
||||
@GradleOption(DefaultValues.BooleanTrueDefault.class)
|
||||
@Argument(value = "no-stdlib", description = "Don't include Kotlin runtime into classpath")
|
||||
public boolean noStdlib;
|
||||
|
||||
@GradleOption(defaultValue = "true")
|
||||
@GradleOption(DefaultValues.BooleanTrueDefault.class)
|
||||
@Argument(value = "no-reflect", description = "Don't include Kotlin reflection implementation into classpath")
|
||||
public boolean noReflect;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
|
||||
@Argument(value = "module-name", description = "Module name")
|
||||
public String moduleName;
|
||||
|
||||
@GradleOption(defaultValue = "\"1.6\"", possibleValues = { "\"1.6\"", "\"1.8\"" })
|
||||
@GradleOption(DefaultValues.JvmTargetVersions.class)
|
||||
@Argument(value = "jvm-target", description = "Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6")
|
||||
@ValueDescription("<version>")
|
||||
public String jvmTarget;
|
||||
|
||||
Reference in New Issue
Block a user