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