diff --git a/flank-scripts/src/main/kotlin/flank/scripts/utils/Archive.kt b/common/src/main/kotlin/flank.common/Archive.kt similarity index 90% rename from flank-scripts/src/main/kotlin/flank/scripts/utils/Archive.kt rename to common/src/main/kotlin/flank.common/Archive.kt index ab71d3db41..d42f101527 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/utils/Archive.kt +++ b/common/src/main/kotlin/flank.common/Archive.kt @@ -1,9 +1,15 @@ -package flank.scripts.utils +package flank.common import org.rauschig.jarchivelib.ArchiveFormat import org.rauschig.jarchivelib.ArchiverFactory import org.rauschig.jarchivelib.CompressionType import java.io.File +import java.io.FileInputStream +import java.io.InputStream +import java.util.zip.ZipEntry +import java.util.zip.ZipFile +import java.util.zip.ZipOutputStream + fun File.extract( destination: File, diff --git a/flank-scripts/src/main/kotlin/flank/scripts/utils/Zip.kt b/common/src/main/kotlin/flank.common/Zip.kt similarity index 60% rename from flank-scripts/src/main/kotlin/flank/scripts/utils/Zip.kt rename to common/src/main/kotlin/flank.common/Zip.kt index cf2084d5f0..1a6bcec68d 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/utils/Zip.kt +++ b/common/src/main/kotlin/flank.common/Zip.kt @@ -1,34 +1,40 @@ -package flank.scripts.utils +package flank.common import java.io.File import java.io.FileInputStream import java.io.InputStream -import java.io.OutputStream import java.util.zip.ZipEntry import java.util.zip.ZipFile import java.util.zip.ZipOutputStream -fun unzip(src: File, dst: File = src.parentFile) { - print("* Unzipping: $src to $dst - ") - ZipFile(src).use { zipFile -> - zipFile.entries().asSequence().forEach { zipEntry -> - val outputFile = File(dst, zipEntry.name) - if (zipEntry.isDirectory) { - outputFile.mkdirs() - return@forEach - } - - outputFile.parentFile.mkdirs() +fun unzipFile(zipFileName: File, unzipPath: String): List { + println("Unzipping: ${zipFileName.absolutePath} to $unzipPath") + return ZipFile(zipFileName).unzipTo(unzipPath) +} - zipFile.getInputStream(zipEntry) useCopyTo outputFile.outputStream() +private fun ZipFile.unzipTo(unzipPath: String) = use { zipFile -> + zipFile.entries() + .asSequence() + .fold(listOf()) { unzippedFiles, zipFileEntry -> + unzippedFiles + zipFileEntry.saveToFile(zipFile, unzipPath) } +} + +private fun ZipEntry.saveToFile(zipFile: ZipFile, unzipPath: String): File { + val outputFile = File(unzipPath, name) + if(isDirectory) { + outputFile.mkdirs() + } else { + zipFile.getInputStream(this).use { zipEntryInput -> zipEntryInput.toFile(outputFile) } } - println("OK") + + return outputFile } -private infix fun InputStream.useCopyTo(output: OutputStream) = - use { zipEntryInput -> output.use { output -> zipEntryInput.copyTo(output) } } +private fun InputStream.toFile(destinationFile: File) { + destinationFile.outputStream().use { output -> copyTo(output) } +} fun zip(src: File, dst: File) { print("* Zipping: $src to $dst - ") diff --git a/test_runner/src/test/kotlin/ftl/log/OutputLoggerTest.kt b/common/src/test/kotlin/flank/common/OutputLoggerTest.kt similarity index 88% rename from test_runner/src/test/kotlin/ftl/log/OutputLoggerTest.kt rename to common/src/test/kotlin/flank/common/OutputLoggerTest.kt index a8852ba7d9..99a2959be2 100644 --- a/test_runner/src/test/kotlin/ftl/log/OutputLoggerTest.kt +++ b/common/src/test/kotlin/flank/common/OutputLoggerTest.kt @@ -1,7 +1,6 @@ -package ftl.log +package flank.common import com.google.common.truth.Truth -import ftl.test.util.TestHelper.normalizeLineEnding import org.junit.After import org.junit.Rule import org.junit.Test @@ -11,7 +10,8 @@ class OutputLoggerTest { @Rule @JvmField - val systemOutRule: SystemOutRule = SystemOutRule().enableLog().muteForSuccessfulTests() + val systemOutRule: SystemOutRule = SystemOutRule() + .enableLog().muteForSuccessfulTests() private val simpleMessage = "print for simple" private val detailedMessage = "print for detailed" diff --git a/test_runner/src/test/kotlin/ftl/util/FilesTest.kt b/flank-scripts/src/test/kotlin/flank/common/FilesTest.kt similarity index 83% rename from test_runner/src/test/kotlin/ftl/util/FilesTest.kt rename to flank-scripts/src/test/kotlin/flank/common/FilesTest.kt index 73ff6fdc45..318904f9d3 100644 --- a/test_runner/src/test/kotlin/ftl/util/FilesTest.kt +++ b/flank-scripts/src/test/kotlin/flank/common/FilesTest.kt @@ -1,7 +1,6 @@ -package ftl.util +package flank.common -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue +import org.junit.Assert import org.junit.Test import java.io.File import java.nio.file.Files @@ -19,7 +18,7 @@ internal class FilesTest { createSymbolicLink(expectedDestination, testFile) // then - assertTrue(Files.isSymbolicLink(expectedDestination)) + Assert.assertTrue(Files.isSymbolicLink(expectedDestination)) // clean testFile.toFile().delete() @@ -33,11 +32,11 @@ internal class FilesTest { val testDestination = Paths.get(Files.createTempDirectory("temp").toString(), "settings.gradle.kts") // when - download(testSource, testDestination) + downloadFile(testSource, testDestination) // then - assertTrue(testDestination.toFile().exists()) - assertTrue(testDestination.toFile().length() > 0) + Assert.assertTrue(testDestination.toFile().exists()) + Assert.assertTrue(testDestination.toFile().length() > 0) } @Test @@ -62,8 +61,8 @@ internal class FilesTest { ) // then - assertTrue(resultTrue) - assertFalse(resultFalse) + Assert.assertTrue(resultTrue) + Assert.assertFalse(resultFalse) // clean testDirectory.toFile().deleteRecursively() diff --git a/test_runner/src/main/kotlin/ftl/util/Zip.kt b/test_runner/src/main/kotlin/ftl/util/Zip.kt deleted file mode 100644 index 0beed68509..0000000000 --- a/test_runner/src/main/kotlin/ftl/util/Zip.kt +++ /dev/null @@ -1,29 +0,0 @@ -package ftl.util - -import java.io.File -import java.io.InputStream -import java.util.zip.ZipEntry -import java.util.zip.ZipFile - -fun unzipFile(zipFileName: File, unzipPath: String): List { - println("Unzipping: ${zipFileName.absolutePath} to $unzipPath") - return ZipFile(zipFileName).unzipTo(unzipPath) -} - -private fun ZipFile.unzipTo(unzipPath: String) = use { zipFile -> - zipFile.entries() - .asSequence() - .fold(listOf()) { unzippedFiles, zipFileEntry -> - unzippedFiles + zipFileEntry.saveToFile(zipFile, unzipPath) - } -} - -private fun ZipEntry.saveToFile(zipFile: ZipFile, unzipPath: String): File { - val outputFile = File(unzipPath, name) - zipFile.getInputStream(this).use { zipEntryInput -> zipEntryInput.toFile(outputFile) } - return outputFile -} - -private fun InputStream.toFile(destinationFile: File) { - destinationFile.outputStream().use { output -> copyTo(output) } -}