Maven plugin: support additional arguments, drop inline/optimize
This commit is contained in:
-39
@@ -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'";
|
||||
}
|
||||
}
|
||||
+7
-2
@@ -11,7 +11,7 @@
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>test-inlineDisabled</artifactId>
|
||||
<artifactId>test-extraArguments</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -69,7 +69,12 @@
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<inline>false</inline>
|
||||
<args>
|
||||
<arg>-Xno-inline</arg>
|
||||
<arg>-Xno-optimize</arg>
|
||||
<arg>-Xno-call-assertions</arg>
|
||||
<arg>-Xno-param-assertions</arg>
|
||||
</args>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
+1
-1
@@ -6,4 +6,4 @@ fun main(args : Array<String>) {
|
||||
|
||||
fun getGreeting() : String {
|
||||
return "Hello, World!"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
package org.jetbrains
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
System.out?.println(getGreeting())
|
||||
}
|
||||
|
||||
fun getGreeting() : String {
|
||||
return "Hello, World!"
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-project</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>test-optimizationDisabled</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-runtime</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${project.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>process-sources</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>process-test-sources</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<optimize>false</optimize>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
-13
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
+8
-17
@@ -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<String> 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) {
|
||||
|
||||
Reference in New Issue
Block a user