From a8b4526b41b1fafb98d7f65782867e1d6665d93b Mon Sep 17 00:00:00 2001 From: Andy Richardson Date: Mon, 2 Jan 2017 16:46:48 +0000 Subject: [PATCH 1/5] Java package support on bash --- lib/grammar-utils/java.js | 9 ++++++++- lib/grammars.coffee | 7 +++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/grammar-utils/java.js b/lib/grammar-utils/java.js index 925d9bfa..baed8c4e 100644 --- a/lib/grammar-utils/java.js +++ b/lib/grammar-utils/java.js @@ -37,6 +37,13 @@ export default { getClassPackage(context) { const projectPath = module.exports.getProjectPath(context); const projectRemoved = (context.filepath.replace(`${projectPath}/`, '')); - return projectRemoved.replace(`/${context.filename}`, ''); + const filenameRemoved = projectRemoved.replace(`/${context.filename}`, ''); + + // File is in root of src directory - no package + if(filenameRemoved == projectRemoved){ + return ""; + } + + return filenameRemoved + "." }, }; diff --git a/lib/grammars.coffee b/lib/grammars.coffee index e20f31a6..8b20d3b0 100644 --- a/lib/grammars.coffee +++ b/lib/grammars.coffee @@ -342,12 +342,15 @@ module.exports = "File Based": command: if GrammarUtils.OperatingSystem.isWindows() then "cmd" else "bash" args: (context) -> - className = context.filename.replace /\.java$/, "" + className = GrammarUtils.Java.getClassName context + classPackages = GrammarUtils.Java.getClassPackage context + args = [] if GrammarUtils.OperatingSystem.isWindows() args = ["/c javac -Xlint #{context.filename} && java #{className}"] else - args = ['-c', "javac -d /tmp '#{context.filepath}' && java -cp /tmp #{className}"] + args = ['-c', "javac -d /tmp '#{context.filepath}' && java -cp /tmp #{classPackages}#{className}"] + return args JavaScript: From 31c7e9bfe36f7f82c9f9bcd059e0139dbec0efc4 Mon Sep 17 00:00:00 2001 From: Andy Richardson Date: Mon, 2 Jan 2017 16:50:19 +0000 Subject: [PATCH 2/5] Update readme for packaging description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a15e706a..50b07936 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Currently supported grammars are: | IcedCoffeeScript | Yes | Yes | | | Inno Setup | Yes | | Requires the path of `ISCC.exe` in your system environment variables | | [ioLanguage](http://iolanguage.org/) | Yes | Yes | | -| Java | Yes | | Windows users should manually add jdk path (...\jdk1.x.x_xx\bin) to their system environment variables | +| Java | Yes | | Windows users should manually add jdk path (...\jdk1.x.x_xx\bin) to their system environment variables. Project directory should be the source directory; subfolders imply packaging. | | Javascript | Yes | Yes | | | [JavaScript for Automation](https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/Introduction.html) (JXA) | Yes | Yes | | | Jolie | Yes | | | From b14da971b31c83205f4082d1d245019023304a66 Mon Sep 17 00:00:00 2001 From: Andy Richardson Date: Mon, 2 Jan 2017 17:32:55 +0000 Subject: [PATCH 3/5] Support importing classes from local packages --- lib/grammars.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/grammars.coffee b/lib/grammars.coffee index 8b20d3b0..a334a6bd 100644 --- a/lib/grammars.coffee +++ b/lib/grammars.coffee @@ -344,12 +344,13 @@ module.exports = args: (context) -> className = GrammarUtils.Java.getClassName context classPackages = GrammarUtils.Java.getClassPackage context + sourcePath = GrammarUtils.Java.getProjectPath context args = [] if GrammarUtils.OperatingSystem.isWindows() args = ["/c javac -Xlint #{context.filename} && java #{className}"] else - args = ['-c', "javac -d /tmp '#{context.filepath}' && java -cp /tmp #{classPackages}#{className}"] + args = ['-c', "javac -sourcepath #{sourcePath} -d /tmp '#{context.filepath}' && java -cp /tmp #{classPackages}#{className}"] return args From 5e368ac72e971906c1f8aa56d97723cc725df033 Mon Sep 17 00:00:00 2001 From: Andy Richardson Date: Mon, 30 Jan 2017 15:34:11 +0000 Subject: [PATCH 4/5] fix build errors - style related --- lib/grammar-utils/java.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/grammar-utils/java.js b/lib/grammar-utils/java.js index baed8c4e..4119b495 100644 --- a/lib/grammar-utils/java.js +++ b/lib/grammar-utils/java.js @@ -40,10 +40,10 @@ export default { const filenameRemoved = projectRemoved.replace(`/${context.filename}`, ''); // File is in root of src directory - no package - if(filenameRemoved == projectRemoved){ - return ""; + if (filenameRemoved === projectRemoved) { + return ''; } - return filenameRemoved + "." + return '${filenameRemoved}.'; }, }; From f227f24a6205aed72cb62cfcfa8a8db93c532e69 Mon Sep 17 00:00:00 2001 From: Andy Richardson Date: Tue, 31 Jan 2017 22:14:16 +0000 Subject: [PATCH 5/5] Update java.js --- lib/grammar-utils/java.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grammar-utils/java.js b/lib/grammar-utils/java.js index 4119b495..c7b44b88 100644 --- a/lib/grammar-utils/java.js +++ b/lib/grammar-utils/java.js @@ -44,6 +44,6 @@ export default { return ''; } - return '${filenameRemoved}.'; + return `${filenameRemoved}.`; }, };