Skip to content

Support java 9 - #90

Merged
Jinbo Wang (testforstephen) merged 7 commits into
masterfrom
jinbo_java9
Nov 6, 2017
Merged

Jinbo Wang (testforstephen) merged 7 commits into
masterfrom
jinbo_java9

Conversation

@testforstephen

@testforstephen Jinbo Wang (testforstephen) commented Nov 2, 2017 •

Copy link
Copy Markdown
Contributor

Support set breakpoint in java 9 source file.
Auto detect the project is modular project or not.
Auto resolve module path from project settings.
Auto resolve main class from module.
Support launch options in java 9. (e.g. --module-path, -m)

Peer PR on vscode side:
microsoft/vscode-java-debug#124

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suspend ==> suspended

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suspend Mode is OK, you can google it, there are many places calling it Suspend Mode.

arguments.get("options").setValue("-cp \"" + classPaths + "\"");
options = vmArguments;
}
if (StringUtils.isNotBlank(modulePaths)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, if the vmArguments already have the --module-path or -cp values, what would happen here?

@testforstephen Jinbo Wang (testforstephen) Nov 6, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 + "\"";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would suggest StringBuilder for options

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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("main").setValue(mainClass);
mainClass += " " + programArguments;
}
arguments.get("main").setValue(mainClass);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should avoid hard coded string if possible

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

sourceProvider.initialize(context.getDebugSession(), options);
}

private boolean isEmptyArray(String[] items) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use since we already refer this lib.

org.apache.commons.lang3.ArrayUtils.isNotEmpty(testArrayName)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

|| (isEmptyArray(launchArguments.modulePaths) && isEmptyArray(launchArguments.classPaths))) {
AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING,
String.format("Failed to launch debuggee VM. Missing mainClass or classPath options in launch configuration"));
String.format("Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration"
==>
"Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in the launch configuration"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

launchArguments.vmArgs, StringUtils.join(launchArguments.classPaths, File.pathSeparator), launchArguments.mainClass, launchArguments.args));
IDebugSession debugSession = DebugUtility.launch(vmProvider.getVirtualMachineManager(), launchArguments.mainClass, launchArguments.args,
launchArguments.vmArgs, Arrays.asList(launchArguments.classPaths), launchArguments.cwd, envVars);
logger.info("Trying to launch Java Program with options:");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use StringBuilder to avoid multiple call of logger

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice.

IModuleDescription module;
try {
module = project.getModuleDescription();
} catch (JavaModelException e) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaModelException to CoreException to keep consistent with the below code.

@@ -89,16 +79,29 @@ private static IJavaProject getJavaProjectFromName(String projectName) throws Co
* CoreException
*/
private static List<IJavaProject> getJavaProjectFromType(String typeFullyQualifiedName) throws CoreException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, typeFullQualifiedName should be fullyQualifiedTypeName

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

throw new IllegalArgumentException("javaProject is null");
}
return JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
String[][] result = new String[2][];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion only: Could use org.apache.commons.lang3.tuple/pair for better reading.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In typescript, tuple is like [10, 11], but in org.apache.commons.lang3.tuple.Pair, tuple is like (10, 11), the serialization/deserialization is not compatile, i would prefer to keep current implementation.

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants