Use ModuleOrderEntry instead of ModuleOrderEntryImpl

`isProductionOnTestDependency` function was moved from implementation to
interface. The fix is important for the new IJ project model.
This commit is contained in:
Alex Plate
2020-02-19 14:35:37 +03:00
committed by Nikita Bobko
parent bc20464bad
commit 801c97f456
5 changed files with 9 additions and 13 deletions
@@ -11,7 +11,6 @@ import com.intellij.openapi.module.impl.scopes.LibraryScopeBase
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.roots.*
import com.intellij.openapi.roots.impl.ModuleOrderEntryImpl
import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.util.ModificationTracker
@@ -92,7 +91,7 @@ private fun orderEntryToModuleInfo(project: Project, orderEntry: OrderEntry, for
}
is ModuleOrderEntry -> {
val module = orderEntry.module ?: return emptyList()
if (forProduction && orderEntry is ModuleOrderEntryImpl && orderEntry.isProductionOnTestDependency) {
if (forProduction && orderEntry.isProductionOnTestDependency) {
listOfNotNull(module.testSourceInfo())
} else {
module.toInfos()
@@ -131,7 +130,7 @@ private fun OrderEntry.acceptAsDependency(forProduction: Boolean): Boolean {
return this !is ExportableOrderEntry
|| !forProduction
// this is needed for Maven/Gradle projects with "production-on-test" dependency
|| this is ModuleOrderEntryImpl && isProductionOnTestDependency
|| this is ModuleOrderEntry && isProductionOnTestDependency
|| scope.isForProductionCompile
}
@@ -15,7 +15,6 @@ 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.configuration.KotlinTargetData
import org.jetbrains.kotlin.idea.configuration.kotlinSourceSet
@@ -48,7 +47,7 @@ class KotlinJavaMPPSourceSetDataService : AbstractProjectDataService<GradleSourc
val moduleEntries = rootModel.orderEntries.filterIsInstance<ModuleOrderEntry>()
moduleEntries.filter { isTestModuleById(it.moduleName, toImport) }.forEach { moduleOrderEntry ->
(moduleOrderEntry as? ModuleOrderEntryImpl)?.isProductionOnTestDependency = true
moduleOrderEntry.isProductionOnTestDependency = true
}
val libraryEntries = rootModel.orderEntries.filterIsInstance<LibraryOrderEntry>()
libraryEntries.forEach { libraryEntry ->
@@ -5,11 +5,10 @@
package org.jetbrains.kotlin.idea
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.DependencyScope
import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.openapi.roots.impl.ModuleOrderEntryImpl
import com.intellij.openapi.diagnostic.Logger
/**
* Returns the dependency scope which has flags specific to the both provided scopes
@@ -57,7 +56,7 @@ fun addModuleDependencyIfNeeded(
dependOnTest: Boolean
) {
val existingEntry = rootModel.findModuleOrderEntry(dependeeModule)
val existingDependOnTest = (existingEntry as? ModuleOrderEntryImpl)?.isProductionOnTestDependency ?: false
val existingDependOnTest = existingEntry?.isProductionOnTestDependency ?: false
val requiredScope = getScopeContainingBoth(if (testScope) DependencyScope.TEST else DependencyScope.COMPILE, existingEntry?.scope)
if (existingEntry != null) {
@@ -72,6 +71,6 @@ fun addModuleDependencyIfNeeded(
}
rootModel.addModuleOrderEntry(dependeeModule).also {
it.scope = requiredScope
(it as? ModuleOrderEntryImpl)?.isProductionOnTestDependency = dependOnTest || existingDependOnTest
it.isProductionOnTestDependency = dependOnTest || existingDependOnTest
}
}
@@ -18,8 +18,8 @@ package org.jetbrains.kotlin.gradle
import com.intellij.openapi.roots.DependencyScope
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.VirtualFile
import com.intellij.util.PathUtil
import junit.framework.TestCase
@@ -43,7 +43,7 @@ class MultiplatformProjectImportingTest : MultiplePluginVersionGradleImportingTe
val depOrderEntry = getModule(moduleName)
.rootManager
.orderEntries
.filterIsInstance<ModuleOrderEntryImpl>()
.filterIsInstance<ModuleOrderEntry>()
.first { it.moduleName == depModuleName }
assert(depOrderEntry.isProductionOnTestDependency == expected)
}
@@ -10,7 +10,6 @@ import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.rootManager
import com.intellij.openapi.roots.*
import com.intellij.openapi.roots.impl.ModuleOrderEntryImpl
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.jps.model.module.JpsModuleSourceRootType
import org.jetbrains.jps.util.JpsPathUtil
@@ -319,7 +318,7 @@ class ModuleInfo(
private fun checkProductionOnTest(library: ExportableOrderEntry, productionOnTest: Boolean?) {
if (productionOnTest == null) return
val actualFlag = (library as? ModuleOrderEntryImpl)?.isProductionOnTestDependency
val actualFlag = (library as? ModuleOrderEntry)?.isProductionOnTestDependency
if (actualFlag == null) {
projectInfo.messageCollector.report(
"Module '${module.name}': Dependency '${library.presentableName}' has no productionOnTest property"