View Javadoc
1   package org.apache.maven.plugins.rar.internal;
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 javax.inject.Named;
23  import javax.inject.Provider;
24  import javax.inject.Singleton;
25  
26  import java.util.Collections;
27  import java.util.HashMap;
28  import java.util.List;
29  import java.util.Map;
30  
31  import org.apache.maven.lifecycle.mapping.Lifecycle;
32  import org.apache.maven.lifecycle.mapping.LifecycleMapping;
33  import org.apache.maven.lifecycle.mapping.LifecyclePhase;
34  
35  /**
36   * {@code rar} packaging plugins bindings provider for {@code default} lifecycle.
37   */
38  @Singleton
39  @Named( "rar" )
40  public final class RarLifecycleMappingProvider
41          implements Provider<LifecycleMapping>
42  {
43      // Note: "this" plugin does NOT have to have version specified, as the version should be specified in
44      // effective POM, otherwise this lifecycle mapping would not be loaded at all. Hence, the version of
45      // "this" plugin (in this case maven-rar-plugin) version is NEVER considered, and will come from
46      // effective POM of project using this plugin.
47      @SuppressWarnings( "checkstyle:linelength" )
48      private static final String[] BINDINGS =
49              {
50                      "process-resources", "org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources",
51                      "compile", "org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile",
52                      "process-test-resources", "org.apache.maven.plugins:maven-resources-plugin:3.2.0:testResources",
53                      "test-compile", "org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile",
54                      "test", "org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test",
55                      "package", "org.apache.maven.plugins:maven-rar-plugin:rar",
56                      "install", "org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install",
57                      "deploy", "org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy"
58              };
59  
60      private final Lifecycle defaultLifecycle;
61      private final LifecycleMapping lifecycleMapping;
62  
63      public RarLifecycleMappingProvider()
64      {
65          HashMap<String, LifecyclePhase> bindings = new HashMap<>();
66          for ( int i = 0; i < BINDINGS.length; i = i + 2 )
67          {
68              bindings.put( BINDINGS[i], new LifecyclePhase( BINDINGS[i + 1] ) );
69          }
70          this.defaultLifecycle = new Lifecycle();
71          this.defaultLifecycle.setId( "default" );
72          this.defaultLifecycle.setLifecyclePhases( bindings );
73  
74  
75          this.lifecycleMapping = new LifecycleMapping()
76          {
77              @Override
78              public Map<String, Lifecycle> getLifecycles()
79              {
80                  return Collections.singletonMap( "default", defaultLifecycle );
81              }
82  
83              @Override
84              public List<String> getOptionalMojos( String lifecycle )
85              {
86                  return null;
87              }
88  
89              @Override
90              public Map<String, String> getPhases( String lifecycle )
91              {
92                  if ( "default".equals( lifecycle ) )
93                  {
94                      return defaultLifecycle.getPhases();
95                  }
96                  else
97                  {
98                      return null;
99                  }
100             }
101         };
102     }
103 
104     @Override
105     public LifecycleMapping get()
106     {
107         return lifecycleMapping;
108     }
109 }