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.execution;
20  
21  import java.util.Collections;
22  import java.util.IdentityHashMap;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.concurrent.CopyOnWriteArrayList;
26  
27  import org.apache.maven.project.DependencyResolutionResult;
28  import org.apache.maven.project.MavenProject;
29  
30  /** @author Jason van Zyl */
31  public class DefaultMavenExecutionResult implements MavenExecutionResult {
32      private MavenProject project;
33  
34      private List<MavenProject> topologicallySortedProjects = Collections.emptyList();
35  
36      private DependencyResolutionResult dependencyResolutionResult;
37  
38      private final List<Throwable> exceptions = new CopyOnWriteArrayList<>();
39  
40      private final Map<MavenProject, BuildSummary> buildSummaries =
41              Collections.synchronizedMap(new IdentityHashMap<MavenProject, BuildSummary>());
42  
43      public MavenExecutionResult setProject(MavenProject project) {
44          this.project = project;
45  
46          return this;
47      }
48  
49      public MavenProject getProject() {
50          return project;
51      }
52  
53      public MavenExecutionResult setTopologicallySortedProjects(List<MavenProject> topologicallySortedProjects) {
54          this.topologicallySortedProjects = topologicallySortedProjects;
55  
56          return this;
57      }
58  
59      public List<MavenProject> getTopologicallySortedProjects() {
60          return null == topologicallySortedProjects
61                  ? Collections.<MavenProject>emptyList()
62                  : Collections.unmodifiableList(topologicallySortedProjects);
63      }
64  
65      public DependencyResolutionResult getDependencyResolutionResult() {
66          return dependencyResolutionResult;
67      }
68  
69      public MavenExecutionResult setDependencyResolutionResult(DependencyResolutionResult dependencyResolutionResult) {
70          this.dependencyResolutionResult = dependencyResolutionResult;
71  
72          return this;
73      }
74  
75      public List<Throwable> getExceptions() {
76          return exceptions;
77      }
78  
79      public MavenExecutionResult addException(Throwable t) {
80          exceptions.add(t);
81  
82          return this;
83      }
84  
85      public boolean hasExceptions() {
86          return !getExceptions().isEmpty();
87      }
88  
89      public BuildSummary getBuildSummary(MavenProject project) {
90          return buildSummaries.get(project);
91      }
92  
93      public void addBuildSummary(BuildSummary summary) {
94          buildSummaries.put(summary.getProject(), summary);
95      }
96  }