diff --git a/build.gradle b/build.gradle index 9ed85e5..c8b0e72 100644 --- a/build.gradle +++ b/build.gradle @@ -23,16 +23,16 @@ subprojects { group 'org.mule.weave.native' version nativeVersion - compileScala { - targetCompatibility = "11" - sourceCompatibility = "11" - } - - - compileJava { - sourceCompatibility = '11' - targetCompatibility = '11' - } +// compileScala { +// targetCompatibility = "11" +// sourceCompatibility = "11" +// } +// +// +// compileJava { +// sourceCompatibility = '11' +// targetCompatibility = '11' +// } publishing { diff --git a/native-cli/src/main/scala/org/mule/weave/dwnative/cli/DataWeaveCLI.scala b/native-cli/src/main/scala/org/mule/weave/dwnative/cli/DataWeaveCLI.scala index 8565ae9..3c0578b 100644 --- a/native-cli/src/main/scala/org/mule/weave/dwnative/cli/DataWeaveCLI.scala +++ b/native-cli/src/main/scala/org/mule/weave/dwnative/cli/DataWeaveCLI.scala @@ -21,6 +21,7 @@ import sun.misc.SignalHandler import java.io.File import java.io.FileOutputStream +import java.io.OutputStream import java.io.PrintWriter import java.io.StringWriter import java.nio.file.Files @@ -362,12 +363,12 @@ class DataWeaveCLIRunner { | --verbose or -v | Enable Verbose Mode. | --output or -o | Specifies output file for the transformation if not standard output will be used. | --main or -m | The full qualified name of the mapping to be execute. - | --file or -f | Path to the file + | --file or -f | Path to the file | --eval | Evaluates the script instead of writing it | --version | The version of the CLI and Runtime | --clean-cache | Cleans the cache where all artifacts are being downloaded this force to download all artifacts every time | --remote-debug | Enables remote debugging - | --telemetry | Enables telemetry reporting + | --telemetry | Enables telemetry reporting | | Example: | @@ -477,9 +478,9 @@ class DataWeaveCLIRunner { } } } else { - val out = if (config.outputPath.isDefined) new FileOutputStream(config.outputPath.get) else System.out + val out: OutputStream = if (config.outputPath.isDefined) new FileOutputStream(config.outputPath.get) else System.out val defaultOutputType = Option(System.getenv(DW_DEFAULT_OUTPUT_MIMETYPE_VAR)).getOrElse("application/json") - val result: WeaveExecutionResult = nativeRuntime.run(module.content, module.nameIdentifier, scriptingBindings, out, defaultOutputType, config.profile, config.remoteDebug, config.telemetry) + val result: WeaveExecutionResult = nativeRuntime.run(module.content, module.nameIdentifier, scriptingBindings, Some(out), defaultOutputType, config.profile, config.remoteDebug, config.telemetry) //load inputs from if (result.success()) { exitCode = 0 diff --git a/native-common/src/main/scala/org/mule/weave/dwnative/NativeRuntime.scala b/native-common/src/main/scala/org/mule/weave/dwnative/NativeRuntime.scala index 8f36fc1..90f1200 100644 --- a/native-common/src/main/scala/org/mule/weave/dwnative/NativeRuntime.scala +++ b/native-common/src/main/scala/org/mule/weave/dwnative/NativeRuntime.scala @@ -9,7 +9,6 @@ import org.mule.weave.v2.exception.InvalidLocationException import org.mule.weave.v2.interpreted.CustomRuntimeModuleNodeCompiler import org.mule.weave.v2.interpreted.RuntimeModuleNodeCompiler import org.mule.weave.v2.interpreted.module.WeaveDataFormat -import org.mule.weave.v2.io.service.DefaultFileService import org.mule.weave.v2.model.EvaluationContext import org.mule.weave.v2.model.ServiceManager import org.mule.weave.v2.model.service.ProtocolUrlSourceProviderResolverService @@ -19,7 +18,6 @@ import org.mule.weave.v2.model.service.UrlProtocolHandler import org.mule.weave.v2.model.service.UrlSourceProviderResolverService import org.mule.weave.v2.model.values.BinaryValue import org.mule.weave.v2.module.reader.AutoPersistedOutputStream -import org.mule.weave.v2.module.reader.DefaultAutoPersistedOutputStream import org.mule.weave.v2.module.reader.SourceProvider import org.mule.weave.v2.parser.ast.variables.NameIdentifier import org.mule.weave.v2.parser.exception.LocatableException @@ -109,28 +107,28 @@ class NativeRuntime(resourcesCacheDir: File, libDir: File, path: Array[File], ex } def run(script: String, nameIdentifier: String, inputs: ScriptingBindings): WeaveExecutionResult = { - run(script,nameIdentifier, inputs, new DefaultAutoPersistedOutputStream(DefaultFileService)) + run(script, nameIdentifier, inputs, None) } - def run(script: String, nameIdentifier: String, inputs: ScriptingBindings, out: OutputStream, defaultOutputMimeType: String = "application/json", profile: Boolean = false, remoteDebug: Boolean = false, telemetry: Boolean = false): WeaveExecutionResult = { + def run(script: String, nameIdentifier: String, inputs: ScriptingBindings, out: Option[OutputStream], defaultOutputMimeType: String = "application/json", profile: Boolean = false, remoteDebug: Boolean = false, telemetry: Boolean = false): WeaveExecutionResult = { try { val dataWeaveScript: DataWeaveScript = compileScript(script, inputs, NameIdentifier(nameIdentifier), defaultOutputMimeType, profile) - if(remoteDebug) { + if (remoteDebug) { dataWeaveScript.enableDebug() } - if(telemetry){ + if (telemetry) { dataWeaveScript.enableTelemetry() dataWeaveScript.enableMemoryTelemetry() } val serviceManager: ServiceManager = createServiceManager() val result: DataWeaveResult = if (profile) { - time(() => dataWeaveScript.write(inputs, serviceManager, Some(out)), "Execution") + time(() => dataWeaveScript.write(inputs, serviceManager, out), "Execution") } else { - dataWeaveScript.write(inputs, serviceManager, Some(out)) + dataWeaveScript.write(inputs, serviceManager, out) } - WeaveSuccessResult(out, result.getCharset().name()) + WeaveSuccessResult(out.get, result.getCharset().name()) } catch { case cr: CompilationException => { WeaveFailureResult(cr.getMessage()) @@ -176,10 +174,10 @@ class NativeRuntime(resourcesCacheDir: File, libDir: File, path: Array[File], ex def eval(script: String, inputs: ScriptingBindings, nameIdentifier: String, profile: Boolean, debug: Boolean = false, telemetry: Boolean = false): ExecuteResult = { try { val dataWeaveScript: DataWeaveScript = compileScript(script, inputs, NameIdentifier(nameIdentifier), "application/dw", profile) - if(debug) { + if (debug) { dataWeaveScript.enableDebug() } - if(telemetry){ + if (telemetry) { dataWeaveScript.enableTelemetry() dataWeaveScript.enableMemoryTelemetry() } @@ -268,7 +266,7 @@ case class WeaveSuccessResult(outputStream: OutputStream, charset: String) exten case ap: AutoPersistedOutputStream => { implicit val context: EvaluationContext = EvaluationContext() try { - new String(BinaryValue.getBytesFromSeekableStream(ap.toInputStream, close = true), charset) + new String(BinaryValue.getBytesFromSeekableStream(ap.toInputStream, close = true, memoryService = context.serviceManager.memoryService), charset) } finally { context.close() }