Skip to content

Commit

Permalink
new version with renamed packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon committed Aug 22, 2018
1 parent 2a3c60e commit 1349b3e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.gradle.api.publish.maven.MavenPom
val kotlinVersion = plugins.getPlugin(KotlinPluginWrapper::class.java).kotlinPluginVersion

project.group = "de.swirtz"
project.version = "0.0.4"
project.version = "0.0.5"
val artifactID = "ktsRunner"

plugins {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.swirtz.ktsobjectloader
package de.swirtz.ktsrunner.objectloader

import java.io.InputStream
import java.io.Reader
Expand All @@ -11,13 +11,13 @@ class KtsObjectLoader {
}

inline fun <reified T> load(script: String): T = engine.eval(script).takeIf { it is T } as T
?: throw IllegalStateException("Could not load script from .kts")
?: throw IllegalStateException("Could not load script from .kts")

inline fun <reified T> load(reader: Reader): T = engine.eval(reader).takeIf { it is T } as T
?: throw IllegalStateException("Could not load script from .kts")
?: throw IllegalStateException("Could not load script from .kts")

inline fun <reified T> load(inputStream: InputStream): T = engine.eval(inputStream.reader()).takeIf { it is T } as T
?: throw IllegalStateException("Could not load script from .kts")
inline fun <reified T> load(inputStream: InputStream): T = load<T>(inputStream.reader())
?: throw IllegalStateException("Could not load script from .kts")

inline fun <reified T> loadAll(vararg inputStream: InputStream): List<T> = inputStream.map(::load)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.swirtz.ktsobjectloader
package de.swirtz.ktsrunner.objectloader

data class ClassFromScript(val x: String) {
fun printme() = println("ClassFromScript with x=$x")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.swirtz.ktsobjectloader
package de.swirtz.ktsrunner.objectloader

import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine
Expand Down Expand Up @@ -77,7 +77,8 @@ class KtsObjectLoaderTest {
fun `multiple classes loaded from script via InputStream`() {
val scriptContent = Files.newInputStream(Paths.get("src/test/resources/testscript.kts"))
val scriptContent2 = Files.newInputStream(Paths.get("src/test/resources/testscript2.kts"))
KtsObjectLoader().loadAll<ClassFromScript>(scriptContent, scriptContent2).forEach {
KtsObjectLoader()
.loadAll<ClassFromScript>(scriptContent, scriptContent2).forEach {
assertEquals(ClassFromScript::class, it::class)
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/test/resources/testscript.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import de.swirtz.ktsobjectloader.ClassFromScript

ClassFromScript("I was created in kts; äö")
de.swirtz.ktsrunner.objectloader.ClassFromScript("I was created in kts; äö")
4 changes: 1 addition & 3 deletions src/test/resources/testscript2.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import de.swirtz.ktsobjectloader.ClassFromScript

ClassFromScript("2) I was created in kts; äö")
de.swirtz.ktsrunner.objectloader.ClassFromScript("2) I was created in kts; äö")

0 comments on commit 1349b3e

Please sign in to comment.