1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.apache.maven.cling.invoker.mvnsh;
20  
21  import java.util.Collections;
22  import java.util.List;
23  
24  import org.apache.commons.cli.ParseException;
25  import org.apache.maven.api.cli.Options;
26  import org.apache.maven.api.cli.mvnsh.ShellOptions;
27  import org.apache.maven.cling.invoker.BaseParser;
28  
29  public class ShellParser extends BaseParser {
30      @Override
31      protected ShellOptions emptyOptions() {
32          try {
33              return CommonsCliShellOptions.parse(new String[0]);
34          } catch (ParseException e) {
35              throw new IllegalArgumentException(e);
36          }
37      }
38  
39      @Override
40      protected ShellInvokerRequest getInvokerRequest(LocalContext context) {
41          return new ShellInvokerRequest(
42                  context.parserRequest,
43                  context.parsingFailed,
44                  context.cwd,
45                  context.installationDirectory,
46                  context.userHomeDirectory,
47                  context.userProperties,
48                  context.systemProperties,
49                  context.topDirectory,
50                  context.rootDirectory,
51                  context.extensions,
52                  (ShellOptions) context.options);
53      }
54  
55      @Override
56      protected List<Options> parseCliOptions(LocalContext context) {
57          return Collections.singletonList(parseShellCliOptions(context.parserRequest.args()));
58      }
59  
60      protected CommonsCliShellOptions parseShellCliOptions(List<String> args) {
61          try {
62              return CommonsCliShellOptions.parse(args.toArray(new String[0]));
63          } catch (ParseException e) {
64              throw new IllegalArgumentException("Failed to parse command line options: " + e.getMessage(), e);
65          }
66      }
67  
68      @Override
69      protected Options assembleOptions(List<Options> parsedOptions) {
70          
71          return parsedOptions.get(0);
72      }
73  }