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.List; 22 23 import org.apache.maven.model.Model; 24 import org.apache.maven.model.Profile; 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 {@code org.apache.maven.api.services.ModelBuilder} instead 31 */ 32 @Deprecated(since = "4.0.0") 33 class ModelData { 34 private final ModelSource source; 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 ModelData(ModelSource source, Model model) { 54 this.source = source; 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 ModelData(ModelSource source, Model model, String groupId, String artifactId, String version) { 67 this.source = source; 68 this.model = model; 69 setGroupId(groupId); 70 setArtifactId(artifactId); 71 setVersion(version); 72 } 73 74 public ModelSource getSource() { 75 return source; 76 } 77 78 /** 79 * Gets the model being wrapped. 80 * 81 * @return The model or {@code null} if not set. 82 */ 83 public Model getModel() { 84 return model; 85 } 86 87 /** 88 * Sets the model being wrapped. 89 * 90 * @param model The model, may be {@code null}. 91 */ 92 public void setModel(Model model) { 93 this.model = model; 94 } 95 96 /** 97 * Gets the raw model being wrapped. 98 * 99 * @return The raw model or {@code null} if not set. 100 */ 101 public Model getRawModel() { 102 return rawModel; 103 } 104 105 /** 106 * Sets the raw model being wrapped. 107 * 108 * @param rawModel The raw model, may be {@code null}. 109 */ 110 public void setRawModel(Model rawModel) { 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 return activeProfiles; 121 } 122 123 /** 124 * Sets the active profiles from the model. 125 * 126 * @param activeProfiles The active profiles, may be {@code null}. 127 */ 128 public void setActiveProfiles(List<Profile> activeProfiles) { 129 this.activeProfiles = activeProfiles; 130 } 131 132 /** 133 * Gets the effective group identifier of the model. 134 * 135 * @return The effective group identifier of the model or an empty string if unknown, never {@code null}. 136 */ 137 public String getGroupId() { 138 return (groupId != null) ? groupId : ""; 139 } 140 141 /** 142 * Sets the effective group identifier of the model. 143 * 144 * @param groupId The effective group identifier of the model, may be {@code null}. 145 */ 146 public void setGroupId(String groupId) { 147 this.groupId = groupId; 148 } 149 150 /** 151 * Gets the effective artifact identifier of the model. 152 * 153 * @return The effective artifact identifier of the model or an empty string if unknown, never {@code null}. 154 */ 155 public String getArtifactId() { 156 return (artifactId != null) ? artifactId : ""; 157 } 158 159 /** 160 * Sets the effective artifact identifier of the model. 161 * 162 * @param artifactId The effective artifact identifier of the model, may be {@code null}. 163 */ 164 public void setArtifactId(String artifactId) { 165 this.artifactId = artifactId; 166 } 167 168 /** 169 * Gets the effective version of the model. 170 * 171 * @return The effective version of the model or an empty string if unknown, never {@code null}. 172 */ 173 public String getVersion() { 174 return (version != null) ? version : ""; 175 } 176 177 /** 178 * Sets the effective version of the model. 179 * 180 * @param version The effective version of the model, may be {@code null}. 181 */ 182 public void setVersion(String version) { 183 this.version = version; 184 } 185 186 /** 187 * Gets the effective identifier of the model in the form {@code <groupId>:<artifactId>:<version>}. 188 * 189 * @return The effective identifier of the model, never {@code null}. 190 */ 191 public String getId() { 192 StringBuilder buffer = new StringBuilder(128); 193 194 buffer.append(getGroupId()) 195 .append(':') 196 .append(getArtifactId()) 197 .append(':') 198 .append(getVersion()); 199 200 return buffer.toString(); 201 } 202 203 @Override 204 public String toString() { 205 return String.valueOf(model); 206 } 207 }