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