001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.metadata; 020 021import java.io.File; 022import java.util.Map; 023 024import static java.util.Objects.requireNonNull; 025 026/** 027 * A basic metadata instance. <em>Note:</em> Instances of this class are immutable and the exposed mutators return new 028 * objects rather than changing the current instance. 029 */ 030public final class DefaultMetadata extends AbstractMetadata { 031 032 private final String groupId; 033 034 private final String artifactId; 035 036 private final String version; 037 038 private final String type; 039 040 private final Nature nature; 041 042 private final File file; 043 044 private final Map<String, String> properties; 045 046 /** 047 * Creates a new metadata for the repository root with the specific type and nature. 048 * 049 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}. 050 * @param nature The nature of the metadata, must not be {@code null}. 051 */ 052 public DefaultMetadata(String type, Nature nature) { 053 this("", "", "", type, nature, null, (File) null); 054 } 055 056 /** 057 * Creates a new metadata for the groupId level with the specific type and nature. 058 * 059 * @param groupId The group identifier to which this metadata applies, may be {@code null}. 060 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}. 061 * @param nature The nature of the metadata, must not be {@code null}. 062 */ 063 public DefaultMetadata(String groupId, String type, Nature nature) { 064 this(groupId, "", "", type, nature, null, (File) null); 065 } 066 067 /** 068 * Creates a new metadata for the groupId:artifactId level with the specific type and nature. 069 * 070 * @param groupId The group identifier to which this metadata applies, may be {@code null}. 071 * @param artifactId The artifact identifier to which this metadata applies, may be {@code null}. 072 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}. 073 * @param nature The nature of the metadata, must not be {@code null}. 074 */ 075 public DefaultMetadata(String groupId, String artifactId, String type, Nature nature) { 076 this(groupId, artifactId, "", type, nature, null, (File) null); 077 } 078 079 /** 080 * Creates a new metadata for the groupId:artifactId:version level with the specific type and nature. 081 * 082 * @param groupId The group identifier to which this metadata applies, may be {@code null}. 083 * @param artifactId The artifact identifier to which this metadata applies, may be {@code null}. 084 * @param version The version to which this metadata applies, may be {@code null}. 085 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}. 086 * @param nature The nature of the metadata, must not be {@code null}. 087 */ 088 public DefaultMetadata(String groupId, String artifactId, String version, String type, Nature nature) { 089 this(groupId, artifactId, version, type, nature, null, (File) null); 090 } 091 092 /** 093 * Creates a new metadata for the groupId:artifactId:version level with the specific type and nature. 094 * 095 * @param groupId The group identifier to which this metadata applies, may be {@code null}. 096 * @param artifactId The artifact identifier to which this metadata applies, may be {@code null}. 097 * @param version The version to which this metadata applies, may be {@code null}. 098 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}. 099 * @param nature The nature of the metadata, must not be {@code null}. 100 * @param file The resolved file of the metadata, may be {@code null}. 101 */ 102 public DefaultMetadata(String groupId, String artifactId, String version, String type, Nature nature, File file) { 103 this(groupId, artifactId, version, type, nature, null, file); 104 } 105 106 /** 107 * Creates a new metadata for the groupId:artifactId:version level with the specific type and nature. 108 * 109 * @param groupId The group identifier to which this metadata applies, may be {@code null}. 110 * @param artifactId The artifact identifier to which this metadata applies, may be {@code null}. 111 * @param version The version to which this metadata applies, may be {@code null}. 112 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}. 113 * @param nature The nature of the metadata, must not be {@code null}. 114 * @param properties The properties of the metadata, may be {@code null} if none. 115 * @param file The resolved file of the metadata, may be {@code null}. 116 */ 117 public DefaultMetadata( 118 String groupId, 119 String artifactId, 120 String version, 121 String type, 122 Nature nature, 123 Map<String, String> properties, 124 File file) { 125 this.groupId = emptify(groupId); 126 this.artifactId = emptify(artifactId); 127 this.version = emptify(version); 128 this.type = emptify(type); 129 this.nature = requireNonNull(nature, "metadata nature cannot be null"); 130 this.file = file; 131 this.properties = copyProperties(properties); 132 } 133 134 DefaultMetadata( 135 String groupId, 136 String artifactId, 137 String version, 138 String type, 139 Nature nature, 140 File file, 141 Map<String, String> properties) { 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 return (str == null) ? "" : str; 154 } 155 156 public String getGroupId() { 157 return groupId; 158 } 159 160 public String getArtifactId() { 161 return artifactId; 162 } 163 164 public String getVersion() { 165 return version; 166 } 167 168 public String getType() { 169 return type; 170 } 171 172 public Nature getNature() { 173 return nature; 174 } 175 176 public File getFile() { 177 return file; 178 } 179 180 public Map<String, String> getProperties() { 181 return properties; 182 } 183}