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