diff --git a/test-fixtures/src/test/kotlin/com/alecstrong/sql/psi/test/fixtures/PassingPredefinedTablesTest.kt b/core/src/test/kotlin/com/alecstrong/sql/psi/core/PassingPredefinedTablesTest.kt similarity index 86% rename from test-fixtures/src/test/kotlin/com/alecstrong/sql/psi/test/fixtures/PassingPredefinedTablesTest.kt rename to core/src/test/kotlin/com/alecstrong/sql/psi/core/PassingPredefinedTablesTest.kt index c7f1ccb9..f24923d4 100644 --- a/test-fixtures/src/test/kotlin/com/alecstrong/sql/psi/test/fixtures/PassingPredefinedTablesTest.kt +++ b/core/src/test/kotlin/com/alecstrong/sql/psi/core/PassingPredefinedTablesTest.kt @@ -1,5 +1,6 @@ -package com.alecstrong.sql.psi.test.fixtures +package com.alecstrong.sql.psi.core +import com.alecstrong.sql.psi.test.fixtures.TestHeadlessParser import org.junit.Assert.fail import org.junit.Test import java.io.File diff --git a/core/src/testFixtures/kotlin/com/alecstrong/sql/psi/test/fixtures/FixturesTest.kt b/core/src/testFixtures/kotlin/com/alecstrong/sql/psi/test/fixtures/FixturesTest.kt index 90291655..6bb97ec3 100644 --- a/core/src/testFixtures/kotlin/com/alecstrong/sql/psi/test/fixtures/FixturesTest.kt +++ b/core/src/testFixtures/kotlin/com/alecstrong/sql/psi/test/fixtures/FixturesTest.kt @@ -5,9 +5,11 @@ import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement import org.junit.Test import java.io.File -import java.util.Enumeration -import java.util.jar.JarEntry -import java.util.jar.JarFile +import java.nio.file.FileSystems +import kotlin.io.path.ExperimentalPathApi +import kotlin.io.path.copyToRecursively +import kotlin.io.path.div +import kotlin.io.path.toPath abstract class FixturesTest( val name: String, @@ -18,7 +20,8 @@ abstract class FixturesTest( abstract fun setupDialect() - @Test fun execute() { + @Test + fun execute() { val errors = ArrayList() val newRoot = File("build/fixtureCopies/${fixtureRoot.name}Copy") @@ -121,31 +124,20 @@ abstract class FixturesTest( } } +@OptIn(ExperimentalPathApi::class) fun Any.loadFolderFromResources(path: String, target: File) { - val jarFile = File(javaClass.protectionDomain.codeSource.location.path) - File(target, path).apply { if (exists()) deleteRecursively() } - - assert(jarFile.isFile) - - val jar = JarFile(jarFile) - val entries: Enumeration = jar.entries() // gives ALL entries in jar - while (entries.hasMoreElements()) { - val entry = entries.nextElement() - val name: String = entry.name - if (name.startsWith("$path/")) { // filter according to the path - if (entry.isDirectory) { - File(target, entry.name).mkdir() - } else { - File(target, entry.name).apply { - createNewFile() - jar.getInputStream(entry).use { - it.copyTo(outputStream()) - } - } - } + val targetFile = File(target, path).apply { if (exists()) deleteRecursively() } + val resourcesUri = javaClass.getResource("/$path")?.toURI() + requireNotNull(resourcesUri) { + "/$path not found in resources" + } + when (resourcesUri.scheme) { + "jar" -> FileSystems.newFileSystem(resourcesUri, emptyMap(), null).use { + it.getPath("/$path").copyToRecursively(target.toPath() / path, overwrite = true, followLinks = false) } + "file" -> resourcesUri.toPath().toFile().copyRecursively(targetFile, overwrite = true) + else -> error("Unsupported scheme ${resourcesUri.scheme} of $resourcesUri") } - jar.close() } private fun formatErrorList(errors: List): String {