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.project;
20  
21  import java.io.File;
22  import java.util.Collections;
23  import java.util.List;
24  
25  import org.apache.maven.model.building.ModelProblem;
26  
27  /**
28   * Collects the output of the project builder.
29   *
30   * @author Benjamin Bentmann
31   */
32  class DefaultProjectBuildingResult implements ProjectBuildingResult {
33  
34      private final String projectId;
35  
36      private final File pomFile;
37  
38      private final MavenProject project;
39  
40      private final List<ModelProblem> problems;
41  
42      private final DependencyResolutionResult dependencyResolutionResult;
43  
44      /**
45       * Creates a new result with the specified contents.
46       *
47       * @param project The project that was built, may be {@code null}.
48       * @param problems The problems that were encountered, may be {@code null}.
49       * @param dependencyResolutionResult The result of the resolution for the project dependencies, may be {@code null}.
50       */
51      DefaultProjectBuildingResult(
52              MavenProject project, List<ModelProblem> problems, DependencyResolutionResult dependencyResolutionResult) {
53          this.projectId = (project != null)
54                  ? project.getGroupId() + ':' + project.getArtifactId() + ':' + project.getVersion()
55                  : "";
56          this.pomFile = (project != null) ? project.getFile() : null;
57          this.project = project;
58          this.problems = problems != null ? problems : Collections.emptyList();
59          this.dependencyResolutionResult = dependencyResolutionResult;
60      }
61  
62      /**
63       * Creates a new result with the specified contents.
64       *
65       * @param projectId The identifier of the project, may be {@code null}.
66       * @param pomFile The POM file from which the project was built, may be {@code null}.
67       * @param problems The problems that were encountered, may be {@code null}.
68       */
69      DefaultProjectBuildingResult(String projectId, File pomFile, List<ModelProblem> problems) {
70          this.projectId = (projectId != null) ? projectId : "";
71          this.pomFile = pomFile;
72          this.project = null;
73          this.problems = problems != null ? problems : Collections.emptyList();
74          this.dependencyResolutionResult = null;
75      }
76  
77      public String getProjectId() {
78          return projectId;
79      }
80  
81      public File getPomFile() {
82          return pomFile;
83      }
84  
85      public MavenProject getProject() {
86          return project;
87      }
88  
89      public List<ModelProblem> getProblems() {
90          return problems;
91      }
92  
93      public DependencyResolutionResult getDependencyResolutionResult() {
94          return dependencyResolutionResult;
95      }
96  }