Android Extensions: Update Android JPS plugin
This commit is contained in:
@@ -23,17 +23,21 @@ import org.jetbrains.jps.model.module.JpsModule
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import org.jetbrains.jps.android.AndroidJpsUtil
|
import org.jetbrains.jps.android.AndroidJpsUtil
|
||||||
import com.intellij.util.PathUtil
|
import com.intellij.util.PathUtil
|
||||||
|
import org.w3c.dom.Document
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory
|
||||||
|
|
||||||
public class KotlinAndroidJpsPlugin : KotlinJpsCompilerArgumentsProvider {
|
public class KotlinAndroidJpsPlugin : KotlinJpsCompilerArgumentsProvider {
|
||||||
override fun getExtraArguments(moduleBuildTarget: ModuleBuildTarget, context: CompileContext): List<String> {
|
override fun getExtraArguments(moduleBuildTarget: ModuleBuildTarget, context: CompileContext): List<String> {
|
||||||
val module = moduleBuildTarget.module
|
val module = moduleBuildTarget.module
|
||||||
val pluginId = ANDROID_COMPILER_PLUGIN_ID
|
val pluginId = ANDROID_COMPILER_PLUGIN_ID
|
||||||
val resPath = getAndroidResPath(module)
|
val resPath = getAndroidResPath(module)
|
||||||
val manifestFile = getAndroidManifest(module)
|
val applicationId = getAndroidManifest(module)?.let { getApplicationPackageFromManifest(it) }
|
||||||
|
|
||||||
return if (resPath != null && manifestFile != null) listOf(
|
return if (resPath != null && applicationId != null) {
|
||||||
getPluginOptionString(pluginId, RESOURCE_PATH_OPTION_NAME, resPath),
|
listOf(
|
||||||
getPluginOptionString(pluginId, MANIFEST_FILE_OPTION_NAME, manifestFile))
|
getPluginOptionString(pluginId, VARIANT_OPTION_NAME, "main;$resPath"),
|
||||||
|
getPluginOptionString(pluginId, PACKAGE_OPTION_NAME, applicationId))
|
||||||
|
}
|
||||||
else listOf()
|
else listOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,21 +60,35 @@ public class KotlinAndroidJpsPlugin : KotlinJpsCompilerArgumentsProvider {
|
|||||||
|
|
||||||
private fun getAndroidResPath(module: JpsModule): String? {
|
private fun getAndroidResPath(module: JpsModule): String? {
|
||||||
val extension = AndroidJpsUtil.getExtension(module) ?: return null
|
val extension = AndroidJpsUtil.getExtension(module) ?: return null
|
||||||
val path = AndroidJpsUtil.getResourceDirForCompilationPath(extension)
|
return AndroidJpsUtil.getResourceDirForCompilationPath(extension)?.absolutePath
|
||||||
return File(path!!.absolutePath + "/layout").absolutePath
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAndroidManifest(module: JpsModule): String? {
|
private fun getAndroidManifest(module: JpsModule): File? {
|
||||||
val extension = AndroidJpsUtil.getExtension(module) ?: return null
|
val extension = AndroidJpsUtil.getExtension(module) ?: return null
|
||||||
return AndroidJpsUtil.getManifestFileForCompilationPath(extension)!!.absolutePath
|
return AndroidJpsUtil.getManifestFileForCompilationPath(extension)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val JAR_FILE_NAME = "android-compiler-plugin.jar"
|
private val JAR_FILE_NAME = "android-compiler-plugin.jar"
|
||||||
private val ANDROID_COMPILER_PLUGIN_ID = "org.jetbrains.kotlin.android"
|
private val ANDROID_COMPILER_PLUGIN_ID = "org.jetbrains.kotlin.android"
|
||||||
|
|
||||||
private val RESOURCE_PATH_OPTION_NAME = "androidRes"
|
private val VARIANT_OPTION_NAME = "variant"
|
||||||
private val MANIFEST_FILE_OPTION_NAME = "androidManifest"
|
private val PACKAGE_OPTION_NAME = "package"
|
||||||
|
|
||||||
|
private fun getApplicationPackageFromManifest(manifestFile: File): String? {
|
||||||
|
try {
|
||||||
|
return manifestFile.parseXml().documentElement.getAttribute("package")
|
||||||
|
}
|
||||||
|
catch (e: Exception) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun File.parseXml(): Document {
|
||||||
|
val factory = DocumentBuilderFactory.newInstance()
|
||||||
|
val builder = factory.newDocumentBuilder()
|
||||||
|
return builder.parse(this)
|
||||||
|
}
|
||||||
|
|
||||||
private fun getPluginOptionString(pluginId: String, key: String, value: String): String {
|
private fun getPluginOptionString(pluginId: String, key: String, value: String): String {
|
||||||
return "plugin:$pluginId:$key=$value"
|
return "plugin:$pluginId:$key=$value"
|
||||||
|
|||||||
+2
-2
@@ -7,14 +7,14 @@ import android.view.LayoutInflater
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
|
||||||
import kotlinx.android.synthetic.main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import kotlinx.android.synthetic.main.fragment.*
|
import kotlinx.android.synthetic.main.fragment.*
|
||||||
import kotlinx.android.synthetic.main.fragment.view.*
|
import kotlinx.android.synthetic.main.fragment.view.*
|
||||||
|
|
||||||
public class MyActivity : Activity() {
|
public class MyActivity : Activity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.main)
|
setContentView(R.layout.activity_main)
|
||||||
textField.setText("test")
|
textField.setText("test")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user