[rfc][icedtea-web] Option Parser

Jiri Vanek jvanek at redhat.com
Mon Aug 25 12:14:11 UTC 2014


On 08/22/2014 04:44 PM, Lukasz Dracz wrote:
> Hello,
>
> I refactored the way Boot parses arguments by creating an Option Parser to use. The reason is that this code could be reused in other parts, instead of writing duplicate code. I have also added unit tests for the parser.
>
> 2014-08-22  Lukasz Dracz  <ldracz at redhat.com>
>
>      Refactored parsing in Boot to use a new class Option Parser
>      * netx/net/sourceforge/jnlp/runtime/Boot.java:
>      (getOption, getOptions): removed
>      (OptionParser): added
>      * netx/net/sourceforge/jnlp/util/OptionParser.java:
>      new class (getArgs, checkOption, isOption, getOptionValue)
>      * tests/netx/unit/net/sourceforge/jnlp/util/OptionParserTest.java:
>      added unit tests for OptionParser (testGetSingleOptionValue,
>      testGetSingleOptionMultipleValues, testGetDifferentOptionValues,
>      testUnsupportedOptionValue, testSupportedOptionValueWithNoUse,
>      testOptionValueWithNoArgument, testOneOptionMultipleTimesMultipleValues,
>      testMultipleOptionsMultipleValues, testCheckOptionExists,
>      testCheckOptionExistsAsNotFirstArg, testCheckOptionNotExists,
>      testGetArgs, testGetArgsCantModifyValue)
>
> Thank you,
> Lukasz Dracz
>


Hi!

I like this  patch, but as omair pointed out, soem stuff needs to go elsewhere.

You need to get rid of doubleArgs, and of thet terrible Enum.

I would suggest you to change
public OptionParser(String[] args)

to

public OptionParser(String[] args, OptionParserConfig cfg)


Where  OptionParserConfig will be wrapper around list of
OptionParserConfigItem. You Will have threeinstances of it avaiable via factory method:
PolicyEditorOptionParserConfig
JavaWSOptionParserConfig
and
ItwSettingsOptionParserConfig


OptionParserConfigItem will consists from
getParamID - returns eg "-Xoffline"
getParamDescription - based on hardcoded key, will return description aded via Transaltor.R()
isDual  - needed for reading input String[]
and
getParam - some  params are in form "key" then  get param will return null. Some are in form "key" 
"value"  and osme in "key=value".
validateParam ? May check if last two of above are valid.


Otherwivese I'm really happy with this patch., It covered  boot's code which was really lacking any 
testing.

TYVM!


J.




More information about the distro-pkg-dev mailing list