1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.execution;
20
21 import java.time.Duration;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.apache.maven.artifact.ArtifactUtils;
28 import org.apache.maven.plugin.descriptor.PluginDescriptor;
29 import org.apache.maven.project.CycleDetectedException;
30 import org.apache.maven.project.DuplicateProjectException;
31 import org.apache.maven.project.MavenProject;
32 import org.apache.maven.project.ProjectSorter;
33
34
35
36
37 @Deprecated
38 public class ReactorManager {
39 public static final String FAIL_FAST = "fail-fast";
40
41 public static final String FAIL_AT_END = "fail-at-end";
42
43 public static final String FAIL_NEVER = "fail-never";
44
45 public static final String MAKE_MODE = "make";
46
47 public static final String MAKE_DEPENDENTS_MODE = "make-dependents";
48
49
50 public static final String MAKE_BOTH_MODE = "make-both";
51
52 private List<String> blackList = new ArrayList<>();
53
54 private Map<String, BuildFailure> buildFailuresByProject = new HashMap<>();
55
56 private Map<String, Map<String, Map>> pluginContextsByProjectAndPluginKey = new HashMap<>();
57
58 private String failureBehavior = FAIL_FAST;
59
60 private final ProjectSorter sorter;
61
62 private Map<String, BuildSuccess> buildSuccessesByProject = new HashMap<>();
63
64 public ReactorManager(List<MavenProject> projects) throws CycleDetectedException, DuplicateProjectException {
65 this.sorter = new ProjectSorter(projects);
66 }
67
68 public Map getPluginContext(PluginDescriptor plugin, MavenProject project) {
69 Map<String, Map> pluginContextsByKey =
70 pluginContextsByProjectAndPluginKey.computeIfAbsent(project.getId(), k -> new HashMap<>());
71
72 return pluginContextsByKey.computeIfAbsent(plugin.getPluginLookupKey(), k -> new HashMap<>());
73 }
74
75 public void setFailureBehavior(String failureBehavior) {
76 if (failureBehavior == null) {
77 this.failureBehavior = FAIL_FAST;
78 return;
79 }
80 if (FAIL_FAST.equals(failureBehavior)
81 || FAIL_AT_END.equals(failureBehavior)
82 || FAIL_NEVER.equals(failureBehavior)) {
83 this.failureBehavior = failureBehavior;
84 } else {
85 throw new IllegalArgumentException("Invalid failure behavior (must be one of: '" + FAIL_FAST + "', '"
86 + FAIL_AT_END + "', '" + FAIL_NEVER + "').");
87 }
88 }
89
90 public String getFailureBehavior() {
91 return failureBehavior;
92 }
93
94 public void blackList(MavenProject project) {
95 blackList(getProjectKey(project));
96 }
97
98 private void blackList(String id) {
99 if (!blackList.contains(id)) {
100 blackList.add(id);
101
102 List<String> dependents = sorter.getDependents(id);
103
104 if (dependents != null && !dependents.isEmpty()) {
105 for (String dependentId : dependents) {
106 if (!buildSuccessesByProject.containsKey(dependentId)
107 && !buildFailuresByProject.containsKey(dependentId)) {
108 blackList(dependentId);
109 }
110 }
111 }
112 }
113 }
114
115 public boolean isBlackListed(MavenProject project) {
116 return blackList.contains(getProjectKey(project));
117 }
118
119 private static String getProjectKey(MavenProject project) {
120 return ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId());
121 }
122
123 public void registerBuildFailure(MavenProject project, Exception error, String task, long time) {
124 buildFailuresByProject.put(getProjectKey(project), new BuildFailure(project, time, error));
125 }
126
127 public void registerBuildFailure(MavenProject project, Exception error, String task, Duration time) {
128 buildFailuresByProject.put(getProjectKey(project), new BuildFailure(project, time, error));
129 }
130
131 public boolean hasBuildFailures() {
132 return !buildFailuresByProject.isEmpty();
133 }
134
135 public boolean hasBuildFailure(MavenProject project) {
136 return buildFailuresByProject.containsKey(getProjectKey(project));
137 }
138
139 public boolean hasMultipleProjects() {
140 return sorter.hasMultipleProjects();
141 }
142
143 public List<MavenProject> getSortedProjects() {
144 return sorter.getSortedProjects();
145 }
146
147 public boolean hasBuildSuccess(MavenProject project) {
148 return buildSuccessesByProject.containsKey(getProjectKey(project));
149 }
150
151 public void registerBuildSuccess(MavenProject project, long time) {
152 buildSuccessesByProject.put(getProjectKey(project), new BuildSuccess(project, time));
153 }
154
155 public void registerBuildSuccess(MavenProject project, Duration time) {
156 buildSuccessesByProject.put(getProjectKey(project), new BuildSuccess(project, time));
157 }
158
159 public BuildFailure getBuildFailure(MavenProject project) {
160 return buildFailuresByProject.get(getProjectKey(project));
161 }
162
163 public BuildSuccess getBuildSuccess(MavenProject project) {
164 return buildSuccessesByProject.get(getProjectKey(project));
165 }
166
167 public boolean executedMultipleProjects() {
168 return buildFailuresByProject.size() + buildSuccessesByProject.size() > 1;
169 }
170 }