diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3416b27..f197643 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,52 +17,49 @@ jobs: OSX_LINUX_WINDOWS: strategy: matrix: -# os: [macos-latest, ubuntu-latest, windows-2019] - os: [macos-latest, ubuntu-latest] + os: [macos-latest, ubuntu-latest, windows-latest] include: -# - os: windows-2019 -# script_name: windows + - os: windows-latest + script_name: windows - os: ubuntu-latest script_name: linux - os: macos-latest script_name: osx runs-on: ${{ matrix.os }} - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - # Runs a single command using the runners shell - - name: Run Build on native - run: ./gradlew --stacktrace native-cli:build - shell: bash - env: - AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}} - AWS_SECRET_KEY: ${{secrets.AWS_SECRET_KEY}} + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + # Read graalvm version + - name: Read Graalvm version + run: | + echo "GRAALVM_VERSION=$(grep graalvmVersion gradle.properties | cut -d '=' -f2)" >> $GITHUB_ENV + shell: bash + + # Setup Graalvm + - name: Setup Graalvm + uses: graalvm/setup-graalvm@v1 + with: + version: ${{env.GRAALVM_VERSION}} + java-version: '11' + components: 'native-image' + github-token: ${{ secrets.GITHUB_TOKEN }} - # Runs a set of commands using the runners shell - - name: Create Native Image - run: ./gradlew --stacktrace --debug native-cli:nativeImage - shell: bash - env: - AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}} - AWS_SECRET_KEY: ${{secrets.AWS_SECRET_KEY}} - - name: Generate Distro - run: | - ./gradlew --stacktrace native-cli:distro - env: - AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}} - AWS_SECRET_KEY: ${{secrets.AWS_SECRET_KEY}} + # Runs a single command using the runners shell + - name: Run Build + run: | + ./gradlew --stacktrace build + shell: bash + + # Generate distro + - name: Create Distro + run: ./gradlew --stacktrace native-cli:distro + shell: bash - # Upload the generated artifact - - name: Upload generated script - uses: actions/upload-artifact@v2 - with: - name: dw-${{env.NATIVE_VERSION}}-${{runner.os}} - path: native-cli/build/distributions/native-cli-${{env.NATIVE_VERSION}}-native-distro-${{ matrix.script_name }}.zip - # This workflow contains a single job called "build" + # Upload the artifact file + - name: Upload generated script + uses: actions/upload-artifact@v2 + with: + name: dw-${{env.NATIVE_VERSION}}-${{runner.os}} + path: native-cli/build/distributions/native-cli-${{env.NATIVE_VERSION}}-native-distro-${{ matrix.script_name }}.zip diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 057a44e..3bf8bf6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,11 +12,10 @@ jobs: RELEASE_EXTENSION: strategy: matrix: -# os: [macos-latest, ubuntu-latest, windows-latest] - os: [macos-latest, ubuntu-latest] + os: [macos-latest, ubuntu-latest, windows-latest] include: -# - os: windows-2019 -# script_name: windows + - os: windows-latest + script_name: windows - os: ubuntu-latest script_name: linux - os: macos-latest @@ -27,25 +26,33 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 + + # Read graalvm version + - name: Read Graalvm version + run: | + echo "GRAALVM_VERSION=$(grep graalvmVersion gradle.properties | cut -d '=' -f2)" >> $GITHUB_ENV + shell: bash + + # Setup Graalvm + - name: Setup Graalvm + uses: graalvm/setup-graalvm@v1 with: - java-version: 11 + version: ${{env.GRAALVM_VERSION}} + java-version: '11' + components: 'native-image' + github-token: ${{ secrets.GITHUB_TOKEN }} - name: Guess Extension Version run: | echo "NATIVE_VERSION=$(echo '${{github.ref}}' | sed -e 's,.*/v\(.*\),\1,')" >> $GITHUB_ENV - + # Runs a single command using the runners shell - - name: Run Build on native - run: ./gradlew native-cli:build -PnativeVersion=${{env.NATIVE_VERSION}} - shell: bash - - # Runs a set of commands using the runners shell - - name: Create Native Image - run: ./gradlew native-cli:nativeImage -PnativeVersion=${{env.NATIVE_VERSION}} + - name: Run Build + run: | + ./gradlew build -PnativeVersion=${{env.NATIVE_VERSION}} shell: bash - + + # Generate distro - name: Create Distro run: ./gradlew native-cli:distro -PnativeVersion=${{env.NATIVE_VERSION}} shell: bash diff --git a/.gitignore b/.gitignore index dfeb072..6091d76 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,7 @@ out/ *.idea # Mac -.DS_Store \ No newline at end of file +.DS_Store + +# GraalVM +.graalvm \ No newline at end of file diff --git a/README.md b/README.md index 407aa6b..682df7d 100644 --- a/README.md +++ b/README.md @@ -35,23 +35,27 @@ brew install dw ``` ### Manual Installation -1. Download the zip - 1. [Mac](https://github.com/mulesoft-labs/data-weave-cli/releases/download/v1.0.16/dw-1.0.16-macOS) - 2. [Linux](https://github.com/mulesoft-labs/data-weave-cli/releases/download/v1.0.16/dw-1.0.16-Linux) - 3. [Windows](https://github.com/mulesoft-labs/data-weave-native/releases/download/v1.0.9/dw-1.0.9-Windows.zip) Very OLD :(! +1. Download the latest [release version](https://github.com/mulesoft-labs/data-weave-cli/releases) according to your OS. 2. Unzip the file on your `/.dw` 3. Add `/.dw/bin` to your **PATH** ### Build and Install -Execute the gradle task `nativeImage` +To build the project, you need to run gradlew with the graalVM distribution based on Java 11. You can download it at https://github.com/graalvm/graalvm-ce-builds/releases +Set: ```bash -./gradlew native-cli:nativeImage +export GRAALVM_HOME=/graalvm-ce-java11-21.2.0/Contents/Home +export JAVA_HOME=/graalvm-ce-java11-21.2.0/Contents/Home +``` +Execute the gradle task `nativeCompile` + +```bash +./gradlew native-cli:nativeCompile ``` It takes several minutes so good time to take and refill your mate. -Once it finishes you will find the `dw` binary in `native-cli/build/graal/dw` +Once it finishes you will find the `dw` binary in `native-cli/build/native/nativeCompile/dw` ## How to Use It diff --git a/build.gradle b/build.gradle index f1f9de2..359a838 100644 --- a/build.gradle +++ b/build.gradle @@ -5,19 +5,12 @@ buildscript { url "https://plugins.gradle.org/m2/" } } - dependencies { - classpath "gradle.plugin.com.palantir.graal:gradle-graal:0.7.2" - } } - -apply plugin: 'com.palantir.graal' - subprojects { apply plugin: "java" apply plugin: "scala" - apply plugin: 'com.palantir.graal' apply plugin: 'maven-publish' group 'org.mule.weave.native' @@ -73,6 +66,7 @@ subprojects { name "jitpack.io" url "https://jitpack.io" } + gradlePluginPortal() } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fbee6f7..9e5688e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip diff --git a/install-graalvm.sh b/install-graalvm.sh new file mode 100755 index 0000000..d2bcb09 --- /dev/null +++ b/install-graalvm.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +source gradle.properties + +graal_dir=.graalvm + +[[ $(uname -a) =~ Darwin ]] && os=darwin || os=linux + +setUpEnvironmentVariables() { + echo "Setup GRAALVM_HOME and JAVA_HOME environment variables" + if [[ $os == darwin ]] + then + export GRAALVM_HOME=${PWD}/${graal_dir}/graalvm-ce-java11-${graalvmVersion}/Contents/Home + else + export GRAALVM_HOME=${PWD}/${graal_dir}/graalvm-ce-java11-${graalvmVersion} + fi + export JAVA_HOME=${GRAALVM_HOME} +} + +if [[ ! -d ${graal_dir}/graalvm-ce-java11-${graalvmVersion} ]] + then + graalvmDist=graalvm-ce-java11-${os}-amd64-${graalvmVersion}.tar.gz + echo "Installing GraalVM: ${graalvmDist}" + mkdir -p ${graal_dir} + pushd ${graal_dir} + curl -OL -A "Mozilla Chrome Safari" https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${graalvmVersion}/${graalvmDist} + tar xf ${graalvmDist} + echo $graal_dir + popd + setUpEnvironmentVariables + ${GRAALVM_HOME}/bin/gu install native-image + else + echo "GraalVM already installed" +fi diff --git a/native-cli-integration-tests/build.gradle b/native-cli-integration-tests/build.gradle index 6e3c8cd..a140654 100644 --- a/native-cli-integration-tests/build.gradle +++ b/native-cli-integration-tests/build.gradle @@ -13,4 +13,4 @@ dependencies { testRuntime 'org.pegdown:pegdown:1.6.0' } -test.dependsOn(":native-cli:nativeImage") \ No newline at end of file +test.dependsOn(":native-cli:nativeCompile") \ No newline at end of file diff --git a/native-cli-integration-tests/src/test/scala/org/mule/weave/native/NativeCliITTestRunner.scala b/native-cli-integration-tests/src/test/scala/org/mule/weave/native/NativeCliITTestRunner.scala index cc23242..48b0c27 100644 --- a/native-cli-integration-tests/src/test/scala/org/mule/weave/native/NativeCliITTestRunner.scala +++ b/native-cli-integration-tests/src/test/scala/org/mule/weave/native/NativeCliITTestRunner.scala @@ -4,14 +4,14 @@ import java.io.File import java.util.concurrent.TimeUnit import scala.io.Source -class NativeCliITTestRunner(args: Array[String]) extends ResourceResolver { +class NativeCliITTestRunner(args: Array[String]) + extends ResourceResolver + with OSSupport { private val NATIVE_CLI_INTEGRATION_TESTS = "native-cli-integration-tests" - private lazy val OS = System.getProperty("os.name").toLowerCase - private lazy val EXECUTABLE_NAME = { - if (OS.contains("win")) { + if (isWindows) { "dw.exe" } else { "dw" @@ -19,12 +19,12 @@ class NativeCliITTestRunner(args: Array[String]) extends ResourceResolver { } private lazy val DW_CLI_EXECUTABLE: String = { - val path = getResourcePath(getClass.getName.replaceAll("\\.", File.separator) + ".class") + val path = getResourcePath(getClass.getName.replace(".", File.separator) + ".class") var nativeCliIntegrationTest = new File(path) while (nativeCliIntegrationTest.getName != NATIVE_CLI_INTEGRATION_TESTS) { nativeCliIntegrationTest = nativeCliIntegrationTest.getParentFile } - val dwPath = new File(nativeCliIntegrationTest.getParentFile, s"native-cli/build/graal/$EXECUTABLE_NAME") + val dwPath = new File(nativeCliIntegrationTest.getParentFile, s"native-cli/build/native/nativeCompile/$EXECUTABLE_NAME") dwPath.getAbsolutePath } diff --git a/native-cli-integration-tests/src/test/scala/org/mule/weave/native/NativeCliRuntimeIT.scala b/native-cli-integration-tests/src/test/scala/org/mule/weave/native/NativeCliRuntimeIT.scala index f29b050..ecac6df 100644 --- a/native-cli-integration-tests/src/test/scala/org/mule/weave/native/NativeCliRuntimeIT.scala +++ b/native-cli-integration-tests/src/test/scala/org/mule/weave/native/NativeCliRuntimeIT.scala @@ -47,7 +47,8 @@ import scala.util.Try class NativeCliRuntimeIT extends FunSpec with Matchers with FolderBasedTest - with ResourceResolver { + with ResourceResolver + with OSSupport { private val TIMEOUT: (Int, TimeUnit) = (30, TimeUnit.SECONDS) private val INPUT_FILE_CONFIG_PROPERTY_PATTERN = Pattern.compile( "in[0-9]+-config\\.properties") @@ -328,13 +329,11 @@ class NativeCliRuntimeIT extends FunSpec } override def ignoreTests(): Array[String] = { + val ignored: Array[String] = // Encoding issues Array("csv-invalid-utf8") ++ // Fail in java11 because broken backwards - Array( - "coerciones_toString", - "date-coercion" - ) ++ + Array("coerciones_toString", "date-coercion") ++ // Use resources (dwl files) that is present in the Tests but not in Cli (e.g: org::mule::weave::v2::libs::) Array("full-qualified-name-ref", "import-component-alias-lib", @@ -348,12 +347,9 @@ class NativeCliRuntimeIT extends FunSpec "try", "urlEncodeDecode") ++ // Uses resource name that is different on Cli than in the Tests - Array( - "try-recursive-call", - "runtime_orElseTry") ++ + Array("try-recursive-call", "runtime_orElseTry") ++ // Use readUrl from classpath - Array("dw-binary", - "read_lines") ++ + Array("dw-binary", "read_lines") ++ // Uses java module Array("java-big-decimal", "java-field-ref", @@ -365,19 +361,68 @@ class NativeCliRuntimeIT extends FunSpec "write-function-with-null" ) ++ // Multipart Object has empty `parts` and expects at least one part - Array("multipart-mixed-message", - "multipart-write-message", - "multipart-write-subtype-override") ++ + Array("multipart-mixed-message", "multipart-write-message", "multipart-write-subtype-override") ++ // Fail pattern match on complex object Array("pattern-match-complex-type") ++ // DataFormats - Array( - "runtime_dataFormatsDescriptors" - ) ++ + Array("runtime_dataFormatsDescriptors") ++ // Cannot coerce Null (null) to Number - Array( - "update-op" + Array("update-op") ++ + // Take too long time + Array("array-concat") + + val osIgnored: Array[String] = if (isWindows) { + Array("base64", + "constant_folding", + "csv-big-field", + "csv-buffered-writer", + "csv-escaped-quoted-input", + "csv-emoji", + "csv-newline", + "csv-no-escape", + "csv-no-header-selection", + "csv-no-quote", + "csv-quote-output", + "csv-reformat", + "csv-separator-input", + "csv-separator-tab", + "csv-single-record", + "csv-streaming-escaped-quoted-input", + "csv-streaming-quote-output", + "csv-streaming-separator-tab", + "csv-to-csv", + "csv-utf8", + "csv-value", + "dfl-string-literal-values", + "encoding", + "env", + "json-utf8", + "json_binary", + "light-input", + "multipart-read-message", + "nested_map_with_filter", + "non-printable-characters", + "runtime_eval", + "runtime_run", + "runtime_run_empty_char_option", + "runtime_run_illegal_arguments", + "runtime_run_invalid_input", + "runtime_run_securityReaderProperty", + "runtime_run_securityReaderProperty_InputDirective", + "runtime_run_unhandled_pattern_syntax_exception", + "runtime_run_unhandled_xml_parser_exception", + "runtime_run_unhandled_xml_parsing_exception", + "write-function-by-id", + "write-function", + "write_function_missing_root_exception", + "xml-encoding", + "xml-string-escape", + "xml_default_namespace_passthru" ) + } else { + Array.empty + } + ignored ++ osIgnored } } diff --git a/native-cli-integration-tests/src/test/scala/org/mule/weave/native/NativeCliTest.scala b/native-cli-integration-tests/src/test/scala/org/mule/weave/native/NativeCliTest.scala index 18c52c8..1fc9bdf 100644 --- a/native-cli-integration-tests/src/test/scala/org/mule/weave/native/NativeCliTest.scala +++ b/native-cli-integration-tests/src/test/scala/org/mule/weave/native/NativeCliTest.scala @@ -36,7 +36,7 @@ class NativeCliTest extends FreeSpec "it should execute with input and script" in { val inputPath = getResourcePath("inputs/payload.json") val transformationPath = getResourcePath("scripts/GetName.dwl") - val (_, output) = NativeCliITTestRunner(Array("-i", "payload", inputPath, "payload.name", "-f", transformationPath)).execute() + val (_, output) = NativeCliITTestRunner(Array("-i", "payload", inputPath, "-f", transformationPath)).execute() output shouldBe "\"Tomo\"" } } diff --git a/native-cli-integration-tests/src/test/scala/org/mule/weave/native/OSSupport.scala b/native-cli-integration-tests/src/test/scala/org/mule/weave/native/OSSupport.scala new file mode 100644 index 0000000..d04eaad --- /dev/null +++ b/native-cli-integration-tests/src/test/scala/org/mule/weave/native/OSSupport.scala @@ -0,0 +1,7 @@ +package org.mule.weave.native + +trait OSSupport { + lazy val OS: String = System.getProperty("os.name").toLowerCase + + def isWindows: Boolean = OS.contains("win") +} diff --git a/native-cli/build.gradle b/native-cli/build.gradle index ce13224..6b64cdf 100644 --- a/native-cli/build.gradle +++ b/native-cli/build.gradle @@ -7,8 +7,11 @@ buildscript { } plugins { -// id 'com.github.johnrengelman.shadow' version '5.2.0' + id 'com.github.johnrengelman.shadow' version '5.2.0' + id "com.github.maiflai.scalatest" version "${scalaTestPluginVersion}" id 'application' + // Apply GraalVM Native Image plugin + id 'org.graalvm.buildtools.native' version '0.9.5' } sourceSets { @@ -25,7 +28,7 @@ mainClassName = 'org.mule.weave.dwnative.cli.DataWeaveCLI' dependencies { compile group: 'org.mule.weave', name: 'runtime', version: weaveVersion - compile group: 'org.graalvm.sdk', name: 'graal-sdk', version: '1.0.0-rc12' + compileOnly group: 'org.graalvm.sdk', name: 'graal-sdk', version: graalvmVersion compile group: 'org.mule.weave', name: 'core-modules', version: weaveVersion compile group: 'org.mule.weave', name: 'yaml-module', version: weaveVersion compile group: 'org.mule.weave', name: 'http-module', version: ioVersion @@ -36,6 +39,7 @@ dependencies { compile group: 'org.mule.weave', name: 'ndjson-module', version: weaveVersion compile group: 'commons-cli', name: 'commons-cli', version: '1.4' testCompile group: 'org.scalatest', name: 'scalatest_2.12', version: scalaTestVersion + testRuntime 'org.pegdown:pegdown:1.6.0' } ext { @@ -74,21 +78,21 @@ compileScala { dependsOn genVersions } -//// Merging Service Files -//shadowJar { -// mergeServiceFiles() -//} +// Merging Service Files +shadowJar { + mergeServiceFiles() +} import org.apache.tools.ant.taskdefs.condition.Os -task distro(dependsOn: nativeImage, type: Zip) { +task distro(dependsOn: nativeCompile, type: Zip) { classifier = "native-distro-" + getOsName() into("libs") { from { configurations.runtime.filter { it.getName().contains("ndjson-module") } } } into("bin") { - from 'build/graal/' + from 'build/native/nativeCompile/' } } @@ -103,43 +107,43 @@ private static String getOsName() { prefix = "windows" prefix } - -graal { - windowsVsVarsPath 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat' - mainClass 'org.mule.weave.dwnative.cli.DataWeaveCLI' - outputName 'dw' - javaVersion '11' - graalVersion graalvmVersion - option "-H:+ReportExceptionStackTraces" - option "-J-Xmx3G" - option "--no-fallback" - option "--allow-incomplete-classpath" - option "-H:EnableURLProtocols=http,https" - option "--initialize-at-run-time=" + - "io.netty," + - "org.asynchttpclient," + - "org.mule.weave.v2.module.http.netty.HttpAsyncClientService," + - "scala.util.Random," + - "org.mule.weave.v2.sdk.SPIBasedModuleLoaderProvider\$" - option "--initialize-at-build-time=" + - "sun.instrument.InstrumentationImpl," + - "org.mule.weave.dwnative.initializer.Startup," + - "org.mule.weave.dwnative.," + - "org.mule.weave.v2.parser.," + - "org.mule.weave.v2.codegen.StringCodeWriter," + - "org.mule.weave.v2.resources.WeaveResourceLoader\$," + - "org.mule.weave.v2.annotations.," + - "org.mule.weave.v2.ts.," + - "org.mule.weave.v2.scope.," + - "org.mule.weave.v2.scope.," + - "org.mule.weave.v2.grammar.," + - "org.mule.weave.v2.sdk.," + - "org.mule.weave.v2.utils.," + - "org.mule.weave.v2.versioncheck.," + - //Parboiled - "scala.," + - "org.parboiled2.," + - "shapeless.syntax." +graalvmNative { + binaries { + main { + // Main options + imageName = 'dw' + mainClass = 'org.mule.weave.dwnative.cli.DataWeaveCLI' + + // Advanced options + buildArgs.add("-H:+ReportExceptionStackTraces") + buildArgs.add("--no-fallback") + buildArgs.add("--allow-incomplete-classpath") + buildArgs.add("-H:EnableURLProtocols=http,https") + buildArgs.add("--initialize-at-run-time=" + + "io.netty," + + "org.asynchttpclient," + + "org.mule.weave.v2.module.http.netty.HttpAsyncClientService," + + "scala.util.Random," + + "org.mule.weave.v2.sdk.SPIBasedModuleLoaderProvider\$") + buildArgs.add("--initialize-at-build-time=" + + "sun.instrument.InstrumentationImpl," + + "org.mule.weave.dwnative.initializer.Startup," + + "org.mule.weave.dwnative.," + + "org.mule.weave.v2.parser.," + + "org.mule.weave.v2.codegen.StringCodeWriter," + + "org.mule.weave.v2.resources.WeaveResourceLoader\$," + + "org.mule.weave.v2.annotations.," + + "org.mule.weave.v2.ts.," + + "org.mule.weave.v2.scope.," + + "org.mule.weave.v2.scope.," + + "org.mule.weave.v2.grammar.," + + "org.mule.weave.v2.sdk.," + + "org.mule.weave.v2.utils.," + + "org.mule.weave.v2.versioncheck.," + + //Parboiled + "scala.," + + "org.parboiled2.," + + "shapeless.syntax.") //For Runtime execution // "org.mule.weave.v2.interpreted.,"+ @@ -147,16 +151,27 @@ graal { // "org.mule.weave.v2.model.types.," // "org.mule.weave.v2.core.functions." // option "-H:+TraceClassInitialization" - option "-H:DeadlockWatchdogInterval=1000" - option "--report-unsupported-elements-at-runtime" - option "-H:CompilationExpirationPeriod=0" - option "--trace-object-instantiation=java.util.Random" - option "-H:+AddAllCharsets" - option "-H:+IncludeAllLocales" + buildArgs.add("-H:DeadlockWatchdogInterval=1000") + buildArgs.add("--report-unsupported-elements-at-runtime") + buildArgs.add("-H:CompilationExpirationPeriod=0") + buildArgs.add("--trace-object-instantiation=java.util.Random") + buildArgs.add("-H:+AddAllCharsets") + buildArgs.add("-H:+IncludeAllLocales") // option "-H:+DashboardAll" // option "-H:DashboardDump=/Users/mdeachaval/labs/palantir/weave-native-library/native-cli/dump" // option "-H:+PrintImageObjectTree" - option "-J-Xmx6G" + buildArgs.add("-J-Xmx6G") + + // Development options + agent = false // Enables the reflection agent. Can be also set on command line using '-Pagent' + + useFatJar = false // Instead of passing each jar individually, builds a fat jar + } + } } +nativeCompile.dependsOn("shadowJar") +tasks.named("nativeCompile") { + classpathJar = file("${buildDir}/libs/native-cli-" + nativeVersion + "-all.jar") +} \ No newline at end of file diff --git a/native-cli/src/main/scala/org/mule/weave/dwnative/NativeRuntime.scala b/native-cli/src/main/scala/org/mule/weave/dwnative/NativeRuntime.scala index c1c81ca..9c22bce 100644 --- a/native-cli/src/main/scala/org/mule/weave/dwnative/NativeRuntime.scala +++ b/native-cli/src/main/scala/org/mule/weave/dwnative/NativeRuntime.scala @@ -12,6 +12,7 @@ import org.mule.weave.v2.io.service.CustomWorkingDirectoryService import org.mule.weave.v2.io.service.WorkingDirectoryService import org.mule.weave.v2.model.EvaluationContext import org.mule.weave.v2.model.ServiceManager +import org.mule.weave.v2.model.service.CharsetProviderService import org.mule.weave.v2.model.service.DefaultSecurityManagerService import org.mule.weave.v2.model.service.LoggingService import org.mule.weave.v2.model.service.ProtocolUrlSourceProviderResolverService @@ -50,6 +51,7 @@ import java.io.OutputStream import java.io.PrintWriter import java.io.StringWriter import java.nio.charset.Charset +import java.nio.charset.StandardCharsets class NativeRuntime(libDir: File, path: Array[File], console: Console) { @@ -104,9 +106,15 @@ class NativeRuntime(libDir: File, path: Array[File], console: Console) { private def createServiceManager(maybePrivileges: Option[Seq[String]] = None): ServiceManager = { + val charsetProviderService = new CharsetProviderService { + override def defaultCharset(): Charset = { + StandardCharsets.UTF_8 + } + } var customServices: Map[Class[_], _] = Map( classOf[UrlSourceProviderResolverService] -> new ProtocolUrlSourceProviderResolverService(Seq(UrlProtocolHandler, WeavePathProtocolHandler(pathBasedResourceResolver))), - classOf[WorkingDirectoryService] -> new CustomWorkingDirectoryService(dataWeaveUtils.getWorkingHome(), true) + classOf[WorkingDirectoryService] -> new CustomWorkingDirectoryService(dataWeaveUtils.getWorkingHome(), true), + classOf[CharsetProviderService] -> charsetProviderService ) if (maybePrivileges.isDefined) { diff --git a/native-cli/src/test/scala/org/mule/weave/dwnative/cli/ArgumentsParserTest.scala b/native-cli/src/test/scala/org/mule/weave/dwnative/cli/ArgumentsParserTest.scala index e02cb97..5273e87 100644 --- a/native-cli/src/test/scala/org/mule/weave/dwnative/cli/ArgumentsParserTest.scala +++ b/native-cli/src/test/scala/org/mule/weave/dwnative/cli/ArgumentsParserTest.scala @@ -10,8 +10,8 @@ import java.io.File class ArgumentsParserTest extends FreeSpec with Matchers { - private def getScriptFolder(script: String): File = { - val url = getClass.getClassLoader.getResource(s"scripts${File.separator}$script") + private def getScriptFolder(scriptFolder: String): File = { + val url = getClass.getClassLoader.getResource(s"scripts/$scriptFolder") val file = new File(url.getFile) file } @@ -99,7 +99,7 @@ class ArgumentsParserTest extends FreeSpec with Matchers { "should fail parsing unrecognized argument" in { val parser = new CLIArgumentsParser(new TestConsole()) - val value = parser.parse(Array("-o", "/tmp/out.json", "--property", "p1", "p2", "p3", "1 to 10" )) + val value = parser.parse(Array("-o", "/tmp/out.json", "--parameter", "p1", "p2", "p3", "1 to 10" )) assert(value.isRight) val message = value.right.get message shouldBe "Invalid argument p3" diff --git a/native-cli/src/test/scala/org/mule/weave/dwnative/cli/DataWeaveCLITest.scala b/native-cli/src/test/scala/org/mule/weave/dwnative/cli/DataWeaveCLITest.scala index 1ca50bf..c3c8cdf 100644 --- a/native-cli/src/test/scala/org/mule/weave/dwnative/cli/DataWeaveCLITest.scala +++ b/native-cli/src/test/scala/org/mule/weave/dwnative/cli/DataWeaveCLITest.scala @@ -1,6 +1,7 @@ package org.mule.weave.dwnative.cli import org.mule.weave.dwnative.utils.DataWeaveUtils +import org.mule.weave.v2.utils.StringHelper.toStringTransformer import org.scalatest.FreeSpec import org.scalatest.Matchers @@ -33,7 +34,7 @@ class DataWeaveCLITest extends FreeSpec with Matchers { val result: String = source.mkString val expected = """ - |Mariano""".stripMargin + |Mariano""".stripMarginAndNormalizeEOL result.trim shouldBe expected } @@ -126,7 +127,7 @@ class DataWeaveCLITest extends FreeSpec with Matchers { val expected = """ |{ | "isEmpty": false - |}""".stripMargin.trim + |}""".stripMarginAndNormalizeEOL.trim result shouldBe expected } @@ -142,7 +143,7 @@ class DataWeaveCLITest extends FreeSpec with Matchers { val expected = """ |{ | "isEmpty": false - |}""".stripMargin.trim + |}""".stripMarginAndNormalizeEOL.trim result shouldBe expected } @@ -164,11 +165,7 @@ class DataWeaveCLITest extends FreeSpec with Matchers { val source = Source.fromBytes(stream.toByteArray, "UTF-8") val result = source.mkString.trim source.close() - val expected = """ - |{ - | "isEmpty": false - |}""".stripMargin.trim - result shouldBe expected + result should include("usage: dw") } "should run using parameter" in { @@ -185,7 +182,7 @@ class DataWeaveCLITest extends FreeSpec with Matchers { |{ | "fullName": "Mariano Lischetti" |} - """.stripMargin.trim + """.stripMarginAndNormalizeEOL.trim result shouldBe expected } }