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 */ 31 class ModelData { 32 private final Source source; 33 34 private final Model model; 35 36 private String groupId; 37 38 private String artifactId; 39 40 private String version; 41 42 /** 43 * Creates a new container for the specified model. 44 * 45 * @param model The model to wrap, may be {@code null}. 46 */ 47 ModelData(Source source, Model model) { 48 this.source = source; 49 this.model = model; 50 } 51 52 /** 53 * Creates a new container for the specified model. 54 * 55 * @param model The model to wrap, may be {@code null}. 56 * @param groupId The effective group identifier of the model, may be {@code null}. 57 * @param artifactId The effective artifact identifier of the model, may be {@code null}. 58 * @param version The effective version of the model, may be {@code null}. 59 */ 60 ModelData(Source source, Model model, String groupId, String artifactId, String version) { 61 this.source = source; 62 this.model = model; 63 this.groupId = groupId; 64 this.artifactId = artifactId; 65 this.version = version; 66 } 67 68 public Source getSource() { 69 return source; 70 } 71 72 /** 73 * Gets the model being wrapped. 74 * 75 * @return The model or {@code null} if not set. 76 */ 77 public Model getModel() { 78 return model; 79 } 80 81 /** 82 * Gets the effective group identifier of the model. 83 * 84 * @return The effective group identifier of the model or an empty string if unknown, never {@code null}. 85 */ 86 public String getGroupId() { 87 return (groupId != null) ? groupId : ""; 88 } 89 90 /** 91 * Gets the effective artifact identifier of the model. 92 * 93 * @return The effective artifact identifier of the model or an empty string if unknown, never {@code null}. 94 */ 95 public String getArtifactId() { 96 return (artifactId != null) ? artifactId : ""; 97 } 98 99 /** 100 * Gets the effective version of the model. 101 * 102 * @return The effective version of the model or an empty string if unknown, never {@code null}. 103 */ 104 public String getVersion() { 105 return (version != null) ? version : ""; 106 } 107 108 /** 109 * Gets unique identifier of the model 110 * 111 * @return The effective identifier of the model, never {@code null}. 112 */ 113 public String getId() { 114 // if source is null, it is the super model, which can be accessed via empty string 115 return Objects.toString(source, ""); 116 } 117 118 @Override 119 public String toString() { 120 return String.valueOf(model); 121 } 122 }