add kotlin gradle plugin integration

This commit is contained in:
dedoz
2014-08-19 19:16:11 +04:00
committed by Yan Zhulanow
parent 972e0f28d0
commit bada0ec7f8
3 changed files with 42 additions and 2 deletions
@@ -103,7 +103,7 @@ abstract class AndroidUIXmlProcessor(val project: Project) {
private fun writeImports(kw: KotlinStringWriter): KotlinWriter {
kw.writePackage(androidAppPackage)
if (ApplicationManager.getApplication()?.isUnitTestMode() ?: false) return kw
// if (ApplicationManager.getApplication()?.isUnitTestMode() ?: false) return kw
for (elem in androidImports)
kw.writeImport(elem)
kw.writeEmptyLine()
@@ -46,6 +46,41 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
private val logger = Logging.getLogger(this.javaClass)
override fun getLogger() = logger
public var resPath: String = ""
public var manifestPath: String = ""
// override setSource to track source directory sets
override fun setSource(source: Any?) {
srcDirsSources.clear()
if (source is SourceDirectorySet) {
srcDirsSources.add(source)
}
super.setSource(source)
}
// override source to track source directory sets
override fun source(vararg sources: Any?): SourceTask? {
for (source in sources) {
if (source is SourceDirectorySet) {
srcDirsSources.add(source)
}
}
return super.source(sources)
}
fun findSrcDirRoot(file: File): File? {
val absPath = file.getAbsolutePath()
for (source in srcDirsSources) {
for (root in source.getSrcDirs()) {
val rootAbsPath = root.getAbsolutePath()
if (FilenameUtils.directoryContains(rootAbsPath, absPath)) {
return root
}
}
}
return null
}
[TaskAction]
override fun compile() {
getLogger().debug("Starting ${javaClass} task")
@@ -75,7 +110,6 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
args.noInline = kotlinOptions.noInline
}
private fun callCompiler(args: T) {
val messageCollector = GradleMessageCollector(getLogger())
getLogger().debug("Calling compiler")
@@ -97,6 +131,9 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
val srcDirsSources = HashSet<SourceDirectorySet>()
override fun populateTargetSpecificArgs(args: K2JVMCompilerArguments) {
args.androidRes = resPath
args.androidManifest = manifestPath
if (StringUtils.isEmpty(kotlinOptions.classpath)) {
val existingClasspathEntries = getClasspath().filter({ it != null && it.exists() })
val effectiveClassPath = (getJavaSourceRoots() + existingClasspathEntries).makeString(File.pathSeparator)
@@ -338,6 +338,9 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
kotlinTask.setClasspath(javaTask.getClasspath())
kotlinTask.setDependsOn(javaTask.getDependsOn())
kotlinTask.resPath = File(variant.getMergeResources()?.getOutputDir()!!.canonicalPath + "/layout").canonicalPath
kotlinTask.manifestPath = variant.getProcessResources().getManifestFile()!!.canonicalPath
val javaSourceList = ArrayList<Any?>()
fun processSourceSet(javaSourceSet: AndroidSourceSet) {