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 36 private Model model; 37 38 private Model rawModel; 39 40 private List<Profile> activeProfiles; 41 42 private String groupId; 43 44 private String artifactId; 45 46 private String version; 47 48 /** 49 * Creates a new container for the specified model. 50 * 51 * @param model The model to wrap, may be {@code null}. 52 */ 53 public ModelData( Model model ) 54 { 55 this.model = model; 56 } 57 58 /** 59 * Creates a new container for the specified model. 60 * 61 * @param model The model to wrap, may be {@code null}. 62 * @param groupId The effective group identifier of the model, may be {@code null}. 63 * @param artifactId The effective artifact identifier of the model, may be {@code null}. 64 * @param version The effective version of the model, may be {@code null}. 65 */ 66 public ModelData( Model model, String groupId, String artifactId, String version ) 67 { 68 this.model = model; 69 setGroupId( groupId ); 70 setArtifactId( artifactId ); 71 setVersion( version ); 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 { 81 return model; 82 } 83 84 /** 85 * Sets the model being wrapped. 86 * 87 * @param model The model, may be {@code null}. 88 */ 89 public void setModel( Model model ) 90 { 91 this.model = model; 92 } 93 94 /** 95 * Gets the raw model being wrapped. 96 * 97 * @return The raw model or {@code null} if not set. 98 */ 99 public Model getRawModel() 100 { 101 return rawModel; 102 } 103 104 /** 105 * Sets the raw model being wrapped. 106 * 107 * @param rawModel The raw model, may be {@code null}. 108 */ 109 public void setRawModel( Model rawModel ) 110 { 111 this.rawModel = rawModel; 112 } 113 114 /** 115 * Gets the active profiles from the model. 116 * 117 * @return The active profiles or {@code null} if not set. 118 */ 119 public List<Profile> getActiveProfiles() 120 { 121 return activeProfiles; 122 } 123 124 /** 125 * Sets the active profiles from the model. 126 * 127 * @param activeProfiles The active profiles, may be {@code null}. 128 */ 129 public void setActiveProfiles( List<Profile> activeProfiles ) 130 { 131 this.activeProfiles = activeProfiles; 132 } 133 134 /** 135 * Gets the effective group identifier of the model. 136 * 137 * @return The effective group identifier of the model or an empty string if unknown, never {@code null}. 138 */ 139 public String getGroupId() 140 { 141 return ( groupId != null ) ? groupId : ""; 142 } 143 144 /** 145 * Sets the effective group identifier of the model. 146 * 147 * @param groupId The effective group identifier of the model, may be {@code null}. 148 */ 149 public void setGroupId( String groupId ) 150 { 151 this.groupId = groupId; 152 } 153 154 /** 155 * Gets the effective artifact identifier of the model. 156 * 157 * @return The effective artifact identifier of the model or an empty string if unknown, never {@code null}. 158 */ 159 public String getArtifactId() 160 { 161 return ( artifactId != null ) ? artifactId : ""; 162 } 163 164 /** 165 * Sets the effective artifact identifier of the model. 166 * 167 * @param artifactId The effective artifact identifier of the model, may be {@code null}. 168 */ 169 public void setArtifactId( String artifactId ) 170 { 171 this.artifactId = artifactId; 172 } 173 174 /** 175 * Gets the effective version of the model. 176 * 177 * @return The effective version of the model or an empty string if unknown, never {@code null}. 178 */ 179 public String getVersion() 180 { 181 return ( version != null ) ? version : ""; 182 } 183 184 /** 185 * Sets the effective version of the model. 186 * 187 * @param version The effective version of the model, may be {@code null}. 188 */ 189 public void setVersion( String version ) 190 { 191 this.version = version; 192 } 193 194 /** 195 * Gets the effective identifier of the model in the form {@code <groupId>:<artifactId>:<version>}. 196 * 197 * @return The effective identifier of the model, never {@code null}. 198 */ 199 public String getId() 200 { 201 StringBuilder buffer = new StringBuilder( 96 ); 202 203 buffer.append( getGroupId() ).append( ':' ).append( getArtifactId() ).append( ':' ).append( getVersion() ); 204 205 return buffer.toString(); 206 } 207 208 @Override 209 public String toString() 210 { 211 return String.valueOf( model ); 212 } 213 214 }