View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.lifecycle.internal;
20  
21  import java.util.Collection;
22  import java.util.Collections;
23  import java.util.HashSet;
24  
25  import org.apache.maven.execution.ProjectDependencyGraph;
26  import org.apache.maven.lifecycle.internal.builder.BuilderCommon;
27  import org.apache.maven.project.MavenProject;
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      private final ProjectDependencyGraph projectDependencyGraph;
37  
38      private final Collection<String> blackListedProjects = Collections.synchronizedSet(new HashSet<String>());
39  
40      private volatile boolean halted = false;
41  
42      public ReactorBuildStatus(ProjectDependencyGraph projectDependencyGraph) {
43          this.projectDependencyGraph = projectDependencyGraph;
44      }
45  
46      public boolean isBlackListed(MavenProject project) {
47          return blackListedProjects.contains(BuilderCommon.getKey(project));
48      }
49  
50      public void blackList(MavenProject project) {
51          if (blackListedProjects.add(BuilderCommon.getKey(project)) && projectDependencyGraph != null) {
52              for (MavenProject downstreamProject : projectDependencyGraph.getDownstreamProjects(project, true)) {
53                  blackListedProjects.add(BuilderCommon.getKey(downstreamProject));
54              }
55          }
56      }
57  
58      public void halt() {
59          halted = true;
60      }
61  
62      public boolean isHalted() {
63          return halted;
64      }
65  
66      public boolean isHaltedOrBlacklisted(MavenProject mavenProject) {
67          return isBlackListed(mavenProject) || isHalted();
68      }
69  }