191: Update Android plugin changes to AS33 (KT-29847)
This commit is contained in:
+1202
File diff suppressed because it is too large
Load Diff
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.caches.project
|
||||||
|
|
||||||
|
import com.intellij.openapi.module.Module
|
||||||
|
import com.intellij.openapi.module.ModuleUtilCore
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.util.Key
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.idea.LIBRARY_KEY
|
||||||
|
import org.jetbrains.kotlin.idea.MODULE_ROOT_TYPE_KEY
|
||||||
|
import org.jetbrains.kotlin.idea.SDK_KEY
|
||||||
|
import org.jetbrains.kotlin.idea.caches.project.UserDataModuleContainer.ForPsiElement
|
||||||
|
import org.jetbrains.kotlin.idea.caches.project.UserDataModuleContainer.ForVirtualFile
|
||||||
|
import org.jetbrains.kotlin.idea.core.getSourceType
|
||||||
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
|
|
||||||
|
// This file declares non-exported API for overriding module info with user-data
|
||||||
|
|
||||||
|
|
||||||
|
private sealed class UserDataModuleContainer {
|
||||||
|
abstract fun <T> getUserData(key: Key<T>): T?
|
||||||
|
abstract fun getModule(): Module?
|
||||||
|
|
||||||
|
data class ForVirtualFile(val virtualFile: VirtualFile, val project: Project) : UserDataModuleContainer() {
|
||||||
|
override fun <T> getUserData(key: Key<T>): T? = virtualFile.getUserData(key)
|
||||||
|
override fun getModule(): Module? = ModuleUtilCore.findModuleForFile(virtualFile, project)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class ForPsiElement(val psiElement: PsiElement) : UserDataModuleContainer() {
|
||||||
|
override fun <T> getUserData(key: Key<T>): T? {
|
||||||
|
return psiElement.getUserData(key)
|
||||||
|
?: psiElement.containingFile?.getUserData(key)
|
||||||
|
?: psiElement.containingFile?.originalFile?.virtualFile?.getUserData(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getModule(): Module? = ModuleUtilCore.findModuleForPsiElement(psiElement)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun collectModuleInfoByUserData(
|
||||||
|
project: Project,
|
||||||
|
container: UserDataModuleContainer
|
||||||
|
): List<IdeaModuleInfo> {
|
||||||
|
fun forModule(): ModuleSourceInfo? {
|
||||||
|
val rootType = container.getUserData(MODULE_ROOT_TYPE_KEY) ?: return null
|
||||||
|
val module = container.getModule() ?: return null
|
||||||
|
|
||||||
|
return when (rootType.getSourceType()) {
|
||||||
|
null -> null
|
||||||
|
SourceType.PRODUCTION -> module.productionSourceInfo()
|
||||||
|
SourceType.TEST -> module.testSourceInfo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val result = mutableListOf<IdeaModuleInfo>()
|
||||||
|
result.addIfNotNull(forModule())
|
||||||
|
|
||||||
|
val library = container.getUserData(LIBRARY_KEY)
|
||||||
|
if (library != null) {
|
||||||
|
result.addAll(createLibraryInfo(project, library))
|
||||||
|
}
|
||||||
|
|
||||||
|
val sdk = container.getUserData(SDK_KEY)
|
||||||
|
if (sdk != null) {
|
||||||
|
result.add(SdkInfo(project, sdk))
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun collectModuleInfoByUserData(
|
||||||
|
project: Project,
|
||||||
|
virtualFile: VirtualFile
|
||||||
|
): List<IdeaModuleInfo> = collectModuleInfoByUserData(project, ForVirtualFile(virtualFile, project))
|
||||||
|
|
||||||
|
fun collectModuleInfoByUserData(
|
||||||
|
psiElement: PsiElement
|
||||||
|
): List<IdeaModuleInfo> = collectModuleInfoByUserData(psiElement.project, ForPsiElement(psiElement))
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea
|
||||||
|
|
||||||
|
import com.intellij.openapi.projectRoots.Sdk
|
||||||
|
import com.intellij.openapi.roots.libraries.Library
|
||||||
|
import com.intellij.openapi.util.Key
|
||||||
|
import org.jetbrains.jps.model.module.JpsModuleSourceRootType
|
||||||
|
|
||||||
|
// WARNING, this API is used by AS3.3+
|
||||||
|
|
||||||
|
|
||||||
|
const val LIBRARY_KEY_NAME = "Kt_Library"
|
||||||
|
const val SDK_KEY_NAME = "Kt_Sdk"
|
||||||
|
const val MODULE_ROOT_TYPE_KEY_NAME = "Kt_SourceRootType"
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
val MODULE_ROOT_TYPE_KEY = getOrCreateKey<JpsModuleSourceRootType<*>>(MODULE_ROOT_TYPE_KEY_NAME)
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
val SDK_KEY = getOrCreateKey<Sdk>(SDK_KEY_NAME)
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
val LIBRARY_KEY = getOrCreateKey<Library>(LIBRARY_KEY_NAME)
|
||||||
|
|
||||||
|
|
||||||
|
inline fun <reified T> getOrCreateKey(name: String): Key<T> {
|
||||||
|
@Suppress("DEPRECATION", "UNCHECKED_CAST")
|
||||||
|
val existingKey = Key.findKeyByName(name) as Key<T>?
|
||||||
|
return existingKey ?: Key.create<T>(name)
|
||||||
|
}
|
||||||
@@ -76,7 +76,7 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
if (Ide.AS33.orHigher()) {
|
if (Ide.AS33.orHigher() || Ide.IJ191.orHigher()) {
|
||||||
"main" { }
|
"main" { }
|
||||||
"test" { }
|
"test" { }
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
if (Ide.IJ()) {
|
if (Ide.IJ() && Platform[183].orLower()) {
|
||||||
"main" {
|
"main" {
|
||||||
projectDefault()
|
projectDefault()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
<idea-plugin>
|
||||||
|
<extensionPoints>
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.updater" beanClass="com.intellij.openapi.fileTypes.FileTypeExtensionPoint"/>
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.projectConfigurator" interface="org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator"/>
|
||||||
|
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.declarationAttributeAltererExtension"
|
||||||
|
interface="org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension"
|
||||||
|
area="IDEA_PROJECT"/>
|
||||||
|
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.idePlatformKindResolution"
|
||||||
|
interface="org.jetbrains.kotlin.caches.resolve.IdePlatformKindResolution"/>
|
||||||
|
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.highlighterExtension"
|
||||||
|
interface="org.jetbrains.kotlin.idea.highlighter.HighlighterExtension"/>
|
||||||
|
|
||||||
|
<extensionPoint name="scratchFileLanguageProvider" beanClass="com.intellij.lang.LanguageExtensionPoint">
|
||||||
|
<with attribute="implementationClass" implements="org.jetbrains.kotlin.idea.scratch.ScratchFileLanguageProvider"/>
|
||||||
|
</extensionPoint>
|
||||||
|
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.binaryExtension"
|
||||||
|
interface="org.jetbrains.kotlin.idea.util.KotlinBinaryExtension"/>
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.facetValidatorCreator"
|
||||||
|
interface="org.jetbrains.kotlin.idea.facet.KotlinFacetValidatorCreator"/>
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.clearBuildState"
|
||||||
|
interface="org.jetbrains.kotlin.idea.compiler.configuration.ClearBuildStateExtension"/>
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.newFileHook"
|
||||||
|
interface="org.jetbrains.kotlin.idea.actions.NewKotlinFileHook"/>
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.completionExtension"
|
||||||
|
interface="org.jetbrains.kotlin.idea.completion.KotlinCompletionExtension"/>
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.buildSystemTypeDetector"
|
||||||
|
interface="org.jetbrains.kotlin.idea.configuration.BuildSystemTypeDetector"/>
|
||||||
|
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.idePlatformKind"
|
||||||
|
interface="org.jetbrains.kotlin.platform.IdePlatformKind"/>
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.idePlatformKindTooling"
|
||||||
|
interface="org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling"/>
|
||||||
|
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.scriptRelatedModulesProvider"
|
||||||
|
interface="org.jetbrains.kotlin.idea.core.script.dependencies.ScriptRelatedModulesProvider"
|
||||||
|
area="IDEA_PROJECT"/>
|
||||||
|
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.scriptDefinitionsProvider"
|
||||||
|
interface="kotlin.script.experimental.intellij.ScriptDefinitionsProvider"
|
||||||
|
area="IDEA_PROJECT"/>
|
||||||
|
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.syntheticScopeProviderExtension"
|
||||||
|
interface="org.jetbrains.kotlin.synthetic.SyntheticScopeProviderExtension"
|
||||||
|
area="IDEA_PROJECT"/>
|
||||||
|
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.resolveScopeEnlarger"
|
||||||
|
interface="org.jetbrains.kotlin.idea.caches.resolve.util.KotlinResolveScopeEnlarger"/>
|
||||||
|
</extensionPoints>
|
||||||
|
|
||||||
|
<extensions defaultExtensionNs="org.jetbrains.kotlin">
|
||||||
|
<projectConfigurator implementation="org.jetbrains.kotlin.idea.configuration.KotlinJavaModuleConfigurator"/>
|
||||||
|
<projectConfigurator implementation="org.jetbrains.kotlin.idea.configuration.KotlinJsModuleConfigurator"/>
|
||||||
|
|
||||||
|
<scriptDefinitionContributor
|
||||||
|
id="ScriptTemplatesFromCompilerSettingsProvider"
|
||||||
|
implementation="org.jetbrains.kotlin.idea.script.ScriptTemplatesFromCompilerSettingsProvider"/>
|
||||||
|
|
||||||
|
<scriptDefinitionContributor
|
||||||
|
id="BridgeScriptDefinitionsContributor"
|
||||||
|
implementation="org.jetbrains.kotlin.idea.script.BridgeScriptDefinitionsContributor"/>
|
||||||
|
|
||||||
|
<scriptDefinitionContributor
|
||||||
|
id="ScriptTemplatesFromDependenciesProvider"
|
||||||
|
implementation="org.jetbrains.kotlin.idea.script.ScriptTemplatesFromDependenciesProvider"/>
|
||||||
|
|
||||||
|
<scriptDefinitionContributor id="StandardScriptDefinitionContributor"
|
||||||
|
order="last"
|
||||||
|
implementation="org.jetbrains.kotlin.idea.core.script.StandardScriptDefinitionContributor"/>
|
||||||
|
|
||||||
|
<scriptDefinitionContributor id="ConsoleScriptDefinitionContributor"
|
||||||
|
implementation="org.jetbrains.kotlin.console.ConsoleScriptDefinitionContributor"/>
|
||||||
|
|
||||||
|
<idePlatformKindResolution implementation="org.jetbrains.kotlin.caches.resolve.JvmPlatformKindResolution"/>
|
||||||
|
<idePlatformKindResolution implementation="org.jetbrains.kotlin.caches.resolve.JsPlatformKindResolution"/>
|
||||||
|
<idePlatformKindResolution implementation="org.jetbrains.kotlin.caches.resolve.CommonPlatformKindResolution"/>
|
||||||
|
|
||||||
|
<scratchFileLanguageProvider language="kotlin" implementationClass="org.jetbrains.kotlin.idea.scratch.KtScratchFileLanguageProvider"/>
|
||||||
|
<scriptRelatedModulesProvider implementation="org.jetbrains.kotlin.idea.scratch.ScratchModuleDependencyProvider"/>
|
||||||
|
</extensions>
|
||||||
|
</idea-plugin>
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
<idea-plugin>
|
||||||
|
<extensions defaultExtensionNs="org.jetbrains.plugins.gradle">
|
||||||
|
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJavaFrameworkSupportProvider"/>
|
||||||
|
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJSFrameworkSupportProvider"/>
|
||||||
|
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJavaFrameworkSupportProvider"/>
|
||||||
|
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJSFrameworkSupportProvider"/>
|
||||||
|
<pluginDescriptions implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradlePluginDescription"/>
|
||||||
|
<projectResolve implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleProjectResolverExtension" order="first"/>
|
||||||
|
<projectResolve implementation="org.jetbrains.kotlin.kapt.idea.KaptProjectResolverExtension" order="last"/>
|
||||||
|
<projectResolve implementation="org.jetbrains.kotlin.allopen.ide.AllOpenProjectResolverExtension" order="last"/>
|
||||||
|
<projectResolve implementation="org.jetbrains.kotlin.noarg.ide.NoArgProjectResolverExtension" order="last"/>
|
||||||
|
<projectResolve implementation="org.jetbrains.kotlin.samWithReceiver.ide.SamWithReceiverProjectResolverExtension" order="last"/>
|
||||||
|
</extensions>
|
||||||
|
|
||||||
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
|
<externalProjectDataService implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleSourceSetDataService"/>
|
||||||
|
<externalProjectDataService implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleProjectDataService"/>
|
||||||
|
<externalProjectDataService implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleLibraryDataService"/>
|
||||||
|
<externalProjectDataService implementation="org.jetbrains.kotlin.idea.configuration.KotlinTargetDataService"/>
|
||||||
|
<externalProjectDataService implementation="org.jetbrains.kotlin.idea.KotlinJavaMPPSourceSetDataService"/>
|
||||||
|
<externalSystemTaskNotificationListener implementation="org.jetbrains.kotlin.idea.core.script.ReloadGradleTemplatesOnSync"/>
|
||||||
|
|
||||||
|
<localInspection
|
||||||
|
implementationClass="org.jetbrains.kotlin.idea.inspections.gradle.DifferentKotlinGradleVersionInspection"
|
||||||
|
displayName="Kotlin Gradle and IDE plugins versions are different"
|
||||||
|
groupName="Kotlin"
|
||||||
|
enabledByDefault="true"
|
||||||
|
language="Groovy"
|
||||||
|
hasStaticDescription="true"
|
||||||
|
level="WARNING"/>
|
||||||
|
|
||||||
|
<localInspection
|
||||||
|
implementationClass="org.jetbrains.kotlin.idea.inspections.gradle.DifferentStdlibGradleVersionInspection"
|
||||||
|
displayName="Kotlin library and Gradle plugin versions are different"
|
||||||
|
groupName="Kotlin"
|
||||||
|
enabledByDefault="true"
|
||||||
|
language="Groovy"
|
||||||
|
hasStaticDescription="true"
|
||||||
|
level="WARNING"/>
|
||||||
|
|
||||||
|
<localInspection
|
||||||
|
implementationClass="org.jetbrains.kotlin.idea.inspections.gradle.DeprecatedGradleDependencyInspection"
|
||||||
|
displayName="Deprecated library is used in Gradle"
|
||||||
|
groupName="Kotlin"
|
||||||
|
enabledByDefault="true"
|
||||||
|
cleanupTool="true"
|
||||||
|
language="Groovy"
|
||||||
|
hasStaticDescription="true"
|
||||||
|
level="WARNING"/>
|
||||||
|
|
||||||
|
<localInspection
|
||||||
|
implementationClass="org.jetbrains.kotlin.idea.inspections.gradle.GradleKotlinxCoroutinesDeprecationInspection"
|
||||||
|
displayName="Incompatible kotlinx.coroutines dependency is used with Kotlin 1.3+ in Gradle"
|
||||||
|
groupPath="Kotlin,Migration"
|
||||||
|
groupName="Gradle"
|
||||||
|
enabledByDefault="true"
|
||||||
|
language="Groovy"
|
||||||
|
hasStaticDescription="true"
|
||||||
|
level="ERROR"/>
|
||||||
|
|
||||||
|
<runConfigurationProducer implementation="org.jetbrains.kotlin.idea.run.KotlinTestClassGradleConfigurationProducer"/>
|
||||||
|
<runConfigurationProducer implementation="org.jetbrains.kotlin.idea.run.KotlinTestMethodGradleConfigurationProducer"/>
|
||||||
|
|
||||||
|
</extensions>
|
||||||
|
|
||||||
|
<extensions defaultExtensionNs="org.jetbrains.kotlin">
|
||||||
|
<gradleProjectImportHandler implementation="org.jetbrains.kotlin.allopen.ide.AllOpenGradleProjectImportHandler"/>
|
||||||
|
<gradleProjectImportHandler implementation="org.jetbrains.kotlin.scripting.idea.plugin.ScriptingGradleProjectImportHandler"/>
|
||||||
|
<gradleProjectImportHandler implementation="org.jetbrains.kotlin.kapt.idea.KaptGradleProjectImportHandler"/>
|
||||||
|
<gradleProjectImportHandler implementation="org.jetbrains.kotlin.noarg.ide.NoArgGradleProjectImportHandler"/>
|
||||||
|
<gradleProjectImportHandler implementation="org.jetbrains.kotlin.samWithReceiver.ide.SamWithReceiverGradleProjectImportHandler"/>
|
||||||
|
<gradleProjectImportHandler implementation="org.jetbrains.kotlinx.serialization.idea.KotlinSerializationGradleImportHandler"/>
|
||||||
|
|
||||||
|
<projectConfigurator implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleModuleConfigurator"/>
|
||||||
|
<projectConfigurator implementation="org.jetbrains.kotlin.idea.configuration.KotlinJsGradleModuleConfigurator"/>
|
||||||
|
<gradleModelFacade implementation="org.jetbrains.kotlin.idea.inspections.gradle.DefaultGradleModelFacade"/>
|
||||||
|
|
||||||
|
<scriptDefinitionContributor implementation="org.jetbrains.kotlin.idea.core.script.GradleScriptDefinitionsContributor" order="first"/>
|
||||||
|
<scriptRelatedModulesProvider implementation="org.jetbrains.kotlin.idea.core.script.GradleBuildSrcModuleDependencyProvider"/>
|
||||||
|
|
||||||
|
<moduleBuilder implementation="org.jetbrains.kotlin.ide.konan.gradle.KotlinGradleNativeMultiplatformModuleBuilder"/>
|
||||||
|
<moduleBuilder implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleWebMultiplatformModuleBuilder"/>
|
||||||
|
<moduleBuilder implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleSharedMultiplatformModuleBuilder"/>
|
||||||
|
<moduleBuilder implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleMobileMultiplatformModuleBuilder"/>
|
||||||
|
<moduleBuilder implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleMobileSharedMultiplatformModuleBuilder"/>
|
||||||
|
</extensions>
|
||||||
|
</idea-plugin>
|
||||||
@@ -25,7 +25,6 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
|||||||
<depends optional="true" config-file="gradle-java.xml">org.jetbrains.plugins.gradle.java</depends>
|
<depends optional="true" config-file="gradle-java.xml">org.jetbrains.plugins.gradle.java</depends>
|
||||||
<depends optional="true" config-file="maven.xml">org.jetbrains.idea.maven</depends>
|
<depends optional="true" config-file="maven.xml">org.jetbrains.idea.maven</depends>
|
||||||
<depends optional="true" config-file="testng-j.xml">TestNG-J</depends>
|
<depends optional="true" config-file="testng-j.xml">TestNG-J</depends>
|
||||||
<depends optional="true" config-file="android.xml">org.jetbrains.android</depends>
|
|
||||||
<depends optional="true" config-file="coverage.xml">Coverage</depends>
|
<depends optional="true" config-file="coverage.xml">Coverage</depends>
|
||||||
<depends optional="true" config-file="i18n.xml">com.intellij.java-i18n</depends>
|
<depends optional="true" config-file="i18n.xml">com.intellij.java-i18n</depends>
|
||||||
<depends optional="true" config-file="decompiler.xml">org.jetbrains.java.decompiler</depends>
|
<depends optional="true" config-file="decompiler.xml">org.jetbrains.java.decompiler</depends>
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
if (Ide.AS33.orHigher()) {
|
if (Ide.AS33.orHigher() || Ide.IJ191.orHigher()) {
|
||||||
"main" { }
|
"main" { }
|
||||||
"test" { }
|
"test" { }
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+78
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.android.model.impl
|
||||||
|
|
||||||
|
import com.android.builder.model.SourceProvider
|
||||||
|
import com.android.tools.idea.gradle.project.GradleProjectInfo
|
||||||
|
import com.android.tools.idea.gradle.project.model.AndroidModuleModel
|
||||||
|
import com.android.tools.idea.res.ResourceRepositoryManager
|
||||||
|
import com.intellij.openapi.module.Module
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import org.jetbrains.android.facet.AndroidFacet
|
||||||
|
import org.jetbrains.kotlin.android.model.AndroidModuleInfoProvider
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class AndroidModuleInfoProviderImpl(override val module: Module) : AndroidModuleInfoProvider {
|
||||||
|
private val androidFacet: AndroidFacet?
|
||||||
|
get() = AndroidFacet.getInstance(module)
|
||||||
|
|
||||||
|
private val androidModuleModel: AndroidModuleModel?
|
||||||
|
get() = AndroidModuleModel.get(module)
|
||||||
|
|
||||||
|
override fun isAndroidModule() = androidFacet != null
|
||||||
|
override fun isGradleModule() = GradleProjectInfo.getInstance(module.project).isBuildWithGradle
|
||||||
|
|
||||||
|
override fun getAllResourceDirectories(): List<VirtualFile> {
|
||||||
|
return androidFacet?.allResourceDirectories ?: emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getApplicationPackage() = androidFacet?.manifest?.`package`?.toString()
|
||||||
|
|
||||||
|
override fun getMainSourceProvider(): AndroidModuleInfoProvider.SourceProviderMirror? {
|
||||||
|
return androidFacet?.mainSourceProvider?.let(::SourceProviderMirrorImpl)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getApplicationResourceDirectories(createIfNecessary: Boolean): Collection<VirtualFile> {
|
||||||
|
return ResourceRepositoryManager.getOrCreateInstance(module)?.getAppResources(createIfNecessary)?.resourceDirs ?: emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getAllSourceProviders(): List<AndroidModuleInfoProvider.SourceProviderMirror> {
|
||||||
|
val androidModuleModel = this.androidModuleModel ?: return emptyList()
|
||||||
|
return androidModuleModel.allSourceProviders.map(::SourceProviderMirrorImpl)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getActiveSourceProviders(): List<AndroidModuleInfoProvider.SourceProviderMirror> {
|
||||||
|
val androidModuleModel = this.androidModuleModel ?: return emptyList()
|
||||||
|
return androidModuleModel.activeSourceProviders.map(::SourceProviderMirrorImpl)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getFlavorSourceProviders(): List<AndroidModuleInfoProvider.SourceProviderMirror> {
|
||||||
|
val androidModuleModel = this.androidModuleModel ?: return emptyList()
|
||||||
|
|
||||||
|
val getFlavorSourceProvidersMethod = try {
|
||||||
|
AndroidFacet::class.java.getMethod("getFlavorSourceProviders")
|
||||||
|
} catch (e: NoSuchMethodException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (getFlavorSourceProvidersMethod != null) {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
val sourceProviders = getFlavorSourceProvidersMethod.invoke(androidFacet) as? List<SourceProvider>
|
||||||
|
sourceProviders?.map(::SourceProviderMirrorImpl) ?: emptyList()
|
||||||
|
} else {
|
||||||
|
androidModuleModel.flavorSourceProviders.map(::SourceProviderMirrorImpl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SourceProviderMirrorImpl(val sourceProvider: SourceProvider) :
|
||||||
|
AndroidModuleInfoProvider.SourceProviderMirror {
|
||||||
|
override val name: String
|
||||||
|
get() = sourceProvider.name
|
||||||
|
|
||||||
|
override val resDirectories: Collection<File>
|
||||||
|
get() = sourceProvider.resDirectories
|
||||||
|
}
|
||||||
|
}
|
||||||
+161
@@ -0,0 +1,161 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 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.kapt.idea
|
||||||
|
|
||||||
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
|
import com.intellij.openapi.externalSystem.model.DataNode
|
||||||
|
import com.intellij.openapi.externalSystem.model.ProjectKeys
|
||||||
|
import com.intellij.openapi.externalSystem.model.project.*
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.tooling.model.idea.IdeaModule
|
||||||
|
import org.jetbrains.kotlin.gradle.AbstractKotlinGradleModelBuilder
|
||||||
|
import org.jetbrains.kotlin.idea.framework.GRADLE_SYSTEM_ID
|
||||||
|
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
|
||||||
|
import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension
|
||||||
|
import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder
|
||||||
|
import java.io.File
|
||||||
|
import java.io.Serializable
|
||||||
|
import java.lang.Exception
|
||||||
|
import java.lang.reflect.Modifier
|
||||||
|
|
||||||
|
interface KaptSourceSetModel : Serializable {
|
||||||
|
val sourceSetName: String
|
||||||
|
val isTest: Boolean
|
||||||
|
val generatedSourcesDir: String
|
||||||
|
val generatedClassesDir: String
|
||||||
|
val generatedKotlinSourcesDir: String
|
||||||
|
|
||||||
|
val generatedSourcesDirFile get() = generatedSourcesDir.takeIf { it.isNotEmpty() }?.let(::File)
|
||||||
|
val generatedClassesDirFile get() = generatedClassesDir.takeIf { it.isNotEmpty() }?.let(::File)
|
||||||
|
val generatedKotlinSourcesDirFile get() = generatedKotlinSourcesDir.takeIf { it.isNotEmpty() }?.let(::File)
|
||||||
|
}
|
||||||
|
|
||||||
|
class KaptSourceSetModelImpl(
|
||||||
|
override val sourceSetName: String,
|
||||||
|
override val isTest: Boolean,
|
||||||
|
override val generatedSourcesDir: String,
|
||||||
|
override val generatedClassesDir: String,
|
||||||
|
override val generatedKotlinSourcesDir: String
|
||||||
|
) : KaptSourceSetModel
|
||||||
|
|
||||||
|
interface KaptGradleModel : Serializable {
|
||||||
|
val isEnabled: Boolean
|
||||||
|
val buildDirectory: File
|
||||||
|
val sourceSets: List<KaptSourceSetModel>
|
||||||
|
}
|
||||||
|
|
||||||
|
class KaptGradleModelImpl(
|
||||||
|
override val isEnabled: Boolean,
|
||||||
|
override val buildDirectory: File,
|
||||||
|
override val sourceSets: List<KaptSourceSetModel>
|
||||||
|
) : KaptGradleModel
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
class KaptProjectResolverExtension : AbstractProjectResolverExtension() {
|
||||||
|
private companion object {
|
||||||
|
private val LOG = Logger.getInstance(KaptProjectResolverExtension::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getExtraProjectModelClasses() = setOf(KaptGradleModel::class.java)
|
||||||
|
override fun getToolingExtensionsClasses() = setOf(KaptModelBuilderService::class.java, Unit::class.java)
|
||||||
|
|
||||||
|
override fun populateModuleExtraModels(gradleModule: IdeaModule, ideModule: DataNode<ModuleData>) {
|
||||||
|
val kaptModel = resolverCtx.getExtraProject(gradleModule, KaptGradleModel::class.java) ?: return
|
||||||
|
|
||||||
|
if (kaptModel.isEnabled) {
|
||||||
|
for (sourceSet in kaptModel.sourceSets) {
|
||||||
|
val sourceSetDataNode = ideModule.findGradleSourceSet(sourceSet.sourceSetName) ?: continue
|
||||||
|
|
||||||
|
fun addSourceSet(path: String, type: ExternalSystemSourceType) {
|
||||||
|
val contentRootData = ContentRootData(GRADLE_SYSTEM_ID, path)
|
||||||
|
contentRootData.storePath(type, path)
|
||||||
|
sourceSetDataNode.createChild(ProjectKeys.CONTENT_ROOT, contentRootData)
|
||||||
|
}
|
||||||
|
|
||||||
|
val sourceType = if (sourceSet.isTest) ExternalSystemSourceType.TEST_GENERATED else ExternalSystemSourceType.SOURCE_GENERATED
|
||||||
|
sourceSet.generatedSourcesDirFile?.let { addSourceSet(it.absolutePath, sourceType) }
|
||||||
|
sourceSet.generatedKotlinSourcesDirFile?.let { addSourceSet(it.absolutePath, sourceType) }
|
||||||
|
|
||||||
|
sourceSet.generatedClassesDirFile?.let { generatedClassesDir ->
|
||||||
|
val libraryData = LibraryData(GRADLE_SYSTEM_ID, "kaptGeneratedClasses")
|
||||||
|
libraryData.addPath(LibraryPathType.BINARY, generatedClassesDir.absolutePath)
|
||||||
|
val libraryDependencyData = LibraryDependencyData(sourceSetDataNode.data, libraryData, LibraryLevel.MODULE)
|
||||||
|
sourceSetDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.populateModuleExtraModels(gradleModule, ideModule)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun DataNode<ModuleData>.findGradleSourceSet(sourceSetName: String): DataNode<GradleSourceSetData>? {
|
||||||
|
val moduleName = data.id
|
||||||
|
for (child in children) {
|
||||||
|
val gradleSourceSetData = child.data as? GradleSourceSetData ?: continue
|
||||||
|
if (gradleSourceSetData.id == "$moduleName:$sourceSetName") {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
return child as DataNode<GradleSourceSetData>?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class KaptModelBuilderService : AbstractKotlinGradleModelBuilder() {
|
||||||
|
override fun getErrorMessageBuilder(project: Project, e: Exception): ErrorMessageBuilder {
|
||||||
|
return ErrorMessageBuilder.create(project, e, "Gradle import errors")
|
||||||
|
.withDescription("Unable to build kotlin-kapt plugin configuration")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canBuild(modelName: String?): Boolean = modelName == KaptGradleModel::class.java.name
|
||||||
|
|
||||||
|
override fun buildAll(modelName: String?, project: Project): Any {
|
||||||
|
val kaptPlugin: Plugin<*>? = project.plugins.findPlugin("kotlin-kapt")
|
||||||
|
val kaptIsEnabled = kaptPlugin != null
|
||||||
|
|
||||||
|
val sourceSets = mutableListOf<KaptSourceSetModel>()
|
||||||
|
|
||||||
|
if (kaptIsEnabled) {
|
||||||
|
project.getAllTasks(false)[project]?.forEach { compileTask ->
|
||||||
|
if (compileTask.javaClass.name !in kotlinCompileTaskClasses) return@forEach
|
||||||
|
|
||||||
|
val sourceSetName = compileTask.getSourceSetName()
|
||||||
|
val isTest = sourceSetName.toLowerCase().endsWith("test")
|
||||||
|
|
||||||
|
val kaptGeneratedSourcesDir = getKaptDirectory("getKaptGeneratedSourcesDir", project, sourceSetName)
|
||||||
|
val kaptGeneratedClassesDir = getKaptDirectory("getKaptGeneratedClassesDir", project, sourceSetName)
|
||||||
|
val kaptGeneratedKotlinSourcesDir = getKaptDirectory("getKaptGeneratedKotlinSourcesDir", project, sourceSetName)
|
||||||
|
sourceSets += KaptSourceSetModelImpl(
|
||||||
|
sourceSetName, isTest, kaptGeneratedSourcesDir, kaptGeneratedClassesDir, kaptGeneratedKotlinSourcesDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return KaptGradleModelImpl(kaptIsEnabled, project.buildDir, sourceSets)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getKaptDirectory(funName: String, project: Project, sourceSetName: String): String {
|
||||||
|
val kotlinKaptPlugin = project.plugins.findPlugin("kotlin-kapt") ?: return ""
|
||||||
|
|
||||||
|
val targetMethod = kotlinKaptPlugin::class.java.methods.firstOrNull {
|
||||||
|
Modifier.isStatic(it.modifiers) && it.name == funName && it.parameterCount == 2
|
||||||
|
} ?: return ""
|
||||||
|
|
||||||
|
return (targetMethod(null, project, sourceSetName) as? File)?.absolutePath ?: ""
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user