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.Arrays;
23 import java.util.Collections;
24 import java.util.LinkedHashMap;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Optional;
28 import java.util.function.Function;
29 import java.util.stream.Collectors;
30
31
32
33
34
35
36 public class LifecyclePhase {
37
38 private List<LifecycleMojo> mojos;
39
40 public LifecyclePhase() {}
41
42 public LifecyclePhase(String goals) {
43 set(goals);
44 }
45
46 public List<LifecycleMojo> getMojos() {
47 return mojos;
48 }
49
50 public void setMojos(List<LifecycleMojo> mojos) {
51 this.mojos = mojos;
52 }
53
54 public void set(String goals) {
55 mojos = new ArrayList<>();
56
57 if (goals != null && !goals.isEmpty()) {
58 String[] mojoGoals = goals.split(",");
59 mojos = Arrays.stream(mojoGoals).map(fromGoalIntoLifecycleMojo).collect(Collectors.toList());
60 }
61 }
62
63 private final Function<String, LifecycleMojo> fromGoalIntoLifecycleMojo = s -> {
64 LifecycleMojo lifecycleMojo = new LifecycleMojo();
65 lifecycleMojo.setGoal(s.trim());
66 return lifecycleMojo;
67 };
68
69 @Override
70 public String toString() {
71 return Optional.ofNullable(getMojos()).orElse(Collections.emptyList()).stream()
72 .map(LifecycleMojo::getGoal)
73 .collect(Collectors.joining(","));
74 }
75
76 @Deprecated
77 public static Map<String, String> toLegacyMap(Map<String, LifecyclePhase> lifecyclePhases) {
78 if (lifecyclePhases == null) {
79 return null;
80 }
81
82 if (lifecyclePhases.isEmpty()) {
83 return Collections.emptyMap();
84 }
85
86 Map<String, String> phases = new LinkedHashMap<>();
87 for (Map.Entry<String, LifecyclePhase> e : lifecyclePhases.entrySet()) {
88 phases.put(e.getKey(), e.getValue().toString());
89 }
90 return phases;
91 }
92 }