Import package prefix from MPP projects
This commit is contained in:
+19
-4
@@ -369,11 +369,26 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
resolverCtx: ProjectResolverContext
|
resolverCtx: ProjectResolverContext
|
||||||
) {
|
) {
|
||||||
val mppModel = resolverCtx.getMppModel(gradleModule) ?: return
|
val mppModel = resolverCtx.getMppModel(gradleModule) ?: return
|
||||||
|
val sourceSetToPackagePrefix = mppModel.targets.flatMap { it.compilations }
|
||||||
|
.flatMap { compilation ->
|
||||||
|
compilation.sourceSets.map { sourceSet -> sourceSet.name to compilation.kotlinTaskProperties.packagePrefix }
|
||||||
|
}
|
||||||
|
.toMap()
|
||||||
if (resolverCtx.getExtraProject(gradleModule, ExternalProject::class.java) == null) return
|
if (resolverCtx.getExtraProject(gradleModule, ExternalProject::class.java) == null) return
|
||||||
processSourceSets(gradleModule, mppModel, ideModule, resolverCtx) { dataNode, sourceSet ->
|
processSourceSets(gradleModule, mppModel, ideModule, resolverCtx) { dataNode, sourceSet ->
|
||||||
if (dataNode == null || sourceSet.actualPlatforms.supports(KotlinPlatform.ANDROID)) return@processSourceSets
|
if (dataNode == null || sourceSet.actualPlatforms.supports(KotlinPlatform.ANDROID)) return@processSourceSets
|
||||||
createContentRootData(sourceSet.sourceDirs, sourceSet.sourceType, dataNode)
|
createContentRootData(
|
||||||
createContentRootData(sourceSet.resourceDirs, sourceSet.resourceType, dataNode)
|
sourceSet.sourceDirs,
|
||||||
|
sourceSet.sourceType,
|
||||||
|
sourceSetToPackagePrefix[sourceSet.name],
|
||||||
|
dataNode
|
||||||
|
)
|
||||||
|
createContentRootData(
|
||||||
|
sourceSet.resourceDirs,
|
||||||
|
sourceSet.resourceType,
|
||||||
|
null,
|
||||||
|
dataNode
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (gradleContentRoot in gradleModule.contentRoots ?: emptySet<IdeaContentRoot?>()) {
|
for (gradleContentRoot in gradleModule.contentRoots ?: emptySet<IdeaContentRoot?>()) {
|
||||||
@@ -529,10 +544,10 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
return ideModule.findChildModuleById(usedModuleId)
|
return ideModule.findChildModuleById(usedModuleId)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createContentRootData(sourceDirs: Set<File>, sourceType: ExternalSystemSourceType, parentNode: DataNode<*>) {
|
private fun createContentRootData(sourceDirs: Set<File>, sourceType: ExternalSystemSourceType, packagePrefix: String?, parentNode: DataNode<*>) {
|
||||||
for (sourceDir in sourceDirs) {
|
for (sourceDir in sourceDirs) {
|
||||||
val contentRootData = ContentRootData(GradleConstants.SYSTEM_ID, sourceDir.absolutePath)
|
val contentRootData = ContentRootData(GradleConstants.SYSTEM_ID, sourceDir.absolutePath)
|
||||||
contentRootData.storePath(sourceType, sourceDir.absolutePath)
|
contentRootData.storePath(sourceType, sourceDir.absolutePath, packagePrefix)
|
||||||
parentNode.createChild(ProjectKeys.CONTENT_ROOT, contentRootData)
|
parentNode.createChild(ProjectKeys.CONTENT_ROOT, contentRootData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,6 +102,8 @@ abstract class AbstractKotlinGradleModelBuilder : ModelBuilderService {
|
|||||||
val kotlinProjectExtensionClass = "org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension"
|
val kotlinProjectExtensionClass = "org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension"
|
||||||
val kotlinSourceSetClass = "org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet"
|
val kotlinSourceSetClass = "org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet"
|
||||||
|
|
||||||
|
val kotlinPluginWrapper = "org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapperKt"
|
||||||
|
|
||||||
fun Task.getSourceSetName(): String {
|
fun Task.getSourceSetName(): String {
|
||||||
return try {
|
return try {
|
||||||
javaClass.methods.firstOrNull { it.name.startsWith("getSourceSetName") && it.parameterTypes.isEmpty() }?.invoke(this) as? String
|
javaClass.methods.firstOrNull { it.name.startsWith("getSourceSetName") && it.parameterTypes.isEmpty() }?.invoke(this) as? String
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ interface KotlinCompilation : KotlinModule {
|
|||||||
val dependencyClasspath: List<String>
|
val dependencyClasspath: List<String>
|
||||||
val disambiguationClassifier: String?
|
val disambiguationClassifier: String?
|
||||||
val platform: KotlinPlatform
|
val platform: KotlinPlatform
|
||||||
|
val kotlinTaskProperties: KotlinTaskProperties
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -268,7 +268,17 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
|
|||||||
val arguments = buildCompilationArguments(compileKotlinTask) ?: return null
|
val arguments = buildCompilationArguments(compileKotlinTask) ?: return null
|
||||||
val dependencyClasspath = buildDependencyClasspath(compileKotlinTask)
|
val dependencyClasspath = buildDependencyClasspath(compileKotlinTask)
|
||||||
val dependencies = buildCompilationDependencies(gradleCompilation, classifier, sourceSetMap, dependencyResolver, project)
|
val dependencies = buildCompilationDependencies(gradleCompilation, classifier, sourceSetMap, dependencyResolver, project)
|
||||||
return KotlinCompilationImpl(gradleCompilation.name, kotlinSourceSets, dependencies, output, arguments, dependencyClasspath)
|
val kotlinTaskProperties = getKotlinTaskProperties(compileKotlinTask)
|
||||||
|
|
||||||
|
return KotlinCompilationImpl(
|
||||||
|
gradleCompilation.name,
|
||||||
|
kotlinSourceSets,
|
||||||
|
dependencies,
|
||||||
|
output,
|
||||||
|
arguments,
|
||||||
|
dependencyClasspath,
|
||||||
|
kotlinTaskProperties
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildCompilationDependencies(
|
private fun buildCompilationDependencies(
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ data class KotlinCompilationImpl(
|
|||||||
override val dependencies: Set<KotlinDependency>,
|
override val dependencies: Set<KotlinDependency>,
|
||||||
override val output: KotlinCompilationOutput,
|
override val output: KotlinCompilationOutput,
|
||||||
override val arguments: KotlinCompilationArguments,
|
override val arguments: KotlinCompilationArguments,
|
||||||
override val dependencyClasspath: List<String>
|
override val dependencyClasspath: List<String>,
|
||||||
|
override val kotlinTaskProperties: KotlinTaskProperties
|
||||||
) : KotlinCompilation {
|
) : KotlinCompilation {
|
||||||
|
|
||||||
// create deep copy
|
// create deep copy
|
||||||
@@ -99,7 +100,8 @@ data class KotlinCompilationImpl(
|
|||||||
kotlinCompilation.dependencies.map { it.deepCopy(cloningCache) }.toSet(),
|
kotlinCompilation.dependencies.map { it.deepCopy(cloningCache) }.toSet(),
|
||||||
KotlinCompilationOutputImpl(kotlinCompilation.output),
|
KotlinCompilationOutputImpl(kotlinCompilation.output),
|
||||||
KotlinCompilationArgumentsImpl(kotlinCompilation.arguments),
|
KotlinCompilationArgumentsImpl(kotlinCompilation.arguments),
|
||||||
ArrayList(kotlinCompilation.dependencyClasspath)
|
ArrayList(kotlinCompilation.dependencyClasspath),
|
||||||
|
KotlinTaskPropertiesImpl(kotlinCompilation.kotlinTaskProperties)
|
||||||
) {
|
) {
|
||||||
disambiguationClassifier = kotlinCompilation.disambiguationClassifier
|
disambiguationClassifier = kotlinCompilation.disambiguationClassifier
|
||||||
platform = kotlinCompilation.platform
|
platform = kotlinCompilation.platform
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.gradle.api.file.SourceDirectorySet
|
|||||||
import org.gradle.api.internal.FactoryNamedDomainObjectContainer
|
import org.gradle.api.internal.FactoryNamedDomainObjectContainer
|
||||||
import org.gradle.api.plugins.JavaPluginConvention
|
import org.gradle.api.plugins.JavaPluginConvention
|
||||||
import org.jetbrains.kotlin.gradle.AbstractKotlinGradleModelBuilder.Companion.getSourceSetName
|
import org.jetbrains.kotlin.gradle.AbstractKotlinGradleModelBuilder.Companion.getSourceSetName
|
||||||
|
import org.jetbrains.kotlin.gradle.AbstractKotlinGradleModelBuilder.Companion.kotlinPluginWrapper
|
||||||
import org.jetbrains.kotlin.gradle.AbstractKotlinGradleModelBuilder.Companion.kotlinProjectExtensionClass
|
import org.jetbrains.kotlin.gradle.AbstractKotlinGradleModelBuilder.Companion.kotlinProjectExtensionClass
|
||||||
import org.jetbrains.kotlin.gradle.AbstractKotlinGradleModelBuilder.Companion.kotlinSourceSetClass
|
import org.jetbrains.kotlin.gradle.AbstractKotlinGradleModelBuilder.Companion.kotlinSourceSetClass
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -19,14 +20,22 @@ interface KotlinTaskProperties : Serializable {
|
|||||||
val incremental: Boolean?
|
val incremental: Boolean?
|
||||||
val packagePrefix: String?
|
val packagePrefix: String?
|
||||||
val pureKotlinSourceFolders: List<File>?
|
val pureKotlinSourceFolders: List<File>?
|
||||||
|
val pluginVersion: String?
|
||||||
}
|
}
|
||||||
|
|
||||||
data class KotlinTaskPropertiesImpl(
|
data class KotlinTaskPropertiesImpl(
|
||||||
override val incremental: Boolean?,
|
override val incremental: Boolean?,
|
||||||
override val packagePrefix: String?,
|
override val packagePrefix: String?,
|
||||||
override val pureKotlinSourceFolders: List<File>?
|
override val pureKotlinSourceFolders: List<File>?,
|
||||||
|
override val pluginVersion: String?
|
||||||
) : KotlinTaskProperties
|
) : KotlinTaskProperties {
|
||||||
|
constructor(kotlinTaskProperties: KotlinTaskProperties) : this(
|
||||||
|
kotlinTaskProperties.incremental,
|
||||||
|
kotlinTaskProperties.packagePrefix,
|
||||||
|
kotlinTaskProperties.pureKotlinSourceFolders?.map { it }?.toList(),
|
||||||
|
kotlinTaskProperties.pluginVersion
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
typealias KotlinTaskPropertiesBySourceSet = MutableMap<String, KotlinTaskProperties>
|
typealias KotlinTaskPropertiesBySourceSet = MutableMap<String, KotlinTaskProperties>
|
||||||
|
|
||||||
@@ -69,11 +78,27 @@ private fun Task.getPureKotlinSourceRoots(sourceSet: String): List<File>? {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Task.getKotlinPluginVersion(): String? {
|
||||||
|
try {
|
||||||
|
val pluginWrapperClass = javaClass.classLoader.loadClass(kotlinPluginWrapper)
|
||||||
|
val getVersionMethod =
|
||||||
|
pluginWrapperClass.getMethod("getKotlinPluginVersion", javaClass.classLoader.loadClass("org.gradle.api.Project"))
|
||||||
|
return getVersionMethod.invoke(null, this.project) as String
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
fun KotlinTaskPropertiesBySourceSet.acknowledgeTask(compileTask: Task) {
|
fun KotlinTaskPropertiesBySourceSet.acknowledgeTask(compileTask: Task) {
|
||||||
this[compileTask.getSourceSetName()] =
|
this[compileTask.getSourceSetName()] =
|
||||||
KotlinTaskPropertiesImpl(
|
getKotlinTaskProperties(compileTask)
|
||||||
compileTask.getIsIncremental(),
|
}
|
||||||
compileTask.getPackagePrefix(),
|
|
||||||
compileTask.getPureKotlinSourceRoots(compileTask.getSourceSetName())
|
fun getKotlinTaskProperties(compileTask: Task): KotlinTaskPropertiesImpl {
|
||||||
)
|
return KotlinTaskPropertiesImpl(
|
||||||
|
compileTask.getIsIncremental(),
|
||||||
|
compileTask.getPackagePrefix(),
|
||||||
|
compileTask.getPureKotlinSourceRoots(compileTask.getSourceSetName()),
|
||||||
|
compileTask.getKotlinPluginVersion()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user