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  import java.io.InputStream;
23  import java.io.OutputStream;
24  
25  import org.apache.maven.api.annotations.Nullable;
26  import org.apache.maven.api.cli.Invoker;
27  import org.apache.maven.api.cli.Parser;
28  import org.apache.maven.api.cli.ParserRequest;
29  import org.apache.maven.cling.invoker.ProtoLookup;
30  import org.apache.maven.cling.invoker.mvn.MavenInvoker;
31  import org.apache.maven.cling.invoker.mvn.MavenParser;
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, null, null, null, false);
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, null, null, null, false);
52      }
53  
54      /**
55       * ClassWorld Launcher "embedded" entry point: returning exitCode and accepts Class World and streams.
56       */
57      public static int main(
58              String[] args,
59              ClassWorld world,
60              @Nullable InputStream stdIn,
61              @Nullable OutputStream stdOut,
62              @Nullable OutputStream stdErr)
63              throws IOException {
64          return new MavenCling(world).run(args, stdIn, stdOut, stdErr, true);
65      }
66  
67      public MavenCling() {
68          super();
69      }
70  
71      public MavenCling(ClassWorld classWorld) {
72          super(classWorld);
73      }
74  
75      @Override
76      protected Invoker createInvoker() {
77          return new MavenInvoker(
78                  ProtoLookup.builder().addMapping(ClassWorld.class, classWorld).build());
79      }
80  
81      @Override
82      protected Parser createParser() {
83          return new MavenParser();
84      }
85  
86      @Override
87      protected ParserRequest.Builder createParserRequestBuilder(String[] args) {
88          return ParserRequest.mvn(args, createMessageBuilderFactory());
89      }
90  }