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