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