Skip to content

Commit b6a682c

Browse files
authored
Merge pull request #1201 from andyrichardson/master
Java package support
2 parents 3d5be3e + f227f24 commit b6a682c

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Currently supported grammars are:
5050
| IcedCoffeeScript | Yes | Yes | |
5151
| Inno Setup | Yes | | Requires the path of `ISCC.exe` in your system environment variables |
5252
| [ioLanguage](http://iolanguage.org/) | Yes | Yes | |
53-
| Java | Yes | | Windows users should manually add jdk path (...\jdk1.x.x_xx\bin) to their system environment variables |
53+
| 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. |
5454
| Javascript | Yes | Yes | |
5555
| [JavaScript for Automation](https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/Introduction.html) (JXA) | Yes | Yes | |
5656
| Jolie | Yes | | |

lib/grammar-utils/java.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ export default {
3737
getClassPackage(context) {
3838
const projectPath = module.exports.getProjectPath(context);
3939
const projectRemoved = (context.filepath.replace(`${projectPath}/`, ''));
40-
return projectRemoved.replace(`/${context.filename}`, '');
40+
const filenameRemoved = projectRemoved.replace(`/${context.filename}`, '');
41+
42+
// File is in root of src directory - no package
43+
if (filenameRemoved === projectRemoved) {
44+
return '';
45+
}
46+
47+
return `${filenameRemoved}.`;
4148
},
4249
};

lib/grammars.coffee

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,16 @@ module.exports =
358358
"File Based":
359359
command: if GrammarUtils.OperatingSystem.isWindows() then "cmd" else "bash"
360360
args: (context) ->
361-
className = context.filename.replace /\.java$/, ""
361+
className = GrammarUtils.Java.getClassName context
362+
classPackages = GrammarUtils.Java.getClassPackage context
363+
sourcePath = GrammarUtils.Java.getProjectPath context
364+
362365
args = []
363366
if GrammarUtils.OperatingSystem.isWindows()
364367
args = ["/c javac -Xlint #{context.filename} && java #{className}"]
365368
else
366-
args = ['-c', "javac -d /tmp '#{context.filepath}' && java -cp /tmp #{className}"]
369+
args = ['-c', "javac -sourcepath #{sourcePath} -d /tmp '#{context.filepath}' && java -cp /tmp #{classPackages}#{className}"]
370+
367371
return args
368372

369373
JavaScript:

0 commit comments

Comments
 (0)