1 package org.apache.maven.api; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import org.apache.maven.api.annotations.Experimental; 23 import org.apache.maven.api.annotations.Immutable; 24 import org.apache.maven.api.annotations.Nonnull; 25 26 /** 27 * An artifact points to a resource such as a jar file or war application. 28 * 29 * @since 4.0 30 */ 31 @Experimental 32 @Immutable 33 public interface Artifact 34 { 35 36 /** 37 * Returns a unique identifier for this artifact. 38 * The identifier is composed of groupId, artifactId, version, classifier, extension 39 * @return the unique identifier 40 */ 41 default String key() 42 { 43 return getGroupId() 44 + ':' + getArtifactId() 45 + ':' + getExtension() 46 + ( getClassifier().length() > 0 ? ":" + getClassifier() : "" ) 47 + ':' + getVersion(); 48 } 49 50 /** 51 * The groupId of the artifact. 52 * 53 * @return The groupId. 54 */ 55 @Nonnull 56 String getGroupId(); 57 58 /** 59 * The artifactId of the artifact. 60 * 61 * @return The artifactId. 62 */ 63 @Nonnull 64 String getArtifactId(); 65 66 /** 67 * The version of the artifact. 68 * 69 * @return The version. 70 */ 71 @Nonnull 72 Version getVersion(); 73 74 /** 75 * The classifier of the artifact. 76 * 77 * @return The classifier or an empty string if none, never {@code null}. 78 */ 79 @Nonnull 80 String getClassifier(); 81 82 /** 83 * The file extension of the artifact. 84 * 85 * @return The extension. 86 */ 87 @Nonnull 88 String getExtension(); 89 90 /** 91 * Determines whether this artifact uses a snapshot version. 92 * 93 * @return {@code true} if the artifact is a snapshot, {@code false} otherwise. 94 * @see org.apache.maven.api.Session#isVersionSnapshot(String) 95 */ 96 boolean isSnapshot(); 97 98 /** 99 * Shortcut for {@code session.createArtifactCoordinate(artifact)} 100 * 101 * @return an {@link ArtifactCoordinate} 102 * @see org.apache.maven.api.Session#createArtifactCoordinate(Artifact) 103 */ 104 @Nonnull 105 ArtifactCoordinate toCoordinate(); 106 107 }