Skip to content

Commit

Permalink
Merge pull request #1201 from andyrichardson/master
Browse files Browse the repository at this point in the history
Java package support
  • Loading branch information
rgbkrk authored Apr 25, 2017
2 parents 3d5be3e + f227f24 commit b6a682c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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 | | |
Expand Down
9 changes: 8 additions & 1 deletion lib/grammar-utils/java.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`;
},
};
8 changes: 6 additions & 2 deletions lib/grammars.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,16 @@ 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
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 #{className}"]
args = ['-c', "javac -sourcepath #{sourcePath} -d /tmp '#{context.filepath}' && java -cp /tmp #{classPackages}#{className}"]

return args

JavaScript:
Expand Down

0 comments on commit b6a682c

Please sign in to comment.