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.ArrayList;
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 String projectId;
35
36 private File pomFile;
37
38 private MavenProject project;
39
40 private List<ModelProblem> problems;
41
42 private 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;
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.problems = problems;
73 }
74
75 public String getProjectId() {
76 return projectId;
77 }
78
79 public File getPomFile() {
80 return pomFile;
81 }
82
83 public MavenProject getProject() {
84 return project;
85 }
86
87 public List<ModelProblem> getProblems() {
88 if (problems == null) {
89 problems = new ArrayList<>();
90 }
91
92 return problems;
93 }
94
95 public DependencyResolutionResult getDependencyResolutionResult() {
96 return dependencyResolutionResult;
97 }
98 }