Skip to content

Commit

Permalink
Make WEAVE_HOME be guessed from the script home
Browse files Browse the repository at this point in the history
  • Loading branch information
machaval committed Nov 6, 2019
1 parent d468ec9 commit c569897
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ package org.mule.weave.dwnative.cli
import java.io.File
import java.io.FileOutputStream

import org.mule.weave.dwnative.AnsiColor
import org.mule.weave.dwnative.DataWeaveUtils
import org.mule.weave.dwnative.NativeRuntime
import org.mule.weave.dwnative.WeaveProperties
import org.mule.weave.dwnative.utils.AnsiColor
import org.mule.weave.dwnative.utils.DataWeaveUtils
import org.mule.weave.dwnative.utils.WeaveProperties
import org.mule.weave.v2.interpreted.module.WeaveDataFormat
import org.mule.weave.v2.model.EvaluationContext
import org.mule.weave.v2.module.DataFormatManager
import org.mule.weave.v2.parser.ast.variables.NameIdentifier
import org.mule.weave.v2.parser.exception.LocatableException
import org.mule.weave.v2.parser.phase.CompilationException
import org.mule.weave.v2.parser.phase.ModuleLoaderManager
import org.mule.weave.v2.runtime.ScriptingBindings
import org.mule.weave.v2.runtime.utils.AnsiColor.red
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mule.weave.dwnative
package org.mule.weave.dwnative.utils

object AnsiColor {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.mule.weave.dwnative
package org.mule.weave.dwnative.utils

import java.io.File

import org.mule.weave.dwnative.CustomWeaveDataFormat
import org.mule.weave.v2.env.StaticServiceProvider
import org.mule.weave.v2.env.WeaveRuntime
import org.mule.weave.v2.model.ServiceRegistration
Expand Down Expand Up @@ -38,6 +39,13 @@ object DataWeaveUtils {
if (defaultDWHomeDir.exists()) {
defaultDWHomeDir
} else {
val dwScriptPath = System.getenv("_")
if(dwScriptPath != null) {
val scriptPath = new File(dwScriptPath)
if(scriptPath.isFile && scriptPath.getName == "dw"){
return scriptPath.getAbsoluteFile.getParentFile
}
}
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}`."))
new File("..")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import org.graalvm.nativeimage.c.function.CEntryPoint;
import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.nativeimage.c.type.CTypeConversion;
import org.mule.weave.dwnative.DataWeaveUtils;
import org.mule.weave.dwnative.NativeRuntime;
import org.mule.weave.dwnative.WeaveExecutionResult;
import org.mule.weave.dwnative.WeaveInput;
import org.mule.weave.v2.module.reader.SourceProvider$;
import org.mule.weave.dwnative.utils.DataWeaveUtils;
import org.mule.weave.v2.runtime.ScriptingBindings;

import java.io.File;
Expand Down

0 comments on commit c569897

Please sign in to comment.