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.eclipse.aether.artifact; 20 21 import java.util.Collections; 22 import java.util.HashMap; 23 import java.util.Map; 24 25 import static java.util.Objects.requireNonNull; 26 27 /** 28 * A simple artifact type. 29 * 30 * @deprecated since 2.0, the artifact types should be defined by the resolver consumer 31 */ 32 @Deprecated 33 public final class DefaultArtifactType implements ArtifactType { 34 35 private final String id; 36 37 private final String extension; 38 39 private final String classifier; 40 41 private final Map<String, String> properties; 42 43 /** 44 * Creates a new artifact type with the specified identifier. This constructor assumes the usual file extension 45 * equals the given type id and that the usual classifier is empty. Additionally, the properties 46 * {@link ArtifactProperties#LANGUAGE}, {@link ArtifactProperties#CONSTITUTES_BUILD_PATH} and 47 * {@link ArtifactProperties#INCLUDES_DEPENDENCIES} will be set to {@code "none"}, {@code true} and {@code false}, 48 * respectively. 49 * 50 * @param id The identifier of the type which will also be used as the value for the {@link ArtifactProperties#TYPE} 51 * property, must not be {@code null} or empty. 52 */ 53 public DefaultArtifactType(String id) { 54 this(id, id, "", "none", false, false); 55 } 56 57 /** 58 * Creates a new artifact type with the specified properties. Additionally, the properties 59 * {@link ArtifactProperties#CONSTITUTES_BUILD_PATH} and {@link ArtifactProperties#INCLUDES_DEPENDENCIES} will be 60 * set to {@code true} and {@code false}, respectively. 61 * 62 * @param id The identifier of the type which will also be used as the value for the {@link ArtifactProperties#TYPE} 63 * property, must not be {@code null} or empty. 64 * @param extension The usual file extension for artifacts of this type, may be {@code null}. 65 * @param classifier The usual classifier for artifacts of this type, may be {@code null}. 66 * @param language The value for the {@link ArtifactProperties#LANGUAGE} property, may be {@code null}. 67 */ 68 public DefaultArtifactType(String id, String extension, String classifier, String language) { 69 this(id, extension, classifier, language, true, false); 70 } 71 72 /** 73 * Creates a new artifact type with the specified properties. 74 * 75 * @param id The identifier of the type which will also be used as the value for the {@link ArtifactProperties#TYPE} 76 * property, must not be {@code null} or empty. 77 * @param extension The usual file extension for artifacts of this type, may be {@code null}. 78 * @param classifier The usual classifier for artifacts of this type, may be {@code null}. 79 * @param language The value for the {@link ArtifactProperties#LANGUAGE} property, may be {@code null}. 80 * @param constitutesBuildPath The value for the {@link ArtifactProperties#CONSTITUTES_BUILD_PATH} property. 81 * @param includesDependencies The value for the {@link ArtifactProperties#INCLUDES_DEPENDENCIES} property. 82 */ 83 public DefaultArtifactType( 84 String id, 85 String extension, 86 String classifier, 87 String language, 88 boolean constitutesBuildPath, 89 boolean includesDependencies) { 90 this.id = requireNonNull(id, "type id cannot be null"); 91 if (id.isEmpty()) { 92 throw new IllegalArgumentException("type id cannot be empty"); 93 } 94 this.extension = emptify(extension); 95 this.classifier = emptify(classifier); 96 Map<String, String> props = new HashMap<>(); 97 props.put(ArtifactProperties.TYPE, id); 98 props.put(ArtifactProperties.LANGUAGE, (language != null && !language.isEmpty()) ? language : "none"); 99 props.put(ArtifactProperties.INCLUDES_DEPENDENCIES, Boolean.toString(includesDependencies)); 100 props.put(ArtifactProperties.CONSTITUTES_BUILD_PATH, Boolean.toString(constitutesBuildPath)); 101 properties = Collections.unmodifiableMap(props); 102 } 103 104 /** 105 * Creates a new artifact type with the specified properties. 106 * 107 * @param id The identifier of the type, must not be {@code null} or empty. 108 * @param extension The usual file extension for artifacts of this type, may be {@code null}. 109 * @param classifier The usual classifier for artifacts of this type, may be {@code null}. 110 * @param properties The properties for artifacts of this type, may be {@code null}. 111 */ 112 public DefaultArtifactType(String id, String extension, String classifier, Map<String, String> properties) { 113 this.id = requireNonNull(id, "type id cannot be null"); 114 if (id.isEmpty()) { 115 throw new IllegalArgumentException("type id cannot be empty"); 116 } 117 this.extension = emptify(extension); 118 this.classifier = emptify(classifier); 119 this.properties = AbstractArtifact.copyProperties(properties); 120 } 121 122 private static String emptify(String str) { 123 return (str == null) ? "" : str; 124 } 125 126 public String getId() { 127 return id; 128 } 129 130 public String getExtension() { 131 return extension; 132 } 133 134 public String getClassifier() { 135 return classifier; 136 } 137 138 public Map<String, String> getProperties() { 139 return properties; 140 } 141 }