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.model.building;
20  
21  import java.util.Objects;
22  
23  import org.apache.maven.building.Source;
24  import org.apache.maven.model.Model;
25  
26  /**
27   * Holds a model along with some auxiliary information. This internal utility class assists the model builder during POM
28   * processing by providing a means to transport information that cannot be (easily) extracted from the model itself.
29   *
30   * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
31   */
32  @Deprecated(since = "4.0.0")
33  class ModelData {
34      private final Source source;
35  
36      private final Model model;
37  
38      private String groupId;
39  
40      private String artifactId;
41  
42      private String version;
43  
44      /**
45       * Creates a new container for the specified model.
46       *
47       * @param model The model to wrap, may be {@code null}.
48       */
49      ModelData(Source source, Model model) {
50          this.source = source;
51          this.model = model;
52      }
53  
54      /**
55       * Creates a new container for the specified model.
56       *
57       * @param model The model to wrap, may be {@code null}.
58       * @param groupId The effective group identifier of the model, may be {@code null}.
59       * @param artifactId The effective artifact identifier of the model, may be {@code null}.
60       * @param version The effective version of the model, may be {@code null}.
61       */
62      ModelData(Source source, Model model, String groupId, String artifactId, String version) {
63          this.source = source;
64          this.model = model;
65          this.groupId = groupId;
66          this.artifactId = artifactId;
67          this.version = version;
68      }
69  
70      public Source getSource() {
71          return source;
72      }
73  
74      /**
75       * Gets the model being wrapped.
76       *
77       * @return The model or {@code null} if not set.
78       */
79      public Model getModel() {
80          return model;
81      }
82  
83      /**
84       * Gets the effective group identifier of the model.
85       *
86       * @return The effective group identifier of the model or an empty string if unknown, never {@code null}.
87       */
88      public String getGroupId() {
89          return (groupId != null) ? groupId : "";
90      }
91  
92      /**
93       * Gets the effective artifact identifier of the model.
94       *
95       * @return The effective artifact identifier of the model or an empty string if unknown, never {@code null}.
96       */
97      public String getArtifactId() {
98          return (artifactId != null) ? artifactId : "";
99      }
100 
101     /**
102      * Gets the effective version of the model.
103      *
104      * @return The effective version of the model or an empty string if unknown, never {@code null}.
105      */
106     public String getVersion() {
107         return (version != null) ? version : "";
108     }
109 
110     /**
111      * Gets unique identifier of the model
112      *
113      * @return The effective identifier of the model, never {@code null}.
114      */
115     public String getId() {
116         // if source is null, it is the super model, which can be accessed via empty string
117         return Objects.toString(source, "");
118     }
119 
120     @Override
121     public String toString() {
122         return String.valueOf(model);
123     }
124 }