1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.lifecycle;
20
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.stream.Collectors;
26
27 import org.apache.maven.lifecycle.mapping.LifecyclePhase;
28
29
30
31
32 public class Lifecycle {
33 public Lifecycle() {}
34
35 public Lifecycle(String id, List<String> phases, Map<String, LifecyclePhase> defaultPhases) {
36 this.id = id;
37 this.phases = phases;
38 this.defaultPhases = defaultPhases;
39 }
40
41 public Lifecycle(
42 org.apache.maven.api.services.LifecycleRegistry registry, org.apache.maven.api.Lifecycle lifecycle) {
43 this.lifecycle = lifecycle;
44 this.id = lifecycle.id();
45 this.phases = registry.computePhases(lifecycle);
46 this.defaultPhases = getDefaultPhases(lifecycle);
47 }
48
49
50
51
52
53
54
55
56
57
58
59
60
61 private String id;
62
63 private List<String> phases;
64
65 private Map<String, LifecyclePhase> defaultPhases;
66
67 private org.apache.maven.api.Lifecycle lifecycle;
68
69 public String getId() {
70 return id;
71 }
72
73 public org.apache.maven.api.Lifecycle getDelegate() {
74 return lifecycle;
75 }
76
77 public List<String> getPhases() {
78 return phases;
79 }
80
81 static Map<String, LifecyclePhase> getDefaultPhases(org.apache.maven.api.Lifecycle lifecycle) {
82 Map<String, List<String>> goals = new HashMap<>();
83 lifecycle.allPhases().forEach(phase -> phase.plugins()
84 .forEach(plugin -> plugin.getExecutions().forEach(exec -> exec.getGoals()
85 .forEach(goal -> goals.computeIfAbsent(phase.name(), n -> new ArrayList<>())
86 .add(plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion()
87 + ":" + goal)))));
88 return goals.entrySet().stream()
89 .collect(Collectors.toMap(Map.Entry::getKey, e -> new LifecyclePhase(String.join(",", e.getValue()))));
90 }
91
92 public Map<String, LifecyclePhase> getDefaultLifecyclePhases() {
93 return defaultPhases;
94 }
95
96 @Deprecated
97 public Map<String, String> getDefaultPhases() {
98 return LifecyclePhase.toLegacyMap(getDefaultLifecyclePhases());
99 }
100
101 @Override
102 public String toString() {
103 return id + " -> "
104 + lifecycle
105 .allPhases()
106 .map(org.apache.maven.api.Lifecycle.Phase::name)
107 .collect(Collectors.joining(", ", "[", "]"));
108 }
109 }