View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.cling.invoker.mvn.forked;
20  
21  import java.nio.file.Path;
22  import java.util.List;
23  
24  import org.apache.commons.cli.ParseException;
25  import org.apache.maven.api.cli.ParserException;
26  import org.apache.maven.api.cli.mvn.MavenOptions;
27  import org.apache.maven.api.cli.mvn.forked.ForkedMavenInvokerRequest;
28  import org.apache.maven.api.cli.mvn.forked.ForkedMavenParser;
29  import org.apache.maven.cling.invoker.mvn.BaseMavenParser;
30  import org.apache.maven.cling.invoker.mvn.CommonsCliMavenOptions;
31  import org.apache.maven.cling.invoker.mvn.LayeredMavenOptions;
32  
33  public class DefaultForkedMavenParser extends BaseMavenParser<MavenOptions, ForkedMavenInvokerRequest>
34          implements ForkedMavenParser {
35  
36      @SuppressWarnings("ParameterNumber")
37      @Override
38      protected ForkedMavenInvokerRequest getInvokerRequest(LocalContext context) {
39          return new DefaultForkedMavenInvokerRequest(
40                  context.parserRequest,
41                  context.cwd,
42                  context.installationDirectory,
43                  context.userHomeDirectory,
44                  context.userProperties,
45                  context.systemProperties,
46                  context.topDirectory,
47                  context.rootDirectory,
48                  context.parserRequest.in(),
49                  context.parserRequest.out(),
50                  context.parserRequest.err(),
51                  context.extensions,
52                  getJvmArguments(context.rootDirectory),
53                  (MavenOptions) context.options);
54      }
55  
56      protected List<String> getJvmArguments(Path rootDirectory) {
57          if (rootDirectory != null) {
58              // TODO: do this
59              return null;
60          }
61          return null;
62      }
63  
64      // TODO: same is in DefaultMavenParser!!! (duplication)
65      @Override
66      protected MavenOptions parseArgs(String source, List<String> args) throws ParserException {
67          try {
68              return CommonsCliMavenOptions.parse(source, args.toArray(new String[0]));
69          } catch (ParseException e) {
70              throw new ParserException("Failed to parse source " + source, e.getCause());
71          }
72      }
73  
74      // TODO: same is in DefaultMavenParser!!! (duplication)
75      @Override
76      protected MavenOptions assembleOptions(List<MavenOptions> parsedOptions) {
77          return LayeredMavenOptions.layerMavenOptions(parsedOptions);
78      }
79  }