Correctly detect library kind when not using modules per sourceset

#KT-19219 Fixed
This commit is contained in:
Dmitry Jemerov
2017-07-25 14:05:16 +02:00
parent fa88fb74c4
commit c78ad9c047
3 changed files with 48 additions and 0 deletions
@@ -123,6 +123,7 @@ private fun findOwnerModule(libraryData: LibraryData,
projectDataNode: DataNode<ProjectData>): DataNode<ModuleData>? {
return projectDataNode.children.firstOrNull { dataNode ->
if (dataNode.data !is ModuleData) return@firstOrNull false
if (dataNode.hasDependency(libraryData)) return@firstOrNull true
val sourceSetDataNodes = dataNode.children.filter { it.data is GradleSourceSetData }
sourceSetDataNodes.any { it.hasDependency(libraryData) }
} as DataNode<ModuleData>?
@@ -694,6 +694,48 @@ compileTestKotlin {
assertEquals(CommonLibraryKind, (stdlib as LibraryEx).kind)
}
@Test
fun testCommonImportByPlatformPlugin_SingleModule() {
createProjectSubFile("build.gradle", """
group 'Again'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
}
}
apply plugin: 'kotlin-platform-common'
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-common:1.1.0"
}
""")
importProjectUsingSingeModulePerGradleProject()
with (facetSettings("project")) {
Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind)
}
val rootManager = ModuleRootManager.getInstance(getModule("project"))
val stdlib = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().mapTo(HashSet()) { it.library }.single()
assertEquals(CommonLibraryKind, (stdlib as LibraryEx).kind)
}
@Test
fun testJvmImportByKotlinPlugin() {
createProjectSubFile("build.gradle", """
@@ -154,6 +154,11 @@ public abstract class GradleImportingTestCase extends ExternalSystemImportingTes
return "build.gradle";
}
protected void importProjectUsingSingeModulePerGradleProject() {
getCurrentExternalProjectSettings().setResolveModulePerSourceSet(false);
importProject();
}
@Override
protected void importProject() {
ExternalSystemApiUtil.subscribe(myProject, GradleConstants.SYSTEM_ID, new ExternalSystemSettingsListenerAdapter() {