Skip to content

Commit a8b4526

Browse files
Java package support on bash
1 parent effd37a commit a8b4526

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,15 @@ module.exports =
342342
"File Based":
343343
command: if GrammarUtils.OperatingSystem.isWindows() then "cmd" else "bash"
344344
args: (context) ->
345-
className = context.filename.replace /\.java$/, ""
345+
className = GrammarUtils.Java.getClassName context
346+
classPackages = GrammarUtils.Java.getClassPackage context
347+
346348
args = []
347349
if GrammarUtils.OperatingSystem.isWindows()
348350
args = ["/c javac -Xlint #{context.filename} && java #{className}"]
349351
else
350-
args = ['-c', "javac -d /tmp '#{context.filepath}' && java -cp /tmp #{className}"]
352+
args = ['-c', "javac -d /tmp '#{context.filepath}' && java -cp /tmp #{classPackages}#{className}"]
353+
351354
return args
352355

353356
JavaScript:

0 commit comments

Comments
 (0)