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 * Partial identification of an {@link Artifact} in a Maven repository. 27 * Each {@code ArtifactCoordinates} instance is basically a pointer to a file in the Maven repository, 28 * except that the exact version may not be known yet. 29 * 30 * @since 4.0.0 31 */ 32 @Experimental 33 @Immutable 34 public interface ArtifactCoordinates { 35 /** 36 * {@return the group identifier of the artifact}. 37 */ 38 @Nonnull 39 String getGroupId(); 40 41 /** 42 * {@return the identifier of the artifact}. 43 */ 44 @Nonnull 45 String getArtifactId(); 46 47 /** 48 * Returns the classifier of the artifact. 49 * 50 * @return the classifier or an empty string if none, never {@code null} 51 */ 52 @Nonnull 53 String getClassifier(); 54 55 /** 56 * {@return the specific version, range of versions or meta-version of the artifact}. 57 * A meta-version is a version suffixed with the {@code SNAPSHOT} keyword. 58 */ 59 @Nonnull 60 VersionConstraint getVersionConstraint(); 61 62 /** 63 * Returns the file extension of the artifact. 64 * The dot separator is <em>not</em> included in the returned string. 65 * 66 * @return the file extension or an empty string if none, never {@code null} 67 */ 68 @Nonnull 69 String getExtension(); 70 71 /** 72 * {@return a unique string representation identifying this artifact} 73 * 74 * The default implementation returns a colon-separated list of group 75 * identifier, artifact identifier, extension, classifier and version. 76 * 77 * @see Artifact#key() 78 */ 79 @Nonnull 80 default String getId() { 81 String c = getClassifier(); 82 return getGroupId() 83 + ':' 84 + getArtifactId() 85 + ':' 86 + getExtension() 87 + ':' 88 + c 89 + (c.isEmpty() ? "" : ":") 90 + getVersionConstraint(); 91 } 92 }