Skip to content

Commit

Permalink
Fix dw home should be picked correctly based on environment variable.…
Browse files Browse the repository at this point in the history
… Fix exception being printed out
  • Loading branch information
machaval committed Nov 7, 2019
1 parent eecc1e0 commit 1835c07
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class DataWeaveCLIRunner {
config.scriptToRun.get
}

val defaultInputType = Option(System.getenv(DW_DEFAULT_INPUT_MIMETYPE_VAR)).getOrElse("application/json");
val defaultInputType = Option(System.getenv(DW_DEFAULT_INPUT_MIMETYPE_VAR)).getOrElse("application/json")
val scriptingBindings = new ScriptingBindings
if (config.inputs.isEmpty) {
scriptingBindings.addBinding("payload", System.in, defaultInputType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.mule.weave.v2.runtime.InputType
import org.mule.weave.v2.runtime.ModuleComponents
import org.mule.weave.v2.runtime.ModuleComponentsFactory
import org.mule.weave.v2.runtime.ScriptingBindings
import org.mule.weave.v2.runtime.ScriptingEngineSetupException
import org.mule.weave.v2.sdk.TwoLevelWeaveResourceResolver
import org.mule.weave.v2.sdk.WeaveResourceResolver

Expand Down Expand Up @@ -72,9 +73,11 @@ class NativeRuntime(libDir: File, path: Array[File]) {
case le: LocatableException => {
WeaveFailureResult(le.getMessage() + " at:\n" + le.location.locationString)
}
case se: ScriptingEngineSetupException => {
WeaveFailureResult(se.getMessage)
}
case le: Exception => {
val writer = new StringWriter()
le.printStackTrace()
le.printStackTrace(new PrintWriter(writer))
WeaveFailureResult("Internal error : " + le.getClass.getName + " : " + le.getMessage + "\n" + writer.toString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ object DataWeaveUtils {
if(dwScriptPath != null) {
val scriptPath = new File(dwScriptPath)
if(scriptPath.isFile && scriptPath.getName == "dw"){
return scriptPath.getCanonicalFile.getParentFile
val homeDirectory = scriptPath.getCanonicalFile.getParentFile.getParentFile
if (WeaveProperties.verbose) {
println(s"[debug] Home Directory detected from script at ${homeDirectory.getAbsolutePath}")
}
return homeDirectory
}
}
println(AnsiColor.yellow(s"[warning] Unable to detect Weave Home directory so local directory is going to be used. Please either define the env variable WEAVE_HOME or copy the weave distro into `${defaultDWHomeDir.getAbsolutePath}`."))
Expand Down

0 comments on commit 1835c07

Please sign in to comment.