-
Notifications
You must be signed in to change notification settings - Fork 269
/
java.js
64 lines (58 loc) · 1.86 KB
/
java.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use babel"
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import path from "path"
import GrammarUtils from "../grammar-utils"
const { command } = GrammarUtils
const windows = GrammarUtils.OperatingSystem.isWindows()
export const Java = {
"File Based": {
command,
args(context) {
const className = GrammarUtils.Java.getClassName(context)
const classPackages = GrammarUtils.Java.getClassPackage(context)
const sourcePath = GrammarUtils.Java.getProjectPath(context)
if (windows) {
return [`/c javac -Xlint ${context.filename} && java ${className}`]
} else {
return [
"-c",
`javac -J-Dfile.encoding=UTF-8 -sourcepath '${sourcePath}' -d /tmp '${context.filepath}' && java -Dfile.encoding=UTF-8 -cp /tmp:%CLASSPATH ${classPackages}${className}`,
]
}
},
},
}
function KotlinArgs(filepath, jar) {
const jarNew = (jar !== null ? jar : path.basename(filepath)).replace(/\.kt$/, ".jar")
const cmd = `kotlinc '${filepath}' -include-runtime -o ${jarNew} && java -jar ${jarNew}`
return GrammarUtils.formatArgs(cmd)
}
export const Kotlin = {
"Selection Based": {
command,
args(context) {
const code = context.getCode()
const tmpFile = GrammarUtils.createTempFileWithCode(code, ".kt")
return KotlinArgs(tmpFile, null)
},
},
"File Based": {
command,
args({ filepath, filename }) {
return KotlinArgs(filepath, path.join(GrammarUtils.createTempFolder("kt-"), filename))
},
},
}
export const Processing = {
"File Based": {
command: "processing-java",
args({ filepath }) {
return [`--sketch=${path.dirname(filepath)}`, "--run"]
},
},
}