001    package org.apache.maven.lifecycle.internal;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *  http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.maven.execution.ProjectDependencyGraph;
023    import org.apache.maven.project.MavenProject;
024    
025    import java.util.Collection;
026    import java.util.Collections;
027    import java.util.HashSet;
028    
029    /**
030     * Contains status information that is global to an entire reactor build.
031     * 
032     * @since 3.0
033     * @author <a href="mailto:kristian.rosenvold@gmail.com">Kristian Rosenvold</a>
034     */
035    public class ReactorBuildStatus
036    {
037        private final ProjectDependencyGraph projectDependencyGraph;
038    
039        private final Collection<String> blackListedProjects = Collections.synchronizedSet( new HashSet<String>() );
040    
041        private volatile boolean halted = false;
042    
043        public ReactorBuildStatus( ProjectDependencyGraph projectDependencyGraph )
044        {
045            this.projectDependencyGraph = projectDependencyGraph;
046        }
047    
048        public boolean isBlackListed( MavenProject project )
049        {
050            return blackListedProjects.contains( BuilderCommon.getKey( project ) );
051        }
052    
053        public void blackList( MavenProject project )
054        {
055            if ( blackListedProjects.add( BuilderCommon.getKey( project ) ) && projectDependencyGraph != null )
056            {
057                for ( MavenProject downstreamProject : projectDependencyGraph.getDownstreamProjects( project, true ) )
058                {
059                    blackListedProjects.add( BuilderCommon.getKey( downstreamProject ) );
060                }
061            }
062        }
063    
064        public void halt()
065        {
066            halted = true;
067        }
068    
069        public boolean isHalted()
070        {
071            return halted;
072        }
073    
074        public boolean isHaltedOrBlacklisted( MavenProject mavenProject )
075        {
076            return isBlackListed( mavenProject ) || isHalted();
077        }
078    
079    }