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  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      // make projects that depend on me, and projects that I depend on
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; // default
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 }