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