fix(DebuggerController) 代码编译问题

This commit is contained in:
youys 2023-08-17 15:52:07 +08:00
parent 5f0cae3f06
commit 7b0d778e82
1 changed files with 26 additions and 13 deletions

View File

@ -55,19 +55,29 @@ public class DebuggerController {
@RequestParam("fileOutPath") String fileOutPath,
@RequestParam("originExecuteFile") String originExecuteFile) throws Exception {
// 编译代码
compileCode(originExecuteFile);
initDebuggerInstance(mainClass, classPath);
outputPath = fileOutPath;
debugger.setInputFile(fileInputPath);
debugger.setOutputFile(fileOutPath);
for (String breakPoint : breakPoints.split(",")) {
String[] segmentation = breakPoint.split(":");
debugger.setBreakPoint(segmentation[0], Integer.valueOf(segmentation[1]));
try {
// 编译代码
compileCode(originExecuteFile);
initDebuggerInstance(mainClass, classPath);
outputPath = fileOutPath;
debugger.setInputFile(fileInputPath);
debugger.setOutputFile(fileOutPath);
for (String breakPoint : breakPoints.split(",")) {
String[] segmentation = breakPoint.split(":");
debugger.setBreakPoint(segmentation[0], Integer.valueOf(segmentation[1]));
}
debugger.startProgram();
return getCurrentState();
}catch (RuntimeException e){
String errorMessage = e.getMessage();
DebugResult result = new DebugResult();
result.setIs_over(true);
result.setCurrent_line(-1);
result.setExpressions(new HashMap<>());
result.setLocals(new HashMap<>());
result.setOut(errorMessage);
return gson.toJson(result);
}
debugger.startProgram();
return getCurrentState();
}
/**
@ -247,8 +257,11 @@ public class DebuggerController {
*/
private void compileCode(String originalEvaluateFile) {
String compilePath = "/data/workspace" + File.separator + originalEvaluateFile.substring(0, originalEvaluateFile.lastIndexOf("/") + 1);
String compileCommand = StringUtils.join("javac -g -cp ", compilePath, " ", "/data/workspace", File.separator, originalEvaluateFile);
String compileCommand = StringUtils.join("javac -g -cp ", compilePath, " ", compilePath+"*.java");
ShellResult shellResult = ShellUtil.executeAndGetExitStatus(compileCommand);
logger.info("编译代码command:{}, status:{}, out:{}", compileCommand, shellResult.getExitStatus(), shellResult.getOut());
if(shellResult.getExitStatus() != 0){
throw new RuntimeException(shellResult.getOut().replaceAll("/data/workspace/", ""));
}
}
}