@@ -4,8 +4,6 @@ import org.utbot.common.PathUtil.toPath
4
4
import org.utbot.common.WorkaroundReason
5
5
import org.utbot.common.workaround
6
6
import org.utbot.framework.plugin.api.CodegenLanguage
7
- import org.utbot.intellij.plugin.ui.CommonErrorNotifier
8
- import org.utbot.intellij.plugin.ui.UnsupportedJdkNotifier
9
7
import com.intellij.openapi.command.WriteCommandAction
10
8
import com.intellij.openapi.externalSystem.model.ProjectSystemId
11
9
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
@@ -14,9 +12,6 @@ import com.intellij.openapi.module.ModuleManager
14
12
import com.intellij.openapi.module.ModuleUtilCore
15
13
import com.intellij.openapi.project.Project
16
14
import com.intellij.openapi.project.guessModuleDir
17
- import com.intellij.openapi.projectRoots.JavaSdk
18
- import com.intellij.openapi.projectRoots.JavaSdkVersion
19
- import com.intellij.openapi.projectRoots.Sdk
20
15
import com.intellij.openapi.roots.ContentEntry
21
16
import com.intellij.openapi.roots.ModifiableRootModel
22
17
import com.intellij.openapi.roots.ModuleRootManager
@@ -29,26 +24,30 @@ import com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile
29
24
import com.intellij.util.PathUtil.getParentPath
30
25
import java.nio.file.Path
31
26
import mu.KotlinLogging
32
- import org.jetbrains.android.sdk.AndroidSdkType
33
27
import org.jetbrains.jps.model.module.JpsModuleSourceRootType
34
28
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
35
29
import org.jetbrains.kotlin.config.TestResourceKotlinRootType
36
30
import org.jetbrains.kotlin.platform.TargetPlatformVersion
37
31
38
32
private val logger = KotlinLogging .logger {}
39
33
40
- data class TestSourceRoot (
41
- val dir : VirtualFile ,
42
- val expectedLanguage : CodegenLanguage
43
- )
34
+ interface ITestSourceRoot {
35
+ val dirPath: String
36
+ val dirName: String
37
+ val dir: VirtualFile ?
38
+ val expectedLanguage : CodegenLanguage
39
+ }
44
40
45
- /* *
46
- * @return jdk version of the module
47
- */
48
- fun Module.jdkVersion (): JavaSdkVersion {
49
- val moduleRootManager = ModuleRootManager .getInstance(this )
50
- val sdk = moduleRootManager.sdk
51
- return jdkVersionBy(sdk)
41
+ class TestSourceRoot (override val dir : VirtualFile , override val expectedLanguage : CodegenLanguage ) : ITestSourceRoot {
42
+ override val dirPath: String = dir.toNioPath().toString()
43
+ override val dirName: String = dir.name
44
+
45
+ override fun toString () = dirPath
46
+
47
+ override fun equals (other : Any? ) =
48
+ other is TestSourceRoot && dir == other.dir && expectedLanguage == other.expectedLanguage
49
+
50
+ override fun hashCode () = 31 * dir.hashCode() + expectedLanguage.hashCode()
52
51
}
53
52
54
53
/* *
@@ -107,11 +106,11 @@ private fun findPotentialModulesForTests(project: Project, srcModule: Module): L
107
106
if (modules.isNotEmpty()) return modules
108
107
109
108
if (srcModule.suitableTestSourceFolders().isEmpty()) {
110
- val modules = mutableSetOf<Module >()
111
- ModuleUtilCore .collectModulesDependsOn(srcModule, modules)
112
- modules.remove(srcModule)
109
+ val modulesWithTestRoot = mutableSetOf<Module >().also {
110
+ ModuleUtilCore .collectModulesDependsOn(srcModule, it)
111
+ it.remove(srcModule)
112
+ }.filter { it.suitableTestSourceFolders().isNotEmpty() }
113
113
114
- val modulesWithTestRoot = modules.filter { it.suitableTestSourceFolders().isNotEmpty() }
115
114
if (modulesWithTestRoot.size == 1 ) return modulesWithTestRoot
116
115
}
117
116
return listOf (srcModule)
@@ -165,11 +164,11 @@ val Project.isBuildWithGradle get() =
165
164
166
165
const val dedicatedTestSourceRootName = " utbot_tests"
167
166
168
- fun Module.addDedicatedTestRoot (testSourceRoots : MutableList <TestSourceRoot >, language : CodegenLanguage ): VirtualFile ? {
169
- // Don't suggest new test source roots for Gradle project where 'unexpected' test roots won't work
167
+ fun Module.addDedicatedTestRoot (testSourceRoots : MutableList <ITestSourceRoot >, language : CodegenLanguage ): VirtualFile ? {
168
+ // Don't suggest new test source roots for a Gradle project where 'unexpected' test roots won't work
170
169
if (project.isBuildWithGradle) return null
171
170
// Dedicated test root already exists
172
- if (testSourceRoots.any { root -> root.dir.name == dedicatedTestSourceRootName }) return null
171
+ if (testSourceRoots.any { root -> root.dir? .name == dedicatedTestSourceRootName }) return null
173
172
174
173
val moduleInstance = ModuleRootManager .getInstance(this )
175
174
val testFolder = moduleInstance.contentEntries.flatMap { it.sourceFolders.toList() }
@@ -256,34 +255,6 @@ fun ContentEntry.addSourceRootIfAbsent(
256
255
}
257
256
}
258
257
259
- /* *
260
- * Obtain JDK version and make sure that it is JDK8 or JDK11
261
- */
262
- private fun jdkVersionBy (sdk : Sdk ? ): JavaSdkVersion {
263
- if (sdk == null ) {
264
- CommonErrorNotifier .notify(" Failed to obtain JDK version of the project" )
265
- }
266
- requireNotNull(sdk)
267
-
268
- val jdkVersion = when (sdk.sdkType) {
269
- is JavaSdk -> {
270
- (sdk.sdkType as JavaSdk ).getVersion(sdk)
271
- }
272
- is AndroidSdkType -> {
273
- ((sdk.sdkType as AndroidSdkType ).dependencyType as JavaSdk ).getVersion(sdk)
274
- }
275
- else -> null
276
- }
277
- if (jdkVersion == null ) {
278
- CommonErrorNotifier .notify(" Failed to obtain JDK version of the project" )
279
- }
280
- requireNotNull(jdkVersion)
281
- if (! jdkVersion.isAtLeast(JavaSdkVersion .JDK_1_8 )) {
282
- UnsupportedJdkNotifier .notify(jdkVersion.description)
283
- }
284
- return jdkVersion
285
- }
286
-
287
258
private val SourceFolder .expectedLanguageForTests: CodegenLanguage ?
288
259
get() {
289
260
// unfortunately, Gradle creates Kotlin test source root with Java source root type, so type is misleading,
0 commit comments