From 6da95e2cead2377b97898e0d4304091b1d54a143 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 1 Aug 2014 20:45:06 -0500 Subject: [PATCH] Maven plugin: support additional arguments, drop inline/optimize --- .../arguments/CompilerArgumentsUtil.java | 39 ---------- .../pom.xml | 9 ++- .../main/kotlin/org/jetbrains/HelloWorld.kt | 2 +- .../org/jetbrains/HelloWorldJavaTest.java | 0 .../verify.bsh | 2 +- .../main/kotlin/org/jetbrains/HelloWorld.kt | 9 --- .../src/it/test-optimizationDisabled/pom.xml | 78 ------------------- .../org/jetbrains/HelloWorldJavaTest.java | 13 ---- .../it/test-optimizationDisabled/verify.bsh | 6 -- .../kotlin/maven/KotlinCompileMojoBase.java | 25 ++---- 10 files changed, 17 insertions(+), 166 deletions(-) delete mode 100644 compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CompilerArgumentsUtil.java rename libraries/tools/kotlin-maven-plugin-test/src/it/{test-inlineDisabled => test-extraArguments}/pom.xml (89%) rename libraries/tools/kotlin-maven-plugin-test/src/it/{test-optimizationDisabled => test-extraArguments}/src/main/kotlin/org/jetbrains/HelloWorld.kt (98%) rename libraries/tools/kotlin-maven-plugin-test/src/it/{test-inlineDisabled => test-extraArguments}/src/test/java/org/jetbrains/HelloWorldJavaTest.java (100%) rename libraries/tools/kotlin-maven-plugin-test/src/it/{test-inlineDisabled => test-extraArguments}/verify.bsh (70%) delete mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-inlineDisabled/src/main/kotlin/org/jetbrains/HelloWorld.kt delete mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-optimizationDisabled/pom.xml delete mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-optimizationDisabled/src/test/java/org/jetbrains/HelloWorldJavaTest.java delete mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-optimizationDisabled/verify.bsh 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 deleted file mode 100644 index d0e266969d5..00000000000 --- a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CompilerArgumentsUtil.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 boolean optionToBooleanFlag(@Nullable String option, boolean defaultValue) { - boolean enabled = "on".equalsIgnoreCase(option) || "true".equalsIgnoreCase(option); - boolean disabled = "off".equalsIgnoreCase(option) || "false".equalsIgnoreCase(option); - return (enabled || disabled) ? enabled : defaultValue; - } - - public static boolean checkOption(@Nullable String option) { - return option == null || - "on".equalsIgnoreCase(option) || - "off".equalsIgnoreCase(option) || - "true".equalsIgnoreCase(option) || - "false".equalsIgnoreCase(option); - } - - public static String getWrongCheckOptionErrorMessage(@Nullable String option, @Nullable String value) { - return "Wrong value for " + option + " option: '" + value + "'. Should be 'on'/'off' or 'true'/'false'"; - } -} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-inlineDisabled/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-extraArguments/pom.xml similarity index 89% rename from libraries/tools/kotlin-maven-plugin-test/src/it/test-inlineDisabled/pom.xml rename to libraries/tools/kotlin-maven-plugin-test/src/it/test-extraArguments/pom.xml index 505a63a79ef..6503940cdc4 100644 --- a/libraries/tools/kotlin-maven-plugin-test/src/it/test-inlineDisabled/pom.xml +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-extraArguments/pom.xml @@ -11,7 +11,7 @@ ../../pom.xml - test-inlineDisabled + test-extraArguments @@ -69,7 +69,12 @@ - false + + -Xno-inline + -Xno-optimize + -Xno-call-assertions + -Xno-param-assertions + diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-optimizationDisabled/src/main/kotlin/org/jetbrains/HelloWorld.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-extraArguments/src/main/kotlin/org/jetbrains/HelloWorld.kt similarity index 98% rename from libraries/tools/kotlin-maven-plugin-test/src/it/test-optimizationDisabled/src/main/kotlin/org/jetbrains/HelloWorld.kt rename to libraries/tools/kotlin-maven-plugin-test/src/it/test-extraArguments/src/main/kotlin/org/jetbrains/HelloWorld.kt index bc4fbf7504e..f412c000c41 100644 --- a/libraries/tools/kotlin-maven-plugin-test/src/it/test-optimizationDisabled/src/main/kotlin/org/jetbrains/HelloWorld.kt +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-extraArguments/src/main/kotlin/org/jetbrains/HelloWorld.kt @@ -6,4 +6,4 @@ fun main(args : Array) { fun getGreeting() : String { return "Hello, World!" -} \ No newline at end of file +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-inlineDisabled/src/test/java/org/jetbrains/HelloWorldJavaTest.java b/libraries/tools/kotlin-maven-plugin-test/src/it/test-extraArguments/src/test/java/org/jetbrains/HelloWorldJavaTest.java similarity index 100% rename from libraries/tools/kotlin-maven-plugin-test/src/it/test-inlineDisabled/src/test/java/org/jetbrains/HelloWorldJavaTest.java rename to libraries/tools/kotlin-maven-plugin-test/src/it/test-extraArguments/src/test/java/org/jetbrains/HelloWorldJavaTest.java diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-inlineDisabled/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-extraArguments/verify.bsh similarity index 70% rename from libraries/tools/kotlin-maven-plugin-test/src/it/test-inlineDisabled/verify.bsh rename to libraries/tools/kotlin-maven-plugin-test/src/it/test-extraArguments/verify.bsh index 5ecd01be2e1..51dc3dc0dab 100644 --- a/libraries/tools/kotlin-maven-plugin-test/src/it/test-inlineDisabled/verify.bsh +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-extraArguments/verify.bsh @@ -1,6 +1,6 @@ import java.io.*; -File file = new File(basedir, "target/test-inlineDisabled-0.1-SNAPSHOT.jar"); +File file = new File(basedir, "target/test-extraArguments-0.1-SNAPSHOT.jar"); if (!file.exists() || !file.isFile()) { throw new FileNotFoundException("Could not find generated JAR: " + file); } diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-inlineDisabled/src/main/kotlin/org/jetbrains/HelloWorld.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-inlineDisabled/src/main/kotlin/org/jetbrains/HelloWorld.kt deleted file mode 100644 index bc4fbf7504e..00000000000 --- a/libraries/tools/kotlin-maven-plugin-test/src/it/test-inlineDisabled/src/main/kotlin/org/jetbrains/HelloWorld.kt +++ /dev/null @@ -1,9 +0,0 @@ -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-test/src/it/test-optimizationDisabled/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-optimizationDisabled/pom.xml deleted file mode 100644 index 9c815f182c6..00000000000 --- a/libraries/tools/kotlin-maven-plugin-test/src/it/test-optimizationDisabled/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - 4.0.0 - - - org.jetbrains.kotlin - kotlin-project - 0.1-SNAPSHOT - ../../pom.xml - - - test-optimizationDisabled - - - - junit - junit - 4.9 - - - org.jetbrains.kotlin - kotlin-runtime - ${project.version} - - - - - - - - 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 - ${project.version} - - - compile - process-sources - - compile - - - - test-compile - process-test-sources - - test-compile - - - - - false - - - - - - diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-optimizationDisabled/src/test/java/org/jetbrains/HelloWorldJavaTest.java b/libraries/tools/kotlin-maven-plugin-test/src/it/test-optimizationDisabled/src/test/java/org/jetbrains/HelloWorldJavaTest.java deleted file mode 100644 index e021388ec28..00000000000 --- a/libraries/tools/kotlin-maven-plugin-test/src/it/test-optimizationDisabled/src/test/java/org/jetbrains/HelloWorldJavaTest.java +++ /dev/null @@ -1,13 +0,0 @@ -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-test/src/it/test-optimizationDisabled/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-optimizationDisabled/verify.bsh deleted file mode 100644 index a867dfdd427..00000000000 --- a/libraries/tools/kotlin-maven-plugin-test/src/it/test-optimizationDisabled/verify.bsh +++ /dev/null @@ -1,6 +0,0 @@ -import java.io.*; - -File file = new File(basedir, "target/test-optimizationDisabled-0.1-SNAPSHOT.jar"); -if (!file.exists() || !file.isFile()) { - throw new FileNotFoundException("Could not find generated JAR: " + 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 8aefe9303e3..fe5aff493ca 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 @@ -17,6 +17,8 @@ package org.jetbrains.kotlin.maven; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.ArrayUtil; +import com.sampullara.cli.Args; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -28,7 +30,6 @@ import org.jetbrains.jet.cli.common.CLICompiler; import org.jetbrains.jet.cli.common.ExitCode; import org.jetbrains.jet.cli.common.KotlinVersion; import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments; -import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil; import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments; import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation; import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity; @@ -145,18 +146,11 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo { public String testModule; /** - * Switch method inlining on/off: possible values are "on" and "off". + * Additional command line arguments for Kotlin compiler. * * @parameter */ - public String inline; - - /** - * Switch method optimization on/off: possible values are "on" and "off". - * - * @parameter - */ - public String optimize; + public List args; @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -313,15 +307,12 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo { arguments.noJdkAnnotations = true; arguments.annotations = getFullAnnotationsPath(log, annotationPaths); log.info("Using kotlin annotations from " + arguments.annotations); - arguments.noInline = !CompilerArgumentsUtil.optionToBooleanFlag(inline, true); - arguments.noOptimize = !CompilerArgumentsUtil.optionToBooleanFlag(optimize, true); - if (!CompilerArgumentsUtil.checkOption(inline)) { - throw new MojoExecutionException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("inline", inline)); + try { + Args.parse(arguments, ArrayUtil.toStringArray(args)); } - - if (!CompilerArgumentsUtil.checkOption(optimize)) { - throw new MojoExecutionException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("optimize", optimize)); + catch (IllegalArgumentException e) { + throw new MojoExecutionException(e.getMessage()); } if (arguments.noInline) {