Files
openide/tools/devLauncher/tests/testSrc/ModuleResourceFileFinderTest.kt
Nikolay Chashnikov 2192a0d35b [dev launcher] provide a way to locate resource files in module sources in dev launcher (RDCT-1405)
To determine which modules should be compiled in IntellijDevLauncher, we need to load product-modules.xml and plugin.xml files. Currently, they are loaded via RuntimeModuleRepository from output directories, so obsolete variant may be loaded or file may not be found at all if modules containing these files aren't compiled yet. This change introduces the ModuleResourceFileFinder class, which can locate resource files in source directories instead. It doesn't use existing functionality for that to avoid adding additional modules to the system classloader. Also, it parses necessary *.iml files only to speed up the process.

GitOrigin-RevId: d55083ba879a3ae8c7985ba6e5f0211ad3062959
2024-05-30 02:53:28 +00:00

39 lines
1.5 KiB
Kotlin

package com.intellij.tools.devLauncher
import com.intellij.openapi.application.ex.PathManagerEx
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.nio.file.Path
import kotlin.io.path.Path
import kotlin.io.path.invariantSeparatorsPathString
import kotlin.io.path.relativeTo
class ModuleResourceFileFinderTest {
private lateinit var projectDir: Path
private lateinit var finder: ModuleResourceFileFinder
@BeforeEach
fun setUp() {
projectDir = Path(PathManagerEx.getCommunityHomePath()).resolve("tools/devLauncher/tests/testData/moduleResourceFinderProject")
finder = ModuleResourceFileFinder(projectDir)
}
@Test
fun `simple roots`() {
assertPath("simple/resources/a.txt", finder.findResourceFile("simple", "a.txt"))
assertPath("simple/src/b/b.txt", finder.findResourceFile("simple", "b/b.txt"))
assertPath(null, finder.findResourceFile("simple", "c.txt"))
}
@Test
fun `roots with prefixes`() {
assertPath("withPrefix/resources/a.txt", finder.findResourceFile("withPrefix", "prefix1/a.txt"))
assertPath("withPrefix/src/b/b.txt", finder.findResourceFile("withPrefix", "prefix2/b/b.txt"))
assertPath("additional-resources/c.txt", finder.findResourceFile("withPrefix", "prefix3/c.txt"))
}
private fun assertPath(expectedPath: String?, file: Path?) {
assertEquals(expectedPath, file?.relativeTo(projectDir)?.invariantSeparatorsPathString)
}
}