Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 327082 - [launch] Trim param name and value
Summary: [launch] Trim param name and value
Status: NEW
Alias: None
Product: EMFT
Classification: Modeling
Component: MWE (show other bugs)
Version: 1.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-06 06:08 EDT by Karsten Thoms CLA
Modified: 2010-10-11 07:24 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karsten Thoms CLA 2010-10-06 06:08:24 EDT
If using whitespace after "-p" the parameter name and value contains those values. Therefore these values should be trimmed.

See Mwe2Launcher, lines 64/65

String name = string.substring(0, index);
String value = string.substring(index + 1);

Change to:
String name = string.substring(0, index).trim();
String value = string.substring(index + 1).trim();


See class WorkflowRunner, line 265

params.put(string[0], string[1]);

Change to:
params.put(string[0].trim(), string[1].trim());
Comment 1 Sebastian Zarnekow CLA 2010-10-06 07:23:48 EDT
Spaces usually seperate command line args while name=value is exactly one arg. Furthermore I can imagine clients who actually want to pass a single space or a tab as an argument e.g. to affect the indentation of the generated code.
As the docs are clear about name=value instead of name = value I'd like to close this as won't fix.
Comment 2 Sven Efftinge CLA 2010-10-06 07:44:16 EDT
I tried 
 -p a=x b="foo bar" 
and got two params a and b (no white space) and the expected values as well.
I tried 
 -p a = x 
and the command line parser interprets them as three parameters.

What scenario did you tried, which didn't result in what you'd expected?
Comment 3 Karsten Thoms CLA 2010-10-11 07:09:17 EDT
I have created a line "-p <key>=<value>" and passed that one to the main method. The parameter key was interpreted with whitespace in front, so instead of having a parameter "<key>" the parameter name is " <key>". I had to make the line to "-p<key>=<value>" to get it work.

Although the docs state "<key>=<value>" they do not make a hint that after "-p" there must be no space. The command line help even hints to add the space.

 -p, --param <key>=<value>  external property ....

I think it should work both with leading space or without.

If you want to pass whitespace explicitly as argument you always have the option to quote that, and this would even the better way to express it on the command-line.
Comment 4 Sven Efftinge CLA 2010-10-11 07:24:41 EDT
Java splits and trims the command line, so that "-p foo=bar" becomes two entries in the passed array.
The API is explaining the command line interface and it is not meant to be called directly from Java.
You can do so, though, but I don't want to add splitting and trimming to the passed String[] in order to make it more forgiving. I tried to make the Mwe2Launcher as thin as possible, such that it acts as a command line facade only.

You should instead use the programming API which is Mwe2Runner.