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  public class DefaultMavenExecutionResult implements MavenExecutionResult {
31      private MavenProject project;
32  
33      private List<MavenProject> topologicallySortedProjects = Collections.emptyList();
34  
35      private DependencyResolutionResult dependencyResolutionResult;
36  
37      private final List<Throwable> exceptions = new CopyOnWriteArrayList<>();
38  
39      private final Map<MavenProject, BuildSummary> buildSummaries = Collections.synchronizedMap(new IdentityHashMap<>());
40  
41      private boolean canResume = false;
42  
43      @Override
44      public MavenExecutionResult setProject(MavenProject project) {
45          this.project = project;
46  
47          return this;
48      }
49  
50      @Override
51      public MavenProject getProject() {
52          return project;
53      }
54  
55      @Override
56      public MavenExecutionResult setTopologicallySortedProjects(List<MavenProject> topologicallySortedProjects) {
57          this.topologicallySortedProjects = topologicallySortedProjects;
58  
59          return this;
60      }
61  
62      @Override
63      public List<MavenProject> getTopologicallySortedProjects() {
64          return null == topologicallySortedProjects
65                  ? Collections.emptyList()
66                  : Collections.unmodifiableList(topologicallySortedProjects);
67      }
68  
69      @Override
70      public DependencyResolutionResult getDependencyResolutionResult() {
71          return dependencyResolutionResult;
72      }
73  
74      @Override
75      public MavenExecutionResult setDependencyResolutionResult(DependencyResolutionResult dependencyResolutionResult) {
76          this.dependencyResolutionResult = dependencyResolutionResult;
77  
78          return this;
79      }
80  
81      @Override
82      public List<Throwable> getExceptions() {
83          return exceptions;
84      }
85  
86      @Override
87      public MavenExecutionResult addException(Throwable t) {
88          exceptions.add(t);
89  
90          return this;
91      }
92  
93      @Override
94      public boolean hasExceptions() {
95          return !getExceptions().isEmpty();
96      }
97  
98      @Override
99      public BuildSummary getBuildSummary(MavenProject project) {
100         return buildSummaries.get(project);
101     }
102 
103     @Override
104     public void addBuildSummary(BuildSummary summary) {
105         buildSummaries.put(summary.getProject(), summary);
106     }
107 
108     @Override
109     public boolean canResume() {
110         return canResume;
111     }
112 
113     @Override
114     public void setCanResume(boolean canResume) {
115         this.canResume = canResume;
116     }
117 }