From ca4609dd2aa4ee4f2046dd250596af6ef5cbd3e1 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Thu, 20 Mar 2014 15:32:20 +0400 Subject: [PATCH] Support inline true/false options --- .../buildtools/ant/BytecodeCompilerTask.java | 9 ++- .../arguments/CompilerArgumentsUtil.java | 45 +++++++++++ .../arguments/K2JVMCompilerArguments.java | 4 +- .../jetbrains/jet/cli/jvm/K2JVMCompiler.java | 12 ++- .../compiler/KotlinToJVMBytecodeCompiler.java | 5 +- .../jet/cli/jvm/repl/ReplInterpreter.java | 4 +- .../src/org/jetbrains/kotlin/AntTaskTest.java | 10 +++ .../inlineDisabled/build.log.expected | 10 +++ .../testData/inlineDisabled/build.xml | 7 ++ .../testData/inlineDisabled/hello.kt | 7 ++ .../inlineDisabled/hello.run.expected | 4 + .../inlineWrongArg/build.log.expected | 31 +++++++ .../testData/inlineWrongArg/build.xml | 7 ++ .../testData/inlineWrongArg/hello.kt | 7 ++ compiler/testData/cli/jvm/help.out | 2 +- compiler/testData/cli/jvm/inline/off.out | 2 +- compiler/testData/cli/jvm/inline/on.out | 2 +- compiler/testData/cli/jvm/inline/wrong.out | 4 +- compiler/testData/cli/jvm/wrongArgument.out | 2 +- .../jet/codegen/CodegenTestUtil.java | 4 +- .../jet/codegen/GenerationUtils.java | 4 +- .../jet/lang/types/lang/InlineUtil.java | 10 --- .../jetbrains/kotlin/gradle/tasks/Tasks.kt | 7 +- .../kotlin/gradle/KotlinGradlePluginIT.kt | 6 ++ .../resources/testProject/alfa/build.gradle | 1 - .../testProject/inlineDisabled/build.gradle | 50 ++++++++++++ .../com/google/common/base/annotations.xml | 11 +++ .../inlineDisabled/src/helloWorld.kt | 13 +++ .../src/it/test-helloworld/pom.xml | 5 -- .../src/it/test-inlineDisabled/pom.xml | 80 +++++++++++++++++++ .../main/kotlin/org/jetbrains/HelloWorld.kt | 9 +++ .../org/jetbrains/HelloWorldJavaTest.java | 13 +++ .../src/it/test-inlineDisabled/verify.bsh | 7 ++ .../kotlin/maven/KotlinCompileMojoBase.java | 9 ++- 34 files changed, 357 insertions(+), 46 deletions(-) create mode 100644 compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CompilerArgumentsUtil.java create mode 100644 compiler/integration-tests/testData/inlineDisabled/build.log.expected create mode 100644 compiler/integration-tests/testData/inlineDisabled/build.xml create mode 100644 compiler/integration-tests/testData/inlineDisabled/hello.kt create mode 100644 compiler/integration-tests/testData/inlineDisabled/hello.run.expected create mode 100644 compiler/integration-tests/testData/inlineWrongArg/build.log.expected create mode 100644 compiler/integration-tests/testData/inlineWrongArg/build.xml create mode 100644 compiler/integration-tests/testData/inlineWrongArg/hello.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/inlineDisabled/build.gradle create mode 100644 libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/inlineDisabled/externalAnnotations/com/google/common/base/annotations.xml create mode 100644 libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/inlineDisabled/src/helloWorld.kt create mode 100644 libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/pom.xml create mode 100644 libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/src/main/kotlin/org/jetbrains/HelloWorld.kt create mode 100644 libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/src/test/java/org/jetbrains/HelloWorldJavaTest.java create mode 100644 libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/verify.bsh diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java index ebd028cb7bc..b384287503b 100644 --- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java @@ -21,8 +21,8 @@ import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; import org.jetbrains.jet.buildtools.core.BytecodeCompiler; import org.jetbrains.jet.buildtools.core.Util; +import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil; import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException; -import org.jetbrains.jet.lang.types.lang.InlineUtil; import java.io.File; import java.util.Arrays; @@ -141,7 +141,12 @@ public class BytecodeCompilerTask extends Task { String stdlibPath = (this.stdlib != null ? getPath(this.stdlib) : null); String[] classpath = (this.compileClasspath != null ? this.compileClasspath.list() : null); String[] externalAnnotationsPath = (this.externalAnnotations != null) ? this.externalAnnotations.list() : null; - boolean enableInline = InlineUtil.optionToInlineFlag(inline); + + if (!CompilerArgumentsUtil.checkInlineOption(inline)) { + throw new CompileEnvironmentException(CompilerArgumentsUtil.getWrongOptionErrorMessage(inline)); + } + + boolean enableInline = CompilerArgumentsUtil.optionToInlineFlag(inline); if (this.src != null) { diff --git a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CompilerArgumentsUtil.java b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CompilerArgumentsUtil.java new file mode 100644 index 00000000000..0f91e2f7932 --- /dev/null +++ b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CompilerArgumentsUtil.java @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2014 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.jet.cli.common.arguments; + +import org.jetbrains.annotations.Nullable; + +public class CompilerArgumentsUtil { + public static final boolean DEFAULT_INLINE_FLAG = true; + public static final boolean DEFAULT_INLINE_FLAG_FOR_TEST = true; + + public static boolean optionToInlineFlag(@Nullable String option) { + boolean enableInline = "on".equalsIgnoreCase(option) || "true".equalsIgnoreCase(option); + return (enableInline || "off".equalsIgnoreCase(option) || "false".equalsIgnoreCase(option)) ? enableInline : DEFAULT_INLINE_FLAG; + } + + public static boolean checkInlineOption(@Nullable String option) { + if (option == null || + "on".equalsIgnoreCase(option) || + "off".equalsIgnoreCase(option) || + "true".equalsIgnoreCase(option) || + "false".equalsIgnoreCase(option)) { + return true; + } + + return false; + } + + public static String getWrongOptionErrorMessage(@Nullable String inline) { + return "Wrong value for inline option: '" + inline + "'. Should be 'on'/'off' or 'true'/'false'"; + } +} diff --git a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JVMCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JVMCompilerArguments.java index 91e830ed936..6366490a492 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JVMCompilerArguments.java +++ b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JVMCompilerArguments.java @@ -66,6 +66,6 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments { @Argument(value = "kotlinHome", description = "Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery") public String kotlinHome; - @Argument(value = "inline", description = "Inlining mode: on/off (default is on)") - public String enableInline; + @Argument(value = "inline", description = "Inlining mode: on/off or true/false (default is on)") + public String inline; } diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java index 547a9fc7e27..7ed301284ef 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java @@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.cli.common.CLICompiler; import org.jetbrains.jet.cli.common.CLIConfigurationKeys; import org.jetbrains.jet.cli.common.ExitCode; +import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil; import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments; import org.jetbrains.jet.cli.common.messages.*; import org.jetbrains.jet.cli.jvm.compiler.*; @@ -32,7 +33,6 @@ import org.jetbrains.jet.codegen.CompilationException; import org.jetbrains.jet.config.CommonConfigurationKeys; import org.jetbrains.jet.config.CompilerConfiguration; import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter; -import org.jetbrains.jet.lang.types.lang.InlineUtil; import org.jetbrains.jet.utils.KotlinPaths; import org.jetbrains.jet.utils.KotlinPathsFromHomeDir; import org.jetbrains.jet.utils.PathUtil; @@ -108,7 +108,7 @@ public class K2JVMCompiler extends CLICompiler { configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, arguments.notNullAssertions); configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, arguments.notNullParamAssertions); - configuration.put(JVMConfigurationKeys.ENABLE_INLINE, InlineUtil.optionToInlineFlag(arguments.enableInline)); + configuration.put(JVMConfigurationKeys.ENABLE_INLINE, CompilerArgumentsUtil.optionToInlineFlag(arguments.inline)); configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector); @@ -197,11 +197,9 @@ public class K2JVMCompiler extends CLICompiler { protected void checkArguments(@NotNull K2JVMCompilerArguments argument) { super.checkArguments(argument); - String inline = argument.enableInline; - if (inline != null) { - if (!"on".equalsIgnoreCase(inline) && !"off".equalsIgnoreCase(inline)) { - throw new IllegalArgumentException("Wrong value for inline option: '" + inline + "'. Should be 'on' or 'off'"); - } + if (!CompilerArgumentsUtil.checkInlineOption(argument.inline)) { + throw new IllegalArgumentException(CompilerArgumentsUtil.getWrongOptionErrorMessage(argument.inline)); } } + } diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java index 22ca7f8e456..83c775c574b 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java @@ -18,7 +18,6 @@ package org.jetbrains.jet.cli.jvm.compiler; import com.google.common.base.Predicates; import com.intellij.openapi.Disposable; -import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.psi.PsiFile; import kotlin.Function0; @@ -30,6 +29,7 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.cli.common.CLIConfigurationKeys; import org.jetbrains.jet.cli.common.CompilerPlugin; import org.jetbrains.jet.cli.common.CompilerPluginContext; +import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil; import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport; import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.cli.common.output.OutputDirector; @@ -48,7 +48,6 @@ import org.jetbrains.jet.lang.resolve.ScriptNameUtil; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.lang.resolve.java.PackageClassUtils; import org.jetbrains.jet.lang.resolve.name.FqName; -import org.jetbrains.jet.lang.types.lang.InlineUtil; import org.jetbrains.jet.plugin.MainFunctionDetector; import org.jetbrains.jet.utils.KotlinPaths; @@ -308,7 +307,7 @@ public class KotlinToJVMBytecodeCompiler { configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false), configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, false), GenerationState.GenerateClassFilter.GENERATE_ALL, - configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineUtil.DEFAULT_INLINE_FLAG) + configuration.get(JVMConfigurationKeys.ENABLE_INLINE, CompilerArgumentsUtil.DEFAULT_INLINE_FLAG) ); KotlinCodegenFacade.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION); return generationState; diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java index 400ddab1406..cdad0f6c4ec 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java @@ -32,6 +32,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.asm4.Type; import org.jetbrains.jet.OutputFile; import org.jetbrains.jet.analyzer.AnalyzeExhaust; +import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil; import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport; import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.cli.common.messages.MessageCollectorToString; @@ -56,7 +57,6 @@ import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl; -import org.jetbrains.jet.lang.types.lang.InlineUtil; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.plugin.JetLanguage; import org.jetbrains.jet.storage.ExceptionTracker; @@ -248,7 +248,7 @@ public class ReplInterpreter { BindingContext bindingContext = AnalyzeExhaust.success(trace.getBindingContext(), module).getBindingContext(); GenerationState generationState = new GenerationState(psiFile.getProject(), ClassBuilderFactories.BINARIES, - bindingContext, Collections.singletonList(psiFile), InlineUtil.DEFAULT_INLINE_FLAG); + bindingContext, Collections.singletonList(psiFile), CompilerArgumentsUtil.DEFAULT_INLINE_FLAG); compileScript(psiFile.getScript(), scriptClassType, earlierScripts, generationState, CompilationErrorHandler.THROW_EXCEPTION); diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java index cee735e96d6..c2af45ea708 100644 --- a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java @@ -85,6 +85,16 @@ public class AntTaskTest extends KotlinIntegrationTestBase { doJvmAntTest(); } + @Test + public void inlineDisabled() throws Exception { + doJvmAntTest(); + } + + @Test + public void inlineWrongArg() throws Exception { + doAntTest(FAILED); + } + @Test public void jvmClasspath() throws Exception { doJvmAntTest(); diff --git a/compiler/integration-tests/testData/inlineDisabled/build.log.expected b/compiler/integration-tests/testData/inlineDisabled/build.log.expected new file mode 100644 index 00000000000..34c09a5fcbf --- /dev/null +++ b/compiler/integration-tests/testData/inlineDisabled/build.log.expected @@ -0,0 +1,10 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: + [kotlinc] Compiling [[[TestData]/hello.kt]] => [[Temp]/hello.jar] + +BUILD SUCCESSFUL +Total time: [time] + +Return code: 0 diff --git a/compiler/integration-tests/testData/inlineDisabled/build.xml b/compiler/integration-tests/testData/inlineDisabled/build.xml new file mode 100644 index 00000000000..018d9dbe233 --- /dev/null +++ b/compiler/integration-tests/testData/inlineDisabled/build.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/compiler/integration-tests/testData/inlineDisabled/hello.kt b/compiler/integration-tests/testData/inlineDisabled/hello.kt new file mode 100644 index 00000000000..5a1704e14e7 --- /dev/null +++ b/compiler/integration-tests/testData/inlineDisabled/hello.kt @@ -0,0 +1,7 @@ +package hello + +fun main(args : Array) { + for (s in arrayList("a")) + println("Hello, $s!") + +} diff --git a/compiler/integration-tests/testData/inlineDisabled/hello.run.expected b/compiler/integration-tests/testData/inlineDisabled/hello.run.expected new file mode 100644 index 00000000000..96c6fc52793 --- /dev/null +++ b/compiler/integration-tests/testData/inlineDisabled/hello.run.expected @@ -0,0 +1,4 @@ +OUT: +Hello, a! + +Return code: 0 diff --git a/compiler/integration-tests/testData/inlineWrongArg/build.log.expected b/compiler/integration-tests/testData/inlineWrongArg/build.log.expected new file mode 100644 index 00000000000..7721932f250 --- /dev/null +++ b/compiler/integration-tests/testData/inlineWrongArg/build.log.expected @@ -0,0 +1,31 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: + +ERR: + +BUILD FAILED +[TestData]/build.xml:5: org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException: Wrong value for inline option: 'wrong'. Should be 'on'/'off' or 'true'/'false' + at org.jetbrains.jet.buildtools.ant.BytecodeCompilerTask.execute(BytecodeCompilerTask.java:146) + at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:597) + at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) + at org.apache.tools.ant.Task.perform(Task.java:348) + at org.apache.tools.ant.Target.execute(Target.java:390) + at org.apache.tools.ant.Target.performTasks(Target.java:411) + at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1360) + at org.apache.tools.ant.Project.executeTarget(Project.java:1329) + at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) + at org.apache.tools.ant.Project.executeTargets(Project.java:1212) + at org.apache.tools.ant.Main.runBuild(Main.java:801) + at org.apache.tools.ant.Main.startAnt(Main.java:218) + at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) + at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109) + +Total time: [time] + +Return code: 1 diff --git a/compiler/integration-tests/testData/inlineWrongArg/build.xml b/compiler/integration-tests/testData/inlineWrongArg/build.xml new file mode 100644 index 00000000000..7023c02f096 --- /dev/null +++ b/compiler/integration-tests/testData/inlineWrongArg/build.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/compiler/integration-tests/testData/inlineWrongArg/hello.kt b/compiler/integration-tests/testData/inlineWrongArg/hello.kt new file mode 100644 index 00000000000..5a1704e14e7 --- /dev/null +++ b/compiler/integration-tests/testData/inlineWrongArg/hello.kt @@ -0,0 +1,7 @@ +package hello + +fun main(args : Array) { + for (s in arrayList("a")) + println("Hello, $s!") + +} diff --git a/compiler/testData/cli/jvm/help.out b/compiler/testData/cli/jvm/help.out index 46f8505bb50..b4de49e89ce 100644 --- a/compiler/testData/cli/jvm/help.out +++ b/compiler/testData/cli/jvm/help.out @@ -13,7 +13,7 @@ Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments -module [String] module to compile -script [flag] evaluate script -kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery - -inline [String] Inlining mode: on/off (default is on) + -inline [String] Inlining mode: on/off or true/false (default is on) -tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag -verbose [flag] Enable verbose logging output -version [flag] Display compiler version diff --git a/compiler/testData/cli/jvm/inline/off.out b/compiler/testData/cli/jvm/inline/off.out index 46f8505bb50..b4de49e89ce 100644 --- a/compiler/testData/cli/jvm/inline/off.out +++ b/compiler/testData/cli/jvm/inline/off.out @@ -13,7 +13,7 @@ Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments -module [String] module to compile -script [flag] evaluate script -kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery - -inline [String] Inlining mode: on/off (default is on) + -inline [String] Inlining mode: on/off or true/false (default is on) -tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag -verbose [flag] Enable verbose logging output -version [flag] Display compiler version diff --git a/compiler/testData/cli/jvm/inline/on.out b/compiler/testData/cli/jvm/inline/on.out index 46f8505bb50..b4de49e89ce 100644 --- a/compiler/testData/cli/jvm/inline/on.out +++ b/compiler/testData/cli/jvm/inline/on.out @@ -13,7 +13,7 @@ Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments -module [String] module to compile -script [flag] evaluate script -kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery - -inline [String] Inlining mode: on/off (default is on) + -inline [String] Inlining mode: on/off or true/false (default is on) -tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag -verbose [flag] Enable verbose logging output -version [flag] Display compiler version diff --git a/compiler/testData/cli/jvm/inline/wrong.out b/compiler/testData/cli/jvm/inline/wrong.out index b97fd79ad55..b94cebe4b2a 100644 --- a/compiler/testData/cli/jvm/inline/wrong.out +++ b/compiler/testData/cli/jvm/inline/wrong.out @@ -1,4 +1,4 @@ -Wrong value for inline option: 'wrong'. Should be 'on' or 'off' +Wrong value for inline option: 'wrong'. Should be 'on'/'off' or 'true'/'false' Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments -jar [String] jar file name -src [String] source file or directory (allows many paths separated by the system path separator) @@ -14,7 +14,7 @@ Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments -module [String] module to compile -script [flag] evaluate script -kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery - -inline [String] Inlining mode: on/off (default is on) + -inline [String] Inlining mode: on/off or true/false (default is on) -tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag -verbose [flag] Enable verbose logging output -version [flag] Display compiler version diff --git a/compiler/testData/cli/jvm/wrongArgument.out b/compiler/testData/cli/jvm/wrongArgument.out index cb802c6268d..4607a19838a 100644 --- a/compiler/testData/cli/jvm/wrongArgument.out +++ b/compiler/testData/cli/jvm/wrongArgument.out @@ -14,7 +14,7 @@ Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments -module [String] module to compile -script [flag] evaluate script -kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery - -inline [String] Inlining mode: on/off (default is on) + -inline [String] Inlining mode: on/off or true/false (default is on) -tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag -verbose [flag] Enable verbose logging output -version [flag] Display compiler version diff --git a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestUtil.java b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestUtil.java index 7f08e6e253b..a192bd27eaa 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestUtil.java +++ b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestUtil.java @@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.analyzer.AnalyzeExhaust; +import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil; import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys; import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime; @@ -31,7 +32,6 @@ import org.jetbrains.jet.codegen.state.Progress; import org.jetbrains.jet.config.CompilerConfiguration; import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; -import org.jetbrains.jet.lang.types.lang.InlineUtil; import org.jetbrains.jet.utils.UtilsPackage; import java.io.File; @@ -62,7 +62,7 @@ public class CodegenTestUtil { configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, true), configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true), GenerationState.GenerateClassFilter.GENERATE_ALL, - configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineUtil.DEFAULT_INLINE_FLAG_FOR_TEST) + configuration.get(JVMConfigurationKeys.ENABLE_INLINE, CompilerArgumentsUtil.DEFAULT_INLINE_FLAG_FOR_TEST) ); KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION); return state.getFactory(); diff --git a/compiler/tests/org/jetbrains/jet/codegen/GenerationUtils.java b/compiler/tests/org/jetbrains/jet/codegen/GenerationUtils.java index d04906b2594..ffff7abfca8 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/GenerationUtils.java +++ b/compiler/tests/org/jetbrains/jet/codegen/GenerationUtils.java @@ -21,11 +21,11 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.analyzer.AnalyzeExhaust; +import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil; import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; -import org.jetbrains.jet.lang.types.lang.InlineUtil; import java.util.Collections; import java.util.List; @@ -59,7 +59,7 @@ public class GenerationUtils { public static GenerationState compileFilesGetGenerationState(@NotNull Project project, @NotNull AnalyzeExhaust analyzeExhaust, @NotNull List files) { analyzeExhaust.throwIfError(); GenerationState state = new GenerationState(project, ClassBuilderFactories.TEST, analyzeExhaust.getBindingContext(), files, - InlineUtil.DEFAULT_INLINE_FLAG_FOR_TEST); + CompilerArgumentsUtil.DEFAULT_INLINE_FLAG_FOR_TEST); KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION); return state; } diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/InlineUtil.java b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/InlineUtil.java index c67eabfa11a..70389518aa1 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/InlineUtil.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/InlineUtil.java @@ -28,16 +28,6 @@ import org.jetbrains.jet.lang.resolve.constants.EnumValue; public class InlineUtil { - public static final boolean DEFAULT_INLINE_FLAG = true; - - public static final boolean DEFAULT_INLINE_FLAG_FOR_TEST = true; - - public static final boolean DEFAULT_INLINE_FLAG_FOR_STUB = false; /*always false*/ - - public static boolean optionToInlineFlag(@Nullable String option) { - return ("on".equalsIgnoreCase(option) || "off".equalsIgnoreCase(option)) ? "on".equalsIgnoreCase(option) : DEFAULT_INLINE_FLAG; - } - public static boolean hasNoinlineAnnotation(@NotNull CallableDescriptor valueParameterDescriptor) { KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance(); return KotlinBuiltIns.containsAnnotation(valueParameterDescriptor, builtIns.getNoinlineClassAnnotation()); diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index 68fd0e78a5e..fe49587e97e 100644 --- a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.gradle.plugin.* import org.jetbrains.kotlin.doc.KDocConfig import java.util.concurrent.Callable import org.gradle.api.Project +import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil public open class KotlinCompile(): AbstractCompile() { @@ -114,7 +115,11 @@ public open class KotlinCompile(): AbstractCompile() { args.noStdlib = true args.noJdkAnnotations = true - args.enableInline = kotlinOptions.enableInline + args.inline = kotlinOptions.inline + + if (!CompilerArgumentsUtil.checkInlineOption(args.inline)) { + throw GradleException(CompilerArgumentsUtil.getWrongOptionErrorMessage(args.inline)) + } val messageCollector = GradleMessageCollector(logger) val exitCode = compiler.exec(messageCollector, args) diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin-core/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt index 6ff2cb9b1e8..48b75c443da 100644 --- a/libraries/tools/kotlin-gradle-plugin-core/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-core/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt @@ -37,6 +37,12 @@ class BasicKotlinGradleIT : BaseGradleIT() { } } + Test fun testInlineDisabled() { + Project("inlineDisabled").build("build", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") { + assertSuccessful() + } + } + Test fun testSimpleKDoc() { Project("delta").build("kdoc", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") { assertSuccessful() diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/alfa/build.gradle b/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/alfa/build.gradle index bc72a588b04..ed580063ded 100644 --- a/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/alfa/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/alfa/build.gradle @@ -45,7 +45,6 @@ task show << { compileKotlin { kotlinOptions.annotations = "externalAnnotations" - kotlinOptions.enableInline = "off"; } diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/inlineDisabled/build.gradle b/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/inlineDisabled/build.gradle new file mode 100644 index 00000000000..984640fd0c2 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/inlineDisabled/build.gradle @@ -0,0 +1,50 @@ +buildscript { + repositories { + mavenCentral() + maven { + url 'file://' + pathToKotlinPlugin + } + } + dependencies { + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin-core:0.1-SNAPSHOT' + } +} + +import org.jetbrains.kotlin.gradle.plugin.KotlinPlugin + +apply plugin: KotlinPlugin + +sourceSets { + main { + kotlin { + srcDir 'src' + } + } +} + +repositories { + maven { + url 'file://' + pathToKotlinPlugin + } + mavenCentral() +} + +dependencies { + compile 'com.google.guava:guava:12.0' + testCompile 'org.testng:testng:6.8' + testRuntime 'org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT' +} + +test { + useTestNG() +} + +compileKotlin { + kotlinOptions.annotations = "externalAnnotations" + kotlinOptions.inline = false +} + + +task wrapper(type: Wrapper) { + gradleVersion="1.4" +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/inlineDisabled/externalAnnotations/com/google/common/base/annotations.xml b/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/inlineDisabled/externalAnnotations/com/google/common/base/annotations.xml new file mode 100644 index 00000000000..fd541a7e6e5 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/inlineDisabled/externalAnnotations/com/google/common/base/annotations.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/inlineDisabled/src/helloWorld.kt b/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/inlineDisabled/src/helloWorld.kt new file mode 100644 index 00000000000..5bb8e316ef5 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-core/src/test/resources/testProject/inlineDisabled/src/helloWorld.kt @@ -0,0 +1,13 @@ +package demo + +import java.util.ArrayList + +class KotlinGreetingJoiner() { + + val names = ArrayList() + + fun addName(name : String?): Unit{ + names.add(name) + } +} + diff --git a/libraries/tools/kotlin-maven-plugin/src/it/test-helloworld/pom.xml b/libraries/tools/kotlin-maven-plugin/src/it/test-helloworld/pom.xml index 80ee55276d2..1d279ecede0 100644 --- a/libraries/tools/kotlin-maven-plugin/src/it/test-helloworld/pom.xml +++ b/libraries/tools/kotlin-maven-plugin/src/it/test-helloworld/pom.xml @@ -70,11 +70,6 @@ - - - off - - diff --git a/libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/pom.xml b/libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/pom.xml new file mode 100644 index 00000000000..e3962d2f054 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/pom.xml @@ -0,0 +1,80 @@ + + + 4.0.0 + + org.jetbrains.kotlin.it + test-inlineDisabled + 1.0 + Test Hello World project + + + Test the kotlin-maven-plugin:compile goal on HelloWorld project. + + + + 0.1-SNAPSHOT + + + + + junit + junit + 4.9 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + + + + ${project.basedir}/src/main/kotlin + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + compile + process-sources + + compile + + + + test-compile + process-test-sources + + test-compile + + + + + false + + + + + + \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/src/main/kotlin/org/jetbrains/HelloWorld.kt b/libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/src/main/kotlin/org/jetbrains/HelloWorld.kt new file mode 100644 index 00000000000..bc4fbf7504e --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/src/main/kotlin/org/jetbrains/HelloWorld.kt @@ -0,0 +1,9 @@ +package org.jetbrains + +fun main(args : Array) { + System.out?.println(getGreeting()) +} + +fun getGreeting() : String { + return "Hello, World!" +} \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/src/test/java/org/jetbrains/HelloWorldJavaTest.java b/libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/src/test/java/org/jetbrains/HelloWorldJavaTest.java new file mode 100644 index 00000000000..e021388ec28 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/src/test/java/org/jetbrains/HelloWorldJavaTest.java @@ -0,0 +1,13 @@ +package org.jetbrains; + +import org.junit.Test; + +import static junit.framework.Assert.assertEquals; + +public class HelloWorldJavaTest { + + @Test + public void greeting() { + assertEquals("Hello, World!", org.jetbrains.JetbrainsPackage.getGreeting()); + } +} diff --git a/libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/verify.bsh b/libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/verify.bsh new file mode 100644 index 00000000000..c6efc3505ec --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin/src/it/test-inlineDisabled/verify.bsh @@ -0,0 +1,7 @@ +import java.io.*; + +File file = new File( basedir, "target/test-inlineDisabled-1.0.jar" ); +if (!file.exists() || !file.isFile()) +{ + throw new FileNotFoundException( "Could not find generated JAR: " + file ); +} \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java index 2d51fdd07cb..0be77778c22 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java @@ -33,7 +33,7 @@ import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation; import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity; import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.cli.jvm.K2JVMCompiler; -import org.jetbrains.jet.lang.types.lang.InlineUtil; +import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil; import java.io.File; import java.io.IOException; @@ -312,8 +312,11 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo { arguments.noJdkAnnotations = true; arguments.annotations = getFullAnnotationsPath(log, annotationPaths); log.info("Using kotlin annotations from " + arguments.annotations); - arguments.enableInline = inline; - log.info("Method inlining is " + InlineUtil.optionToInlineFlag(arguments.enableInline)); + arguments.inline = inline; + if (!CompilerArgumentsUtil.checkInlineOption(arguments.inline)) { + throw new MojoExecutionException(CompilerArgumentsUtil.getWrongOptionErrorMessage(arguments.inline)); + } + log.info("Method inlining is " + CompilerArgumentsUtil.optionToInlineFlag(arguments.inline)); } protected String getFullAnnotationsPath(Log log, List annotations) {