From 1db66a4fcabe8e43be1ecf8833c9254d81cf60bd Mon Sep 17 00:00:00 2001 From: Hippo Date: Sat, 11 Jul 2020 03:31:02 -0500 Subject: [PATCH] Minor config and gradle patch --- build.gradle | 17 +++++++++++++++++ .../impl/JavaScriptConfiguration.scala | 14 +++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index c8b2487..ec9b437 100644 --- a/build.gradle +++ b/build.gradle @@ -19,3 +19,20 @@ dependencies { compile group: 'org.tinylog', name: 'tinylog-api', version: '2.1.2' compile group: 'org.tinylog', name: 'tinylog-impl', version: '2.1.2' } + +jar { + from { + configurations.compile.collect { + if (!it.isDirectory()) { + zipTree(it) + } + } + } + + manifest { + attributes( + "Manifest-Version": 1.0, + "Main-Class": "rip.hippo.mosey.Main" + ) + } +} \ No newline at end of file diff --git a/src/main/scala/rip/hippo/mosey/configuration/impl/JavaScriptConfiguration.scala b/src/main/scala/rip/hippo/mosey/configuration/impl/JavaScriptConfiguration.scala index 085e987..5499134 100644 --- a/src/main/scala/rip/hippo/mosey/configuration/impl/JavaScriptConfiguration.scala +++ b/src/main/scala/rip/hippo/mosey/configuration/impl/JavaScriptConfiguration.scala @@ -2,7 +2,7 @@ package rip.hippo.mosey.configuration.impl import java.io.{File, FileReader, IOException} -import javax.script.ScriptEngineManager +import javax.script.{ScriptEngineManager, ScriptException} import jdk.nashorn.api.scripting.ScriptObjectMirror import rip.hippo.mosey.configuration.Configuration import rip.hippo.mosey.logger.Logger @@ -18,17 +18,17 @@ final class JavaScriptConfiguration(configPath: String) extends Configuration { private val scriptEngineManager = new ScriptEngineManager() private val scriptEngine = scriptEngineManager.getEngineByExtension("js") - private val fileReader = new FileReader(new File(configPath)) + private var fileReader: FileReader = _ try { + fileReader = new FileReader(new File(configPath)) Logger.info("Evaluating config...") scriptEngine.eval(fileReader) Logger.info("Config evaluated.") } catch { - case e: IOException => Logger.error(e, String.format("Failed to evaluate config %s.", configPath)) - } finally { - fileReader.close() - } + case e@(_: IOException | _: ScriptException) => Logger.error(e, String.format("Failed to evaluate config %s.", configPath)) + } finally if(fileReader != null) fileReader.close() + private var runtimePath = scriptEngine.get("runtime").toString @@ -66,4 +66,4 @@ final class JavaScriptConfiguration(configPath: String) extends Configuration { override def get[T](parent: String, key: String): T = { scriptEngine.get(parent).asInstanceOf[ScriptObjectMirror].get(key).asInstanceOf[T] } -} +} \ No newline at end of file