From d030c3357b2ce09582643e4b4f7ef5d2b1bdb802 Mon Sep 17 00:00:00 2001 From: oshai Date: Wed, 27 Jun 2018 12:15:45 +0300 Subject: [PATCH 1/4] allow to include same file from multiple files add a set of already added files and check if files was already added, in such case do not try to add it again --- src/main/kotlin/kscript/app/AppHelpers.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/kscript/app/AppHelpers.kt b/src/main/kotlin/kscript/app/AppHelpers.kt index a447d3b3..7b04b5a1 100644 --- a/src/main/kotlin/kscript/app/AppHelpers.kt +++ b/src/main/kotlin/kscript/app/AppHelpers.kt @@ -241,11 +241,15 @@ sourceSets.main.java.srcDirs 'src' // https://stackoverflow.com/questions/17926459/creating-a-symbolic-link-with-java createSymLink(File(this, scriptFile.name), scriptFile) - + val includedFiles = mutableSetOf() // also symlink all includes includeURLs.forEach { val includeFileName = it.toURI().path.split("/").last() - + //make sure not to include each file more than once (it will fail) + if (!includedFiles.add(includeFileName)) { + return@forEach + } + val includeFile = when { it.protocol == "file" -> File(it.toURI()) else -> fetchFromURL(it.toString()) @@ -367,4 +371,4 @@ exec java -jar ${'$'}0 "${'$'}@" } infoMsg("Finished packaging into ${pckgedJar}") -} \ No newline at end of file +} From 8fc94a2448f4f568237d669d25236f080e1f7f2c Mon Sep 17 00:00:00 2001 From: oshai Date: Thu, 28 Jun 2018 23:35:45 +0300 Subject: [PATCH 2/4] change include urls to use distinctBy file name --- src/main/kotlin/kscript/app/AppHelpers.kt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/kscript/app/AppHelpers.kt b/src/main/kotlin/kscript/app/AppHelpers.kt index 7b04b5a1..5a81f246 100644 --- a/src/main/kotlin/kscript/app/AppHelpers.kt +++ b/src/main/kotlin/kscript/app/AppHelpers.kt @@ -241,15 +241,11 @@ sourceSets.main.java.srcDirs 'src' // https://stackoverflow.com/questions/17926459/creating-a-symbolic-link-with-java createSymLink(File(this, scriptFile.name), scriptFile) - val includedFiles = mutableSetOf() // also symlink all includes - includeURLs.forEach { - val includeFileName = it.toURI().path.split("/").last() - //make sure not to include each file more than once (it will fail) - if (!includedFiles.add(includeFileName)) { - return@forEach - } - + includeURLs.distinctBy { it.fileName() } + .forEach { + val includeFileName = it.fileName() + val includeFile = when { it.protocol == "file" -> File(it.toURI()) else -> fetchFromURL(it.toString()) @@ -262,6 +258,7 @@ sourceSets.main.java.srcDirs 'src' return "idea ${tmpProjectDir.absolutePath}" } +private fun URL.fileName() = this.toURI().path.split("/").last() private fun createSymLink(link: File, target: File) { try { From d4d29580e6fbc24f0fa5f1977a2615c28e421bae Mon Sep 17 00:00:00 2001 From: oshai Date: Thu, 28 Jun 2018 23:39:43 +0300 Subject: [PATCH 3/4] removed unused val --- src/main/kotlin/kscript/app/AppHelpers.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/kscript/app/AppHelpers.kt b/src/main/kotlin/kscript/app/AppHelpers.kt index 5a81f246..a6daf606 100644 --- a/src/main/kotlin/kscript/app/AppHelpers.kt +++ b/src/main/kotlin/kscript/app/AppHelpers.kt @@ -244,14 +244,13 @@ sourceSets.main.java.srcDirs 'src' // also symlink all includes includeURLs.distinctBy { it.fileName() } .forEach { - val includeFileName = it.fileName() - + val includeFile = when { it.protocol == "file" -> File(it.toURI()) else -> fetchFromURL(it.toString()) } - createSymLink(File(this, includeFileName), includeFile) + createSymLink(File(this, it.fileName()), includeFile) } } From 24c16464f3a2bac1db293bf44e0efcaf6efa542a Mon Sep 17 00:00:00 2001 From: oshai Date: Thu, 28 Jun 2018 23:54:54 +0300 Subject: [PATCH 4/4] add multiple include file --- test/resources/diamond.kts | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 test/resources/diamond.kts diff --git a/test/resources/diamond.kts b/test/resources/diamond.kts new file mode 100644 index 00000000..5f6e5c26 --- /dev/null +++ b/test/resources/diamond.kts @@ -0,0 +1,6 @@ +#!/usr/bin/env kscript + + +@file:Include("includes/include_3.kt") +@file:Include("includes/include_3.kt") +