aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelData.java
blob: 4fefe0df11849c987db9bdd658a0447fcd816f52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package org.apache.maven.model.building;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.util.List;

import org.apache.maven.model.Model;
import org.apache.maven.model.Profile;

/**
 * Holds a model along with some auxiliary information. This internal utility class assists the model builder during POM
 * processing by providing a means to transport information that cannot be (easily) extracted from the model itself.
 *
 * @author Benjamin Bentmann
 */
class ModelData
{
    private final ModelSource source;

    private Model model;

    private Model rawModel;

    private List<Profile> activeProfiles;

    private String groupId;

    private String artifactId;

    private String version;

    /**
     * Creates a new container for the specified model.
     *
     * @param model The model to wrap, may be {@code null}.
     */
    public ModelData( ModelSource source, Model model )
    {
        this.source = source;
        this.model = model;
    }

    /**
     * Creates a new container for the specified model.
     *
     * @param model The model to wrap, may be {@code null}.
     * @param groupId The effective group identifier of the model, may be {@code null}.
     * @param artifactId The effective artifact identifier of the model, may be {@code null}.
     * @param version The effective version of the model, may be {@code null}.
     */
    public ModelData( ModelSource source, Model model, String groupId, String artifactId, String version )
    {
        this.source = source;
        this.model = model;
        setGroupId( groupId );
        setArtifactId( artifactId );
        setVersion( version );
    }

    public ModelSource getSource()
    {
        return source;
    }

    /**
     * Gets the model being wrapped.
     *
     * @return The model or {@code null} if not set.
     */
    public Model getModel()
    {
        return model;
    }

    /**
     * Sets the model being wrapped.
     *
     * @param model The model, may be {@code null}.
     */
    public void setModel( Model model )
    {
        this.model = model;
    }

    /**
     * Gets the raw model being wrapped.
     *
     * @return The raw model or {@code null} if not set.
     */
    public Model getRawModel()
    {
        return rawModel;
    }

    /**
     * Sets the raw model being wrapped.
     *
     * @param rawModel The raw model, may be {@code null}.
     */
    public void setRawModel( Model rawModel )
    {
        this.rawModel = rawModel;
    }

    /**
     * Gets the active profiles from the model.
     *
     * @return The active profiles or {@code null} if not set.
     */
    public List<Profile> getActiveProfiles()
    {
        return activeProfiles;
    }

    /**
     * Sets the active profiles from the model.
     *
     * @param activeProfiles The active profiles, may be {@code null}.
     */
    public void setActiveProfiles( List<Profile> activeProfiles )
    {
        this.activeProfiles = activeProfiles;
    }

    /**
     * Gets the effective group identifier of the model.
     *
     * @return The effective group identifier of the model or an empty string if unknown, never {@code null}.
     */
    public String getGroupId()
    {
        return ( groupId != null ) ? groupId : "";
    }

    /**
     * Sets the effective group identifier of the model.
     *
     * @param groupId The effective group identifier of the model, may be {@code null}.
     */
    public void setGroupId( String groupId )
    {
        this.groupId = groupId;
    }

    /**
     * Gets the effective artifact identifier of the model.
     *
     * @return The effective artifact identifier of the model or an empty string if unknown, never {@code null}.
     */
    public String getArtifactId()
    {
        return ( artifactId != null ) ? artifactId : "";
    }

    /**
     * Sets the effective artifact identifier of the model.
     *
     * @param artifactId The effective artifact identifier of the model, may be {@code null}.
     */
    public void setArtifactId( String artifactId )
    {
        this.artifactId = artifactId;
    }

    /**
     * Gets the effective version of the model.
     *
     * @return The effective version of the model or an empty string if unknown, never {@code null}.
     */
    public String getVersion()
    {
        return ( version != null ) ? version : "";
    }

    /**
     * Sets the effective version of the model.
     *
     * @param version The effective version of the model, may be {@code null}.
     */
    public void setVersion( String version )
    {
        this.version = version;
    }

    /**
     * Gets the effective identifier of the model in the form {@code <groupId>:<artifactId>:<version>}.
     *
     * @return The effective identifier of the model, never {@code null}.
     */
    public String getId()
    {
        StringBuilder buffer = new StringBuilder( 96 );

        buffer.append( getGroupId() ).append( ':' ).append( getArtifactId() ).append( ':' ).append( getVersion() );

        return buffer.toString();
    }

    @Override
    public String toString()
    {
        return String.valueOf( model );
    }

}