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.apache.maven.api;
20
21 import org.apache.maven.api.annotations.Experimental;
22 import org.apache.maven.api.annotations.Immutable;
23 import org.apache.maven.api.annotations.Nonnull;
24
25 /**
26 * An artifact points to a resource such as a jar file or war application.
27 *
28 * @since 4.0
29 */
30 @Experimental
31 @Immutable
32 public interface Artifact {
33
34 /**
35 * Returns a unique identifier for this artifact.
36 * The identifier is composed of groupId, artifactId, version, classifier, extension.
37 *
38 * @return the unique identifier
39 */
40 default String key() {
41 return getGroupId()
42 + ':'
43 + getArtifactId()
44 + ':'
45 + getExtension()
46 + (getClassifier().length() > 0 ? ":" + getClassifier() : "")
47 + ':'
48 + getVersion();
49 }
50
51 /**
52 * The groupId of the artifact.
53 *
54 * @return the groupId
55 */
56 @Nonnull
57 String getGroupId();
58
59 /**
60 * The artifactId of the artifact.
61 *
62 * @return the artifactId
63 */
64 @Nonnull
65 String getArtifactId();
66
67 /**
68 * The version of the artifact.
69 *
70 * @return the version
71 */
72 @Nonnull
73 Version getVersion();
74
75 /**
76 * The classifier of the artifact.
77 *
78 * @return the classifier or an empty string if none, never {@code null}
79 */
80 @Nonnull
81 String getClassifier();
82
83 /**
84 * The file extension of the artifact.
85 *
86 * @return the extension
87 */
88 @Nonnull
89 String getExtension();
90
91 /**
92 * Determines whether this artifact uses a snapshot version.
93 *
94 * @return {@code true} if the artifact is a snapshot, {@code false} otherwise
95 * @see org.apache.maven.api.Session#isVersionSnapshot(String)
96 */
97 boolean isSnapshot();
98
99 /**
100 * Shortcut for {@code session.createArtifactCoordinate(artifact)}
101 *
102 * @return an {@link ArtifactCoordinate}
103 * @see org.apache.maven.api.Session#createArtifactCoordinate(Artifact)
104 */
105 @Nonnull
106 ArtifactCoordinate toCoordinate();
107 }