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.ArrayList;
22 import java.util.Collections;
23 import java.util.LinkedHashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.codehaus.plexus.util.StringUtils;
28
29
30
31
32 public class LifecyclePhase {
33
34 private List<LifecycleMojo> mojos;
35
36 public LifecyclePhase() {}
37
38 public LifecyclePhase(String goals) {
39 set(goals);
40 }
41
42 public List<LifecycleMojo> getMojos() {
43 return mojos;
44 }
45
46 public void setMojos(List<LifecycleMojo> mojos) {
47 this.mojos = mojos;
48 }
49
50 public void set(String goals) {
51 mojos = new ArrayList<>();
52
53 if (StringUtils.isNotEmpty(goals)) {
54 String[] mojoGoals = StringUtils.split(goals, ",");
55
56 for (String mojoGoal : mojoGoals) {
57 LifecycleMojo lifecycleMojo = new LifecycleMojo();
58 lifecycleMojo.setGoal(mojoGoal.trim());
59 mojos.add(lifecycleMojo);
60 }
61 }
62 }
63
64 @Override
65 public String toString() {
66 StringBuilder sb = new StringBuilder();
67 boolean first = true;
68 List<LifecycleMojo> mojos = getMojos();
69 if (mojos != null) {
70 for (LifecycleMojo mojo : mojos) {
71 if (first) {
72 first = false;
73 } else {
74 sb.append(',');
75 }
76 sb.append(mojo.getGoal());
77 }
78 }
79 return sb.toString();
80 }
81
82 @Deprecated
83 public static Map<String, String> toLegacyMap(Map<String, LifecyclePhase> lifecyclePhases) {
84 if (lifecyclePhases == null) {
85 return null;
86 }
87
88 if (lifecyclePhases.isEmpty()) {
89 return Collections.emptyMap();
90 }
91
92 Map<String, String> phases = new LinkedHashMap<>();
93 for (Map.Entry<String, LifecyclePhase> e : lifecyclePhases.entrySet()) {
94 phases.put(e.getKey(), e.getValue().toString());
95 }
96 return phases;
97 }
98 }