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.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26
27
28
29 public class DefaultLifecycleMapping
30 implements LifecycleMapping
31 {
32
33 private List<Lifecycle> lifecycles;
34
35 private Map<String, Lifecycle> lifecycleMap;
36
37
38 private Map<String, LifecyclePhase> phases;
39
40
41
42
43 private void initLifecycleMap()
44 {
45 if ( lifecycleMap == null )
46 {
47 lifecycleMap = new HashMap<>();
48
49 if ( lifecycles != null )
50 {
51 for ( Lifecycle lifecycle : lifecycles )
52 {
53 lifecycleMap.put( lifecycle.getId(), lifecycle );
54 }
55 }
56 else
57 {
58
59
60
61
62
63 String[] lifecycleIds = { "default", "clean", "site" };
64
65 for ( String lifecycleId : lifecycleIds )
66 {
67 Map<String, LifecyclePhase> phases = getLifecyclePhases( lifecycleId );
68 if ( phases != null )
69 {
70 Lifecycle lifecycle = new Lifecycle();
71
72 lifecycle.setId( lifecycleId );
73 lifecycle.setLifecyclePhases( phases );
74
75 lifecycleMap.put( lifecycleId, lifecycle );
76 }
77 }
78 }
79 }
80 }
81
82 public Map<String, Lifecycle> getLifecycles()
83 {
84 initLifecycleMap();
85
86 return lifecycleMap;
87 }
88
89 public List<String> getOptionalMojos( String lifecycle )
90 {
91 return null;
92 }
93
94 private Map<String, LifecyclePhase> getLifecyclePhases( String lifecycle )
95 {
96 initLifecycleMap();
97
98 Lifecycle lifecycleMapping = lifecycleMap.get( lifecycle );
99
100 if ( lifecycleMapping != null )
101 {
102 return lifecycleMapping.getLifecyclePhases();
103 }
104 else if ( "default".equals( lifecycle ) )
105 {
106 return phases;
107 }
108 else
109 {
110 return null;
111 }
112 }
113
114 @Deprecated
115 public Map<String, String> getPhases( String lifecycle )
116 {
117 return LifecyclePhase.toLegacyMap( getLifecyclePhases( lifecycle ) );
118 }
119
120 }