View Javadoc

1   package org.apache.maven.execution;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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      // make projects that depend on me, and projects that I depend on
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; // default
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 ( 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 }