Configuration: Include test roots of dependent modules to the module scope
#KT-23914 Fixed
This commit is contained in:
+1
@@ -216,6 +216,7 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension()
|
|||||||
val moduleDependencyData = ModuleDependencyData(ideModule.data, targetModule.data)
|
val moduleDependencyData = ModuleDependencyData(ideModule.data, targetModule.data)
|
||||||
moduleDependencyData.scope = DependencyScope.COMPILE
|
moduleDependencyData.scope = DependencyScope.COMPILE
|
||||||
moduleDependencyData.isExported = false
|
moduleDependencyData.isExported = false
|
||||||
|
moduleDependencyData.isProductionOnTestDependency = targetModule.sourceSetName == "test"
|
||||||
ideModule.createChild(ProjectKeys.MODULE_DEPENDENCY, moduleDependencyData)
|
ideModule.createChild(ProjectKeys.MODULE_DEPENDENCY, moduleDependencyData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+28
@@ -19,11 +19,14 @@ package org.jetbrains.kotlin.gradle
|
|||||||
import com.intellij.openapi.roots.DependencyScope
|
import com.intellij.openapi.roots.DependencyScope
|
||||||
import com.intellij.openapi.roots.LibraryOrderEntry
|
import com.intellij.openapi.roots.LibraryOrderEntry
|
||||||
import com.intellij.openapi.roots.OrderRootType
|
import com.intellij.openapi.roots.OrderRootType
|
||||||
|
import com.intellij.openapi.roots.impl.ModuleOrderEntryImpl
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import com.intellij.util.PathUtil
|
import com.intellij.util.PathUtil
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.gradle.GradleImportingTestCase
|
import org.jetbrains.kotlin.idea.codeInsight.gradle.GradleImportingTestCase
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.gradle.facetSettings
|
import org.jetbrains.kotlin.idea.codeInsight.gradle.facetSettings
|
||||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
||||||
|
import org.jetbrains.kotlin.idea.util.rootManager
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
@@ -34,9 +37,25 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
|
|||||||
.filterIsInstance<LibraryOrderEntry>()
|
.filterIsInstance<LibraryOrderEntry>()
|
||||||
.flatMap { it.getUrls(OrderRootType.CLASSES).map { it.replace(projectPath, "") } }
|
.flatMap { it.getUrls(OrderRootType.CLASSES).map { it.replace(projectPath, "") } }
|
||||||
|
|
||||||
|
private fun assertProductionOnTestDependency(moduleName: String, depModuleName: String, expected: Boolean) {
|
||||||
|
val depOrderEntry = getModule(moduleName)
|
||||||
|
.rootManager
|
||||||
|
.orderEntries
|
||||||
|
.filterIsInstance<ModuleOrderEntryImpl>()
|
||||||
|
.first { it.moduleName == depModuleName }
|
||||||
|
assert(depOrderEntry.isProductionOnTestDependency == expected)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertFileInModuleScope(file: VirtualFile, moduleName: String) {
|
||||||
|
assert(getModule(moduleName).getModuleWithDependenciesAndLibrariesScope(true).contains(file))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testPlatformToCommonDependency() {
|
fun testPlatformToCommonDependency() {
|
||||||
createProjectSubFile("settings.gradle", "include ':common', ':jvm', ':js'")
|
createProjectSubFile("settings.gradle", "include ':common', ':jvm', ':js'")
|
||||||
|
val commonTestFile = createProjectSubFile("common/src/test/kotlin/test.kt", "")
|
||||||
|
createProjectSubFile("jvm/src/test/kotlin/test.kt", "")
|
||||||
|
createProjectSubFile("js/src/test/kotlin/test.kt", "")
|
||||||
|
|
||||||
val kotlinVersion = "1.1.0"
|
val kotlinVersion = "1.1.0"
|
||||||
|
|
||||||
@@ -75,10 +94,19 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
importProject()
|
importProject()
|
||||||
|
|
||||||
assertModuleModuleDepScope("jvm_main", "common_main", DependencyScope.COMPILE)
|
assertModuleModuleDepScope("jvm_main", "common_main", DependencyScope.COMPILE)
|
||||||
assertModuleModuleDepScope("jvm_test", "common_test", DependencyScope.COMPILE)
|
assertModuleModuleDepScope("jvm_test", "common_test", DependencyScope.COMPILE)
|
||||||
assertModuleModuleDepScope("js_main", "common_main", DependencyScope.COMPILE)
|
assertModuleModuleDepScope("js_main", "common_main", DependencyScope.COMPILE)
|
||||||
assertModuleModuleDepScope("js_test", "common_test", DependencyScope.COMPILE)
|
assertModuleModuleDepScope("js_test", "common_test", DependencyScope.COMPILE)
|
||||||
|
|
||||||
|
assertProductionOnTestDependency("jvm_main", "common_main", false)
|
||||||
|
assertProductionOnTestDependency("jvm_test", "common_test", true)
|
||||||
|
assertProductionOnTestDependency("js_main", "common_main", false)
|
||||||
|
assertProductionOnTestDependency("js_test", "common_test", true)
|
||||||
|
|
||||||
|
assertFileInModuleScope(commonTestFile, "jvm_test")
|
||||||
|
assertFileInModuleScope(commonTestFile, "js_test")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -838,6 +838,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
|||||||
|
|
||||||
<project.converterProvider implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmSourceRootConverterProvider"/>
|
<project.converterProvider implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmSourceRootConverterProvider"/>
|
||||||
|
|
||||||
|
<orderEnumerationHandlerFactory implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmOrderEnumerationHandler$Factory"/>
|
||||||
|
|
||||||
<intentionAction>
|
<intentionAction>
|
||||||
<className>org.jetbrains.kotlin.idea.intentions.FoldInitializerAndIfToElvisIntention</className>
|
<className>org.jetbrains.kotlin.idea.intentions.FoldInitializerAndIfToElvisIntention</className>
|
||||||
<category>Kotlin</category>
|
<category>Kotlin</category>
|
||||||
|
|||||||
@@ -835,6 +835,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
|||||||
|
|
||||||
<project.converterProvider implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmSourceRootConverterProvider"/>
|
<project.converterProvider implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmSourceRootConverterProvider"/>
|
||||||
|
|
||||||
|
<orderEnumerationHandlerFactory implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmOrderEnumerationHandler$Factory"/>
|
||||||
|
|
||||||
<intentionAction>
|
<intentionAction>
|
||||||
<className>org.jetbrains.kotlin.idea.intentions.FoldInitializerAndIfToElvisIntention</className>
|
<className>org.jetbrains.kotlin.idea.intentions.FoldInitializerAndIfToElvisIntention</className>
|
||||||
<category>Kotlin</category>
|
<category>Kotlin</category>
|
||||||
|
|||||||
@@ -838,6 +838,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
|||||||
|
|
||||||
<project.converterProvider implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmSourceRootConverterProvider"/>
|
<project.converterProvider implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmSourceRootConverterProvider"/>
|
||||||
|
|
||||||
|
<orderEnumerationHandlerFactory implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmOrderEnumerationHandler$Factory"/>
|
||||||
|
|
||||||
<intentionAction>
|
<intentionAction>
|
||||||
<className>org.jetbrains.kotlin.idea.intentions.FoldInitializerAndIfToElvisIntention</className>
|
<className>org.jetbrains.kotlin.idea.intentions.FoldInitializerAndIfToElvisIntention</className>
|
||||||
<category>Kotlin</category>
|
<category>Kotlin</category>
|
||||||
|
|||||||
@@ -839,6 +839,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
|||||||
|
|
||||||
<project.converterProvider implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmSourceRootConverterProvider"/>
|
<project.converterProvider implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmSourceRootConverterProvider"/>
|
||||||
|
|
||||||
|
<orderEnumerationHandlerFactory implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmOrderEnumerationHandler$Factory"/>
|
||||||
|
|
||||||
<intentionAction>
|
<intentionAction>
|
||||||
<className>org.jetbrains.kotlin.idea.intentions.FoldInitializerAndIfToElvisIntention</className>
|
<className>org.jetbrains.kotlin.idea.intentions.FoldInitializerAndIfToElvisIntention</className>
|
||||||
<category>Kotlin</category>
|
<category>Kotlin</category>
|
||||||
|
|||||||
@@ -838,6 +838,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
|||||||
|
|
||||||
<project.converterProvider implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmSourceRootConverterProvider"/>
|
<project.converterProvider implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmSourceRootConverterProvider"/>
|
||||||
|
|
||||||
|
<orderEnumerationHandlerFactory implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmOrderEnumerationHandler$Factory"/>
|
||||||
|
|
||||||
<intentionAction>
|
<intentionAction>
|
||||||
<className>org.jetbrains.kotlin.idea.intentions.FoldInitializerAndIfToElvisIntention</className>
|
<className>org.jetbrains.kotlin.idea.intentions.FoldInitializerAndIfToElvisIntention</className>
|
||||||
<category>Kotlin</category>
|
<category>Kotlin</category>
|
||||||
|
|||||||
@@ -838,6 +838,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
|||||||
|
|
||||||
<project.converterProvider implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmSourceRootConverterProvider"/>
|
<project.converterProvider implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmSourceRootConverterProvider"/>
|
||||||
|
|
||||||
|
<orderEnumerationHandlerFactory implementation="org.jetbrains.kotlin.idea.roots.KotlinNonJvmOrderEnumerationHandler$Factory"/>
|
||||||
|
|
||||||
<intentionAction>
|
<intentionAction>
|
||||||
<className>org.jetbrains.kotlin.idea.intentions.FoldInitializerAndIfToElvisIntention</className>
|
<className>org.jetbrains.kotlin.idea.intentions.FoldInitializerAndIfToElvisIntention</className>
|
||||||
<category>Kotlin</category>
|
<category>Kotlin</category>
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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.roots
|
||||||
|
|
||||||
|
import com.intellij.openapi.module.Module
|
||||||
|
import com.intellij.openapi.roots.ModuleRootModel
|
||||||
|
import com.intellij.openapi.roots.OrderEnumerationHandler
|
||||||
|
import com.intellij.openapi.roots.OrderRootType
|
||||||
|
import org.jetbrains.jps.model.module.JpsModuleSourceRootType
|
||||||
|
import org.jetbrains.kotlin.config.KotlinResourceRootType
|
||||||
|
import org.jetbrains.kotlin.config.KotlinSourceRootType
|
||||||
|
|
||||||
|
object KotlinNonJvmOrderEnumerationHandler : OrderEnumerationHandler() {
|
||||||
|
class Factory : OrderEnumerationHandler.Factory() {
|
||||||
|
override fun isApplicable(module: Module) = true
|
||||||
|
override fun createHandler(module: Module) = KotlinNonJvmOrderEnumerationHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
private val kotlinTestSourceRootTypes: Set<JpsModuleSourceRootType<*>> =
|
||||||
|
setOf(KotlinSourceRootType.TestSource, KotlinResourceRootType.TestResource)
|
||||||
|
|
||||||
|
override fun addCustomModuleRoots(
|
||||||
|
type: OrderRootType,
|
||||||
|
rootModel: ModuleRootModel,
|
||||||
|
result: MutableCollection<String>,
|
||||||
|
includeProduction: Boolean,
|
||||||
|
includeTests: Boolean
|
||||||
|
): Boolean {
|
||||||
|
if (type == OrderRootType.SOURCES) {
|
||||||
|
if (includeProduction) {
|
||||||
|
rootModel.getSourceRoots(includeTests).mapTo(result) { it.url }
|
||||||
|
} else {
|
||||||
|
rootModel.getSourceRoots(kotlinTestSourceRootTypes).mapTo(result) { it.url }
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user