View Javadoc

1   package org.apache.maven.lifecycle.internal;
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.execution.ProjectDependencyGraph;
23  import org.apache.maven.project.MavenProject;
24  
25  import java.util.Collection;
26  import java.util.Collections;
27  import java.util.HashSet;
28  
29  /**
30   * Contains status information that is global to an entire reactor build.
31   * 
32   * @since 3.0
33   * @author <a href="mailto:kristian.rosenvold@gmail.com">Kristian Rosenvold</a>
34   */
35  public class ReactorBuildStatus
36  {
37      private final ProjectDependencyGraph projectDependencyGraph;
38  
39      private final Collection<String> blackListedProjects = Collections.synchronizedSet( new HashSet<String>() );
40  
41      private volatile boolean halted = false;
42  
43      public ReactorBuildStatus( ProjectDependencyGraph projectDependencyGraph )
44      {
45          this.projectDependencyGraph = projectDependencyGraph;
46      }
47  
48      public boolean isBlackListed( MavenProject project )
49      {
50          return blackListedProjects.contains( BuilderCommon.getKey( project ) );
51      }
52  
53      public void blackList( MavenProject project )
54      {
55          if ( blackListedProjects.add( BuilderCommon.getKey( project ) ) && projectDependencyGraph != null )
56          {
57              for ( MavenProject downstreamProject : projectDependencyGraph.getDownstreamProjects( project, true ) )
58              {
59                  blackListedProjects.add( BuilderCommon.getKey( downstreamProject ) );
60              }
61          }
62      }
63  
64      public void halt()
65      {
66          halted = true;
67      }
68  
69      public boolean isHalted()
70      {
71          return halted;
72      }
73  
74      public boolean isHaltedOrBlacklisted( MavenProject mavenProject )
75      {
76          return isBlackListed( mavenProject ) || isHalted();
77      }
78  
79  }