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
23 import org.apache.maven.artifact.ArtifactUtils;
24 import org.apache.maven.plugin.descriptor.PluginDescriptor;
25 import org.apache.maven.project.DuplicateProjectException;
26 import org.apache.maven.project.MavenProject;
27 import org.apache.maven.project.ProjectSorter;
28 import org.codehaus.plexus.util.dag.CycleDetectedException;
29
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.Iterator;
33 import java.util.List;
34 import java.util.Map;
35
36 @Deprecated
37 public class ReactorManager
38 {
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 blackList = new ArrayList();
53
54 private Map buildFailuresByProject = new HashMap();
55
56 private Map pluginContextsByProjectAndPluginKey = new HashMap();
57
58 private String failureBehavior = FAIL_FAST;
59
60 private final ProjectSorter sorter;
61
62 private Map buildSuccessesByProject = new HashMap();
63
64 public ReactorManager( List projects )
65 throws CycleDetectedException, DuplicateProjectException
66 {
67 this.sorter = new ProjectSorter( projects );
68 }
69
70 public Map getPluginContext( PluginDescriptor plugin, MavenProject project )
71 {
72 Map pluginContextsByKey = (Map) pluginContextsByProjectAndPluginKey.get( project.getId() );
73
74 if ( pluginContextsByKey == null )
75 {
76 pluginContextsByKey = new HashMap();
77 pluginContextsByProjectAndPluginKey.put( project.getId(), pluginContextsByKey );
78 }
79
80 Map pluginContext = (Map) pluginContextsByKey.get( plugin.getPluginLookupKey() );
81
82 if ( pluginContext == null )
83 {
84 pluginContext = new HashMap();
85 pluginContextsByKey.put( plugin.getPluginLookupKey(), pluginContext );
86 }
87
88 return pluginContext;
89 }
90
91 public void setFailureBehavior( String failureBehavior )
92 {
93 if ( failureBehavior == null )
94 {
95 this.failureBehavior = FAIL_FAST;
96 return;
97 }
98 if ( FAIL_FAST.equals( failureBehavior ) || FAIL_AT_END.equals( failureBehavior )
99 || FAIL_NEVER.equals( failureBehavior ) )
100 {
101 this.failureBehavior = failureBehavior;
102 }
103 else
104 {
105 throw new IllegalArgumentException( "Invalid failure behavior (must be one of: \'" + FAIL_FAST + "\', \'"
106 + FAIL_AT_END + "\', \'" + FAIL_NEVER + "\')." );
107 }
108 }
109
110 public String getFailureBehavior()
111 {
112 return failureBehavior;
113 }
114
115 public void blackList( MavenProject project )
116 {
117 blackList( getProjectKey( project ) );
118 }
119
120 private void blackList( String id )
121 {
122 if ( !blackList.contains( id ) )
123 {
124 blackList.add( id );
125
126 List dependents = sorter.getDependents( id );
127
128 if ( dependents != null && !dependents.isEmpty() )
129 {
130 for ( Object dependent : dependents )
131 {
132 String dependentId = (String) dependent;
133
134 if ( !buildSuccessesByProject.containsKey( dependentId ) && !buildFailuresByProject.containsKey(
135 dependentId ) )
136 {
137 blackList( dependentId );
138 }
139 }
140 }
141 }
142 }
143
144 public boolean isBlackListed( MavenProject project )
145 {
146 return blackList.contains( getProjectKey( project ) );
147 }
148
149 private static String getProjectKey( MavenProject project )
150 {
151 return ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
152 }
153
154 public void registerBuildFailure( MavenProject project, Exception error, String task, long time )
155 {
156 buildFailuresByProject.put( getProjectKey( project ), new BuildFailure( project, time, error ) );
157 }
158
159 public boolean hasBuildFailures()
160 {
161 return !buildFailuresByProject.isEmpty();
162 }
163
164 public boolean hasBuildFailure( MavenProject project )
165 {
166 return buildFailuresByProject.containsKey( getProjectKey( project ) );
167 }
168
169 public boolean hasMultipleProjects()
170 {
171 return sorter.hasMultipleProjects();
172 }
173
174 public List<MavenProject> getSortedProjects()
175 {
176 return sorter.getSortedProjects();
177 }
178
179 public MavenProject getTopLevelProject()
180 {
181 return sorter.getTopLevelProject();
182 }
183
184 public boolean hasBuildSuccess( MavenProject project )
185 {
186 return buildSuccessesByProject.containsKey( getProjectKey( project ) );
187 }
188
189 public void registerBuildSuccess( MavenProject project, long time )
190 {
191 buildSuccessesByProject.put( getProjectKey( project ), new BuildSuccess( project, time ) );
192 }
193
194 public BuildFailure getBuildFailure( MavenProject project )
195 {
196 return (BuildFailure) buildFailuresByProject.get( getProjectKey( project ) );
197 }
198
199 public BuildSuccess getBuildSuccess( MavenProject project )
200 {
201 return (BuildSuccess) buildSuccessesByProject.get( getProjectKey( project ) );
202 }
203
204 public boolean executedMultipleProjects()
205 {
206 return buildFailuresByProject.size() + buildSuccessesByProject.size() > 1;
207 }
208 }