Fixed import of package prefix in non-MPP projects
#KT-33038 Fixed
This commit is contained in:
+1
-1
@@ -294,7 +294,7 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension()
|
|||||||
val gradleSourceSets = ideModule.children.filter { it.data is GradleSourceSetData } as Collection<DataNode<GradleSourceSetData>>
|
val gradleSourceSets = ideModule.children.filter { it.data is GradleSourceSetData } as Collection<DataNode<GradleSourceSetData>>
|
||||||
for (gradleSourceSetNode in gradleSourceSets) {
|
for (gradleSourceSetNode in gradleSourceSets) {
|
||||||
val propertiesForSourceSet =
|
val propertiesForSourceSet =
|
||||||
gradleModel.kotlinTaskProperties.filter { (k, v) -> gradleSourceSetNode.data.externalName == "$moduleNamePrefix:$k" }
|
gradleModel.kotlinTaskProperties.filter { (k, v) -> gradleSourceSetNode.data.id == "$moduleNamePrefix:$k" }
|
||||||
.toList().singleOrNull()
|
.toList().singleOrNull()
|
||||||
gradleSourceSetNode.children.forEach { dataNode ->
|
gradleSourceSetNode.children.forEach { dataNode ->
|
||||||
val data = dataNode.data as? ContentRootData
|
val data = dataNode.data as? ContentRootData
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* 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.gradle
|
||||||
|
|
||||||
|
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
||||||
|
import com.intellij.openapi.module.ModuleManager
|
||||||
|
import com.intellij.openapi.roots.*
|
||||||
|
import com.intellij.openapi.roots.impl.ModulesOrderEnumerator
|
||||||
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
|
import org.jetbrains.jps.model.java.JavaResourceRootType
|
||||||
|
import org.jetbrains.jps.model.java.JavaSourceRootType
|
||||||
|
import org.jetbrains.kotlin.idea.codeInsight.gradle.MultiplePluginVersionGradleImportingTestCase
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class PackagePrefixImportingTest : MultiplePluginVersionGradleImportingTestCase() {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testPackagePrefixNonMPP() {
|
||||||
|
configureByFiles()
|
||||||
|
importProject()
|
||||||
|
|
||||||
|
checkProjectStructure(
|
||||||
|
project,
|
||||||
|
projectPath,
|
||||||
|
exhaustiveModuleList = true,
|
||||||
|
exhaustiveSourceSourceRootList = true,
|
||||||
|
exhaustiveDependencyList = false
|
||||||
|
) {
|
||||||
|
module("project") {
|
||||||
|
}
|
||||||
|
module("project_main") {
|
||||||
|
sourceFolder("src/main/java", JavaSourceRootType.SOURCE, "package.prefix.main")
|
||||||
|
sourceFolder("src/main/kotlin", JavaSourceRootType.SOURCE, "package.prefix.main")
|
||||||
|
sourceFolder("src/main/resources", JavaResourceRootType.RESOURCE)
|
||||||
|
}
|
||||||
|
module("project_test") {
|
||||||
|
sourceFolder("src/test/java", JavaSourceRootType.TEST_SOURCE, "package.prefix.test")
|
||||||
|
sourceFolder("src/test/kotlin", JavaSourceRootType.TEST_SOURCE, "package.prefix.test")
|
||||||
|
sourceFolder("src/test/resources", JavaResourceRootType.TEST_RESOURCE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun importProject() {
|
||||||
|
val isCreateEmptyContentRootDirectories = currentExternalProjectSettings.isCreateEmptyContentRootDirectories
|
||||||
|
currentExternalProjectSettings.isCreateEmptyContentRootDirectories = true
|
||||||
|
try {
|
||||||
|
super.importProject()
|
||||||
|
} finally {
|
||||||
|
currentExternalProjectSettings.isCreateEmptyContentRootDirectories = isCreateEmptyContentRootDirectories
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun testDataDirName(): String {
|
||||||
|
return "packagePrefixImport"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -204,12 +204,19 @@ class ModuleInfo(
|
|||||||
expectedDependencyNames += moduleEntry.presentableName
|
expectedDependencyNames += moduleEntry.presentableName
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sourceFolder(pathInProject: String, rootType: JpsModuleSourceRootType<*>) {
|
private val ANY_PACKAGE_PREFIX = "any_package_prefix"
|
||||||
|
|
||||||
|
fun sourceFolder(pathInProject: String, rootType: JpsModuleSourceRootType<*>, packagePrefix: String? = ANY_PACKAGE_PREFIX) {
|
||||||
val sourceFolder = sourceFolderByPath[pathInProject]
|
val sourceFolder = sourceFolderByPath[pathInProject]
|
||||||
if (sourceFolder == null) {
|
if (sourceFolder == null) {
|
||||||
projectInfo.messageCollector.report("Module '${module.name}': No source folder found: '$pathInProject'")
|
projectInfo.messageCollector.report("Module '${module.name}': No source folder found: '$pathInProject'")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (packagePrefix != ANY_PACKAGE_PREFIX && sourceFolder.packagePrefix != packagePrefix) {
|
||||||
|
projectInfo.messageCollector.report(
|
||||||
|
"Module '${module.name}', source root '$pathInProject': Expected package prefix $packagePrefix doesn't match the actual one: ${sourceFolder.packagePrefix}"
|
||||||
|
)
|
||||||
|
}
|
||||||
expectedSourceRoots += pathInProject
|
expectedSourceRoots += pathInProject
|
||||||
val actualRootType = sourceFolder.rootType
|
val actualRootType = sourceFolder.rootType
|
||||||
if (actualRootType != rootType) {
|
if (actualRootType != rootType) {
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
apply from: "include.gradle"
|
||||||
|
def kotlinVersion = gradleKotlinPluginVersion('1.3.20')
|
||||||
|
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'kotlin'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
|
||||||
|
}
|
||||||
|
|
||||||
|
compileKotlin {
|
||||||
|
javaPackagePrefix = "package.prefix.main"
|
||||||
|
}
|
||||||
|
|
||||||
|
compileTestKotlin {
|
||||||
|
javaPackagePrefix = "package.prefix.test"
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user