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;
20  
21  import java.io.IOException;
22  
23  import org.apache.maven.api.cli.Invoker;
24  import org.apache.maven.api.cli.InvokerRequest;
25  import org.apache.maven.api.cli.ParserException;
26  import org.apache.maven.api.cli.ParserRequest;
27  import org.apache.maven.cling.invoker.ProtoLogger;
28  import org.apache.maven.cling.invoker.ProtoLookup;
29  import org.apache.maven.cling.invoker.mvn.MavenParser;
30  import org.apache.maven.cling.invoker.mvn.local.LocalMavenInvoker;
31  import org.apache.maven.jline.JLineMessageBuilderFactory;
32  import org.codehaus.plexus.classworlds.ClassWorld;
33  
34  /**
35   * Maven CLI "new-gen".
36   */
37  public class MavenCling extends ClingSupport {
38      /**
39       * "Normal" Java entry point. Note: Maven uses ClassWorld Launcher and this entry point is NOT used under normal
40       * circumstances.
41       */
42      public static void main(String[] args) throws IOException {
43          int exitCode = new MavenCling().run(args);
44          System.exit(exitCode);
45      }
46  
47      /**
48       * ClassWorld Launcher "enhanced" entry point: returning exitCode and accepts Class World.
49       */
50      public static int main(String[] args, ClassWorld world) throws IOException {
51          return new MavenCling(world).run(args);
52      }
53  
54      public MavenCling() {
55          super();
56      }
57  
58      public MavenCling(ClassWorld classWorld) {
59          super(classWorld);
60      }
61  
62      @Override
63      protected Invoker createInvoker() {
64          return new LocalMavenInvoker(
65                  ProtoLookup.builder().addMapping(ClassWorld.class, classWorld).build());
66      }
67  
68      @Override
69      protected InvokerRequest parseArguments(String[] args) throws ParserException, IOException {
70          return new MavenParser()
71                  .parseInvocation(ParserRequest.mvn(args, new ProtoLogger(), new JLineMessageBuilderFactory())
72                          .build());
73      }
74  }