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; 20 21 /** 22 * Class InputSource. 23 * 24 * @version $Revision$ $Date$ 25 */ 26 @SuppressWarnings("all") 27 public class InputSource implements java.io.Serializable, Cloneable { 28 29 // --------------------------/ 30 // - Class/Member Variables -/ 31 // --------------------------/ 32 33 /** 34 * 35 * 36 * The identifier of the POM in the format {@code 37 * <groupId>:<artifactId>:<version>}. 38 * 39 * 40 */ 41 private String modelId; 42 43 /** 44 * 45 * 46 * The path/URL of the POM or {@code null} if 47 * unknown. 48 * 49 * 50 */ 51 private String location; 52 53 /** 54 * 55 * 56 * The location of the POM from which this POM was 57 * imported from or {@code null} if unknown. 58 */ 59 private InputLocation importedFrom; 60 61 /** 62 * Cached hashCode for performance. 63 */ 64 private volatile int hashCode = 0; 65 66 // ----------------/ 67 // - Constructors -/ 68 // ----------------/ 69 70 /** 71 * Default constructor for InputSource. 72 */ 73 public InputSource() {} 74 75 /** 76 * Creates a new InputSource from an API model InputSource. 77 * This constructor is used for converting between the API model and the compat model. 78 * 79 * @param source the API model InputSource to convert from 80 */ 81 public InputSource(org.apache.maven.api.model.InputSource source) { 82 this.modelId = source.getModelId(); 83 this.location = source.getLocation(); 84 this.importedFrom = source.getImportedFrom() != null ? new InputLocation(source.getImportedFrom()) : null; 85 } 86 87 // -----------/ 88 // - Methods -/ 89 // -----------/ 90 91 /** 92 * Method clone. 93 * 94 * @return InputSource 95 */ 96 public InputSource clone() { 97 try { 98 InputSource copy = (InputSource) super.clone(); 99 100 return copy; 101 } catch (Exception ex) { 102 throw (RuntimeException) 103 new UnsupportedOperationException(getClass().getName() + " does not support clone()").initCause(ex); 104 } 105 } // -- InputSource clone() 106 107 /** 108 * Get the path/URL of the POM or {@code null} if unknown. 109 * 110 * @return String 111 */ 112 public String getLocation() { 113 return this.location; 114 } // -- String getLocation() 115 116 /** 117 * Get the identifier of the POM in the format {@code 118 * <groupId>:<artifactId>:<version>}. 119 * 120 * @return String 121 */ 122 public String getModelId() { 123 return this.modelId; 124 } // -- String getModelId() 125 126 /** 127 * Set the path/URL of the POM or {@code null} if unknown. 128 * 129 * @param location 130 */ 131 public void setLocation(String location) { 132 this.location = location; 133 } // -- void setLocation( String ) 134 135 /** 136 * Set the identifier of the POM in the format {@code 137 * <groupId>:<artifactId>:<version>}. 138 * 139 * @param modelId 140 */ 141 public void setModelId(String modelId) { 142 this.modelId = modelId; 143 } // -- void setModelId( String ) 144 145 /** 146 * Get the location of the POM from which this POM was imported from. 147 * Can return {@code null} if this POM was not imported. 148 * 149 * @return the InputLocation where this POM was imported from, or null if not imported 150 */ 151 public InputLocation getImportedFrom() { 152 return importedFrom; 153 } 154 155 /** 156 * Set the location of the POM from which this POM was imported from. 157 * 158 * @param importedFrom the InputLocation where this POM was imported from, or null if not imported 159 */ 160 public void setImportedFrom(InputLocation importedFrom) { 161 this.importedFrom = importedFrom; 162 } 163 164 @Override 165 public boolean equals(Object o) { 166 if (this == o) { 167 return true; 168 } 169 if (o == null || getClass() != o.getClass()) { 170 return false; 171 } 172 InputSource that = (InputSource) o; 173 return java.util.Objects.equals(modelId, that.modelId) 174 && java.util.Objects.equals(location, that.location) 175 && java.util.Objects.equals(importedFrom, that.importedFrom); 176 } 177 178 @Override 179 public int hashCode() { 180 int result = hashCode; 181 if (result == 0) { 182 result = java.util.Objects.hash(modelId, location, importedFrom); 183 hashCode = result; 184 } 185 return result; 186 } 187 188 @Override 189 public String toString() { 190 return getModelId() + " " + getLocation(); 191 } 192 193 /** 194 * Converts this compat model InputSource to an API model InputSource. 195 * This method is used for converting between the compat model and the API model. 196 * 197 * @return the equivalent API model InputSource 198 */ 199 public org.apache.maven.api.model.InputSource toApiSource() { 200 return org.apache.maven.api.model.InputSource.of(modelId, location); 201 } 202 }