Skip to content
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

Customize launching connector to support cwd and enviroment variable #89

Merged
merged 7 commits into from
Nov 1, 2017

Conversation

testforstephen
Copy link
Contributor

No description provided.

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
@@ -91,6 +91,68 @@ public static IDebugSession launch(VirtualMachineManager vmManager, String mainC
return new DebugSession(vm);
}

public static IDebugSession launch(VirtualMachineManager vmManager, String mainClass, String programArguments, String vmArguments, List<String> classPaths,
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete the old launch method.

@@ -91,6 +91,68 @@ public static IDebugSession launch(VirtualMachineManager vmManager, String mainC
return new DebugSession(vm);
}

public static IDebugSession launch(VirtualMachineManager vmManager, String mainClass, String programArguments, String vmArguments, List<String> classPaths,
String cwd, String[] envp) throws IOException, IllegalConnectorArgumentsException, VMStartException {
Copy link
Member

Choose a reason for hiding this comment

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

envp -> envVars

* 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[] envp) throws IOException, IllegalConnectorArgumentsException, VMStartException {
Copy link
Member

Choose a reason for hiding this comment

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

envp -> envVars

for (Entry<String, String> entry : launchArguments.env.entrySet()) {
// For duplicated variable, show a warning message.
if (environment.containsKey(entry.getKey())) {
logger.warning(String.format("There is the same variable '%s' existed in the system environment, "
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

// For duplicated variable, show a warning message.
if (environment.containsKey(entry.getKey())) {
logger.warning(String.format("There is the same variable '%s' existed in the system environment, "
+ "the program will use the newly configured variable to override the system environment variable.", entry.getKey()));
Copy link
Member

Choose a reason for hiding this comment

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

There are duplicated environment variables. The values specified in launch.json will be used. Here are the duplicated entries: env1, env2.

Map<String, String> environment = new HashMap<>(System.getenv());
for (Entry<String, String> entry : launchArguments.env.entrySet()) {
// For duplicated variable, show a warning message.
if (environment.containsKey(entry.getKey())) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggest finding all the duplicated entries and output one aggregated warning.

@@ -91,11 +94,30 @@ public void handle(Command command, Arguments arguments, Response response, IDeb
}
sourceProvider.initialize(options);

// Append environment to native environment.
String[] envp = null;
Copy link
Member

Choose a reason for hiding this comment

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

envp -> envVars

import com.sun.jdi.event.EventQueue;
import com.sun.jdi.request.EventRequestManager;

public class VirtualMachineLauncher {
Copy link
Member

Choose a reason for hiding this comment

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

This implementation is a bit overwhelming. I'll continue the review later.

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
* @param argument the string array arguments
* @return the encoded string
*/
public static String encodeArrayArgument(String[] argument) {
Copy link
Member

Choose a reason for hiding this comment

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

We already referenced the apache commons lib. We can still keep the function but please use org.apache.commons.lang3.StringUtils.join as implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My implementation is not to join the array but use the special rule to encode the string array. Can you explain why need to use StringUtils.join as implementation?

Copy link
Member

Choose a reason for hiding this comment

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

We can pair two calls to achieve what we want: StringUtils.join(args, '\n') and String.Utils.split(str, '\n')

Copy link
Contributor Author

@testforstephen testforstephen Oct 31, 2017

Choose a reason for hiding this comment

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

The environment variable may contain "\n" by itself, the join/split cannot handle this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use URLEncoder/Decoder to encode/decode string array.

* when the argument is not encoded by the rules defined in the encodeArrayArgument.
*/
public static String[] decodeArrayArgument(String argument) throws IllegalArgumentException {
if (argument == null) {
Copy link
Member

Choose a reason for hiding this comment

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

Here we can use org.apache.commons.lang3.StringUtils.split as impelemntation.

return vm;
}

private static String[] constructLaunchCommand(Map<String, ? extends Argument> launchingOptions, String address) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the implementation from the base class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

* @param args command line as a single string.
* @return the arguments array.
*/
private static List<String> parseArguments(String cmdStr) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the implementation from the base class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

return list;
}

class AdvancedStringArgumentImpl extends StringArgumentImpl implements StringArgument {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to implement this one? Seems the implementation does not do much...

Copy link
Contributor Author

@testforstephen testforstephen Oct 31, 2017

Choose a reason for hiding this comment

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

The base StringArgumentImpl doesn't expose it's constructor method (protected). Cannot access the constructor in our code.

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
* @param argument the string array arguments
* @return the encoded string
*/
public static String encodeArrayArgument(String[] argument) {
Copy link
Member

Choose a reason for hiding this comment

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

We can pair two calls to achieve what we want: StringUtils.join(args, '\n') and String.Utils.split(str, '\n')

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.

None yet

3 participants