Skip to content

Commit

Permalink
Expose loading fixtures from resources jar
Browse files Browse the repository at this point in the history
  • Loading branch information
hfhbd committed Aug 15, 2023
1 parent ca977cf commit 1c0058a
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ abstract class FixturesTest(

companion object {
init {
loadFolderFromResources("fixtures")
loadFolderFromResources("fixtures", target = File("build"))
}

@JvmStatic
Expand All @@ -126,10 +126,9 @@ abstract class FixturesTest(
}
}

private fun Any.loadFolderFromResources(path: String) {
fun Any.loadFolderFromResources(path: String, target: File) {
val jarFile = File(javaClass.protectionDomain.codeSource.location.path)
val parentFile = File("build")
File(parentFile, path).apply { if (exists()) deleteRecursively() }
File(target, path).apply { if (exists()) deleteRecursively() }

assert(jarFile.isFile)

Expand All @@ -140,9 +139,9 @@ private fun Any.loadFolderFromResources(path: String) {
val name: String = entry.name
if (name.startsWith("$path/")) { // filter according to the path
if (entry.isDirectory) {
File(parentFile, entry.name).mkdir()
File(target, entry.name).mkdir()
} else {
File(parentFile, entry.name).apply {
File(target, entry.name).apply {
createNewFile()
jar.getInputStream(entry).use {
it.copyTo(outputStream())
Expand Down

0 comments on commit 1c0058a

Please sign in to comment.