Skip to content

Commit

Permalink
Minor config and gradle patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Hippo committed Jul 11, 2020
1 parent 3454758 commit 1db66a4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
17 changes: 17 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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]
}
}
}

0 comments on commit 1db66a4

Please sign in to comment.