Merge pull request #288 from nskvortsov/master

Kotlin plugin for Google's new android build system
This commit is contained in:
Leonid Shalupov
2013-07-21 02:59:24 -07:00
51 changed files with 1437 additions and 84 deletions
@@ -0,0 +1,5 @@
<root>
<item name='com.android.build.gradle.BaseExtension org.gradle.api.NamedDomainObjectContainer&lt;com.android.build.gradle.api.AndroidSourceSet&gt; getSourceSets()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item name="com.android.build.gradle.api.AndroidSourceSet org.gradle.api.file.SourceDirectorySet getAllJava()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="com.android.build.gradle.api.AndroidSourceSet org.gradle.api.file.SourceDirectorySet getAllSource()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="com.android.build.gradle.api.AndroidSourceSet org.gradle.api.file.SourceDirectorySet getJava()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="com.android.build.gradle.api.ApkVariant com.android.builder.DefaultBuildType getBuildType()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="com.android.build.gradle.api.ApkVariant java.util.List&lt;com.android.builder.DefaultProductFlavor&gt; getProductFlavors()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="com.android.build.gradle.api.BaseVariant com.android.build.gradle.tasks.AidlCompile getAidlCompile()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="com.android.build.gradle.api.BaseVariant com.android.build.gradle.tasks.ProcessAndroidResources getProcessResources()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="com.android.build.gradle.api.BaseVariant com.android.build.gradle.tasks.RenderscriptCompile getRenderscriptCompile()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="com.android.build.gradle.api.LibraryVariant com.android.builder.DefaultBuildType getBuildType()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
</root>
@@ -1,18 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item name='org.gradle.api.Plugin void apply(T)'>
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
<val name="value" val="&quot;fun apply(p0 : T) : Unit&quot;"/>
</annotation>
</item>
<item name='org.gradle.api.Project org.gradle.api.plugins.PluginContainer getPlugins()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='org.gradle.api.Project org.gradle.api.plugins.Convention getConvention()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='org.gradle.api.Project org.gradle.api.initialization.dsl.ScriptHandler getBuildscript()'>
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
<val name="value" val="&quot;fun getBuildscript() : ScriptHandler&quot;"/>
</annotation>
</item>
</root>
<item name="org.gradle.api.NamedDomainObjectCollection T getByName(java.lang.String)">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="org.gradle.api.Plugin void apply(T)">
<annotation name="jet.runtime.typeinfo.KotlinSignature">
<val name="value" val="&quot;fun apply(p0 : T) : Unit&quot;" />
</annotation>
</item>
<item name="org.gradle.api.Project org.gradle.api.file.ConfigurableFileCollection files(java.lang.Object...)">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="org.gradle.api.Project org.gradle.api.initialization.dsl.ScriptHandler getBuildscript()">
<annotation name="jet.runtime.typeinfo.KotlinSignature">
<val name="value" val="&quot;fun getBuildscript() : ScriptHandler&quot;" />
</annotation>
</item>
<item name="org.gradle.api.Project org.gradle.api.logging.Logger getLogger()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="org.gradle.api.Project org.gradle.api.plugins.Convention getConvention()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="org.gradle.api.Project org.gradle.api.plugins.PluginContainer getPlugins()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
</root>
@@ -2,4 +2,7 @@
<item name='org.gradle.api.file.FileCollection org.gradle.api.file.FileCollection filter(org.gradle.api.specs.Spec&lt;? super java.io.File&gt;)'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='org.gradle.api.file.SourceDirectorySet java.util.Set&lt;java.io.File&gt; getSrcDirs()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
@@ -1,15 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item name='org.gradle.api.internal.HasConvention org.gradle.api.plugins.Convention getConvention()'>
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
<val name="value" val="&quot;fun getConvention() : Convention&quot;"/>
</annotation>
</item>
<item name='org.gradle.api.internal.AbstractTask org.gradle.api.logging.Logger getLogger()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='org.gradle.api.internal.AbstractTask org.gradle.api.Project getProject()'>
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
<val name="value" val="&quot;fun getProject() : Project&quot;"/>
</annotation>
</item>
</root>
<item name="org.gradle.api.internal.AbstractTask org.gradle.api.Project getProject()">
<annotation name="jet.runtime.typeinfo.KotlinSignature">
<val name="value" val="&quot;fun getProject() : Project&quot;" />
</annotation>
</item>
<item name="org.gradle.api.internal.AbstractTask org.gradle.api.logging.Logger getLogger()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="org.gradle.api.internal.HasConvention org.gradle.api.plugins.Convention getConvention()">
<annotation name="jet.runtime.typeinfo.KotlinSignature">
<val name="value" val="&quot;fun getConvention() : Convention&quot;" />
</annotation>
</item>
</root>
@@ -1,22 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item name='org.gradle.api.plugins.Convention java.util.Map&lt;java.lang.String,java.lang.Object&gt; getPlugins()'>
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
<val name="value" val="&quot;fun getPlugins() : MutableMap&lt;String, Any&gt;&quot;"/>
</annotation>
</item>
<item name='org.gradle.api.plugins.Convention org.gradle.api.internal.DynamicObject getExtensionsAsDynamicObject()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
<val name="value" val="&quot;fun getExtensionsAsDynamicObject() : DynamicObject&quot;"/>
</annotation>
</item>
<item name='org.gradle.api.plugins.PluginContainer org.gradle.api.Plugin apply(java.lang.String)'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='org.gradle.api.plugins.PluginContainer T apply(java.lang.Class&lt;T&gt;)'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='org.gradle.api.plugins.Convention T getPlugin(java.lang.Class&lt;T&gt;)'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
<item name="org.gradle.api.plugins.Convention T getPlugin(java.lang.Class&lt;T&gt;)">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="org.gradle.api.plugins.Convention java.util.Map&lt;java.lang.String,java.lang.Object&gt; getPlugins()">
<annotation name="jet.runtime.typeinfo.KotlinSignature">
<val name="value" val="&quot;fun getPlugins() : MutableMap&lt;String, Any&gt;&quot;" />
</annotation>
</item>
<item name="org.gradle.api.plugins.Convention org.gradle.api.internal.DynamicObject getExtensionsAsDynamicObject()">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name="jet.runtime.typeinfo.KotlinSignature">
<val name="value" val="&quot;fun getExtensionsAsDynamicObject() : DynamicObject&quot;" />
</annotation>
</item>
<item name="org.gradle.api.plugins.ExtensionAware org.gradle.api.plugins.ExtensionContainer getExtensions()">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="org.gradle.api.plugins.PluginContainer T apply(java.lang.Class&lt;T&gt;)">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="org.gradle.api.plugins.PluginContainer org.gradle.api.Plugin apply(java.lang.String)">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
</root>
@@ -20,6 +20,12 @@
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.android.tools.build</groupId>
<artifactId>gradle</artifactId>
<version>0.4.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -4,18 +4,11 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.plugins.JavaPlugin
import groovy.lang.Closure
import org.gradle.api.tasks.SourceSet
import org.jetbrains.kotlin.gradle.internal.KotlinSourceSetImpl
import org.gradle.api.internal.project.ProjectInternal
import org.gradle.api.internal.IConventionAware
import org.gradle.api.internal.HasConvention
import org.gradle.api.internal.file.collections.SimpleFileCollection
import org.gradle.api.file.FileTreeElement
import org.jetbrains.kotlin.gradle.internal.KotlinSourceSet
import org.gradle.api.file.SourceDirectorySet
import org.codehaus.groovy.runtime.MethodClosure
import org.gradle.api.specs.Spec
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.tasks.KDoc
@@ -23,7 +16,23 @@ import java.io.File
import java.util.concurrent.Callable
import org.gradle.api.Action
import org.gradle.api.tasks.compile.AbstractCompile
import java.util.Arrays
import org.gradle.api.logging.Logging
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.AppExtension
import com.android.build.gradle.LibraryExtension
import org.gradle.api.internal.DefaultDomainObjectSet
import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.api.AndroidSourceSet
import org.gradle.api.plugins.ExtensionAware
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
import java.util.ArrayList
import com.android.build.gradle.BasePlugin
import com.android.build.gradle.api.LibraryVariant
import com.android.build.gradle.api.ApkVariant
import com.android.builder.model.BuildType
import com.android.builder.BuilderConstants
import com.android.build.gradle.api.TestVariant
import org.gradle.api.plugins.JavaPlugin
open class KotlinPlugin: Plugin<Project> {
@@ -43,17 +52,15 @@ open class KotlinPlugin: Plugin<Project> {
javaPluginConvention: JavaPluginConvention) {
javaPluginConvention.getSourceSets()?.all(object : Action<SourceSet> {
override fun execute(sourceSet: SourceSet?) {
if (sourceSet is HasConvention) {
if (sourceSet is ExtensionAware) {
val sourceSetName = sourceSet.getName()
val kotlinSourceSet = KotlinSourceSetImpl(sourceSetName, project.getFileResolver())
val kotlinSourceSet = sourceSet.getExtensions().create("kotlin", javaClass<KotlinSourceSetImpl>(), sourceSetName, project.getFileResolver())!!
val kotlinDirSet = kotlinSourceSet.getKotlin()
kotlinDirSet.srcDir(project.file("src/${sourceSetName}/kotlin"))
sourceSet.getAllJava()?.source(kotlinDirSet)
sourceSet.getAllSource()?.source(kotlinDirSet)
sourceSet.getConvention().getPlugins().put("kotlin", kotlinSourceSet)
sourceSet.getResources()?.getFilter()?.exclude(KSpec({ elem ->
kotlinDirSet.contains(elem.getFile())
}))
@@ -82,12 +89,15 @@ open class KotlinPlugin: Plugin<Project> {
}
private fun configureKDoc(project: Project, javaPluginConvention: JavaPluginConvention) {
val mainSourceSet = javaPluginConvention.getSourceSets()?.getByName(SourceSet.MAIN_SOURCE_SET_NAME)!! as HasConvention
val mainSourceSet = javaPluginConvention.getSourceSets()?.findByName(SourceSet.MAIN_SOURCE_SET_NAME) as HasConvention?
val kdoc = project.getTasks()?.add(KDOC_TASK_NAME, javaClass<KDoc>())!!
kdoc.setDescription("Generates KDoc API documentation for the main source code.")
kdoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP)
kdoc.setSource(mainSourceSet.getConvention().getExtensionsAsDynamicObject().getProperty("kotlin"))
if (mainSourceSet != null) {
val kdoc = project.getTasks()?.add(KDOC_TASK_NAME, javaClass<KDoc>())!!
kdoc.setDescription("Generates KDoc API documentation for the main source code.")
kdoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP)
kdoc.setSource(mainSourceSet.getConvention().getExtensionsAsDynamicObject().getProperty("kotlin"))
}
project.getTasks()?.withType(javaClass<KDoc>(), object : Action<KDoc> {
override fun execute(param: KDoc?) {
@@ -104,6 +114,145 @@ open class KotlinPlugin: Plugin<Project> {
}
open class KotlinAndroidPlugin: Plugin<Project> {
val log = Logging.getLogger(getClass())
public override fun apply(p0: Project) {
val project = p0 as ProjectInternal
val ext = project.getExtensions().getByName("android") as BaseExtension
ext.getSourceSets()?.all(object : Action<AndroidSourceSet> {
override fun execute(sourceSet: AndroidSourceSet?) {
if (sourceSet is ExtensionAware) {
val sourceSetName = sourceSet.getName()
val kotlinSourceSet = sourceSet.getExtensions().create("kotlin", javaClass<KotlinSourceSetImpl>(), sourceSetName, project.getFileResolver())!!
val kotlinDirSet = kotlinSourceSet.getKotlin()
kotlinDirSet.srcDir(project.file("src/${sourceSetName}/kotlin"))
sourceSet.getAllJava().source(kotlinDirSet)
sourceSet.getAllSource().source(kotlinDirSet)
sourceSet.getResources()?.getFilter()?.exclude(KSpec({ elem ->
kotlinDirSet.contains(elem.getFile())
}))
project.getLogger().debug("Created kotlin sourceDirectorySet at ${kotlinDirSet.getSrcDirs()}")
}
}
})
(ext as ExtensionAware).getExtensions().add("kotlinOptions", K2JVMCompilerArguments())
project.afterEvaluate( { (project: Project?): Unit ->
if (project != null) {
val testVariants = ext.getTestVariants()!!
processVariants(testVariants, project, ext)
if (ext is AppExtension) {
val appVariants = ext.getApplicationVariants()!!
processVariants(appVariants, project, ext)
}
if (ext is LibraryExtension) {
val libVariants = ext.getLibraryVariants()!!;
processVariants(libVariants, project, ext)
}
}
})
}
private fun processVariants(variants: DefaultDomainObjectSet<out BaseVariant>, project: Project, androidExt: BaseExtension): Unit {
val logger = project.getLogger()
val kotlinOptions = getExtention<K2JVMCompilerArguments>(androidExt, "kotlinOptions")
val sourceSets = androidExt.getSourceSets()
val mainSourceSet = sourceSets.getByName(BuilderConstants.MAIN)
val testSourceSet = sourceSets.getByName(BuilderConstants.INSTRUMENT_TEST)
for (variant in variants) {
if (variant is LibraryVariant || variant is ApkVariant) {
val buildType: BuildType = if (variant is LibraryVariant) {
variant.getBuildType()
} else {
(variant as ApkVariant).getBuildType()
}
val buildTypeSourceSetName = buildType.getName()
logger.debug("Variant build type is [$buildTypeSourceSetName]")
val buildTypeSourceSet : AndroidSourceSet? = sourceSets.findByName(buildTypeSourceSetName)
val javaTask = variant.getJavaCompile()!!
val variantName = variant.getName()
val kotlinTaskName = "compile${variantName}Kotlin"
val kotlinTask: KotlinCompile = project.getTasks()!!.add(kotlinTaskName, javaClass<KotlinCompile>())!!
kotlinTask.kotlinOptions = kotlinOptions
// store kotlin classes in separate directory. They will serve as class-path to java compiler
val kotlinOutputDir = File(project.getBuildDir(), "kotlin-classes/${variantName}")
kotlinTask.kotlinDestinationDir = kotlinOutputDir;
kotlinTask.setDestinationDir(javaTask.getDestinationDir())
kotlinTask.setDescription("Compiles the ${variantName} kotlin.")
kotlinTask.setClasspath(javaTask.getClasspath())
kotlinTask.setDependsOn(javaTask.getDependsOn())
val javaSourceList = ArrayList<Any?>()
if (variant is TestVariant) {
javaSourceList.addAll(testSourceSet.getJava().getSrcDirs())
val testKotlinSource = getExtention<KotlinSourceSet>(testSourceSet, "kotlin")
kotlinTask.source(testKotlinSource.getKotlin())
} else {
javaSourceList.addAll(mainSourceSet.getJava().getSrcDirs())
val mainKotlinSource = getExtention<KotlinSourceSet>(mainSourceSet, "kotlin")
kotlinTask.source(mainKotlinSource.getKotlin())
}
if (null != buildTypeSourceSet) {
javaSourceList.add(buildTypeSourceSet.getJava().getSrcDirs())
kotlinTask.source(getExtention<KotlinSourceSet>(buildTypeSourceSet, "kotlin").getKotlin())
}
javaSourceList.add(callable<File?>{ variant.getProcessResources().getSourceOutputDir() })
javaSourceList.add(callable<File?>{ variant.getGenerateBuildConfig()?.getSourceOutputDir() })
javaSourceList.add(callable<File?>{ variant.getAidlCompile().getSourceOutputDir() })
javaSourceList.add(callable<File?>{ variant.getRenderscriptCompile().getSourceOutputDir() })
if (variant is ApkVariant) {
for (flavour in variant.getProductFlavors().iterator()) {
val flavourSourceSetName = buildTypeSourceSetName + flavour.getName()
val flavourSourceSet : AndroidSourceSet? = sourceSets.findByName(flavourSourceSetName)
if (flavourSourceSet != null) {
javaSourceList.add(flavourSourceSet.getJava())
kotlinTask.source((buildTypeSourceSet as ExtensionAware).getExtensions().getByName("kotlin"))
}
}
}
kotlinTask.doFirst({ task ->
var plugin = project.getPlugins().getPlugin("android")
if (null == plugin) {
plugin = project.getPlugins().getPlugin("android-library")
}
val basePlugin : BasePlugin = plugin as BasePlugin
val javaSources = project.files(javaSourceList)
val androidRT = project.files(basePlugin.getRuntimeJarList())
val fullClasspath = javaTask.getClasspath() + (javaSources + androidRT)
(task as AbstractCompile).setClasspath(fullClasspath)
})
javaTask.dependsOn(kotlinTaskName)
val javacClassPath = javaTask.getClasspath() + project.files(kotlinTask.kotlinDestinationDir);
javaTask.setClasspath(javacClassPath)
}
}
}
fun <T> getExtention(obj: Any, extensionName: String): T {
return (obj as ExtensionAware).getExtensions().getByName(extensionName) as T
}
}
open class KSpec<T: Any?>(val predicate: (T) -> Boolean): Spec<T> {
public override fun isSatisfiedBy(p0: T?): Boolean {
return p0 != null && predicate(p0)
@@ -31,7 +31,7 @@ public open class KotlinCompile(): AbstractCompile() {
val compiler = K2JVMCompiler()
val logger = Logging.getLogger(getClass())
public val kotlinOptions: K2JVMCompilerArguments = K2JVMCompilerArguments();
public var kotlinOptions: K2JVMCompilerArguments = K2JVMCompilerArguments();
public var kotlinDestinationDir : File? = getDestinationDir()
@@ -67,7 +67,7 @@ public open class KotlinCompile(): AbstractCompile() {
override fun compile() {
val args = kotlinOptions
val args = K2JVMCompilerArguments()
val javaSrcRoots = HashSet<File>()
val sources = ArrayList<File>()
@@ -10,7 +10,10 @@ buildscript {
}
}
apply plugin: org.jetbrains.kotlin.gradle.plugin.KotlinPlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinPlugin
apply plugin: KotlinPlugin
apply plugin: 'java'
sourceSets {
deploy
@@ -89,6 +89,9 @@
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<localRepositoryPath>local-repo</localRepositoryPath>
<postBuildHookScript>verify</postBuildHookScript> <!-- no extension required -->
<extraArtifacts>
<extraArtifact>org.jetbrains.kotlin:kotlin-gradle-plugin-core:${project.version}</extraArtifact>
</extraArtifacts>
</configuration>
<executions>
<execution>
@@ -12,7 +12,7 @@ import org.gradle.api.logging.Logging
import java.util.Properties
import java.io.FileNotFoundException
open class KotlinPluginWrapper: Plugin<Project> {
open abstract class KotlinBasePluginWrapper: Plugin<Project> {
val log = Logging.getLogger(getClass())!!
@@ -45,7 +45,7 @@ open class KotlinPluginWrapper: Plugin<Project> {
log.debug("Load plugin in parent-last URL classloader")
val kotlinPluginClassloader = ParentLastURLClassLoader(kotlinPluginDependencies, getClass().getClassLoader())
log.debug("Class loader created")
val cls = Class.forName("org.jetbrains.kotlin.gradle.plugin.KotlinPlugin", true, kotlinPluginClassloader)
val cls = Class.forName(getPluginClassName(), true, kotlinPluginClassloader)
log.debug("Plugin class loaded")
val pluginInstance = cls.newInstance()
log.debug("Plugin class instantiated")
@@ -55,6 +55,20 @@ open class KotlinPluginWrapper: Plugin<Project> {
applyMethod.invoke(pluginInstance, project);
log.debug("'apply' method invoked successfully")
}
public abstract fun getPluginClassName():String
}
open class KotlinPluginWrapper: KotlinBasePluginWrapper() {
public override fun getPluginClassName():String {
return "org.jetbrains.kotlin.gradle.plugin.KotlinPlugin"
}
}
open class KotlinAndriodPluginWrapper: KotlinBasePluginWrapper() {
public override fun getPluginClassName():String {
return "org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPlugin"
}
}
open class KSpec<T: Any?>(val predicate: (T) -> Boolean): Spec<T> {
@@ -0,0 +1 @@
implementation-class=org.jetbrains.kotlin.gradle.plugin.KotlinAndriodPluginWrapper
@@ -0,0 +1,142 @@
package org.jetbrains.kotlin.gradle
import com.google.common.io.Files
import com.intellij.openapi.util.SystemInfo
import java.io.File
import java.util.Arrays
import java.util.Scanner
import org.junit.Before
import org.junit.After
import org.junit.Test
import kotlin.test.assertTrue
import kotlin.test.assertEquals
import kotlin.test.fail
import org.gradle.testfixtures.ProjectBuilder
class KotlinAndroidGradleIT {
var workingDir: File = File(".")
Before fun setUp() {
workingDir = Files.createTempDir()
workingDir.mkdirs()
copyRecursively(File("src/test/resources/testProject/AndroidAlfaProject"), workingDir)
}
After fun tearDown() {
deleteRecursively(workingDir)
}
Test fun testSimpleCompile() {
val projectDir = File(workingDir, "AndroidAlfaProject")
val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("local-repo").getAbsolutePath()
val cmd = if (SystemInfo.isWindows)
listOf("cmd", "/C", "gradlew.bat", "build", pathToKotlinPlugin, "--no-daemon", "--debug")
else
listOf("/bin/bash", "./gradlew", "build", pathToKotlinPlugin, "--no-daemon", "--debug")
val builder = ProcessBuilder(cmd)
builder.directory(projectDir)
builder.redirectErrorStream(true)
val process = builder.start()
val s = Scanner(process.getInputStream()!!)
val text = StringBuilder()
while (s.hasNextLine()) {
text append s.nextLine()
text append "\n"
}
s.close()
val result = process.waitFor()
val buildOutput = text.toString()
println(buildOutput)
assertEquals(result, 0)
assertTrue(buildOutput.contains(":compileFlavor1DebugKotlin"), "Should contain ':compileFlavor1DebugKotlin'")
assertTrue(buildOutput.contains(":compileFlavor2DebugKotlin"), "Should contain ':compileFlavor2DebugKotlin'")
assertTrue(buildOutput.contains(":compileFlavor1JnidebugKotlin"), "Should contain ':compileFlavor1JnidebugKotlin'")
assertTrue(buildOutput.contains(":compileFlavor1ReleaseKotlin"), "Should contain ':compileFlavor1ReleaseKotlin'")
assertTrue(buildOutput.contains(":compileFlavor2JnidebugKotlin"), "Should contain ':compileFlavor2JnidebugKotlin'")
assertTrue(buildOutput.contains(":compileFlavor2ReleaseKotlin"), "Should contain ':compileFlavor2ReleaseKotlin'")
assertTrue(buildOutput.contains(":compileFlavor1Debug"), "Should contain ':compileFlavor1Debug'")
assertTrue(buildOutput.contains(":compileFlavor2Debug"), "Should contain ':compileFlavor2Debug'")
assertTrue(buildOutput.contains(":compileFlavor1Jnidebug"), "Should contain ':compileFlavor1Jnidebug'")
assertTrue(buildOutput.contains(":compileFlavor2Jnidebug"), "Should contain ':compileFlavor2Jnidebug'")
assertTrue(buildOutput.contains(":compileFlavor1Release"), "Should contain ':compileFlavor1Release'")
assertTrue(buildOutput.contains(":compileFlavor2Release"), "Should contain ':compileFlavor2Release'")
// Run the build second time, assert everything is up-to-date
val up2dateBuilder = ProcessBuilder(cmd)
up2dateBuilder.directory(projectDir)
up2dateBuilder.redirectErrorStream(true)
val up2dateProcess = up2dateBuilder.start()
val up2dateProcessScanner = Scanner(up2dateProcess.getInputStream()!!)
val up2dateText = StringBuilder()
while (up2dateProcessScanner.hasNextLine()) {
up2dateText append up2dateProcessScanner.nextLine()
up2dateText append "\n"
}
up2dateProcessScanner.close()
val up2dateResult = up2dateProcess.waitFor()
val up2dateBuildOutput = up2dateText.toString()
println(up2dateBuildOutput)
assertEquals(up2dateResult, 0)
assertTrue(up2dateBuildOutput.contains(":compileFlavor1DebugKotlin UP-TO-DATE"), "Should contain ':compileFlavor1DebugKotlin UP-TO-DATE'")
assertTrue(up2dateBuildOutput.contains(":compileFlavor2DebugKotlin UP-TO-DATE"), "Should contain ':compileFlavor2DebugKotlin UP-TO-DATE'")
assertTrue(up2dateBuildOutput.contains(":compileFlavor1JnidebugKotlin UP-TO-DATE"), "Should contain ':compileFlavor1JnidebugKotlin' UP-TO-DATE")
assertTrue(up2dateBuildOutput.contains(":compileFlavor1ReleaseKotlin UP-TO-DATE"), "Should contain ':compileFlavor1ReleaseKotlin UP-TO-DATE'")
assertTrue(up2dateBuildOutput.contains(":compileFlavor2JnidebugKotlin UP-TO-DATE"), "Should contain ':compileFlavor2JnidebugKotlin UP-TO-DATE'")
assertTrue(up2dateBuildOutput.contains(":compileFlavor2ReleaseKotlin UP-TO-DATE"), "Should contain ':compileFlavor2ReleaseKotlin UP-TO-DATE'")
assertTrue(up2dateBuildOutput.contains(":compileFlavor1Debug UP-TO-DATE"), "Should contain ':compileFlavor1Debug UP-TO-DATE'")
assertTrue(up2dateBuildOutput.contains(":compileFlavor2Debug UP-TO-DATE"), "Should contain ':compileFlavor2Debug UP-TO-DATE'")
assertTrue(up2dateBuildOutput.contains(":compileFlavor1Jnidebug UP-TO-DATE"), "Should contain ':compileFlavor1Jnidebug UP-TO-DATE'")
assertTrue(up2dateBuildOutput.contains(":compileFlavor2Jnidebug UP-TO-DATE"), "Should contain ':compileFlavor2Jnidebug UP-TO-DATE'")
assertTrue(up2dateBuildOutput.contains(":compileFlavor1Release UP-TO-DATE"), "Should contain ':compileFlavor1Release UP-TO-DATE'")
assertTrue(up2dateBuildOutput.contains(":compileFlavor2Release UP-TO-DATE"), "Should contain ':compileFlavor2Release UP-TO-DATE'")
}
fun copyRecursively(source: File, target: File) {
assertTrue(target.isDirectory())
val targetFile = File(target, source.getName())
if (source.isDirectory()) {
targetFile.mkdir()
val array = source.listFiles()
if (array != null) {
for (child in array) {
copyRecursively(child, targetFile)
}
}
} else {
Files.copy(source, targetFile)
}
}
fun deleteRecursively(f: File): Unit {
if (f.isDirectory()) {
val children = f.listFiles()
if (children != null) {
for (child in children) {
deleteRecursively(child)
}
}
val shouldBeEmpty = f.listFiles()
if (shouldBeEmpty != null) {
assertTrue(shouldBeEmpty.isEmpty())
} else {
fail("Error listing directory content")
}
}
f.delete()
}
}
@@ -19,7 +19,6 @@ class BasicKotlinGradleIT {
Before fun setUp() {
workingDir = Files.createTempDir()
workingDir.mkdirs()
copyRecursively(File("src/test/resources/testProject/alfa"), workingDir)
}
@@ -27,15 +26,16 @@ class BasicKotlinGradleIT {
deleteRecursively(workingDir)
}
Test fun testSimpleCompile() {
Test fun testCrossCompile() {
copyRecursively(File("src/test/resources/testProject/alfa"), workingDir)
val projectDir = File(workingDir, "alfa")
val pathToKotlinPluginWrapper = "-PpathToKotlinPluginWrapper=" + File("local-repo").getAbsolutePath()
val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("../kotlin-gradle-plugin-core/local-repo").getAbsolutePath()
val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("local-repo").getAbsolutePath()
val cmd = if (SystemInfo.isWindows)
listOf("cmd", "/C", "gradlew.bat", "compileDeployKotlin", "build", pathToKotlinPluginWrapper, pathToKotlinPlugin, "--no-daemon", "--debug")
listOf("cmd", "/C", "gradlew.bat", "compileDeployKotlin", "build", pathToKotlinPlugin, "--no-daemon", "--debug")
else
listOf("/bin/bash", "./gradlew", "compileDeployKotlin", "build", pathToKotlinPluginWrapper, pathToKotlinPlugin, "--no-daemon", "--debug")
listOf("/bin/bash", "./gradlew", "compileDeployKotlin", "build", pathToKotlinPlugin, "--no-daemon", "--debug")
val builder = ProcessBuilder(cmd)
builder.directory(projectDir)
@@ -89,6 +89,64 @@ class BasicKotlinGradleIT {
}
Test fun testKotlinOnlyCompile() {
copyRecursively(File("src/test/resources/testProject/beta"), workingDir)
val projectDir = File(workingDir, "beta")
val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("local-repo").getAbsolutePath()
val cmd = if (SystemInfo.isWindows)
listOf("cmd", "/C", "gradlew.bat", "build", pathToKotlinPlugin, "--no-daemon", "--debug")
else
listOf("/bin/bash", "./gradlew", "build", pathToKotlinPlugin, "--no-daemon", "--debug")
val builder = ProcessBuilder(cmd)
builder.directory(projectDir)
builder.redirectErrorStream(true)
val process = builder.start()
val s = Scanner(process.getInputStream()!!)
val text = StringBuilder()
while (s.hasNextLine()) {
text append s.nextLine()
text append "\n"
}
s.close()
val result = process.waitFor()
val buildOutput = text.toString()
println(buildOutput)
assertEquals(result, 0)
assertTrue(buildOutput.contains(":compileKotlin"), "Should contain ':compileKotlin'")
assertTrue(buildOutput.contains(":compileTestKotlin"), "Should contain ':compileTestKotlin'")
assertTrue(File(projectDir, "build/reports/tests/demo.TestSource.html").exists(), "Test report does not exist. Were tests executed?")
// Run the build second time, assert everything is up-to-date
val up2dateBuilder = ProcessBuilder(cmd)
up2dateBuilder.directory(projectDir)
up2dateBuilder.redirectErrorStream(true)
val up2dateProcess = up2dateBuilder.start()
val up2dateProcessScanner = Scanner(up2dateProcess.getInputStream()!!)
val up2dateText = StringBuilder()
while (up2dateProcessScanner.hasNextLine()) {
up2dateText append up2dateProcessScanner.nextLine()
up2dateText append "\n"
}
up2dateProcessScanner.close()
val up2dateResult = up2dateProcess.waitFor()
val up2dateBuildOutput = up2dateText.toString()
println(up2dateBuildOutput)
assertEquals(up2dateResult, 0)
assertTrue(up2dateBuildOutput.contains(":compileKotlin UP-TO-DATE"), "Should contain ':compileKotlin UP-TO-DATE'")
assertTrue(up2dateBuildOutput.contains(":compileTestKotlin UP-TO-DATE"), "Should contain ':compileTestKotlin UP-TO-DATE'")
}
fun copyRecursively(source: File, target: File) {
assertTrue(target.isDirectory())
val targetFile = File(target, source.getName())
@@ -0,0 +1,52 @@
buildscript {
repositories {
mavenCentral()
maven {
url 'file://' + pathToKotlinPlugin
}
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.1-SNAPSHOT'
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
apply plugin: 'kotlin-android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
kotlinOptions {
annotations = "kotlinAnnotations"
}
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
buildTypes {
jnidebug.initWith(buildTypes.debug)
jnidebug {
packageNameSuffix ".jnidebug"
jniDebugBuild true
}
}
productFlavors {
flavor1 {
packageName "com.example.flavor1"
versionCode 20
}
flavor2 {
packageName "com.example.flavor2"
minSdkVersion 14
}
}
}
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.jetbrains.kotlin.gradle.test.androidalfa"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="org.jetbrains.kotlin.gradle.test.androidalfa.MainActivity"
android:label="@string/title_activity_main_activity1" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="org.jetbrains.kotlin.gradle.test.androidalfa.MainActivity2"
android:label="@string/title_activity_main_activity2" >
</activity>
</application>
</manifest>
@@ -0,0 +1,36 @@
package org.jetbrains.kotlin.gradle.test.androidalfa;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import org.jetbrains.kotlin.gradle.test.androidalfa.R;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button next = (Button) findViewById(R.id.Button01);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), MainActivity2.class);
startActivityForResult(myIntent, 0);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
@@ -0,0 +1,33 @@
package org.jetbrains.kotlin.gradle.test.androidalfa
import android.content.Intent
import android.os.Bundle
import android.app.Activity
import android.view.Menu
import android.view.View
import android.widget.Button
import org.jetbrains.kotlin.gradle.test.androidalfa.R
open class MainActivity2: Activity() {
protected override fun onCreate(savedInstanceState: Bundle?): Unit {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main2)
var next: Button = findViewById(R.id.Button02) as Button
next.setOnClickListener(object: View.OnClickListener {
public override fun onClick(view: View?): Unit {
val intent: Intent = Intent()
setResult(Activity.RESULT_OK, intent)
finish()
}
})
}
public override fun onCreateOptionsMenu(menu: Menu?): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_activity2, menu);
return true
}
}
@@ -0,0 +1,24 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Activity 1" />
<Button android:text="Next"
android:id="@+id/Button01"
android:layout_width="250px"
android:textSize="18px"
android:layout_height="55px">
</Button>
</LinearLayout>
@@ -0,0 +1,24 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Activity 2" />
<Button android:text="Next"
android:id="@+id/Button02"
android:layout_width="250px"
android:textSize="18px"
android:layout_height="55px">
</Button>
</LinearLayout>
@@ -0,0 +1,6 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>
@@ -0,0 +1,6 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>
@@ -0,0 +1,4 @@
<resources>
<!-- Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw600dp devices (e.g. 7" tablets) here. -->
</resources>
@@ -0,0 +1,5 @@
<resources>
<!-- Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here. -->
<dimen name="activity_horizontal_margin">128dp</dimen>
</resources>
@@ -0,0 +1,11 @@
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
@@ -0,0 +1,12 @@
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
@@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AndroidAlfa</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="title_activity_main_activity1">MainActivity1</string>
<string name="title_activity_main_activity2">MainActivity2</string>
</resources>
@@ -0,0 +1,20 @@
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
@@ -0,0 +1 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
@@ -0,0 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.6-bin.zip
@@ -0,0 +1,164 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
@@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
@@ -0,0 +1,5 @@
<root>
<item name='android.app.Activity android.view.MenuInflater getMenuInflater()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
@@ -0,0 +1,10 @@
# This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=C:/Program Files (x86)/Android/android-studio/sdk
@@ -4,9 +4,6 @@ buildscript {
maven {
url 'file://' + pathToKotlinPlugin
}
maven {
url 'file://' + pathToKotlinPluginWrapper
}
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.1-SNAPSHOT'
@@ -14,6 +11,7 @@ buildscript {
}
apply plugin: "kotlin"
apply plugin: "java"
sourceSets {
deploy
@@ -49,4 +47,4 @@ compileKotlin {
task wrapper(type: Wrapper) {
gradleVersion="1.4"
}
}
@@ -0,0 +1,45 @@
buildscript {
repositories {
mavenCentral()
maven {
url 'file://' + pathToKotlinPlugin
}
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.1-SNAPSHOT'
}
}
apply plugin: "kotlin"
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()
}
task show << {
buildscript.configurations.classpath.each { println it }
}
compileKotlin {
kotlinOptions.annotations = "externalAnnotations"
}
task wrapper(type: Wrapper) {
gradleVersion="1.4"
}
@@ -0,0 +1,18 @@
<root>
<item name='com.google.common.base.Joiner com.google.common.base.Joiner on(java.lang.String)'>
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
<val name="value" val="&quot;fun on(separator : String?) : Joiner&quot;"/>
</annotation>
</item>
<item name='com.google.common.base.Joiner com.google.common.base.Joiner.MapJoiner withKeyValueSeparator(java.lang.String)'>
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
<val name="value"
val="&quot;fun withKeyValueSeparator(keyValueSeparator : String?) : Joiner.MapJoiner?&quot;"/>
</annotation>
</item>
<item name='com.google.common.base.Joiner com.google.common.base.Joiner skipNulls()'>
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
<val name="value" val="&quot;fun skipNulls() : Joiner&quot;"/>
</annotation>
</item>
</root>
@@ -0,0 +1,6 @@
#Thu Feb 28 14:00:49 MSK 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.4-bin.zip
@@ -0,0 +1,164 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
@@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
@@ -0,0 +1,22 @@
package demo
import com.google.common.primitives.Ints
import com.google.common.base.Joiner
import java.util.ArrayList
class KotlinGreetingJoiner(val greeter : Greeter) {
val names = ArrayList<String?>()
fun addName(name : String?): Unit{
names.add(name)
}
fun getJoinedGreeting() : String? {
val joiner = Joiner.on(" and ").skipNulls();
return "${greeter.greeting} ${joiner.join(names)}"
}
}
public open class Greeter(val greeting : String)
@@ -0,0 +1,21 @@
package demo
import com.google.common.primitives.Ints
import com.google.common.base.Joiner
import org.testng.Assert.*
import org.testng.annotations.AfterMethod
import org.testng.annotations.BeforeMethod
import org.testng.annotations.Test as test
class TestSource() {
test fun f() {
val example : KotlinGreetingJoiner = KotlinGreetingJoiner(Greeter("Hi"))
example.addName("Harry")
example.addName("Ron")
example.addName(null)
example.addName("Hermione")
assertEquals(example.getJoinedGreeting(), "Hi Harry and Ron and Hermione")
}
}