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.io.File;
022import java.nio.file.Path;
023import java.util.Map;
024
025/**
026 * A specific artifact. In a nutshell, an artifact has identifying coordinates and optionally a file that denotes its
027 * data. <em>Note:</em> Artifact instances are supposed to be immutable, e.g. any exposed mutator method returns a new
028 * artifact instance and leaves the original instance unchanged. <em>Note:</em> Implementors are strongly advised to
029 * inherit from {@link AbstractArtifact} instead of directly implementing this interface.
030 *
031 * @noimplement This interface is not intended to be implemented by clients.
032 * @noextend This interface is not intended to be extended by clients.
033 */
034public interface Artifact {
035
036    /**
037     * Gets the group identifier of this artifact, for example "org.apache.maven".
038     *
039     * @return The group identifier, never {@code null}.
040     */
041    String getGroupId();
042
043    /**
044     * Gets the artifact identifier of this artifact, for example "maven-model".
045     *
046     * @return The artifact identifier, never {@code null}.
047     */
048    String getArtifactId();
049
050    /**
051     * Gets the version of this artifact, for example "1.0-20100529-1213". Note that in case of meta versions like
052     * "1.0-SNAPSHOT", the artifact's version depends on the state of the artifact. Artifacts that have been resolved or
053     * deployed will usually have the meta version expanded.
054     * This may also return version ranges like "[1.0,2.0)". The exact syntax for (meta) versions and version ranges
055     * depends on the underlying provider (encapsulated in {@link org.eclipse.aether.RepositorySystem}).
056     *
057     * @return The version, never {@code null}.
058     */
059    String getVersion();
060
061    /**
062     * Sets the version of the artifact.
063     *
064     * @param version The version of this artifact, may be {@code null} or empty.
065     * @return The new artifact, never {@code null}.
066     */
067    Artifact setVersion(String version);
068
069    /**
070     * Gets the base version of this artifact, for example "1.0-SNAPSHOT". In contrast to the {@link #getVersion()}, the
071     * base version will always refer to the unresolved meta version.
072     *
073     * @return The base version, never {@code null}.
074     */
075    String getBaseVersion();
076
077    /**
078     * Determines whether this artifact uses a snapshot version.
079     *
080     * @return {@code true} if the artifact is a snapshot, {@code false} otherwise.
081     */
082    boolean isSnapshot();
083
084    /**
085     * Gets the classifier of this artifact, for example "sources".
086     *
087     * @return The classifier or an empty string if none, never {@code null}.
088     */
089    String getClassifier();
090
091    /**
092     * Gets the (file) extension of this artifact, for example "jar" or "tar.gz".
093     *
094     * @return The file extension (without leading period), never {@code null}.
095     */
096    String getExtension();
097
098    /**
099     * Gets the file of this artifact. Note that only resolved artifacts have a file associated with them. In general,
100     * callers must not assume any relationship between an artifact's filename and its coordinates.
101     *
102     * @return The file or {@code null} if the artifact isn't resolved.
103     * @deprecated Use {@link #getPath()} instead.
104     */
105    @Deprecated
106    File getFile();
107
108    /**
109     * Gets the file of this artifact. Note that only resolved artifacts have a file associated with them. In general,
110     * callers must not assume any relationship between an artifact's filename and its coordinates.
111     *
112     * @return The file or {@code null} if the artifact isn't resolved.
113     * @since 2.0.0
114     */
115    Path getPath();
116
117    /**
118     * Sets the file of the artifact.
119     *
120     * @param file The file of the artifact, may be {@code null}
121     * @return The new artifact, never {@code null}.
122     * @deprecated Use {@link #setPath(Path)} instead.
123     */
124    @Deprecated
125    Artifact setFile(File file);
126
127    /**
128     * Sets the file of the artifact.
129     *
130     * @param path The file of the artifact, may be {@code null}
131     * @return The new artifact, never {@code null}.
132     * @since 2.0.0
133     */
134    Artifact setPath(Path path);
135
136    /**
137     * Gets the specified property.
138     *
139     * @param key The name of the property, must not be {@code null}.
140     * @param defaultValue The default value to return in case the property is not set, may be {@code null}.
141     * @return The requested property value or {@code null} if the property is not set and no default value was
142     *         provided.
143     * @see ArtifactProperties
144     */
145    String getProperty(String key, String defaultValue);
146
147    /**
148     * Gets the properties of this artifact. Clients may use these properties to associate non-persistent values with an
149     * artifact that help later processing when the artifact gets passed around within the application.
150     *
151     * @return The (read-only) properties, never {@code null}.
152     * @see ArtifactProperties
153     */
154    Map<String, String> getProperties();
155
156    /**
157     * Sets the properties for the artifact. Note that these properties exist merely in memory and are not persisted
158     * when the artifact gets installed/deployed to a repository.
159     *
160     * @param properties The properties for the artifact, may be {@code null}.
161     * @return The new artifact, never {@code null}.
162     * @see ArtifactProperties
163     */
164    Artifact setProperties(Map<String, String> properties);
165}