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