From 5a61f1ff733d0069bebac3c56f876a8583e11177 Mon Sep 17 00:00:00 2001 From: Manami Hatano Date: Wed, 12 May 2021 12:55:51 +0900 Subject: [PATCH 1/7] Fix Garbled message in non-English Windows Quick fix for the issue #1166, Java build in non-English editions of Window will result garbled message, stdout and stderr displayed. This fix would have further issue: if user's final target deployment would have different encodings from all-UTF-8 setup, (such as "normal" Windows cmd.exe, they normally have ANSI encodings for average users) so testing and evaluating might become more difficult. --- lib/grammars/java.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grammars/java.js b/lib/grammars/java.js index 09126d65..685ee2e2 100644 --- a/lib/grammars/java.js +++ b/lib/grammars/java.js @@ -20,7 +20,7 @@ export const Java = { const classPackages = GrammarUtils.Java.getClassPackage(context) const sourcePath = GrammarUtils.Java.getProjectPath(context) if (windows) { - return [`/c javac -Xlint ${context.filename} && java ${className}`] + return [`/c javac ーJ-Dfile.encoding=UTF-8 -Xlint ${context.filename} && java -Dfile.encoding=UTF-8 ${className}`] } else { return [ "-c", From d73f270b098d0c22144ec9b59c983bf62428f995 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 11 May 2021 23:29:56 -0500 Subject: [PATCH 2/7] fix: fix execution of Java files + support UTF-8 encoding --- examples/HelloWorld.java | 1 + lib/grammars/java.js | 11 +++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/examples/HelloWorld.java b/examples/HelloWorld.java index 3b449d9e..ada42c6b 100644 --- a/examples/HelloWorld.java +++ b/examples/HelloWorld.java @@ -1,5 +1,6 @@ class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); + System.out.println("سلام"); } } diff --git a/lib/grammars/java.js b/lib/grammars/java.js index 685ee2e2..1732e7d9 100644 --- a/lib/grammars/java.js +++ b/lib/grammars/java.js @@ -19,14 +19,9 @@ export const Java = { const className = GrammarUtils.Java.getClassName(context) const classPackages = GrammarUtils.Java.getClassPackage(context) const sourcePath = GrammarUtils.Java.getProjectPath(context) - if (windows) { - return [`/c javac ーJ-Dfile.encoding=UTF-8 -Xlint ${context.filename} && java -Dfile.encoding=UTF-8 ${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}`, - ] - } + const tempFolder = GrammarUtils.createTempFolder("jar-") + const cmd = `javac -encoding UTF-8 -sourcepath '${sourcePath}' -d '${tempFolder}' '${context.filepath}' && java -D'file.encoding'='UTF-8' -cp '${tempFolder}' ${classPackages}${className}` + return GrammarUtils.formatArgs(cmd) }, }, } From 0e1c38b11531e7d887bc7d29c6c5369f418f2ea8 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 11 May 2021 23:31:30 -0500 Subject: [PATCH 3/7] chore: remove unused parameter --- lib/grammars/java.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/grammars/java.js b/lib/grammars/java.js index 1732e7d9..41b213ce 100644 --- a/lib/grammars/java.js +++ b/lib/grammars/java.js @@ -10,8 +10,6 @@ import path from "path" import GrammarUtils from "../grammar-utils" const { command } = GrammarUtils -const windows = GrammarUtils.OperatingSystem.isWindows() - export const Java = { "File Based": { command, From 29fbce7651ec803e3a90ee8cabbc84ace23dc5ec Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 11 May 2021 23:36:02 -0500 Subject: [PATCH 4/7] refactor: JavaArgs function --- lib/grammars/java.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/grammars/java.js b/lib/grammars/java.js index 41b213ce..6b908190 100644 --- a/lib/grammars/java.js +++ b/lib/grammars/java.js @@ -10,16 +10,20 @@ import path from "path" import GrammarUtils from "../grammar-utils" const { command } = GrammarUtils +function JavaArgs(sourcePath, filepath, className, classPackages, tempFolder) { + const cmd = `javac -encoding UTF-8 -sourcepath '${sourcePath}' -d '${tempFolder}' '${filepath}' && java -D'file.encoding'='UTF-8' -cp '${tempFolder}' ${classPackages}${className}` + return GrammarUtils.formatArgs(cmd) +} + export const Java = { "File Based": { command, args(context) { + const sourcePath = GrammarUtils.Java.getProjectPath(context) const className = GrammarUtils.Java.getClassName(context) const classPackages = GrammarUtils.Java.getClassPackage(context) - const sourcePath = GrammarUtils.Java.getProjectPath(context) const tempFolder = GrammarUtils.createTempFolder("jar-") - const cmd = `javac -encoding UTF-8 -sourcepath '${sourcePath}' -d '${tempFolder}' '${context.filepath}' && java -D'file.encoding'='UTF-8' -cp '${tempFolder}' ${classPackages}${className}` - return GrammarUtils.formatArgs(cmd) + return JavaArgs(sourcePath, context.filepath, className, classPackages, tempFolder) }, }, } From 85152009948648b8cc702f6d0fd0369f6851b8b4 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 11 May 2021 23:41:56 -0500 Subject: [PATCH 5/7] feat: add selection based Java support --- lib/grammars/java.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/grammars/java.js b/lib/grammars/java.js index 6b908190..6e35279c 100644 --- a/lib/grammars/java.js +++ b/lib/grammars/java.js @@ -16,6 +16,18 @@ function JavaArgs(sourcePath, filepath, className, classPackages, tempFolder) { } export const Java = { + "Selection Based": { + command, + args(context) { + const code = context.getCode() + const tmpFile = GrammarUtils.createTempFileWithCode(code, ".java") + const sourcePath = GrammarUtils.Java.getProjectPath(context) + const className = GrammarUtils.Java.getClassName(context) + const classPackages = GrammarUtils.Java.getClassPackage(context) + const tempFolder = GrammarUtils.createTempFolder("jar-") + return JavaArgs(sourcePath, tmpFile, className, classPackages, tempFolder) + }, + }, "File Based": { command, args(context) { From af697fccb275824ede7d98ef1df8bc6b120c624d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 11 May 2021 23:44:43 -0500 Subject: [PATCH 6/7] refactor: move the common parts into JavaArgs function --- lib/grammars/java.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/grammars/java.js b/lib/grammars/java.js index 6e35279c..cb612638 100644 --- a/lib/grammars/java.js +++ b/lib/grammars/java.js @@ -10,7 +10,11 @@ import path from "path" import GrammarUtils from "../grammar-utils" const { command } = GrammarUtils -function JavaArgs(sourcePath, filepath, className, classPackages, tempFolder) { +function JavaArgs(filepath, context) { + const sourcePath = GrammarUtils.Java.getProjectPath(context) + const className = GrammarUtils.Java.getClassName(context) + const classPackages = GrammarUtils.Java.getClassPackage(context) + const tempFolder = GrammarUtils.createTempFolder("jar-") const cmd = `javac -encoding UTF-8 -sourcepath '${sourcePath}' -d '${tempFolder}' '${filepath}' && java -D'file.encoding'='UTF-8' -cp '${tempFolder}' ${classPackages}${className}` return GrammarUtils.formatArgs(cmd) } @@ -21,21 +25,13 @@ export const Java = { args(context) { const code = context.getCode() const tmpFile = GrammarUtils.createTempFileWithCode(code, ".java") - const sourcePath = GrammarUtils.Java.getProjectPath(context) - const className = GrammarUtils.Java.getClassName(context) - const classPackages = GrammarUtils.Java.getClassPackage(context) - const tempFolder = GrammarUtils.createTempFolder("jar-") - return JavaArgs(sourcePath, tmpFile, className, classPackages, tempFolder) + return JavaArgs(tmpFile, context) }, }, "File Based": { command, args(context) { - const sourcePath = GrammarUtils.Java.getProjectPath(context) - const className = GrammarUtils.Java.getClassName(context) - const classPackages = GrammarUtils.Java.getClassPackage(context) - const tempFolder = GrammarUtils.createTempFolder("jar-") - return JavaArgs(sourcePath, context.filepath, className, classPackages, tempFolder) + return JavaArgs(context.filepath, context) }, }, } From c7a78bec13fed3f801880046f542c1779ba5d897 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 11 May 2021 23:45:41 -0500 Subject: [PATCH 7/7] chore: remove decaffeinate suggestions [skip ci] --- lib/grammars/java.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/grammars/java.js b/lib/grammars/java.js index cb612638..eac62878 100644 --- a/lib/grammars/java.js +++ b/lib/grammars/java.js @@ -1,11 +1,4 @@ "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