Repository navigation
Support java 9 #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support java 9 #90
Changes from all commits
d7e5df8
a2cfe68
585ebd2
2ab99c2
88d5407
028bae7
e0b62fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,10 +40,39 @@ | |
| import com.sun.jdi.request.StepRequest; | ||
|
|
||
| public class DebugUtility { | ||
| public static final String HOME = "home"; | ||
| public static final String OPTIONS = "options"; | ||
| public static final String MAIN = "main"; | ||
| public static final String SUSPEND = "suspend"; | ||
| public static final String QUOTE = "quote"; | ||
| public static final String EXEC = "vmexec"; | ||
| public static final String CWD = "cwd"; | ||
| public static final String ENV = "env"; | ||
| public static final String HOSTNAME = "hostname"; | ||
| public static final String PORT = "port"; | ||
| public static final String TIMEOUT = "timeout"; | ||
|
|
||
| public static IDebugSession launch(VirtualMachineManager vmManager, String mainClass, String programArguments, String vmArguments, List<String> classPaths, | ||
| String cwd, String[] envVars) throws IOException, IllegalConnectorArgumentsException, VMStartException { | ||
| return DebugUtility.launch(vmManager, mainClass, programArguments, vmArguments, String.join(File.pathSeparator, classPaths), cwd, envVars); | ||
| /** | ||
| * Launch a debuggee in suspend mode. | ||
| * @see {@link #launch(VirtualMachineManager, String, String, String, String, String)} | ||
| */ | ||
| public static IDebugSession launch(VirtualMachineManager vmManager, | ||
| String mainClass, | ||
| String programArguments, | ||
| String vmArguments, | ||
| List<String> modulePaths, | ||
| List<String> classPaths, | ||
| String cwd, | ||
| String[] envVars) | ||
| throws IOException, IllegalConnectorArgumentsException, VMStartException { | ||
| return DebugUtility.launch(vmManager, | ||
| mainClass, | ||
| programArguments, | ||
| vmArguments, | ||
| String.join(File.pathSeparator, modulePaths), | ||
| String.join(File.pathSeparator, classPaths), | ||
| cwd, | ||
| envVars); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -57,6 +86,8 @@ public static IDebugSession launch(VirtualMachineManager vmManager, String mainC | |
| * the program arguments. | ||
| * @param vmArguments | ||
| * the vm arguments. | ||
| * @param modulePaths | ||
| * the module paths. | ||
| * @param classPaths | ||
| * the class paths. | ||
| * @param cwd | ||
|
|
@@ -73,30 +104,49 @@ public static IDebugSession launch(VirtualMachineManager vmManager, String mainC | |
| * when the debuggee was successfully launched, but terminated | ||
| * with an error before a connection could be established. | ||
| */ | ||
| public static IDebugSession launch(VirtualMachineManager vmManager, String mainClass, String programArguments, String vmArguments, String classPaths, | ||
| String cwd, String[] envVars) throws IOException, IllegalConnectorArgumentsException, VMStartException { | ||
| public static IDebugSession launch(VirtualMachineManager vmManager, | ||
| String mainClass, | ||
| String programArguments, | ||
| String vmArguments, | ||
| String modulePaths, | ||
| String classPaths, | ||
| String cwd, | ||
| String[] envVars) | ||
| throws IOException, IllegalConnectorArgumentsException, VMStartException { | ||
| List<LaunchingConnector> connectors = vmManager.launchingConnectors(); | ||
| LaunchingConnector connector = connectors.get(0); | ||
|
|
||
| Map<String, Argument> arguments = connector.defaultArguments(); | ||
| arguments.get("suspend").setValue("true"); | ||
| arguments.get(SUSPEND).setValue("true"); | ||
|
|
||
| String options = ""; | ||
| if (StringUtils.isNotBlank(vmArguments)) { | ||
| arguments.get("options").setValue(vmArguments + " -cp \"" + classPaths + "\""); | ||
| } else { | ||
| arguments.get("options").setValue("-cp \"" + classPaths + "\""); | ||
| options = vmArguments; | ||
| } | ||
| if (StringUtils.isNotBlank(modulePaths)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, if the vmArguments already have the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be overided. We don't claim supporting --classpath in vmArguments. |
||
| options += " --module-path \"" + modulePaths + "\""; | ||
| } | ||
| if (StringUtils.isNotBlank(classPaths)) { | ||
| options += " -cp \"" + classPaths + "\""; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would suggest StringBuilder for options
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For simple string concatenation operation, i would prefer the concatenation because the code is shorter. For loop or large string operations, StringBuilder is preferable. |
||
| } | ||
| arguments.get(OPTIONS).setValue(options); | ||
|
|
||
| // For java 9 project, should specify "-m $MainClass". | ||
| String[] mainClasses = mainClass.split("/"); | ||
| if (StringUtils.isNotBlank(modulePaths) || mainClasses.length == 2) { | ||
| mainClass = "-m " + mainClass; | ||
| } | ||
| if (StringUtils.isNotBlank(programArguments)) { | ||
| arguments.get("main").setValue(mainClass + " " + programArguments); | ||
| } else { | ||
| arguments.get("main").setValue(mainClass); | ||
| mainClass += " " + programArguments; | ||
| } | ||
| arguments.get(MAIN).setValue(mainClass); | ||
|
|
||
| if (arguments.get("cwd") != null) { | ||
| arguments.get("cwd").setValue(cwd); | ||
| if (arguments.get(CWD) != null) { | ||
| arguments.get(CWD).setValue(cwd); | ||
| } | ||
|
|
||
| if (arguments.get("env") != null) { | ||
| arguments.get("env").setValue(encodeArrayArgument(envVars)); | ||
| if (arguments.get(ENV) != null) { | ||
| arguments.get(ENV).setValue(encodeArrayArgument(envVars)); | ||
| } | ||
|
|
||
| VirtualMachine vm = connector.launch(arguments); | ||
|
|
@@ -131,9 +181,9 @@ public static IDebugSession attach(VirtualMachineManager vmManager, String hostN | |
| List<AttachingConnector> connectors = vmManager.attachingConnectors(); | ||
| AttachingConnector connector = connectors.get(0); | ||
| Map<String, Argument> arguments = connector.defaultArguments(); | ||
| arguments.get("hostname").setValue(hostName); | ||
| arguments.get("port").setValue(String.valueOf(port)); | ||
| arguments.get("timeout").setValue(String.valueOf(attachTimeout)); | ||
| arguments.get(HOSTNAME).setValue(hostName); | ||
| arguments.get(PORT).setValue(String.valueOf(port)); | ||
| arguments.get(TIMEOUT).setValue(String.valueOf(attachTimeout)); | ||
| return new DebugSession(connector.attach(arguments)); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suspend ==> suspended
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suspend Modeis OK, you can google it, there are many places calling itSuspend Mode.