-
Notifications
You must be signed in to change notification settings - Fork 143
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
Conversation
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, |
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.
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 { |
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.
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 { |
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.
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, " |
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.
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())); |
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.
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())) { |
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.
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; |
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.
envp -> envVars
import com.sun.jdi.event.EventQueue; | ||
import com.sun.jdi.request.EventRequestManager; | ||
|
||
public class VirtualMachineLauncher { |
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.
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) { |
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.
We already referenced the apache commons lib. We can still keep the function but please use org.apache.commons.lang3.StringUtils.join as implementation
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.
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?
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.
We can pair two calls to achieve what we want: StringUtils.join(args, '\n') and String.Utils.split(str, '\n')
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.
The environment variable may contain "\n" by itself, the join/split cannot handle this case.
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.
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) { |
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.
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) { |
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.
Can we use the implementation from the base class?
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.
fixed.
* @param args command line as a single string. | ||
* @return the arguments array. | ||
*/ | ||
private static List<String> parseArguments(String cmdStr) { |
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.
Can we use the implementation from the base class?
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.
fixed.
return list; | ||
} | ||
|
||
class AdvancedStringArgumentImpl extends StringArgumentImpl implements StringArgument { |
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.
Why do we need to implement this one? Seems the implementation does not do much...
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.
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) { |
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.
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>
No description provided.