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.Objects; 23 24 import org.apache.maven.building.Source; 25 import org.apache.maven.model.Model; 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 private final Source source; 36 37 private final Model model; 38 39 private String groupId; 40 41 private String artifactId; 42 43 private String version; 44 45 /** 46 * Creates a new container for the specified model. 47 * 48 * @param model The model to wrap, may be {@code null}. 49 */ 50 ModelData( Source source, Model model ) 51 { 52 this.source = source; 53 this.model = model; 54 } 55 56 /** 57 * Creates a new container for the specified model. 58 * 59 * @param model The model to wrap, may be {@code null}. 60 * @param groupId The effective group identifier of the model, may be {@code null}. 61 * @param artifactId The effective artifact identifier of the model, may be {@code null}. 62 * @param version The effective version of the model, may be {@code null}. 63 */ 64 ModelData( Source source, Model model, String groupId, String artifactId, String version ) 65 { 66 this.source = source; 67 this.model = model; 68 this.groupId = groupId; 69 this.artifactId = artifactId; 70 this.version = version; 71 } 72 73 public Source getSource() 74 { 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 { 85 return model; 86 } 87 88 /** 89 * Gets the effective group identifier of the model. 90 * 91 * @return The effective group identifier of the model or an empty string if unknown, never {@code null}. 92 */ 93 public String getGroupId() 94 { 95 return ( groupId != null ) ? groupId : ""; 96 } 97 98 /** 99 * Gets the effective artifact identifier of the model. 100 * 101 * @return The effective artifact identifier of the model or an empty string if unknown, never {@code null}. 102 */ 103 public String getArtifactId() 104 { 105 return ( artifactId != null ) ? artifactId : ""; 106 } 107 108 /** 109 * Gets the effective version of the model. 110 * 111 * @return The effective version of the model or an empty string if unknown, never {@code null}. 112 */ 113 public String getVersion() 114 { 115 return ( version != null ) ? version : ""; 116 } 117 118 /** 119 * Gets unique identifier of the model 120 * 121 * @return The effective identifier of the model, never {@code null}. 122 */ 123 public String getId() 124 { 125 // if source is null, it is the super model, which can be accessed via empty string 126 return Objects.toString( source, "" ); 127 } 128 129 @Override 130 public String toString() 131 { 132 return String.valueOf( model ); 133 } 134 135 }