View Javadoc
1   package org.apache.maven.model.building;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.List;
23  
24  import org.apache.maven.model.Model;
25  import org.apache.maven.model.Profile;
26  
27  /**
28   * Holds a model along with some auxiliary information. This internal utility class assists the model builder during POM
29   * processing by providing a means to transport information that cannot be (easily) extracted from the model itself.
30   *
31   * @author Benjamin Bentmann
32   */
33  class ModelData
34  {
35      private final ModelSource source;
36  
37      private Model model;
38  
39      private Model rawModel;
40  
41      private List<Profile> activeProfiles;
42  
43      private String groupId;
44  
45      private String artifactId;
46  
47      private String version;
48  
49      /**
50       * Creates a new container for the specified model.
51       *
52       * @param model The model to wrap, may be {@code null}.
53       */
54      public ModelData( ModelSource source, Model model )
55      {
56          this.source = source;
57          this.model = model;
58      }
59  
60      /**
61       * Creates a new container for the specified model.
62       *
63       * @param model The model to wrap, may be {@code null}.
64       * @param groupId The effective group identifier of the model, may be {@code null}.
65       * @param artifactId The effective artifact identifier of the model, may be {@code null}.
66       * @param version The effective version of the model, may be {@code null}.
67       */
68      public ModelData( ModelSource source, Model model, String groupId, String artifactId, String version )
69      {
70          this.source = source;
71          this.model = model;
72          setGroupId( groupId );
73          setArtifactId( artifactId );
74          setVersion( version );
75      }
76  
77      public ModelSource getSource()
78      {
79          return source;
80      }
81  
82      /**
83       * Gets the model being wrapped.
84       *
85       * @return The model or {@code null} if not set.
86       */
87      public Model getModel()
88      {
89          return model;
90      }
91  
92      /**
93       * Sets the model being wrapped.
94       *
95       * @param model The model, may be {@code null}.
96       */
97      public void setModel( Model model )
98      {
99          this.model = model;
100     }
101 
102     /**
103      * Gets the raw model being wrapped.
104      *
105      * @return The raw model or {@code null} if not set.
106      */
107     public Model getRawModel()
108     {
109         return rawModel;
110     }
111 
112     /**
113      * Sets the raw model being wrapped.
114      *
115      * @param rawModel The raw model, may be {@code null}.
116      */
117     public void setRawModel( Model rawModel )
118     {
119         this.rawModel = rawModel;
120     }
121 
122     /**
123      * Gets the active profiles from the model.
124      *
125      * @return The active profiles or {@code null} if not set.
126      */
127     public List<Profile> getActiveProfiles()
128     {
129         return activeProfiles;
130     }
131 
132     /**
133      * Sets the active profiles from the model.
134      *
135      * @param activeProfiles The active profiles, may be {@code null}.
136      */
137     public void setActiveProfiles( List<Profile> activeProfiles )
138     {
139         this.activeProfiles = activeProfiles;
140     }
141 
142     /**
143      * Gets the effective group identifier of the model.
144      *
145      * @return The effective group identifier of the model or an empty string if unknown, never {@code null}.
146      */
147     public String getGroupId()
148     {
149         return ( groupId != null ) ? groupId : "";
150     }
151 
152     /**
153      * Sets the effective group identifier of the model.
154      *
155      * @param groupId The effective group identifier of the model, may be {@code null}.
156      */
157     public void setGroupId( String groupId )
158     {
159         this.groupId = groupId;
160     }
161 
162     /**
163      * Gets the effective artifact identifier of the model.
164      *
165      * @return The effective artifact identifier of the model or an empty string if unknown, never {@code null}.
166      */
167     public String getArtifactId()
168     {
169         return ( artifactId != null ) ? artifactId : "";
170     }
171 
172     /**
173      * Sets the effective artifact identifier of the model.
174      *
175      * @param artifactId The effective artifact identifier of the model, may be {@code null}.
176      */
177     public void setArtifactId( String artifactId )
178     {
179         this.artifactId = artifactId;
180     }
181 
182     /**
183      * Gets the effective version of the model.
184      *
185      * @return The effective version of the model or an empty string if unknown, never {@code null}.
186      */
187     public String getVersion()
188     {
189         return ( version != null ) ? version : "";
190     }
191 
192     /**
193      * Sets the effective version of the model.
194      *
195      * @param version The effective version of the model, may be {@code null}.
196      */
197     public void setVersion( String version )
198     {
199         this.version = version;
200     }
201 
202     /**
203      * Gets the effective identifier of the model in the form {@code <groupId>:<artifactId>:<version>}.
204      *
205      * @return The effective identifier of the model, never {@code null}.
206      */
207     public String getId()
208     {
209         StringBuilder buffer = new StringBuilder( 96 );
210 
211         buffer.append( getGroupId() ).append( ':' ).append( getArtifactId() ).append( ':' ).append( getVersion() );
212 
213         return buffer.toString();
214     }
215 
216     @Override
217     public String toString()
218     {
219         return String.valueOf( model );
220     }
221 
222 }