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