View Javadoc
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 base version of the artifact.
78       *
79       * @return the version
80       */
81      @Nonnull
82      Version getBaseVersion();
83  
84      /**
85       * The classifier of the artifact.
86       *
87       * @return the classifier or an empty string if none, never {@code null}
88       */
89      @Nonnull
90      String getClassifier();
91  
92      /**
93       * The file extension of the artifact.
94       *
95       * @return the extension
96       */
97      @Nonnull
98      String getExtension();
99  
100     /**
101      * Determines whether this artifact uses a snapshot version.
102      *
103      * @return {@code true} if the artifact is a snapshot, {@code false} otherwise
104      * @see org.apache.maven.api.Session#isVersionSnapshot(String)
105      */
106     boolean isSnapshot();
107 
108     /**
109      * Shortcut for {@code session.createArtifactCoordinate(artifact)}
110      *
111      * @return an {@link ArtifactCoordinate}
112      * @see org.apache.maven.api.Session#createArtifactCoordinate(Artifact)
113      */
114     @Nonnull
115     ArtifactCoordinate toCoordinate();
116 }