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   */
34  public class ReactorBuildStatus {
35      private final ProjectDependencyGraph projectDependencyGraph;
36  
37      private final Collection<String> blackListedProjects = Collections.synchronizedSet(new HashSet<>());
38  
39      private volatile boolean halted = false;
40  
41      public ReactorBuildStatus(ProjectDependencyGraph projectDependencyGraph) {
42          this.projectDependencyGraph = projectDependencyGraph;
43      }
44  
45      public boolean isBlackListed(MavenProject project) {
46          return blackListedProjects.contains(BuilderCommon.getKey(project));
47      }
48  
49      public void blackList(MavenProject project) {
50          if (blackListedProjects.add(BuilderCommon.getKey(project)) && projectDependencyGraph != null) {
51              for (MavenProject downstreamProject : projectDependencyGraph.getDownstreamProjects(project, true)) {
52                  blackListedProjects.add(BuilderCommon.getKey(downstreamProject));
53              }
54          }
55      }
56  
57      public void halt() {
58          halted = true;
59      }
60  
61      public boolean isHalted() {
62          return halted;
63      }
64  
65      public boolean isHaltedOrBlacklisted(MavenProject mavenProject) {
66          return isBlackListed(mavenProject) || isHalted();
67      }
68  }