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