|
1 | 1 | "use babel"
|
2 |
| - |
3 |
| -/* |
4 |
| - * decaffeinate suggestions: |
5 |
| - * DS102: Remove unnecessary code created because of implicit returns |
6 |
| - * DS207: Consider shorter variations of null checks |
7 |
| - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md |
8 |
| - */ |
9 | 2 | import path from "path"
|
10 | 3 | import GrammarUtils from "../grammar-utils"
|
11 | 4 | const { command } = GrammarUtils
|
12 | 5 |
|
13 |
| -const windows = GrammarUtils.OperatingSystem.isWindows() |
| 6 | +function JavaArgs(filepath, context) { |
| 7 | + const sourcePath = GrammarUtils.Java.getProjectPath(context) |
| 8 | + const className = GrammarUtils.Java.getClassName(context) |
| 9 | + const classPackages = GrammarUtils.Java.getClassPackage(context) |
| 10 | + const tempFolder = GrammarUtils.createTempFolder("jar-") |
| 11 | + const cmd = `javac -encoding UTF-8 -sourcepath '${sourcePath}' -d '${tempFolder}' '${filepath}' && java -D'file.encoding'='UTF-8' -cp '${tempFolder}' ${classPackages}${className}` |
| 12 | + return GrammarUtils.formatArgs(cmd) |
| 13 | +} |
14 | 14 |
|
15 | 15 | export const Java = {
|
| 16 | + "Selection Based": { |
| 17 | + command, |
| 18 | + args(context) { |
| 19 | + const code = context.getCode() |
| 20 | + const tmpFile = GrammarUtils.createTempFileWithCode(code, ".java") |
| 21 | + return JavaArgs(tmpFile, context) |
| 22 | + }, |
| 23 | + }, |
16 | 24 | "File Based": {
|
17 | 25 | command,
|
18 | 26 | args(context) {
|
19 |
| - const className = GrammarUtils.Java.getClassName(context) |
20 |
| - const classPackages = GrammarUtils.Java.getClassPackage(context) |
21 |
| - const sourcePath = GrammarUtils.Java.getProjectPath(context) |
22 |
| - if (windows) { |
23 |
| - return [`/c javac -Xlint ${context.filename} && java ${className}`] |
24 |
| - } else { |
25 |
| - return [ |
26 |
| - "-c", |
27 |
| - `javac -J-Dfile.encoding=UTF-8 -sourcepath '${sourcePath}' -d /tmp '${context.filepath}' && java -Dfile.encoding=UTF-8 -cp /tmp:%CLASSPATH ${classPackages}${className}`, |
28 |
| - ] |
29 |
| - } |
| 27 | + return JavaArgs(context.filepath, context) |
30 | 28 | },
|
31 | 29 | },
|
32 | 30 | }
|
|
0 commit comments