Kotlin Gradle subplugin support
This commit is contained in:
@@ -568,6 +568,10 @@
|
|||||||
public protected *;
|
public protected *;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-keepclassmembers class com.intellij.openapi.vfs.VirtualFile {
|
||||||
|
public InputStream getInputStream();
|
||||||
|
}
|
||||||
|
|
||||||
-keep class jet.** {
|
-keep class jet.** {
|
||||||
public protected *;
|
public protected *;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@
|
|||||||
<module>tools/kotlin-js-library</module>
|
<module>tools/kotlin-js-library</module>
|
||||||
<module>tools/kotlin-gradle-plugin</module>
|
<module>tools/kotlin-gradle-plugin</module>
|
||||||
<module>tools/kotlin-gradle-plugin-core</module>
|
<module>tools/kotlin-gradle-plugin-core</module>
|
||||||
|
<module>tools/kotlin-gradle-plugin-api</module>
|
||||||
<module>tools/kotlin-android-compiler-plugin</module>
|
<module>tools/kotlin-android-compiler-plugin</module>
|
||||||
<module>tools/kotlin-maven-plugin</module>
|
<module>tools/kotlin-maven-plugin</module>
|
||||||
<module>tools/kotlin-maven-plugin-test</module>
|
<module>tools/kotlin-maven-plugin-test</module>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>kotlin-android-compiler-plugin</artifactId>
|
<artifactId>kotlin-android-compiler-plugin</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<description>Android compiler plugin for Kotlin</description>
|
<description>Android compiler plugin for Kotlin</description>
|
||||||
|
|
||||||
@@ -26,40 +26,95 @@
|
|||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-stdlib</artifactId>
|
<artifactId>kotlin-stdlib</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-gradle-plugin-core</artifactId>
|
<artifactId>kotlin-gradle-plugin-api</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>gradle-api</artifactId>
|
||||||
|
<version>1.6</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.android.tools.build</groupId>
|
||||||
|
<artifactId>gradle</artifactId>
|
||||||
|
<version>0.4.2</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.basedir}/src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
<artifactId>build-helper-maven-plugin</artifactId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<annotationPaths>
|
||||||
|
<annotationPath>${basedir}/kotlinAnnotation</annotationPath>
|
||||||
|
</annotationPaths>
|
||||||
|
</configuration>
|
||||||
|
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals> <goal>compile</goal> </goals>
|
||||||
|
<configuration>
|
||||||
|
<sourceDirs>
|
||||||
|
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
|
||||||
|
</sourceDirs>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
|
||||||
|
<execution>
|
||||||
|
<id>test-compile</id>
|
||||||
|
<phase>test-compile</phase>
|
||||||
|
<goals> <goal>test-compile</goal> </goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
<version>1.7</version>
|
<version>1.7</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>attach-artifacts</id>
|
<id>prepare</id>
|
||||||
<phase>compile</phase>
|
<phase>compile</phase>
|
||||||
<goals>
|
|
||||||
<goal>attach-artifact</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<artifacts>
|
<tasks>
|
||||||
<artifact>
|
<unzip src="${kotlin-sdk}/lib/android-compiler-plugin.jar" dest="target/classes/" />
|
||||||
<file>${kotlin-sdk}/lib/android-compiler-plugin.jar</file>
|
</tasks>
|
||||||
<type>jar</type>
|
|
||||||
</artifact>
|
|
||||||
</artifacts>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>jetbrains-utils</id>
|
||||||
|
<url>http://repository.jetbrains.com/utils</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.kotlin.android
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin
|
||||||
|
import org.gradle.api
|
||||||
|
import com.android.build.gradle.BaseExtension
|
||||||
|
import java.io.File
|
||||||
|
import org.gradle.api.tasks.compile.AbstractCompile
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
|
||||||
|
|
||||||
|
public class AndroidSubplugin : KotlinGradleSubplugin {
|
||||||
|
|
||||||
|
override fun getExtraArguments(project: api.Project, task: AbstractCompile): List<SubpluginOption>? {
|
||||||
|
val androidExtension = project.getExtensions().getByName("android") as? BaseExtension
|
||||||
|
|
||||||
|
if (androidExtension == null) return null
|
||||||
|
|
||||||
|
val sourceSets = androidExtension.getSourceSets()
|
||||||
|
val mainSourceSet = sourceSets.getByName("main")
|
||||||
|
|
||||||
|
val resourceDir = mainSourceSet.getRes().getSrcDirs().firstOrNull()
|
||||||
|
val manifestFile = mainSourceSet.getManifest().getSrcFile()
|
||||||
|
|
||||||
|
if (resourceDir != null) {
|
||||||
|
val layoutDir = File(resourceDir, "layout")
|
||||||
|
task.source(layoutDir)
|
||||||
|
return listOf(
|
||||||
|
SubpluginOption("androidRes", layoutDir.getAbsolutePath()),
|
||||||
|
SubpluginOption("androidManifest", manifestFile.getAbsolutePath())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getPluginName(): String {
|
||||||
|
return "org.jetbrains.kotlin.android"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getGroupName(): String {
|
||||||
|
return "org.jetbrains.kotlin"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getArtifactName(): String {
|
||||||
|
return "kotlin-android-compiler-plugin"
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
org.jetbrains.kotlin.android.AndroidSubplugin
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<properties>
|
||||||
|
<maven-plugin-anno.version>1.4.1</maven-plugin-anno.version>
|
||||||
|
<maven.version>3.0.4</maven.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-project</artifactId>
|
||||||
|
<version>0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>kotlin-gradle-plugin-api</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<description>Gradle plugin API for Kotlin</description>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>jetbrains-utils</id>
|
||||||
|
<url>http://repository.jetbrains.com/utils</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-stdlib</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>gradle-api</artifactId>
|
||||||
|
<version>1.6</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.android.tools.build</groupId>
|
||||||
|
<artifactId>gradle</artifactId>
|
||||||
|
<version>0.4.2</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<annotationPaths>
|
||||||
|
<annotationPath>${basedir}/kotlinAnnotation</annotationPath>
|
||||||
|
</annotationPaths>
|
||||||
|
</configuration>
|
||||||
|
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals> <goal>compile</goal> </goals>
|
||||||
|
</execution>
|
||||||
|
|
||||||
|
<execution>
|
||||||
|
<id>test-compile</id>
|
||||||
|
<phase>test-compile</phase>
|
||||||
|
<goals> <goal>test-compile</goal> </goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* 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.kotlin.gradle.plugin
|
||||||
|
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.tasks.compile.AbstractCompile
|
||||||
|
|
||||||
|
public class SubpluginOption(val key: String, val value: String)
|
||||||
|
|
||||||
|
public trait KotlinGradleSubplugin {
|
||||||
|
public fun getExtraArguments(project: Project, task: AbstractCompile): List<SubpluginOption>?
|
||||||
|
public fun getPluginName(): String
|
||||||
|
public fun getGroupName(): String
|
||||||
|
public fun getArtifactName(): String
|
||||||
|
}
|
||||||
@@ -25,6 +25,12 @@
|
|||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>2.4</version>
|
<version>2.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-gradle-plugin-api</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency> <!-- required in runtime -->
|
<dependency> <!-- required in runtime -->
|
||||||
<groupId>commons-lang</groupId>
|
<groupId>commons-lang</groupId>
|
||||||
<artifactId>commons-lang</artifactId>
|
<artifactId>commons-lang</artifactId>
|
||||||
|
|||||||
+14
-8
@@ -46,8 +46,8 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
|
|||||||
private val logger = Logging.getLogger(this.javaClass)
|
private val logger = Logging.getLogger(this.javaClass)
|
||||||
override fun getLogger() = logger
|
override fun getLogger() = logger
|
||||||
|
|
||||||
public var resPath: String = ""
|
var compilerPluginClasspaths: Array<String> = array()
|
||||||
public var manifestPath: String = ""
|
var compilerPluginArguments: Array<String> = array()
|
||||||
|
|
||||||
// override setSource to track source directory sets
|
// override setSource to track source directory sets
|
||||||
override fun setSource(source: Any?) {
|
override fun setSource(source: Any?) {
|
||||||
@@ -97,10 +97,14 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
|
|||||||
afterCompileHook(args)
|
afterCompileHook(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun isJava(it: File): Boolean = it.extension.equalsIgnoreCase(JavaFileType.INSTANCE.getDefaultExtension())
|
private fun getKotlinSources(): List<File> = getSource().filter { it.isKotlinFile() }
|
||||||
protected fun isKotlin(it: File): Boolean = it.extension.equalsIgnoreCase(JetFileType.INSTANCE.getDefaultExtension())
|
|
||||||
|
|
||||||
private fun getKotlinSources(): List<File> = getSource().filter{ isKotlin(it) }
|
private fun File.isKotlinFile(): Boolean {
|
||||||
|
return when (FilenameUtils.getExtension(getName()).toLowerCase()) {
|
||||||
|
"kt", "kts" -> true
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun populateCommonArgs(args: T, sources: List<File>) {
|
private fun populateCommonArgs(args: T, sources: List<File>) {
|
||||||
args.freeArgs = sources.map { it.getAbsolutePath() }
|
args.freeArgs = sources.map { it.getAbsolutePath() }
|
||||||
@@ -131,8 +135,8 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
|||||||
val srcDirsSources = HashSet<SourceDirectorySet>()
|
val srcDirsSources = HashSet<SourceDirectorySet>()
|
||||||
|
|
||||||
override fun populateTargetSpecificArgs(args: K2JVMCompilerArguments) {
|
override fun populateTargetSpecificArgs(args: K2JVMCompilerArguments) {
|
||||||
args.pluginClasspaths = kotlinOptions.pluginClasspaths
|
args.pluginClasspaths = compilerPluginClasspaths
|
||||||
args.pluginOptions = kotlinOptions.pluginOptions
|
args.pluginOptions = compilerPluginArguments
|
||||||
|
|
||||||
if (StringUtils.isEmpty(kotlinOptions.classpath)) {
|
if (StringUtils.isEmpty(kotlinOptions.classpath)) {
|
||||||
val existingClasspathEntries = getClasspath().filter({ it != null && it.exists() })
|
val existingClasspathEntries = getClasspath().filter({ it != null && it.exists() })
|
||||||
@@ -161,11 +165,13 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
|||||||
|
|
||||||
private fun getJavaSourceRoots(): Set<File> =
|
private fun getJavaSourceRoots(): Set<File> =
|
||||||
getSource()
|
getSource()
|
||||||
.filter { isJava(it) }
|
.filter { it.isJavaFile() }
|
||||||
.map { findSrcDirRoot(it) }
|
.map { findSrcDirRoot(it) }
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
.toSet()
|
.toSet()
|
||||||
|
|
||||||
|
private fun File.isJavaFile() = extension.equalsIgnoreCase(JavaFileType.INSTANCE.getDefaultExtension())
|
||||||
|
|
||||||
override fun afterCompileHook(args: K2JVMCompilerArguments) {
|
override fun afterCompileHook(args: K2JVMCompilerArguments) {
|
||||||
getLogger().debug("Copying resulting files to classes")
|
getLogger().debug("Copying resulting files to classes")
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,11 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-gradle-plugin-api</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+57
-16
@@ -39,6 +39,8 @@ import groovy.lang.Closure
|
|||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||||
import org.jetbrains.kotlin.compiler.plugin.CliOption
|
import org.jetbrains.kotlin.compiler.plugin.CliOption
|
||||||
import org.jetbrains.kotlin.android.AndroidCommandLineProcessor
|
import org.jetbrains.kotlin.android.AndroidCommandLineProcessor
|
||||||
|
import java.util.ServiceLoader
|
||||||
|
import org.jetbrains.kotlin.compiler.plugin.getPluginOptionString
|
||||||
|
|
||||||
val DEFAULT_ANNOTATIONS = "org.jebrains.kotlin.gradle.defaultAnnotations"
|
val DEFAULT_ANNOTATIONS = "org.jebrains.kotlin.gradle.defaultAnnotations"
|
||||||
|
|
||||||
@@ -144,6 +146,8 @@ class Kotlin2JvmSourceSetProcessor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadSubplugins(project).addSubpluginArguments(project, kotlinTask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,10 +308,6 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
|||||||
project.getExtensions().add(DEFAULT_ANNOTATIONS, GradleUtils(scriptHandler, project).resolveKotlinPluginDependency("kotlin-android-sdk-annotations"))
|
project.getExtensions().add(DEFAULT_ANNOTATIONS, GradleUtils(scriptHandler, project).resolveKotlinPluginDependency("kotlin-android-sdk-annotations"))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun makePluginOption(option: CliOption, value: String): String {
|
|
||||||
return "plugin:${AndroidCommandLineProcessor.ANDROID_COMPILER_PLUGIN_ID}:${option.name}=$value"
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun processVariants(variants: DefaultDomainObjectSet<out BaseVariant>, project: Project, androidExt: BaseExtension): Unit {
|
private fun processVariants(variants: DefaultDomainObjectSet<out BaseVariant>, project: Project, androidExt: BaseExtension): Unit {
|
||||||
val logger = project.getLogger()
|
val logger = project.getLogger()
|
||||||
val kotlinOptions = getExtension<Any?>(androidExt, "kotlinOptions")
|
val kotlinOptions = getExtension<Any?>(androidExt, "kotlinOptions")
|
||||||
@@ -320,6 +320,8 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
|||||||
sourceSets.getByName("androidTest")
|
sourceSets.getByName("androidTest")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val subpluginEnvironment = loadSubplugins(project)
|
||||||
|
|
||||||
for (variant in variants) {
|
for (variant in variants) {
|
||||||
if (variant is LibraryVariant || variant is ApkVariant) {
|
if (variant is LibraryVariant || variant is ApkVariant) {
|
||||||
val buildTypeSourceSetName = AndroidGradleWrapper.getVariantName(variant)
|
val buildTypeSourceSetName = AndroidGradleWrapper.getVariantName(variant)
|
||||||
@@ -330,17 +332,6 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
|||||||
val javaTask = variant.getJavaCompile()!!
|
val javaTask = variant.getJavaCompile()!!
|
||||||
val variantName = variant.getName()
|
val variantName = variant.getName()
|
||||||
|
|
||||||
val resourceDir = AndroidGradleWrapper.getResourceDirs(mainSourceSet).firstOrNull()
|
|
||||||
val manifestFile = AndroidGradleWrapper.getManifestFile(mainSourceSet)
|
|
||||||
|
|
||||||
if (resourceDir != null) {
|
|
||||||
val layoutDir = File(resourceDir, "layout")
|
|
||||||
kotlinOptions.pluginOptions = array(
|
|
||||||
makePluginOption("androidRes", layoutDir.getAbsolutePath()),
|
|
||||||
makePluginOption("androidManifest", manifestFile.getAbsolutePath())
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val kotlinTaskName = "compile${variantName.capitalize()}Kotlin"
|
val kotlinTaskName = "compile${variantName.capitalize()}Kotlin"
|
||||||
val kotlinTask = tasksProvider.createKotlinJVMTask(project, kotlinTaskName)
|
val kotlinTask = tasksProvider.createKotlinJVMTask(project, kotlinTaskName)
|
||||||
if (kotlinOptions != null) {
|
if (kotlinOptions != null) {
|
||||||
@@ -400,6 +391,8 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subpluginEnvironment.addSubpluginArguments(project, kotlinTask)
|
||||||
|
|
||||||
kotlinTask doFirst {
|
kotlinTask doFirst {
|
||||||
var plugin = project.getPlugins().findPlugin("android")
|
var plugin = project.getPlugins().findPlugin("android")
|
||||||
if (null == plugin) {
|
if (null == plugin) {
|
||||||
@@ -429,9 +422,57 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
|||||||
val result = (obj as HasConvention).getConvention().getPlugins()[extensionName]
|
val result = (obj as HasConvention).getConvention().getPlugins()[extensionName]
|
||||||
return result as T
|
return result as T
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadSubplugins(project: Project): SubpluginEnvironment {
|
||||||
|
try {
|
||||||
|
val subplugins = ServiceLoader.load(
|
||||||
|
javaClass<KotlinGradleSubplugin>(), project.getBuildscript().getClassLoader()).toList()
|
||||||
|
val subpluginDependencyNames =
|
||||||
|
subplugins.mapTo(hashSetOf<String>()) { it.getGroupName() + ":" + it.getArtifactName() }
|
||||||
|
|
||||||
|
val classpath = project.getBuildscript().getConfigurations().getByName("classpath")
|
||||||
|
val subpluginClasspaths = hashMapOf<KotlinGradleSubplugin, List<String>>()
|
||||||
|
|
||||||
|
for (subplugin in subplugins) {
|
||||||
|
val files = classpath.getDependencies()
|
||||||
|
.filter { subpluginDependencyNames.contains(it.getGroup() + ":" + it.getName()) }
|
||||||
|
.flatMap { classpath.files(it).map { it.getAbsolutePath() } }
|
||||||
|
subpluginClasspaths.put(subplugin, files)
|
||||||
|
}
|
||||||
|
|
||||||
|
return SubpluginEnvironment(subpluginClasspaths, subplugins)
|
||||||
|
} catch (e: NoClassDefFoundError) {
|
||||||
|
// Skip plugin loading if KotlinGradleSubplugin is not defined.
|
||||||
|
// It is true now for tests in kotlin-gradle-plugin-core.
|
||||||
|
return SubpluginEnvironment(mapOf(), listOf())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SubpluginEnvironment(
|
||||||
|
val subpluginClasspaths: Map<KotlinGradleSubplugin, List<String>>,
|
||||||
|
val subplugins: List<KotlinGradleSubplugin>
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun addSubpluginArguments(project: Project, compileTask: KotlinCompile) {
|
||||||
|
val realPluginClasspaths = arrayListOf<String>()
|
||||||
|
val pluginArguments = arrayListOf<String>()
|
||||||
|
|
||||||
|
subplugins.forEach { subplugin ->
|
||||||
|
val args = subplugin.getExtraArguments(project, compileTask)
|
||||||
|
if (args != null) {
|
||||||
|
realPluginClasspaths.addAll(subpluginClasspaths[subplugin])
|
||||||
|
for (arg in args) {
|
||||||
|
val option = getPluginOptionString(subplugin.getPluginName(), arg.key, arg.value)
|
||||||
|
pluginArguments.add(option)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
compileTask.compilerPluginClasspaths = realPluginClasspaths.copyToArray()
|
||||||
|
compileTask.compilerPluginArguments = pluginArguments.copyToArray()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open class GradleUtils(val scriptHandler: ScriptHandler, val project: ProjectInternal) {
|
open class GradleUtils(val scriptHandler: ScriptHandler, val project: ProjectInternal) {
|
||||||
public fun resolveDependencies(vararg coordinates: String): Collection<File> {
|
public fun resolveDependencies(vararg coordinates: String): Collection<File> {
|
||||||
|
|||||||
-10
@@ -46,16 +46,6 @@ class AndroidGradleWrapper {
|
|||||||
return androidSourceSet.getJava().getSrcDirs()
|
return androidSourceSet.getJava().getSrcDirs()
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
static def Set<File> getResourceDirs(Object androidSourceSet) {
|
|
||||||
return androidSourceSet.getRes().getSrcDirs()
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
static def File getManifestFile(Object androidSourceSet) {
|
|
||||||
return androidSourceSet.getManifest().getSrcFile()
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
static def List<String> getProductFlavorsNames(ApkVariant variant) {
|
static def List<String> getProductFlavorsNames(ApkVariant variant) {
|
||||||
return variant.getProductFlavors().iterator().collect { it.getName() }
|
return variant.getProductFlavors().iterator().collect { it.getName() }
|
||||||
|
|||||||
Reference in New Issue
Block a user