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 = pluginContextsByProjectAndPluginKey.get( project.getId() );
74
75 if ( pluginContextsByKey == null )
76 {
77 pluginContextsByKey = new HashMap<>();
78 pluginContextsByProjectAndPluginKey.put( project.getId(), pluginContextsByKey );
79 }
80
81 Map pluginContext = pluginContextsByKey.get( plugin.getPluginLookupKey() );
82
83 if ( pluginContext == null )
84 {
85 pluginContext = new HashMap<>();
86 pluginContextsByKey.put( plugin.getPluginLookupKey(), pluginContext );
87 }
88
89 return pluginContext;
90 }
91
92 public void setFailureBehavior( String failureBehavior )
93 {
94 if ( failureBehavior == null )
95 {
96 this.failureBehavior = FAIL_FAST;
97 return;
98 }
99 if ( FAIL_FAST.equals( failureBehavior ) || FAIL_AT_END.equals( failureBehavior ) || FAIL_NEVER.equals(
100 failureBehavior ) )
101 {
102 this.failureBehavior = failureBehavior;
103 }
104 else
105 {
106 throw new IllegalArgumentException(
107 "Invalid failure behavior (must be one of: \'" + FAIL_FAST + "\', \'" + FAIL_AT_END + "\', \'"
108 + FAIL_NEVER + "\')." );
109 }
110 }
111
112 public String getFailureBehavior()
113 {
114 return failureBehavior;
115 }
116
117 public void blackList( MavenProject project )
118 {
119 blackList( getProjectKey( project ) );
120 }
121
122 private void blackList( String id )
123 {
124 if ( !blackList.contains( id ) )
125 {
126 blackList.add( id );
127
128 List<String> dependents = sorter.getDependents( id );
129
130 if ( dependents != null && !dependents.isEmpty() )
131 {
132 for ( String dependentId : dependents )
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 boolean hasBuildSuccess( MavenProject project )
180 {
181 return buildSuccessesByProject.containsKey( getProjectKey( project ) );
182 }
183
184 public void registerBuildSuccess( MavenProject project, long time )
185 {
186 buildSuccessesByProject.put( getProjectKey( project ), new BuildSuccess( project, time ) );
187 }
188
189 public BuildFailure getBuildFailure( MavenProject project )
190 {
191 return buildFailuresByProject.get( getProjectKey( project ) );
192 }
193
194 public BuildSuccess getBuildSuccess( MavenProject project )
195 {
196 return buildSuccessesByProject.get( getProjectKey( project ) );
197 }
198
199 public boolean executedMultipleProjects()
200 {
201 return buildFailuresByProject.size() + buildSuccessesByProject.size() > 1;
202 }
203 }