View Javadoc
1   package org.apache.maven.lifecycle.providers.packaging;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Collections;
23  import java.util.HashMap;
24  
25  import javax.inject.Provider;
26  
27  import org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping;
28  import org.apache.maven.lifecycle.mapping.Lifecycle;
29  import org.apache.maven.lifecycle.mapping.LifecycleMapping;
30  import org.apache.maven.lifecycle.mapping.LifecyclePhase;
31  
32  import static java.util.Objects.requireNonNull;
33  
34  /**
35   * Base lifecycle mapping provider, ie per-packaging plugin bindings for {@code default} lifecycle.
36   */
37  public abstract class AbstractLifecycleMappingProvider
38      implements Provider<LifecycleMapping>
39  {
40      protected static final String RESOURCES_PLUGIN_VERSION = "3.2.0";
41  
42      protected static final String COMPILER_PLUGIN_VERSION = "3.8.1";
43  
44      protected static final String SUREFIRE_PLUGIN_VERSION = "3.0.0-M5";
45  
46      protected static final String INSTALL_PLUGIN_VERSION = "3.0.0-M1";
47  
48      protected static final String DEPLOY_PLUGIN_VERSION = "3.0.0-M2";
49  
50      // packaging
51  
52      protected static final String JAR_PLUGIN_VERSION = "3.2.0";
53  
54      protected static final String EAR_PLUGIN_VERSION = "3.1.2";
55  
56      protected static final String EJB_PLUGIN_VERSION = "3.1.0";
57  
58      protected static final String PLUGIN_PLUGIN_VERSION = "3.6.0";
59  
60      protected static final String RAR_PLUGIN_VERSION = "2.4"; // TODO: Update!!!
61  
62      protected static final String WAR_PLUGIN_VERSION = "3.3.1";
63  
64      private final LifecycleMapping lifecycleMapping;
65  
66      protected AbstractLifecycleMappingProvider( String[] pluginBindings )
67      {
68          requireNonNull( pluginBindings );
69          final int len = pluginBindings.length;
70          if ( len < 2 || len % 2 != 0 )
71          {
72              throw new IllegalArgumentException( "Plugin bindings must have more than 0, even count of elements" );
73          }
74  
75          HashMap<String, LifecyclePhase> lifecyclePhaseBindings = new HashMap<>( len / 2 );
76          for ( int i = 0; i < len; i = i + 2 )
77          {
78              lifecyclePhaseBindings.put( pluginBindings[i], new LifecyclePhase( pluginBindings[i + 1] ) );
79          }
80  
81          Lifecycle lifecycle = new Lifecycle();
82          lifecycle.setId( "default" );
83          lifecycle.setLifecyclePhases( Collections.unmodifiableMap( lifecyclePhaseBindings ) );
84  
85          this.lifecycleMapping = new DefaultLifecycleMapping( Collections.singletonList( lifecycle ) );
86      }
87  
88      @Override
89      public LifecycleMapping get()
90      {
91          return lifecycleMapping;
92      }
93  }