Logic related to command-line options moved to android-compiler-plugin

This commit is contained in:
Andrey Breslav
2014-09-23 18:23:39 +04:00
committed by Yan Zhulanow
parent febfdde89e
commit 1e70369cf8
11 changed files with 152 additions and 32 deletions
+2
View File
@@ -3,6 +3,8 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Kotlin.iml" filepath="$PROJECT_DIR$/Kotlin.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/android-compiler-plugin/android-compiler-plugin.iml" filepath="$PROJECT_DIR$/plugins/android-compiler-plugin/android-compiler-plugin.iml" group="plugins" />
<module fileurl="file://$PROJECT_DIR$/plugins/android-jps-plugin/android-jps-plugin.iml" filepath="$PROJECT_DIR$/plugins/android-jps-plugin/android-jps-plugin.iml" group="plugins" />
<module fileurl="file://$PROJECT_DIR$/android-studio/android-studio.iml" filepath="$PROJECT_DIR$/android-studio/android-studio.iml" group="ide" />
<module fileurl="file://$PROJECT_DIR$/compiler/android-tests/android-tests.iml" filepath="$PROJECT_DIR$/compiler/android-tests/android-tests.iml" group="compiler" />
<module fileurl="file://$PROJECT_DIR$/ant/ant.iml" filepath="$PROJECT_DIR$/ant/ant.iml" />
@@ -66,14 +66,6 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
@Argument(value = "Xno-optimize", description = "Disable optimizations")
public boolean noOptimize;
@Argument(value = "androidRes", description = "Android resources path")
@ValueDescription("<path>")
public String androidRes;
@Argument(value = "androidManifest", description = "Android manifest file")
@ValueDescription("<path>")
public String androidManifest;
@Override
@NotNull
public String executableScriptFileName() {
@@ -51,10 +51,4 @@ public class JVMConfigurationKeys {
public static final CompilerConfigurationKey<List<String>> MODULE_IDS =
CompilerConfigurationKey.create("module id strings");
public static final CompilerConfigurationKey<String> ANDROID_RES_PATH =
CompilerConfigurationKey.create("android resources search path");
public static final CompilerConfigurationKey<String> ANDROID_MANIFEST =
CompilerConfigurationKey.create("android manifest file");
}
@@ -31,6 +31,7 @@ import com.intellij.util.Processor
import org.jetbrains.jet.codegen.CodegenTestFiles
import java.util.regex.Pattern
import org.jetbrains.jet.config.CompilerConfiguration
import org.jetbrains.kotlin.android.AndroidConfigurationKeys
public abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
@@ -43,8 +44,8 @@ public abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
}
private fun createEnvironmentForConfiguration(configuration: CompilerConfiguration, path: String) {
configuration.put(JVMConfigurationKeys.ANDROID_RES_PATH, path + "layout/");
configuration.put(JVMConfigurationKeys.ANDROID_MANIFEST, path + "AndroidManifest.xml");
configuration.put(AndroidConfigurationKeys.ANDROID_RES_PATH, path + "layout/");
configuration.put(AndroidConfigurationKeys.ANDROID_MANIFEST, path + "AndroidManifest.xml");
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration);
}
@@ -23,6 +23,7 @@ import org.jetbrains.jet.TestJdkKind
import org.jetbrains.jet.config.CompilerConfiguration
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
import org.jetbrains.kotlin.android.AndroidConfigurationKeys
public abstract class AbstractAndroidBytecodePersistenceTest : AbstractBytecodeTextTest() {
@@ -35,8 +36,8 @@ public abstract class AbstractAndroidBytecodePersistenceTest : AbstractBytecodeT
}
private fun createEnvironmentForConfiguration(configuration: CompilerConfiguration, path: String) {
configuration.put(JVMConfigurationKeys.ANDROID_RES_PATH, path + "res/layout/");
configuration.put(JVMConfigurationKeys.ANDROID_MANIFEST, path + "../AndroidManifest.xml");
configuration.put(AndroidConfigurationKeys.ANDROID_RES_PATH, path + "res/layout/");
configuration.put(AndroidConfigurationKeys.ANDROID_MANIFEST, path + "../AndroidManifest.xml");
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration);
}
public override fun doTest(path: String) {
@@ -16,7 +16,6 @@
package org.jetbrains.jet.android
import com.intellij.testFramework.UsefulTestCase
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
import org.jetbrains.jet.lang.resolve.android.CliAndroidUIXmlProcessor
import org.jetbrains.jet.JetTestUtils
@@ -24,20 +23,10 @@ import org.jetbrains.jet.ConfigurationKind
import org.jetbrains.jet.TestJdkKind
import org.jetbrains.jet.plugin.android.IDEAndroidUIXmlProcessor
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys
import junit.framework.TestCase
import kotlin.test.assertEquals
import org.jetbrains.jet.plugin.android.TestConst
import com.intellij.testFramework.LightCodeInsightTestCase
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.jetbrains.jet.plugin.PluginTestCaseBase
import org.jetbrains.jet.test.TestMetadata
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase
import com.intellij.ide.startup.impl.StartupManagerImpl
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
import org.jetbrains.jet.JetTestCaseBuilder
import com.intellij.openapi.startup.StartupManager
import com.android.SdkConstants
import com.intellij.openapi.application.PathManager
import org.jetbrains.kotlin.android.AndroidConfigurationKeys
public abstract class AbstractCrossParserTest : KotlinAndroidTestCase() {
public fun doTest(path: String) {
@@ -55,8 +44,8 @@ public abstract class AbstractCrossParserTest : KotlinAndroidTestCase() {
private fun getEnvironment(testPath: String): JetCoreEnvironment {
val configuration = JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK)
configuration.put<String>(JVMConfigurationKeys.ANDROID_RES_PATH, testPath + "/layout")
configuration.put<String>(JVMConfigurationKeys.ANDROID_MANIFEST, testPath + "/AndroidManifest.xml")
configuration.put<String>(AndroidConfigurationKeys.ANDROID_RES_PATH, testPath + "/layout")
configuration.put<String>(AndroidConfigurationKeys.ANDROID_MANIFEST, testPath + "/AndroidManifest.xml")
return JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration)
}
@@ -0,0 +1,64 @@
/*
* 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.compiler.plugin.ComponentRegistrar
import org.jetbrains.jet.lang.resolve.android.CliAndroidUIXmlProcessor
import org.jetbrains.jet.config.CompilerConfiguration
import org.jetbrains.jet.lang.resolve.android.AndroidUIXmlProcessor
import com.intellij.mock.MockProject
import org.jetbrains.jet.config.CompilerConfigurationKey
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
import org.jetbrains.kotlin.compiler.plugin.CliOption
import org.jetbrains.kotlin.compiler.plugin.CliOptionProcessingException
public object AndroidConfigurationKeys {
public val ANDROID_RES_PATH: CompilerConfigurationKey<String> = CompilerConfigurationKey.create<String>("android resources search path")
public val ANDROID_MANIFEST: CompilerConfigurationKey<String> = CompilerConfigurationKey.create<String>("android manifest file")
}
public class AndroidCommandLineProcessor : CommandLineProcessor {
class object {
public val ANDROID_COMPILER_PLUGIN_ID: String = "org.jetbrains.kotlin.android"
public val RESOURCE_PATH_OPTION: CliOption = CliOption("androidRes", "<path>", "Android resources path")
public val MANIFEST_FILE_OPTION: CliOption = CliOption("androidManifest", "<path>", "Android manifest file")
}
override val pluginId: String = ANDROID_COMPILER_PLUGIN_ID
override val pluginOptions: Collection<CliOption> = listOf(RESOURCE_PATH_OPTION, MANIFEST_FILE_OPTION)
override fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) {
when (option) {
RESOURCE_PATH_OPTION -> configuration.put(AndroidConfigurationKeys.ANDROID_RES_PATH, value)
MANIFEST_FILE_OPTION -> configuration.put(AndroidConfigurationKeys.ANDROID_MANIFEST, value)
else -> throw CliOptionProcessingException("Unknown option: ${option.name}")
}
}
}
public class AndroidComponentRegistrar : ComponentRegistrar {
public override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
val androidResPath = configuration.get(AndroidConfigurationKeys.ANDROID_RES_PATH)
val androidManifest = configuration.get(AndroidConfigurationKeys.ANDROID_MANIFEST)
project.registerService(javaClass<AndroidUIXmlProcessor>(), CliAndroidUIXmlProcessor(project, androidResPath, androidManifest))
}
}
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Implementation-Vendor: JetBrains
Name: org.jetbrains.kotlin.compiler.plugin
CommandLineProcessor: org.jetbrains.kotlin.android.AndroidCommandLineProcessor
ComponentRegistrar: org.jetbrains.kotlin.android.AndroidComponentRegistrar
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="jps-plugin" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="jps" level="project" />
<orderEntry type="library" scope="PROVIDED" name="android" level="project" />
<orderEntry type="library" name="kotlin-runtime" level="project" />
<orderEntry type="module" module-name="android-compiler-plugin" />
</component>
</module>
@@ -0,0 +1,53 @@
/*
* 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.jps
import org.jetbrains.jet.jps.build.KotlinJpsCompilerArgumentsProvider
import org.jetbrains.jps.incremental.ModuleBuildTarget
import org.jetbrains.jps.incremental.CompileContext
import org.jetbrains.jps.model.module.JpsModule
import java.io.File
import org.jetbrains.jps.android.AndroidJpsUtil
import org.jetbrains.kotlin.android.AndroidCommandLineProcessor
import org.jetbrains.kotlin.compiler.plugin.CliOption
public class KotlinAndroidJpsPlugin : KotlinJpsCompilerArgumentsProvider {
override fun getExtraArguments(moduleBuildTarget: ModuleBuildTarget, context: CompileContext): List<String> {
val module = moduleBuildTarget.getModule()
return listOf(
makePluginOption(AndroidCommandLineProcessor.RESOURCE_PATH_OPTION, getAndroidResPath(module)),
makePluginOption(AndroidCommandLineProcessor.MANIFEST_FILE_OPTION, getAndroidManifest(module))
)
}
private fun makePluginOption(option: CliOption, value: String): String {
return "plugin:${AndroidCommandLineProcessor.ANDROID_COMPILER_PLUGIN_ID}:${option.name}=$value"
}
private fun getAndroidResPath(module: JpsModule): String {
val extension = AndroidJpsUtil.getExtension(module)
if (extension == null) return ""
val path = AndroidJpsUtil.getResourceDirForCompilationPath(extension)
return File(path!!.getAbsolutePath() + "/layout").getAbsolutePath()
}
private fun getAndroidManifest(module: JpsModule): String {
val extension = AndroidJpsUtil.getExtension(module)
if (extension == null) return ""
return AndroidJpsUtil.getManifestFileForCompilationPath(extension)!!.getAbsolutePath()
}
}
@@ -0,0 +1 @@
org.jetbrains.kotlin.android.jps.KotlinAndroidJpsPlugin