001    package org.apache.maven.execution;
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 java.util.Collections;
023    import java.util.IdentityHashMap;
024    import java.util.List;
025    import java.util.Map;
026    import java.util.concurrent.CopyOnWriteArrayList;
027    
028    import org.apache.maven.project.DependencyResolutionResult;
029    import org.apache.maven.project.MavenProject;
030    
031    /** @author Jason van Zyl */
032    public class DefaultMavenExecutionResult
033        implements MavenExecutionResult
034    {
035        private MavenProject project;
036    
037        private List<MavenProject> topologicallySortedProjects = Collections.emptyList();
038    
039        private DependencyResolutionResult dependencyResolutionResult;
040    
041        private List<Throwable> exceptions = new CopyOnWriteArrayList<Throwable>();
042    
043        private Map<MavenProject, BuildSummary> buildSummaries;
044    
045        public MavenExecutionResult setProject( MavenProject project )
046        {
047            this.project = project;
048    
049            return this;
050        }
051    
052        public MavenProject getProject()
053        {
054            return project;
055        }
056    
057        public MavenExecutionResult setTopologicallySortedProjects( List<MavenProject> topologicallySortedProjects )
058        {
059            this.topologicallySortedProjects = topologicallySortedProjects;
060    
061            return this;
062        }
063    
064        public List<MavenProject> getTopologicallySortedProjects()
065        {
066            return null == topologicallySortedProjects ? Collections.<MavenProject> emptyList() : topologicallySortedProjects;
067        }
068    
069        public DependencyResolutionResult getDependencyResolutionResult()
070        {
071            return dependencyResolutionResult;
072        }
073    
074        public MavenExecutionResult setDependencyResolutionResult( DependencyResolutionResult dependencyResolutionResult )
075        {
076            this.dependencyResolutionResult = dependencyResolutionResult;
077    
078            return this;
079        }
080    
081        public List<Throwable> getExceptions()
082        {
083            return exceptions == null ? Collections.<Throwable> emptyList() : exceptions;
084        }
085    
086        public MavenExecutionResult addException( Throwable t )
087        {
088            exceptions.add( t );
089    
090            return this;
091        }
092    
093        public boolean hasExceptions()
094        {
095            return !getExceptions().isEmpty();
096        }
097    
098        public BuildSummary getBuildSummary( MavenProject project )
099        {
100            return ( buildSummaries != null ) ? buildSummaries.get( project ) : null;
101        }
102    
103        public void addBuildSummary( BuildSummary summary )
104        {
105            if ( buildSummaries == null )
106            {
107                buildSummaries = new IdentityHashMap<MavenProject, BuildSummary>();
108            }
109            buildSummaries.put( summary.getProject(), summary );
110        }
111    
112    }