Bug 209559 - Sendopts API hard to use
Sendopts API hard to use
Status: RESOLVED FIXED
Product: platform
Classification: Unclassified
Component: Launchers&CLI
7.2
PC Linux
: P2 (vote)
: 7.2
Assigned To: Jaroslav Tulach
issues@platform
: API_REVIEW_FAST
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-03-14 09:12 UTC by Petr Hrebejk
Modified: 2012-03-22 11:13 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Hrebejk 2012-03-14 09:12:27 UTC
1. Sendopts should be standalone library. But using CommandLine.usage() results into CNFE (NbBundle)

2. It would be nice if Env would contain the usage method to be able to react to --help option in the process method of implementation of ArgsProcessor

3. An option with @Arg(implicit = true) still requires long name. Without a fake long name it does not get handled.

4. If the param array of CommandLine.process is empty the ArgProcessor is not called. Which may or may not be intentional (don't know)

5. Javadoc should encourage the usage of ArgsProcessor. It is really hard to find out how to get the options processed.
Comment 1 Jaroslav Tulach 2012-03-15 10:01:56 UTC
#1 addressed in ergonomics#54c0eca30d5c
Comment 2 Jaroslav Tulach 2012-03-15 10:27:40 UTC
#5 addressed in ergonomics#5caef2783920
Comment 3 Jaroslav Tulach 2012-03-15 14:43:44 UTC
#3 - Since ergonomics#5630f2e4ddd3 either long or short name is required
Comment 4 Jaroslav Tulach 2012-03-15 15:31:05 UTC
#2 implemented in http://hg.netbeans.org/ergonomics/rev/6892e1e02b9b which should be reviewed as an API enhancement. 

#4 is still not addressed and it is not clear how to address it. It does not make much sense to introduce an artificial field (annotated with @Arg) which will not be used for anything. It might make sense to create a special annotation for the class that implements ArgsProcessor (or Runnable) to tell the system this class is about to be called everytime.Something like 

@ArgsPolicy(always=true)
class MyOptions implements Runnable {
  public void run() { /* always called */ }
}

An enhancement would be to tight this behavior to grouping of options (not implemented when using @Arg now). In such case there would be 

@ArgsGrouping(GroupingPolicy.ANY) /* values {ALL|ANY|ONE|SOME} as defined by http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-sendopts/org/netbeans/spi/sendopts/OptionGroups.html */
class MyOptions implements Runnable {
  public @Arg(longName="nomatch") String never;

  public void run() {
    // called if 0-n options is matches - e.g. always.
  }
}

the grouping is however a complex operation that will need to wait. To match with functionality of OptionGroups, it needs to support subgroups of options - which would best be expressed as an fields of complex type

  public MySubOptions subOptions;

where the class MySubOptions could have its own fields annotated by @Arg. This is complex and will not happen for 7.2. I am afraid.
Comment 5 Quality Engineering 2012-03-17 10:37:48 UTC
Integrated into 'main-golden', will be available in build *201203170400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/54c0eca30d5c
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #209559: Point 1: CommandLine.usage() works in standalone mode (without openide.util and openide.util.lookup)
Comment 6 Jesse Glick 2012-03-20 03:51:49 UTC
#1 is contrary to standard practice in any other API - you are assumed to have transitive dependencies on classpath.
Comment 7 Petr Hrebejk 2012-03-20 08:52:41 UTC
Ad JG #1. Don't agree. Sendopts has offers some additional features when used in NetBeans, but is capable of running as standalone library. Transitive deps of sendopts is 2 jars of more than 1M size. I don't see why people using the lib in a small command line utility should make theirs distro 1M larger when not necessary.
Comment 8 Petr Hrebejk 2012-03-20 08:56:53 UTC
#6 (Additionl bug) Sendopts jar contains OptionAnnotationProcessor. When used as standalone lib and added into a plain J2SE project, the processor likely throws and exception and stops the building process. That results in an empty .jar (not containig any classes) in the dist folder after running "Clean & Build" or "ant jar.". For printing out the ex use -Xdev as javac option (may be)
Comment 9 Jaroslav Tulach 2012-03-20 10:29:58 UTC
#6 fixed in 2b954be54bfa
Comment 10 Jesse Glick 2012-03-20 18:14:30 UTC
(In reply to comment #7)
> Sendopts has offers some additional features when used
> in NetBeans, but is capable of running as standalone library.

True, but the same is true of plenty of NB APIs. Refactoring Platform API modules to minimize the size of the dependency footprint from any given starting point is always beneficial, but we do not advocate running any other APIs with some of their declared dependencies missing.

> people using the lib in a small command line utility

Why? Its raison d'être is to send CLI commands to a running NB Platform-based app using CLIHandler based on $userdir/lock. If you just want a lightweight argument processor for a standalone CLI utility (not making a connection to a running app), use args4j or Commons CLI or the like.
Comment 11 Jaroslav Tulach 2012-03-21 10:05:51 UTC
(In reply to comment #10)
> If you just want a lightweight
> argument processor for a standalone CLI utility (not making a connection to a
> running app), use args4j or Commons CLI or the like.

In case this bug is found by someone interested in CLI parsing library, please ignore the above comment and feel free to use sendopts. It is my intention to make it usable as a standalone API.
Comment 12 Jaroslav Tulach 2012-03-22 09:33:19 UTC
I think all the issues are fixed, except the #4 - to support grouping/always present option. That one is more an enhancement and will be implemented as soon as somebody finds time and will to do it. Closing for now.
Comment 13 Quality Engineering 2012-03-22 11:13:43 UTC
Integrated into 'main-golden', will be available in build *201203220400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/2b954be54bfa
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #209559: Point #6 - making sure the annotation processor is disabled in standalone mode


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo