Skip to content

Commit

Permalink
[maven] IDEA-364947 make tests extend MavenMultiVersionImportingTestCase
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 2bc93832b302ecc82631f3692418c0eaebc0079e
  • Loading branch information
Dmitry Kichinsky authored and intellij-monorepo-bot committed Dec 22, 2024
1 parent a522f96 commit 728cf6e
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package org.jetbrains.idea.maven.execution

import com.intellij.execution.configurations.JavaParameters
import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCaseLegacy
import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCase
import com.intellij.openapi.application.readAction
import com.intellij.openapi.application.writeAction
import com.intellij.openapi.command.WriteCommandAction
Expand All @@ -28,13 +28,15 @@ import com.intellij.util.ArrayUtilRt
import com.intellij.util.CommonProcessors.CollectProcessor
import com.intellij.util.PathsList
import com.intellij.util.ReflectionUtil
import com.intellij.util.io.createDirectories
import kotlinx.coroutines.runBlocking
import org.jetbrains.idea.maven.importing.ArtifactsDownloadingTestCase.Companion.createEmptyJar
import org.junit.Test
import java.io.File
import java.io.IOException
import java.nio.file.Paths

class MavenClasspathsAndSearchScopesTest : MavenMultiVersionImportingTestCaseLegacy() {
class MavenClasspathsAndSearchScopesTest : MavenMultiVersionImportingTestCase() {
private enum class Type {
PRODUCTION, TESTS
}
Expand Down Expand Up @@ -1187,7 +1189,7 @@ $scope</scope>
private suspend fun checkDirIndexTestModulesWithCompileOrRuntimeScope(modules: List<Module>) {
assertEquals(6, modules.size)
val index = ProjectFileIndex.getInstance(project)
val m3JavaDir = VfsUtil.findFileByIoFile(File(projectPath, "m3/src/main/java"), true)
val m3JavaDir = VfsUtil.findFile(Paths.get(projectPath.toString(), "m3/src/main/java"), true)
assertNotNull(m3JavaDir)
// Should be: m1 -> m3, m2 -> m3, m3 -> source, and m4 -> m3
val orderEntries = readAction { index.getOrderEntriesForFile(m3JavaDir!!) }
Expand All @@ -1200,7 +1202,7 @@ $scope</scope>
val m3E2 = orderEntries[2]
UsefulTestCase.assertInstanceOf(m3E2, ModuleSourceOrderEntry::class.java)

val m6javaDir = VfsUtil.findFileByIoFile(File(projectPath, "m6/src/main/java"), true)
val m6javaDir = VfsUtil.findFile(Paths.get(projectPath.toString(), "m6/src/main/java"), true)
assertNotNull(m6javaDir)
// Should be m1 -> m6, m2 -> m6, m5 -> m6, m6 -> source
val m6OrderEntries = readAction { index.getOrderEntriesForFile(m6javaDir!!) }
Expand Down Expand Up @@ -1235,7 +1237,7 @@ $scope</scope>
val modules = setupDirIndexTestModulesWithScope("test")
assertEquals(6, modules.size)
val index = ProjectFileIndex.getInstance(project)
val m3JavaDir = VfsUtil.findFileByIoFile(File(projectPath, "m3/src/main/java"), true)
val m3JavaDir = VfsUtil.findFile(Paths.get(projectPath.toString(), "m3/src/main/java"), true)
assertNotNull(m3JavaDir)
// Should be no transitive deps: m2 -> m3, m3 -> source, and m4 -> m3
val orderEntries = readAction { index.getOrderEntriesForFile(m3JavaDir!!) }
Expand All @@ -1248,7 +1250,7 @@ $scope</scope>
val m3E1 = orderEntries[1]
UsefulTestCase.assertInstanceOf(m3E1, ModuleSourceOrderEntry::class.java)

val m6javaDir = VfsUtil.findFileByIoFile(File(projectPath, "m6/src/main/java"), true)
val m6javaDir = VfsUtil.findFile(Paths.get(projectPath.toString(), "m6/src/main/java"), true)
assertNotNull(m6javaDir)
// Still has some transitive deps because m5 -> m6 is hardcoded to be compile scope
// m2 -> m6, m5 -> m6, m6 -> source
Expand Down Expand Up @@ -1291,10 +1293,10 @@ $scope</scope>
ModuleRootModificationUtil.addDependency(nonMavenM2, modules[0], DependencyScope.COMPILE, true)
createProjectSubDirs("nonMavenM1/src/main/java", "nonMavenM1/src/test/java",
"nonMavenM2/src/main/java", "nonMavenM2/src/test/java")
val nonMavenM1JavaDir = VfsUtil.findFileByIoFile(File(projectPath, "nonMavenM1/src/main/java"), true)
val nonMavenM1JavaDir = VfsUtil.findFile(Paths.get(projectPath.toString(), "nonMavenM1/src/main/java"), true)
assertNotNull(nonMavenM1JavaDir)
PsiTestUtil.addSourceContentToRoots(nonMavenM1, nonMavenM1JavaDir!!)
val nonMavenM2JavaDir = VfsUtil.findFileByIoFile(File(projectPath, "nonMavenM2/src/main/java"), true)
val nonMavenM2JavaDir = VfsUtil.findFile(Paths.get(projectPath.toString(), "nonMavenM2/src/main/java"), true)
assertNotNull(nonMavenM2JavaDir)
PsiTestUtil.addSourceContentToRoots(nonMavenM2, nonMavenM2JavaDir!!)
}
Expand All @@ -1304,7 +1306,7 @@ $scope</scope>
assertModuleModuleDeps("m1", "m2", "m3", "m5", "m6")

val index = ProjectFileIndex.getInstance(project)
val m3JavaDir = VfsUtil.findFileByIoFile(File(projectPath, "m3/src/main/java"), true)
val m3JavaDir = VfsUtil.findFile(Paths.get(projectPath.toString(), "m3/src/main/java"), true)
assertNotNull(m3JavaDir)
// Should be: m1 -> m3, m2 -> m3, m3 -> source, and m4 -> m3
// It doesn't trace back to nonMavenM1 and nonMavenM2.
Expand All @@ -1314,7 +1316,7 @@ $scope</scope>
assertOrderedElementsAreEqual(ownerModules, listOf(modules[0], modules[1], modules[2], modules[3]))
assertOrderedElementsAreEqual(depModules, listOf(modules[2], modules[2], null, modules[2]))

val m6javaDir = VfsUtil.findFileByIoFile(File(projectPath, "m6/src/main/java"), true)
val m6javaDir = VfsUtil.findFile(Paths.get(projectPath.toString(), "m6/src/main/java"), true)
assertNotNull(m6javaDir)
// Should be m1 -> m6, m2 -> m6, m5 -> m6, m6 -> source
val m6OrderEntries = readAction { index.getOrderEntriesForFile(m6javaDir!!) }
Expand All @@ -1323,7 +1325,7 @@ $scope</scope>
assertOrderedElementsAreEqual(m6OwnerModules, listOf(modules[0], modules[1], modules[4], modules[5]))
assertOrderedElementsAreEqual(m6DepModules, listOf(modules[5], modules[5], modules[5], null))

val nonMavenM2JavaDir = VfsUtil.findFileByIoFile(File(projectPath, "nonMavenM2/src/main/java"), true)
val nonMavenM2JavaDir = VfsUtil.findFile(Paths.get(projectPath.toString(), "nonMavenM2/src/main/java"), true)
assertNotNull(nonMavenM2JavaDir)
// Should be nonMavenM1 -> nonMavenM2, nonMavenM2 -> source
val nonMavenM2JavaOrderEntries = readAction { index.getOrderEntriesForFile(nonMavenM2JavaDir!!) }
Expand Down Expand Up @@ -1470,10 +1472,10 @@ $scope</scope>
}

private fun createRepositoryFile(filePath: String) {
val f = File(projectPath, "repo/$filePath")
f.parentFile.mkdirs()
val f = Paths.get(projectPath.toString(), "repo/$filePath")
f.parent.createDirectories()

createEmptyJar(f.parent, f.name)
createEmptyJar(f.parent.toString(), f.fileName.toString())
repositoryPath = createProjectSubDir("repo").path
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package org.jetbrains.idea.maven.execution

import com.intellij.execution.configurations.JavaParameters
import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCaseLegacy
import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCase
import com.intellij.openapi.application.readAction
import com.intellij.openapi.module.Module
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.toCanonicalPath
import com.intellij.openapi.util.registry.Registry
import com.intellij.testFramework.IdeaTestUtil
import com.intellij.util.PathUtil
Expand All @@ -32,7 +32,7 @@ import java.io.File
import java.nio.file.Paths
import kotlin.io.path.name

class MavenJUnitPatcherTest : MavenMultiVersionImportingTestCaseLegacy() {
class MavenJUnitPatcherTest : MavenMultiVersionImportingTestCase() {
override fun setUp() = runBlocking {
super.setUp()
MavenProjectSettings.getInstance(project).testRunningSettings.isPassArgLine = true
Expand Down Expand Up @@ -669,7 +669,7 @@ org.jetbrains:annotations
patchJavaParameters(mavenJUnitPatcher, module, javaParameters)

val pathList = javaParameters.classPath.pathList.mapNotNull {
FileUtil.getRelativePath(File(projectPath), File(it))
getRelativePath(projectPath, it)
}
assertOrderedEquals(
pathList,
Expand Down Expand Up @@ -789,7 +789,7 @@ org.jetbrains:annotations
patchJavaParameters(mavenJUnitPatcher, module, javaParameters)

val pathList = javaParameters.classPath.pathList.mapNotNull {
FileUtil.getRelativePath(File(projectPath), File(it))
getRelativePath(projectPath, it)
}
assertOrderedEquals(
pathList,
Expand Down Expand Up @@ -903,7 +903,7 @@ org.jetbrains:annotations
patchJavaParameters(mavenJUnitPatcher, module, javaParameters)

val pathList = javaParameters.classPath.pathList.mapNotNull {
FileUtil.getRelativePath(File(projectPath), File(it))
getRelativePath(projectPath, it)
}
assertOrderedEquals(
pathList,
Expand All @@ -913,8 +913,8 @@ org.jetbrains:annotations
)
}

private fun buildDir(path: String): File {
return File(File(projectPath), path)
private fun buildDir(path: String): String {
return Paths.get(projectPath.toString(), path).toCanonicalPath().toString()
}

private suspend fun patchJavaParameters(mavenJUnitPatcher: MavenJUnitPatcher, module: Module, javaParameters: JavaParameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package org.jetbrains.idea.maven.importing

import com.intellij.execution.CommonProgramRunConfigurationParameters
import com.intellij.execution.util.ProgramParametersUtil
import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCaseLegacy
import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCase
import com.intellij.openapi.application.writeAction
import com.intellij.openapi.externalSystem.service.project.ProjectDataManager
import com.intellij.openapi.module.ModuleManager.Companion.getInstance
Expand All @@ -36,7 +36,7 @@ import java.io.File
import java.io.IOException
import java.util.function.Consumer

class FoldersImportingTest : MavenMultiVersionImportingTestCaseLegacy() {
class FoldersImportingTest : MavenMultiVersionImportingTestCase() {

override fun setUp() {
super.setUp()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.idea.maven.importing

import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCaseLegacy
import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCase
import com.intellij.openapi.Disposable
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
Expand All @@ -24,7 +24,7 @@ import java.util.*
import java.util.function.Function
import kotlin.io.path.exists

class MiscImportingTest : MavenMultiVersionImportingTestCaseLegacy() {
class MiscImportingTest : MavenMultiVersionImportingTestCase() {
private val myEventsTestHelper = MavenEventsTestHelper()

override fun setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package org.jetbrains.idea.maven.importing

import com.intellij.compiler.CompilerConfiguration
import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCaseLegacy
import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCase
import com.intellij.openapi.application.readAction
import com.intellij.openapi.module.LanguageLevelUtil
import com.intellij.openapi.module.Module
Expand All @@ -13,9 +13,9 @@ import com.intellij.util.io.zipFile
import kotlinx.coroutines.runBlocking
import org.intellij.lang.annotations.Language
import org.junit.Test
import java.io.File
import java.nio.file.Paths

class ReimportingTest : MavenMultiVersionImportingTestCaseLegacy() {
class ReimportingTest : MavenMultiVersionImportingTestCase() {
override fun setUp() = runBlocking {
super.setUp()
createProjectPom("""
Expand Down Expand Up @@ -247,7 +247,7 @@ class ReimportingTest : MavenMultiVersionImportingTestCaseLegacy() {
fun testMoveModuleWithSystemScopedDependency() = runBlocking {
zipFile {
file("a.txt")
}.generate(File(projectPath, "lib.jar"))
}.generate(Paths.get(projectPath.toString(), "lib.jar").toFile())
updateModulePom("m1", generatePomWithSystemDependency("../lib.jar"))
importProjectAsync()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.idea.maven.project.importing

import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCaseLegacy
import com.intellij.maven.testFramework.MavenMultiVersionImportingTestCase
import com.intellij.openapi.application.writeAction
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vfs.LocalFileSystem
import kotlinx.coroutines.runBlocking
import org.junit.Test
import java.io.File
import java.nio.file.Paths

class MavenProjectsManagerSettingsXmlTest : MavenMultiVersionImportingTestCaseLegacy() {
class MavenProjectsManagerSettingsXmlTest : MavenMultiVersionImportingTestCase() {
override fun setUp() {
super.setUp()
initProjectsManager(true)
Expand Down Expand Up @@ -128,7 +128,7 @@ class MavenProjectsManagerSettingsXmlTest : MavenMultiVersionImportingTestCaseLe
}

private suspend fun deleteSettingsXmlAndWaitForImport() {
val f = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(File(dir, "settings.xml"))!!
val f = LocalFileSystem.getInstance().refreshAndFindFileByNioFile(Paths.get(dir.toString(), "settings.xml"))!!
waitForImportWithinTimeout {
writeAction {
f.delete(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ package org.jetbrains.idea.maven.statistics
import com.intellij.internal.statistic.FUCollectorTestCase.collectProjectStateCollectorEvents
import com.intellij.internal.statistic.eventLog.validator.ValidationResultType
import com.intellij.internal.statistic.eventLog.validator.rules.EventContext
import com.intellij.maven.testFramework.MavenImportingTestCaseLegacy
import com.intellij.maven.testFramework.MavenImportingTestCase
import kotlinx.coroutines.runBlocking
import org.junit.Test

class MavenPluginCollectorTest : MavenImportingTestCaseLegacy() {
class MavenPluginCollectorTest : MavenImportingTestCase() {

override fun runInDispatchThread(): Boolean = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.intellij.openapi.ui.TestDialog
import com.intellij.openapi.ui.TestDialogManager
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.toCanonicalPath
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
Expand Down Expand Up @@ -54,6 +55,7 @@ import org.jetbrains.idea.maven.server.MavenServerManager
import org.jetbrains.idea.maven.utils.MavenLog
import org.jetbrains.idea.maven.utils.MavenUtil
import org.jetbrains.jps.model.library.JpsMavenRepositoryLibraryDescriptor
import java.nio.file.Path
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Semaphore
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -157,11 +159,15 @@ abstract class MavenImportingTestCase : MavenTestCase() {
protected val projectsTree: MavenProjectsTree
get() = projectsManager.getProjectsTree()

protected fun assertModuleOutput(moduleName: String, output: String?, testOutput: String?) {
protected fun assertModuleOutput(moduleName: String, output: String, testOutput: String) {
val e = getCompilerExtension(moduleName)
assertFalse(e!!.isCompilerOutputPathInherited())
assertEquals(output, getAbsolutePath(e.getCompilerOutputUrl()))
assertEquals(testOutput, getAbsolutePath(e.getCompilerOutputUrlForTests()))
assertEquals(getAbsolutePath(output), getAbsolutePath(e.getCompilerOutputUrl()))
assertEquals(getAbsolutePath(testOutput), getAbsolutePath(e.getCompilerOutputUrlForTests()))
}

protected fun assertModuleOutput(moduleName: String, output: Path, testOutput: Path) {
assertModuleOutput(moduleName, output.toString(), testOutput.toString())
}

protected val projectsManager: MavenProjectsManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.jetbrains.jps.model.module.JpsModuleSourceRootType
import org.junit.Assume
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.nio.file.Path
import java.util.*
import kotlin.math.min

Expand Down Expand Up @@ -246,6 +247,10 @@ abstract class MavenMultiVersionImportingTestCase : MavenImportingTestCase() {
assertUnorderedPathsAreEqual(actual, expectedRoots.map { VfsUtilCore.pathToUrl(it) })
}

protected fun assertContentRoots(moduleName: String, vararg expectedRoots: Path) {
assertContentRoots(moduleName, *expectedRoots.map { it.toString() }.toTypedArray())
}

protected fun assertGeneratedSources(moduleName: String, vararg expectedSources: String) {
val contentRoot = getContentRoot(moduleName)
val folders: MutableList<ContentFolder> = ArrayList<ContentFolder>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.ThrowableComputable
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.findOrCreateFile
import com.intellij.openapi.util.io.toCanonicalPath
import com.intellij.openapi.util.io.toNioPathOrNull
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
Expand Down Expand Up @@ -795,7 +796,7 @@ abstract class MavenTestCase : UsefulTestCase() {
}

protected fun getRelativePath(base: Path, path: String) : String {
return base.relativize(Path.of(path)).toString()
return base.relativize(Path.of(path)).toCanonicalPath().toString()
}

companion object {
Expand Down

0 comments on commit 728cf6e

Please sign in to comment.