Fixed setting production-on-test flag if project was not build
Make importing production-on-test flag more accurate when the project to be imported was not previously build
This commit is contained in:
@@ -13,8 +13,11 @@ import com.intellij.openapi.externalSystem.service.project.manage.AbstractProjec
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.LibraryOrderEntry
|
||||
import com.intellij.openapi.roots.ModuleOrderEntry
|
||||
import com.intellij.openapi.roots.OrderRootType
|
||||
import com.intellij.openapi.roots.impl.ModuleOrderEntryImpl
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import org.jetbrains.kotlin.idea.caches.project.isTestModule
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinTargetData
|
||||
import org.jetbrains.kotlin.idea.configuration.kotlinSourceSet
|
||||
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
|
||||
@@ -22,6 +25,9 @@ import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
|
||||
class KotlinJavaMPPSourceSetDataService : AbstractProjectDataService<GradleSourceSetData, Void>() {
|
||||
override fun getTargetDataKey() = GradleSourceSetData.KEY
|
||||
|
||||
private fun isTestModuleById(id: String, toImport: Collection<DataNode<GradleSourceSetData>>): Boolean =
|
||||
toImport.firstOrNull { it.data.internalName == id }?.kotlinSourceSet?.isTestModule ?: false
|
||||
|
||||
override fun postProcess(
|
||||
toImport: MutableCollection<DataNode<GradleSourceSetData>>,
|
||||
projectData: ProjectData?,
|
||||
@@ -40,8 +46,14 @@ class KotlinJavaMPPSourceSetDataService : AbstractProjectDataService<GradleSourc
|
||||
val moduleData = nodeToImport.data
|
||||
val module = modelsProvider.findIdeModule(moduleData) ?: continue
|
||||
val rootModel = modelsProvider.getModifiableRootModel(module)
|
||||
|
||||
val moduleEntries = rootModel.orderEntries.filterIsInstance<ModuleOrderEntry>()
|
||||
moduleEntries.filter { isTestModuleById(it.moduleName, toImport) }.forEach {moduleOrderEntry ->
|
||||
(moduleOrderEntry as? ModuleOrderEntryImpl)?.isProductionOnTestDependency = true
|
||||
}
|
||||
val libraryEntries = rootModel.orderEntries.filterIsInstance<LibraryOrderEntry>()
|
||||
libraryEntries.forEach { libraryEntry ->
|
||||
//TODO check that this code is nessecary any more. In general case all dependencies on MPP are already resolved into module dependencies
|
||||
val library = libraryEntry.library ?: return@forEach
|
||||
val libraryModel = modelsProvider.getModifiableLibraryModel(library)
|
||||
val classesUrl = libraryModel.getUrls(OrderRootType.CLASSES).singleOrNull() ?: return@forEach
|
||||
|
||||
+1
-2
@@ -585,8 +585,7 @@ class NewMultiplatformProjectImportingTest : MultiplePluginVersionGradleImportin
|
||||
|
||||
checkProjectStructure(false, false, false ) {
|
||||
module("project.javaModule.test") {
|
||||
moduleDependency("project.mppModule.jvmTest", DependencyScope.TEST, true)
|
||||
moduleDependency("project.mppModule.jvmMain", DependencyScope.COMPILE, false)
|
||||
moduleDependency("project.mppModule.jvmTest", DependencyScope.COMPILE, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
|
||||
evaluationDependsOn(":mppModule")
|
||||
dependencies {
|
||||
testCompile project(':mppModule')
|
||||
}
|
||||
testCompile project(':mppModule').kotlin.targets.jvm.compilations.test.output.allOutputs
|
||||
}
|
||||
+2
-1
@@ -1,2 +1,3 @@
|
||||
include 'javaModule'
|
||||
include 'mppModule'
|
||||
include 'javaModule'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user