1 package org.apache.maven.lifecycle;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.plexus.component.annotations.Component;
23 import org.codehaus.plexus.component.annotations.Requirement;
24 import org.codehaus.plexus.logging.Logger;
25 import org.codehaus.plexus.util.StringUtils;
26
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.HashMap;
30 import java.util.LinkedHashMap;
31 import java.util.LinkedHashSet;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Set;
35
36
37
38
39
40
41
42
43 @Component( role = DefaultLifecycles.class )
44 public class DefaultLifecycles
45 {
46 public static final String[] STANDARD_LIFECYCLES = { "default", "clean", "site" };
47
48
49
50 @Requirement( role = Lifecycle.class )
51 private Map<String, Lifecycle> lifecycles;
52
53 @Requirement
54 private Logger logger;
55
56 @SuppressWarnings( { "UnusedDeclaration" } )
57 public DefaultLifecycles()
58 {
59 }
60
61 public DefaultLifecycles( Map<String, Lifecycle> lifecycles, Logger logger )
62 {
63 this.lifecycles = new LinkedHashMap<String, Lifecycle>();
64 this.logger = logger;
65 this.lifecycles = lifecycles;
66 }
67
68 public Lifecycle get( String key )
69 {
70 return getPhaseToLifecycleMap().get( key );
71 }
72
73
74
75
76
77
78
79 public Map<String, Lifecycle> getPhaseToLifecycleMap()
80 {
81
82
83
84 HashMap<String, Lifecycle> phaseToLifecycleMap = new HashMap<String, Lifecycle>();
85
86 for ( Lifecycle lifecycle : getLifeCycles() )
87 {
88 if ( logger.isDebugEnabled() )
89 {
90 logger.debug( "Lifecycle " + lifecycle );
91 }
92
93 for ( String phase : lifecycle.getPhases() )
94 {
95
96 if ( !phaseToLifecycleMap.containsKey( phase ) )
97 {
98 phaseToLifecycleMap.put( phase, lifecycle );
99 }
100 else
101 {
102 Lifecycle original = phaseToLifecycleMap.get( phase );
103 logger.warn( "Duplicated lifecycle phase " + phase + ". Defined in " + original.getId()
104 + " but also in " + lifecycle.getId() );
105 }
106 }
107 }
108
109 return phaseToLifecycleMap;
110 }
111
112 public List<Lifecycle> getLifeCycles()
113 {
114
115
116 Map<String, Lifecycle> lifecycles = new LinkedHashMap<String, Lifecycle>( this.lifecycles );
117
118 LinkedHashSet<String> lifecycleNames = new LinkedHashSet<String>( Arrays.asList( STANDARD_LIFECYCLES ) );
119 lifecycleNames.addAll( lifecycles.keySet() );
120 ArrayList<Lifecycle> result = new ArrayList<Lifecycle>();
121 for ( String name : lifecycleNames )
122 {
123 result.add( lifecycles.get( name ) );
124 }
125
126 return result;
127 }
128
129 public String getLifecyclePhaseList()
130 {
131 Set<String> phases = new LinkedHashSet<String>();
132
133 for ( Lifecycle lifecycle : lifecycles.values() )
134 {
135 phases.addAll( lifecycle.getPhases() );
136 }
137
138 return StringUtils.join( phases.iterator(), ", " );
139 }
140
141 }