001 package org.apache.maven.execution;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022
023 import org.apache.maven.artifact.ArtifactUtils;
024 import org.apache.maven.plugin.descriptor.PluginDescriptor;
025 import org.apache.maven.project.DuplicateProjectException;
026 import org.apache.maven.project.MavenProject;
027 import org.apache.maven.project.ProjectSorter;
028 import org.codehaus.plexus.util.dag.CycleDetectedException;
029
030 import java.util.ArrayList;
031 import java.util.HashMap;
032 import java.util.Iterator;
033 import java.util.List;
034 import java.util.Map;
035
036 @Deprecated
037 public class ReactorManager
038 {
039 public static final String FAIL_FAST = "fail-fast";
040
041 public static final String FAIL_AT_END = "fail-at-end";
042
043 public static final String FAIL_NEVER = "fail-never";
044
045 public static final String MAKE_MODE = "make";
046
047 public static final String MAKE_DEPENDENTS_MODE = "make-dependents";
048
049 // make projects that depend on me, and projects that I depend on
050 public static final String MAKE_BOTH_MODE = "make-both";
051
052 private List blackList = new ArrayList();
053
054 private Map buildFailuresByProject = new HashMap();
055
056 private Map pluginContextsByProjectAndPluginKey = new HashMap();
057
058 private String failureBehavior = FAIL_FAST;
059
060 private final ProjectSorter sorter;
061
062 private Map buildSuccessesByProject = new HashMap();
063
064 public ReactorManager( List projects )
065 throws CycleDetectedException, DuplicateProjectException
066 {
067 this.sorter = new ProjectSorter( projects );
068 }
069
070 public Map getPluginContext( PluginDescriptor plugin, MavenProject project )
071 {
072 Map pluginContextsByKey = (Map) pluginContextsByProjectAndPluginKey.get( project.getId() );
073
074 if ( pluginContextsByKey == null )
075 {
076 pluginContextsByKey = new HashMap();
077 pluginContextsByProjectAndPluginKey.put( project.getId(), pluginContextsByKey );
078 }
079
080 Map pluginContext = (Map) pluginContextsByKey.get( plugin.getPluginLookupKey() );
081
082 if ( pluginContext == null )
083 {
084 pluginContext = new HashMap();
085 pluginContextsByKey.put( plugin.getPluginLookupKey(), pluginContext );
086 }
087
088 return pluginContext;
089 }
090
091 public void setFailureBehavior( String failureBehavior )
092 {
093 if ( failureBehavior == null )
094 {
095 this.failureBehavior = FAIL_FAST; // default
096 return;
097 }
098 if ( FAIL_FAST.equals( failureBehavior ) || FAIL_AT_END.equals( failureBehavior )
099 || 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 ( Iterator it = dependents.iterator(); it.hasNext(); )
131 {
132 String dependentId = (String) it.next();
133
134 if ( !buildSuccessesByProject.containsKey( dependentId )
135 && !buildFailuresByProject.containsKey( 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 }