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