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.artifact;
020
021import java.util.Collections;
022import java.util.HashMap;
023import java.util.Map;
024
025import static java.util.Objects.requireNonNull;
026
027/**
028 * A simple artifact type.
029 *
030 * @deprecated since 2.0, the artifact types should be defined by the resolver consumer
031 */
032@Deprecated
033public final class DefaultArtifactType implements ArtifactType {
034
035    private final String id;
036
037    private final String extension;
038
039    private final String classifier;
040
041    private final Map<String, String> properties;
042
043    /**
044     * Creates a new artifact type with the specified identifier. This constructor assumes the usual file extension
045     * equals the given type id and that the usual classifier is empty. Additionally, the properties
046     * {@link ArtifactProperties#LANGUAGE}, {@link ArtifactProperties#CONSTITUTES_BUILD_PATH} and
047     * {@link ArtifactProperties#INCLUDES_DEPENDENCIES} will be set to {@code "none"}, {@code true} and {@code false},
048     * respectively.
049     *
050     * @param id The identifier of the type which will also be used as the value for the {@link ArtifactProperties#TYPE}
051     *            property, must not be {@code null} or empty.
052     */
053    public DefaultArtifactType(String id) {
054        this(id, id, "", "none", false, false);
055    }
056
057    /**
058     * Creates a new artifact type with the specified properties. Additionally, the properties
059     * {@link ArtifactProperties#CONSTITUTES_BUILD_PATH} and {@link ArtifactProperties#INCLUDES_DEPENDENCIES} will be
060     * set to {@code true} and {@code false}, respectively.
061     *
062     * @param id The identifier of the type which will also be used as the value for the {@link ArtifactProperties#TYPE}
063     *            property, must not be {@code null} or empty.
064     * @param extension The usual file extension for artifacts of this type, may be {@code null}.
065     * @param classifier The usual classifier for artifacts of this type, may be {@code null}.
066     * @param language The value for the {@link ArtifactProperties#LANGUAGE} property, may be {@code null}.
067     */
068    public DefaultArtifactType(String id, String extension, String classifier, String language) {
069        this(id, extension, classifier, language, true, false);
070    }
071
072    /**
073     * Creates a new artifact type with the specified properties.
074     *
075     * @param id The identifier of the type which will also be used as the value for the {@link ArtifactProperties#TYPE}
076     *            property, must not be {@code null} or empty.
077     * @param extension The usual file extension for artifacts of this type, may be {@code null}.
078     * @param classifier The usual classifier for artifacts of this type, may be {@code null}.
079     * @param language The value for the {@link ArtifactProperties#LANGUAGE} property, may be {@code null}.
080     * @param constitutesBuildPath The value for the {@link ArtifactProperties#CONSTITUTES_BUILD_PATH} property.
081     * @param includesDependencies The value for the {@link ArtifactProperties#INCLUDES_DEPENDENCIES} property.
082     */
083    public DefaultArtifactType(
084            String id,
085            String extension,
086            String classifier,
087            String language,
088            boolean constitutesBuildPath,
089            boolean includesDependencies) {
090        this.id = requireNonNull(id, "type id cannot be null");
091        if (id.isEmpty()) {
092            throw new IllegalArgumentException("type id cannot be empty");
093        }
094        this.extension = emptify(extension);
095        this.classifier = emptify(classifier);
096        Map<String, String> props = new HashMap<>();
097        props.put(ArtifactProperties.TYPE, id);
098        props.put(ArtifactProperties.LANGUAGE, (language != null && !language.isEmpty()) ? language : "none");
099        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}