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