View Javadoc

1   package org.apache.maven.lifecycle.mapping;
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.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  
26  public class DefaultLifecycleMapping
27      implements LifecycleMapping
28  {
29  
30      private List<Lifecycle> lifecycles;
31  
32      private Map<String, Lifecycle> lifecycleMap;
33  
34      /** @deprecated use lifecycles instead */
35      private Map<String, String> phases;
36  
37      /**
38       * Populates the lifecycle map from the injected list of lifecycle mappings (if not already done).
39       */
40      private void initLifecycleMap()
41      {
42          if ( lifecycleMap == null )
43          {
44              lifecycleMap = new HashMap<String, Lifecycle>();
45  
46              if ( lifecycles != null )
47              {
48                  for ( Lifecycle lifecycle : lifecycles )
49                  {
50                      lifecycleMap.put( lifecycle.getId(), lifecycle );
51                  }
52              }
53              else
54              {
55                  /*
56                   * NOTE: This is to provide a migration path for implementors of the legacy API which did not know about
57                   * getLifecycles().
58                   */
59  
60                  String[] lifecycleIds = { "default", "clean", "site" };
61  
62                  for ( String lifecycleId : lifecycleIds )
63                  {
64                      Map<String, String> phases = getPhases( lifecycleId );
65                      if ( phases != null )
66                      {
67                          Lifecycle lifecycle = new Lifecycle();
68  
69                          lifecycle.setId( lifecycleId );
70                          lifecycle.setPhases( phases );
71  
72                          lifecycleMap.put( lifecycleId, lifecycle );
73                      }
74                  }
75              }
76          }
77      }
78  
79      public Map<String, Lifecycle> getLifecycles()
80      {
81          initLifecycleMap();
82  
83          return lifecycleMap;
84      }
85  
86      public List<String> getOptionalMojos( String lifecycle )
87      {
88          return null;
89      }
90  
91      public Map<String, String> getPhases( String lifecycle )
92      {
93          initLifecycleMap();
94  
95          Lifecycle lifecycleMapping = lifecycleMap.get( lifecycle );
96  
97          if ( lifecycleMapping != null )
98          {
99              return lifecycleMapping.getPhases();
100         }
101         else if ( "default".equals( lifecycle ) )
102         {
103             return phases;
104         }
105         else
106         {
107             return null;
108         }
109     }
110 
111 }