Added "optimize" flag to settings everywhere

This commit is contained in:
Denis Zharkov
2014-07-11 12:39:14 +04:00
committed by Alexander Udalov
parent 433c9cd4a5
commit 0e683b0b99
28 changed files with 301 additions and 25 deletions
@@ -121,9 +121,14 @@ public open class KotlinCompile(): AbstractCompile() {
args.noStdlib = true
args.noJdkAnnotations = true
args.inline = kotlinOptions.inline
args.optimize = kotlinOptions.optimize
if (!CompilerArgumentsUtil.checkOption(args.inline)) {
throw GradleException(CompilerArgumentsUtil.getWrongInlineOptionErrorMessage(args.inline))
throw GradleException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("inline", args.inline))
}
if (!CompilerArgumentsUtil.checkOption(args.optimize)) {
throw GradleException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("optimize", args.optimize))
}
val messageCollector = GradleMessageCollector(getLogger())
@@ -43,6 +43,12 @@ class BasicKotlinGradleIT : BaseGradleIT() {
}
}
Test fun testOptimizationDisabled() {
Project("optimizationDisabled", "1.6").build("build", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") {
assertSuccessful()
}
}
Test fun testSimpleKDoc() {
Project("kdocProject", "1.6").build("kdoc", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") {
assertSuccessful()
@@ -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.optimize = false
}
task wrapper(type: Wrapper) {
gradleVersion="1.4"
}
@@ -0,0 +1,11 @@
<root>
<item name='com.google.common.base.Joiner com.google.common.base.Joiner on(java.lang.String)'>
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name='com.google.common.base.Joiner com.google.common.base.Joiner.MapJoiner withKeyValueSeparator(java.lang.String)'>
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name='com.google.common.base.Joiner com.google.common.base.Joiner skipNulls()'>
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
</root>
@@ -0,0 +1,13 @@
package demo
import java.util.ArrayList
class KotlinGreetingJoiner() {
val names = ArrayList<String?>()
fun addName(name : String?): Unit{
names.add(name)
}
}
@@ -0,0 +1,78 @@
<?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>
@@ -0,0 +1,9 @@
package org.jetbrains
fun main(args : Array<String>) {
System.out?.println(getGreeting())
}
fun getGreeting() : String {
return "Hello, World!"
}
@@ -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());
}
}
@@ -0,0 +1,6 @@
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);
}
@@ -35,6 +35,7 @@ import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil;
import org.jetbrains.jet.codegen.inline.InlineCodegenUtil;
import org.jetbrains.jet.codegen.optimization.OptimizationUtils;
import java.io.File;
import java.io.IOException;
@@ -158,6 +159,13 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
*/
public String inline;
/**
* Switch method optimization on/off: possible values are "on" and "off".
*
* @parameter
*/
public String optimize;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Kotlin Compiler version " + KotlinVersion.VERSION);
@@ -314,10 +322,23 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
arguments.annotations = getFullAnnotationsPath(log, annotationPaths);
log.info("Using kotlin annotations from " + arguments.annotations);
arguments.inline = inline;
arguments.optimize = optimize;
if (!CompilerArgumentsUtil.checkOption(arguments.inline)) {
throw new MojoExecutionException(CompilerArgumentsUtil.getWrongInlineOptionErrorMessage(arguments.inline));
throw new MojoExecutionException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("inline", arguments.inline));
}
if (!CompilerArgumentsUtil.checkOption(arguments.optimize)) {
throw new MojoExecutionException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("optimize", arguments.optimize));
}
log.info("Method inlining is " + CompilerArgumentsUtil.optionToBooleanFlag(arguments.inline, InlineCodegenUtil.DEFAULT_INLINE_FLAG));
log.info(
"Optimization mode is " + CompilerArgumentsUtil.optionToBooleanFlag(
arguments.optimize,
OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG
)
);
}
protected String getFullAnnotationsPath(Log log, List<String> annotations) {