1 package org.apache.maven.lifecycle.mapping;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 import static java.util.function.Function.identity;
28 import static java.util.stream.Collectors.toMap;
29
30
31
32
33 public class DefaultLifecycleMapping
34 implements LifecycleMapping
35 {
36
37 private List<Lifecycle> lifecycles;
38
39 private Map<String, Lifecycle> lifecycleMap;
40
41
42 private Map<String, LifecyclePhase> phases;
43
44
45
46
47
48
49
50 @Deprecated
51 public DefaultLifecycleMapping()
52 {
53 }
54
55
56
57
58 public DefaultLifecycleMapping( final List<Lifecycle> lifecycles )
59 {
60 this.lifecycleMap = Collections.unmodifiableMap(
61 lifecycles.stream().collect( toMap( Lifecycle::getId, identity() ) )
62 );
63 }
64
65
66
67
68 private void initLifecycleMap()
69 {
70 if ( lifecycleMap == null )
71 {
72 lifecycleMap = new HashMap<>();
73
74 if ( lifecycles != null )
75 {
76 for ( Lifecycle lifecycle : lifecycles )
77 {
78 lifecycleMap.put( lifecycle.getId(), lifecycle );
79 }
80 }
81 else
82 {
83
84
85
86
87
88 String[] lifecycleIds = { "default", "clean", "site" };
89
90 for ( String lifecycleId : lifecycleIds )
91 {
92 Map<String, LifecyclePhase> phases = getLifecyclePhases( lifecycleId );
93 if ( phases != null )
94 {
95 Lifecycle lifecycle = new Lifecycle();
96
97 lifecycle.setId( lifecycleId );
98 lifecycle.setLifecyclePhases( phases );
99
100 lifecycleMap.put( lifecycleId, lifecycle );
101 }
102 }
103 }
104 }
105 }
106
107 @Override
108 public Map<String, Lifecycle> getLifecycles()
109 {
110 initLifecycleMap();
111
112 return lifecycleMap;
113 }
114
115 @Deprecated
116 @Override
117 public List<String> getOptionalMojos( String lifecycle )
118 {
119 return null;
120 }
121
122 private Map<String, LifecyclePhase> getLifecyclePhases( String lifecycle )
123 {
124 initLifecycleMap();
125
126 Lifecycle lifecycleMapping = lifecycleMap.get( lifecycle );
127
128 if ( lifecycleMapping != null )
129 {
130 return lifecycleMapping.getLifecyclePhases();
131 }
132 else if ( "default".equals( lifecycle ) )
133 {
134 return phases;
135 }
136 else
137 {
138 return null;
139 }
140 }
141
142 @Deprecated
143 @Override
144 public Map<String, String> getPhases( String lifecycle )
145 {
146 return LifecyclePhase.toLegacyMap( getLifecyclePhases( lifecycle ) );
147 }
148 }