Class ArtifactId

java.lang.Object
org.apache.sling.feature.ArtifactId
All Implemented Interfaces:
Serializable, Comparable<ArtifactId>

public class ArtifactId extends Object implements Comparable<ArtifactId>, Serializable
An artifact identifier. An artifact is described by it's Apache Maven coordinates consisting of group id, artifact id, and version. In addition, the classifier and type can be specified. If no type is specified, jar is assumed. This class is thread-safe.
See Also:
  • Field Details

    • DEFAULT_TYPE

      public static final String DEFAULT_TYPE
      The default type if null is provided as a type. @since 1.3
      See Also:
  • Constructor Details

    • ArtifactId

      public ArtifactId(String groupId, String artifactId, String version, String classifier, String type)
      Create a new artifact object
      Parameters:
      groupId - The group id (required)
      artifactId - The artifact id (required)
      version - The version (required)
      classifier - The classifier (optional)
      type - The type/extension (optional, defaults to #DEFAULT_TYPE.
      Throws:
      IllegalArgumentException - If group id, artifact id or version are null.
  • Method Details

    • parse

      public static ArtifactId parse(String s)
      Create a new artifact id from a string, the string must either be a mvn url or a mvn id (= coordinates)
      Parameters:
      s - The string to parse
      Returns:
      The artifact id
      Throws:
      IllegalArgumentException - if the string can't be parsed to a valid artifact id.
    • fromMvnUrl

      public static ArtifactId fromMvnUrl(String url)
      Create a new artifact id from a maven url, 'mvn:' group-id '/' artifact-id [ '/' [version] [ '/' [type] [ '/' classifier ] ] ] ]
      Parameters:
      url - The url
      Returns:
      A new artifact id
      Throws:
      IllegalArgumentException - If the url is not valid
    • fromMvnId

      public static ArtifactId fromMvnId(String coordinates)
      Create a new artifact id from maven coordinates/id groupId:artifactId[:packaging[:classifier]]:version
      Parameters:
      coordinates - The coordinates as outlined above
      Returns:
      A new artifact id
      Throws:
      IllegalArgumentException - If the id is not valid
    • fromMvnPath

      public static ArtifactId fromMvnPath(String path)
      Create a new artifact id from a maven path The schema is groupIdPath/artifactId/version/artifactId-version[-classifier].type
      Parameters:
      path - The maven path
      Returns:
      A new artifact id
      Throws:
      IllegalArgumentException - If the path is not valid
      Since:
      1.3.0
    • toMvnUrl

      public String toMvnUrl()
      Return a mvn url
      Returns:
      A mvn url
      See Also:
    • toMvnId

      public String toMvnId()
      Return a mvn id
      Returns:
      The mvn id #see fromMvnId(String)
    • getGroupId

      public String getGroupId()
      Return the group id.
      Returns:
      The group id.
    • getArtifactId

      public String getArtifactId()
      Return the artifact id.
      Returns:
      The artifact id.
    • getClassifier

      public String getClassifier()
      Return the optional classifier.
      Returns:
      The classifier or null.
    • getType

      public String getType()
      Return the type.
      Returns:
      The type.
    • getVersion

      public String getVersion()
      Return the version.
      Returns:
      The version.
    • isSame

      public boolean isSame(ArtifactId id)
      Test whether the artifact id is pointing to the same artifact but potentially a different version
      Parameters:
      id - The artifact id
      Returns:
      true if group id, artifact id, type and classifier equal
    • getOSGiVersion

      public org.osgi.framework.Version getOSGiVersion()
      Return the OSGi version
      Returns:
      The OSGi version
      Throws:
      IllegalArgumentException - If the numerical components are negative or the qualifier string is invalid.
    • toMvnPath

      public String toMvnPath()
      Create a Maven like relative repository path.
      Returns:
      A relative repository path. The path does not start with a slash.
    • toMvnName

      public String toMvnName()
      Create a Maven like repository name
      Returns:
      Just the name of the artifact (including version, classifier, type)
      Since:
      1.2
    • changeVersion

      public ArtifactId changeVersion(String newVersion)
      Provide artifact id with a different version.
      Parameters:
      newVersion - The new version
      Returns:
      New artifact id based on this id with just a different version.
      Throws:
      IllegalArgumentException - if the version is null
      Since:
      1.3
    • changeType

      public ArtifactId changeType(String newType)
      Provide artifact id with a different type.
      Parameters:
      newType - The new type, if null the default #DEFAULT_TYPE is used
      Returns:
      New artifact id based on this id with just a different type.
      Since:
      1.3
    • changeClassifier

      public ArtifactId changeClassifier(String newClassifier)
      Provide artifact id with a different classifier.
      Parameters:
      newClassifier - The new classifier
      Returns:
      New artifact id based on this id with just a different classifier.
      Since:
      1.3
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(ArtifactId o)
      Specified by:
      compareTo in interface Comparable<ArtifactId>
    • toString

      public String toString()
      Overrides:
      toString in class Object