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 import java.util.stream.Stream;
27
28 import org.apache.maven.lifecycle.mapping.LifecyclePhase;
29
30 import static org.apache.maven.api.Lifecycle.AFTER;
31 import static org.apache.maven.api.Lifecycle.BEFORE;
32
33
34
35
36 public class Lifecycle {
37 public Lifecycle() {}
38
39 public Lifecycle(String id, List<String> phases, Map<String, LifecyclePhase> defaultPhases) {
40 this.id = id;
41 this.phases = phases;
42 this.defaultPhases = defaultPhases;
43 }
44
45 public Lifecycle(
46 org.apache.maven.api.services.LifecycleRegistry registry, org.apache.maven.api.Lifecycle lifecycle) {
47 this.lifecycle = lifecycle;
48 this.id = lifecycle.id();
49 this.phases = registry.computePhases(lifecycle).stream()
50 .flatMap(p -> Stream.of(BEFORE + p, p, AFTER + p))
51 .toList();
52 this.defaultPhases = getDefaultPhases(lifecycle);
53 }
54
55
56
57
58
59
60
61
62
63
64
65
66
67 private String id;
68
69 private List<String> phases;
70
71 private Map<String, LifecyclePhase> defaultPhases;
72
73 private org.apache.maven.api.Lifecycle lifecycle;
74
75 public String getId() {
76 return id;
77 }
78
79 public org.apache.maven.api.Lifecycle getDelegate() {
80 return lifecycle;
81 }
82
83 public List<String> getPhases() {
84 return phases;
85 }
86
87 static Map<String, LifecyclePhase> getDefaultPhases(org.apache.maven.api.Lifecycle lifecycle) {
88 Map<String, List<String>> goals = new HashMap<>();
89 lifecycle.allPhases().forEach(phase -> phase.plugins()
90 .forEach(plugin -> plugin.getExecutions().forEach(exec -> exec.getGoals()
91 .forEach(goal -> goals.computeIfAbsent(phase.name(), n -> new ArrayList<>())
92 .add(plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion()
93 + ":" + goal)))));
94 return goals.entrySet().stream()
95 .collect(Collectors.toMap(Map.Entry::getKey, e -> new LifecyclePhase(String.join(",", e.getValue()))));
96 }
97
98 public Map<String, LifecyclePhase> getDefaultLifecyclePhases() {
99 return defaultPhases;
100 }
101
102 @Deprecated
103 public Map<String, String> getDefaultPhases() {
104 return LifecyclePhase.toLegacyMap(getDefaultLifecyclePhases());
105 }
106
107 @Override
108 public String toString() {
109 return id + " -> "
110 + lifecycle
111 .allPhases()
112 .map(org.apache.maven.api.Lifecycle.Phase::name)
113 .collect(Collectors.joining(", ", "[", "]"));
114 }
115 }