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