1 package org.eclipse.aether.metadata; 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.io.File; 23 import java.util.Map; 24 import static java.util.Objects.requireNonNull; 25 26 /** 27 * A basic metadata instance. <em>Note:</em> Instances of this class are immutable and the exposed mutators return new 28 * objects rather than changing the current instance. 29 */ 30 public final class DefaultMetadata 31 extends AbstractMetadata 32 { 33 34 private final String groupId; 35 36 private final String artifactId; 37 38 private final String version; 39 40 private final String type; 41 42 private final Nature nature; 43 44 private final File file; 45 46 private final Map<String, String> properties; 47 48 /** 49 * Creates a new metadata for the repository root with the specific type and nature. 50 * 51 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}. 52 * @param nature The nature of the metadata, must not be {@code null}. 53 */ 54 public DefaultMetadata( String type, Nature nature ) 55 { 56 this( "", "", "", type, nature, null, (File) null ); 57 } 58 59 /** 60 * Creates a new metadata for the groupId level with the specific type and nature. 61 * 62 * @param groupId The group identifier to which this metadata applies, may be {@code null}. 63 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}. 64 * @param nature The nature of the metadata, must not be {@code null}. 65 */ 66 public DefaultMetadata( String groupId, String type, Nature nature ) 67 { 68 this( groupId, "", "", type, nature, null, (File) null ); 69 } 70 71 /** 72 * Creates a new metadata for the groupId:artifactId level with the specific type and nature. 73 * 74 * @param groupId The group identifier to which this metadata applies, may be {@code null}. 75 * @param artifactId The artifact identifier to which this metadata applies, may be {@code null}. 76 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}. 77 * @param nature The nature of the metadata, must not be {@code null}. 78 */ 79 public DefaultMetadata( String groupId, String artifactId, String type, Nature nature ) 80 { 81 this( groupId, artifactId, "", type, nature, null, (File) null ); 82 } 83 84 /** 85 * Creates a new metadata for the groupId:artifactId:version level with the specific type and nature. 86 * 87 * @param groupId The group identifier to which this metadata applies, may be {@code null}. 88 * @param artifactId The artifact identifier to which this metadata applies, may be {@code null}. 89 * @param version The version to which this metadata applies, may be {@code null}. 90 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}. 91 * @param nature The nature of the metadata, must not be {@code null}. 92 */ 93 public DefaultMetadata( String groupId, String artifactId, String version, String type, Nature nature ) 94 { 95 this( groupId, artifactId, version, type, nature, null, (File) null ); 96 } 97 98 /** 99 * Creates a new metadata for the groupId:artifactId:version level with the specific type and nature. 100 * 101 * @param groupId The group identifier to which this metadata applies, may be {@code null}. 102 * @param artifactId The artifact identifier to which this metadata applies, may be {@code null}. 103 * @param version The version to which this metadata applies, may be {@code null}. 104 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}. 105 * @param nature The nature of the metadata, must not be {@code null}. 106 * @param file The resolved file of the metadata, may be {@code null}. 107 */ 108 public DefaultMetadata( String groupId, String artifactId, String version, String type, Nature nature, File file ) 109 { 110 this( groupId, artifactId, version, type, nature, null, file ); 111 } 112 113 /** 114 * Creates a new metadata for the groupId:artifactId:version level with the specific type and nature. 115 * 116 * @param groupId The group identifier to which this metadata applies, may be {@code null}. 117 * @param artifactId The artifact identifier to which this metadata applies, may be {@code null}. 118 * @param version The version to which this metadata applies, may be {@code null}. 119 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}. 120 * @param nature The nature of the metadata, must not be {@code null}. 121 * @param properties The properties of the metadata, may be {@code null} if none. 122 * @param file The resolved file of the metadata, may be {@code null}. 123 */ 124 public DefaultMetadata( String groupId, String artifactId, String version, String type, Nature nature, 125 Map<String, String> properties, File file ) 126 { 127 this.groupId = emptify( groupId ); 128 this.artifactId = emptify( artifactId ); 129 this.version = emptify( version ); 130 this.type = emptify( type ); 131 this.nature = requireNonNull( nature, "metadata nature cannot be null" ); 132 this.file = file; 133 this.properties = copyProperties( properties ); 134 } 135 136 DefaultMetadata( String groupId, String artifactId, String version, String type, Nature nature, File file, 137 Map<String, String> properties ) 138 { 139 // NOTE: This constructor assumes immutability of the provided properties, for internal use only 140 this.groupId = emptify( groupId ); 141 this.artifactId = emptify( artifactId ); 142 this.version = emptify( version ); 143 this.type = emptify( type ); 144 this.nature = nature; 145 this.file = file; 146 this.properties = properties; 147 } 148 149 private static String emptify( String str ) 150 { 151 return ( str == null ) ? "" : str; 152 } 153 154 public String getGroupId() 155 { 156 return groupId; 157 } 158 159 public String getArtifactId() 160 { 161 return artifactId; 162 } 163 164 public String getVersion() 165 { 166 return version; 167 } 168 169 public String getType() 170 { 171 return type; 172 } 173 174 public Nature getNature() 175 { 176 return nature; 177 } 178 179 public File getFile() 180 { 181 return file; 182 } 183 184 public Map<String, String> getProperties() 185 { 186 return properties; 187 } 188 189 }