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.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, extension, classifier, and version.
37 *
38 * @return the unique identifier
39 */
40 @Nonnull
41 default String key() {
42 return getGroupId()
43 + ':'
44 + getArtifactId()
45 + ':'
46 + getExtension()
47 + (getClassifier().isEmpty() ? "" : ":" + getClassifier())
48 + ':'
49 + getVersion();
50 }
51
52 /**
53 * The groupId of the artifact.
54 *
55 * @return the groupId
56 */
57 @Nonnull
58 String getGroupId();
59
60 /**
61 * The artifactId of the artifact.
62 *
63 * @return the artifactId
64 */
65 @Nonnull
66 String getArtifactId();
67
68 /**
69 * The version of the artifact.
70 *
71 * @return the version
72 */
73 @Nonnull
74 Version getVersion();
75
76 /**
77 * The classifier of the artifact.
78 *
79 * @return the classifier or an empty string if none, never {@code null}
80 */
81 @Nonnull
82 String getClassifier();
83
84 /**
85 * The file extension of the artifact.
86 *
87 * @return the extension
88 */
89 @Nonnull
90 String getExtension();
91
92 /**
93 * Determines whether this artifact uses a snapshot version.
94 *
95 * @return {@code true} if the artifact is a snapshot, {@code false} otherwise
96 * @see org.apache.maven.api.Session#isVersionSnapshot(String)
97 */
98 boolean isSnapshot();
99
100 /**
101 * Shortcut for {@code session.createArtifactCoordinate(artifact)}
102 *
103 * @return an {@link ArtifactCoordinate}
104 * @see org.apache.maven.api.Session#createArtifactCoordinate(Artifact)
105 */
106 @Nonnull
107 ArtifactCoordinate toCoordinate();
108 }