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