-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding migration from dw1 to dw2 support inside the CLI (#62)
* Adding migration from dw1 to dw2 support inside the CLI * Fixing build
- Loading branch information
Showing
7 changed files
with
101 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
native-cli-integration-tests/src/test/resources/dw1/SimpleFile.dw1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
%dw 1.0 | ||
%var arr = ["foo"] | ||
--- | ||
{ | ||
a: [0, 1, 2] contains [1, 2], | ||
b: sum [1..1000], | ||
c: sizeOf ("123") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
native-cli/src/main/scala/org/mule/weave/dwnative/cli/commands/MigrateDW1Command.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.mule.weave.dwnative.cli.commands | ||
|
||
import org.mule.weave.dwnative.cli.Console | ||
import org.mule.weave.v2.V2LangMigrant | ||
|
||
import java.io.File | ||
import java.io.FileWriter | ||
import java.nio.charset.StandardCharsets | ||
import scala.io.Source | ||
|
||
class MigrateDW1Command(val oldScriptPath: String, console: Console) extends WeaveCommand { | ||
|
||
def exec(): Int = { | ||
var statusCode = ExitCodes.SUCCESS | ||
val oldScriptFile = new File(oldScriptPath) | ||
if (!oldScriptFile.exists()) { | ||
console.error(s"Unable to find dw1 script to migrate") | ||
statusCode = ExitCodes.FAILURE | ||
} else { | ||
val source = Source.fromFile(oldScriptFile, StandardCharsets.UTF_8.name()) | ||
try { | ||
val str = V2LangMigrant.migrateToV2(source.mkString) | ||
console.out.write(str.getBytes(StandardCharsets.UTF_8)) | ||
} finally { | ||
source.close() | ||
} | ||
} | ||
statusCode | ||
} | ||
|
||
|
||
} |