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.Iterator;
24 import java.util.List;
25 import java.util.Map;
26
27 /**
28 * Lifecycle mapping for a POM.
29 *
30 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
31 * @version $Id: DefaultLifecycleMapping.java 640549 2008-03-24 20:05:11Z bentmann $
32 */
33 public class DefaultLifecycleMapping
34 implements LifecycleMapping
35 {
36 private List lifecycles;
37
38 private Map lifecycleMap;
39
40 /** @deprecated use lifecycles instead */
41 private Map phases;
42
43 public List getOptionalMojos( String lifecycle )
44 {
45 if ( lifecycleMap == null )
46 {
47 lifecycleMap = new HashMap();
48
49 if ( lifecycles != null )
50 {
51 for ( Iterator i = lifecycles.iterator(); i.hasNext(); )
52 {
53 Lifecycle l = (Lifecycle) i.next();
54 lifecycleMap.put( l.getId(), l );
55 }
56 }
57 }
58 Lifecycle l = (Lifecycle) lifecycleMap.get( lifecycle );
59
60 if ( l != null )
61 {
62 return l.getOptionalMojos();
63 }
64 else
65 {
66 return null;
67 }
68 }
69
70 public Map getPhases( String lifecycle )
71 {
72 if ( lifecycleMap == null )
73 {
74 lifecycleMap = new HashMap();
75
76 if ( lifecycles != null )
77 {
78 for ( Iterator i = lifecycles.iterator(); i.hasNext(); )
79 {
80 Lifecycle l = (Lifecycle) i.next();
81 lifecycleMap.put( l.getId(), l );
82 }
83 }
84 }
85 Lifecycle l = (Lifecycle) lifecycleMap.get( lifecycle );
86
87 Map mappings = null;
88 if ( l == null )
89 {
90 if ( "default".equals( lifecycle ) )
91 {
92 mappings = phases;
93 }
94 }
95 else
96 {
97 mappings = l.getPhases();
98 }
99
100 return mappings;
101 }
102
103 }