Class DefaultArtifact

  • All Implemented Interfaces:
    Artifact

    public final class DefaultArtifact
    extends AbstractArtifact
    A simple artifact. Note: Instances of this class are immutable and the exposed mutators return new objects rather than changing the current instance.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String artifactId  
      private java.lang.String classifier  
      private static java.util.regex.Pattern COORDINATE_PATTERN  
      private java.lang.String extension  
      private java.io.File file  
      private java.lang.String groupId  
      private java.util.Map<java.lang.String,​java.lang.String> properties  
      private java.lang.String version  
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultArtifact​(java.lang.String coords)
      Creates a new artifact with the specified coordinates.
      DefaultArtifact​(java.lang.String groupId, java.lang.String artifactId, java.lang.String extension, java.lang.String version)
      Creates a new artifact with the specified coordinates and no classifier.
      DefaultArtifact​(java.lang.String groupId, java.lang.String artifactId, java.lang.String classifier, java.lang.String extension, java.lang.String version)
      Creates a new artifact with the specified coordinates.
      DefaultArtifact​(java.lang.String groupId, java.lang.String artifactId, java.lang.String classifier, java.lang.String extension, java.lang.String version, java.io.File file, java.util.Map<java.lang.String,​java.lang.String> properties)  
      DefaultArtifact​(java.lang.String groupId, java.lang.String artifactId, java.lang.String classifier, java.lang.String extension, java.lang.String version, java.util.Map<java.lang.String,​java.lang.String> properties, java.io.File file)
      Creates a new artifact with the specified coordinates, properties and file.
      DefaultArtifact​(java.lang.String groupId, java.lang.String artifactId, java.lang.String classifier, java.lang.String extension, java.lang.String version, java.util.Map<java.lang.String,​java.lang.String> properties, ArtifactType type)
      Creates a new artifact with the specified coordinates and properties.
      DefaultArtifact​(java.lang.String groupId, java.lang.String artifactId, java.lang.String classifier, java.lang.String extension, java.lang.String version, ArtifactType type)
      Creates a new artifact with the specified coordinates.
      DefaultArtifact​(java.lang.String coords, java.util.Map<java.lang.String,​java.lang.String> properties)
      Creates a new artifact with the specified coordinates and properties.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String emptify​(java.lang.String str)  
      private static java.lang.String get​(java.lang.String value, java.lang.String defaultValue)  
      java.lang.String getArtifactId()
      Gets the artifact identifier of this artifact, for example "maven-model".
      java.lang.String getClassifier()
      Gets the classifier of this artifact, for example "sources".
      java.lang.String getExtension()
      Gets the (file) extension of this artifact, for example "jar" or "tar.gz".
      java.io.File getFile()
      Gets the file of this artifact.
      java.lang.String getGroupId()
      Gets the group identifier of this artifact, for example "org.apache.maven".
      java.util.Map<java.lang.String,​java.lang.String> getProperties()
      Gets the properties of this artifact.
      java.lang.String getVersion()
      Gets the version of this artifact, for example "1.0-20100529-1213".
      private static java.util.Map<java.lang.String,​java.lang.String> merge​(java.util.Map<java.lang.String,​java.lang.String> dominant, java.util.Map<java.lang.String,​java.lang.String> recessive)  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • COORDINATE_PATTERN

        private static final java.util.regex.Pattern COORDINATE_PATTERN
      • groupId

        private final java.lang.String groupId
      • artifactId

        private final java.lang.String artifactId
      • version

        private final java.lang.String version
      • classifier

        private final java.lang.String classifier
      • extension

        private final java.lang.String extension
      • file

        private final java.io.File file
      • properties

        private final java.util.Map<java.lang.String,​java.lang.String> properties
    • Constructor Detail

      • DefaultArtifact

        public DefaultArtifact​(java.lang.String coords)
        Creates a new artifact with the specified coordinates. If not specified in the artifact coordinates, the artifact's extension defaults to jar and classifier to an empty string.
        Parameters:
        coords - The artifact coordinates in the format <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>, must not be null.
        Throws:
        java.lang.IllegalArgumentException - If the artifact coordinates found in coords do not match the expected format.
      • DefaultArtifact

        public DefaultArtifact​(java.lang.String coords,
                               java.util.Map<java.lang.String,​java.lang.String> properties)
        Creates a new artifact with the specified coordinates and properties. If not specified in the artifact coordinates, the artifact's extension defaults to jar and classifier to an empty string.
        Parameters:
        coords - The artifact coordinates in the format <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>, must not be null.
        properties - The artifact properties, may be null.
        Throws:
        java.lang.IllegalArgumentException - If the artifact coordinates found in coords do not match the expected format.
      • DefaultArtifact

        public DefaultArtifact​(java.lang.String groupId,
                               java.lang.String artifactId,
                               java.lang.String extension,
                               java.lang.String version)
        Creates a new artifact with the specified coordinates and no classifier. Passing null for any of the coordinates is equivalent to specifying an empty string.
        Parameters:
        groupId - The group identifier of the artifact, may be null.
        artifactId - The artifact identifier of the artifact, may be null.
        extension - The file extension of the artifact, may be null.
        version - The version of the artifact, may be null.
      • DefaultArtifact

        public DefaultArtifact​(java.lang.String groupId,
                               java.lang.String artifactId,
                               java.lang.String classifier,
                               java.lang.String extension,
                               java.lang.String version)
        Creates a new artifact with the specified coordinates. Passing null for any of the coordinates is equivalent to specifying an empty string.
        Parameters:
        groupId - The group identifier of the artifact, may be null.
        artifactId - The artifact identifier of the artifact, may be null.
        classifier - The classifier of the artifact, may be null.
        extension - The file extension of the artifact, may be null.
        version - The version of the artifact, may be null.
      • DefaultArtifact

        public DefaultArtifact​(java.lang.String groupId,
                               java.lang.String artifactId,
                               java.lang.String classifier,
                               java.lang.String extension,
                               java.lang.String version,
                               ArtifactType type)
        Creates a new artifact with the specified coordinates. Passing null for any of the coordinates is equivalent to specifying an empty string. The optional artifact type provided to this constructor will be used to determine the artifact's classifier and file extension if the corresponding arguments for this constructor are null.
        Parameters:
        groupId - The group identifier of the artifact, may be null.
        artifactId - The artifact identifier of the artifact, may be null.
        classifier - The classifier of the artifact, may be null.
        extension - The file extension of the artifact, may be null.
        version - The version of the artifact, may be null.
        type - The artifact type from which to query classifier, file extension and properties, may be null.
      • DefaultArtifact

        public DefaultArtifact​(java.lang.String groupId,
                               java.lang.String artifactId,
                               java.lang.String classifier,
                               java.lang.String extension,
                               java.lang.String version,
                               java.util.Map<java.lang.String,​java.lang.String> properties,
                               ArtifactType type)
        Creates a new artifact with the specified coordinates and properties. Passing null for any of the coordinates is equivalent to specifying an empty string. The optional artifact type provided to this constructor will be used to determine the artifact's classifier and file extension if the corresponding arguments for this constructor are null. If the artifact type specifies properties, those will get merged with the properties passed directly into the constructor, with the latter properties taking precedence.
        Parameters:
        groupId - The group identifier of the artifact, may be null.
        artifactId - The artifact identifier of the artifact, may be null.
        classifier - The classifier of the artifact, may be null.
        extension - The file extension of the artifact, may be null.
        version - The version of the artifact, may be null.
        properties - The properties of the artifact, may be null if none.
        type - The artifact type from which to query classifier, file extension and properties, may be null.
      • DefaultArtifact

        public DefaultArtifact​(java.lang.String groupId,
                               java.lang.String artifactId,
                               java.lang.String classifier,
                               java.lang.String extension,
                               java.lang.String version,
                               java.util.Map<java.lang.String,​java.lang.String> properties,
                               java.io.File file)
        Creates a new artifact with the specified coordinates, properties and file. Passing null for any of the coordinates is equivalent to specifying an empty string.
        Parameters:
        groupId - The group identifier of the artifact, may be null.
        artifactId - The artifact identifier of the artifact, may be null.
        classifier - The classifier of the artifact, may be null.
        extension - The file extension of the artifact, may be null.
        version - The version of the artifact, may be null.
        properties - The properties of the artifact, may be null if none.
        file - The resolved file of the artifact, may be null.
      • DefaultArtifact

        DefaultArtifact​(java.lang.String groupId,
                        java.lang.String artifactId,
                        java.lang.String classifier,
                        java.lang.String extension,
                        java.lang.String version,
                        java.io.File file,
                        java.util.Map<java.lang.String,​java.lang.String> properties)
    • Method Detail

      • get

        private static java.lang.String get​(java.lang.String value,
                                            java.lang.String defaultValue)
      • merge

        private static java.util.Map<java.lang.String,​java.lang.String> merge​(java.util.Map<java.lang.String,​java.lang.String> dominant,
                                                                                    java.util.Map<java.lang.String,​java.lang.String> recessive)
      • emptify

        private static java.lang.String emptify​(java.lang.String str)
      • getGroupId

        public java.lang.String getGroupId()
        Description copied from interface: Artifact
        Gets the group identifier of this artifact, for example "org.apache.maven".
        Returns:
        The group identifier, never null.
      • getArtifactId

        public java.lang.String getArtifactId()
        Description copied from interface: Artifact
        Gets the artifact identifier of this artifact, for example "maven-model".
        Returns:
        The artifact identifier, never null.
      • getVersion

        public java.lang.String getVersion()
        Description copied from interface: Artifact
        Gets the version of this artifact, for example "1.0-20100529-1213". Note that in case of meta versions like "1.0-SNAPSHOT", the artifact's version depends on the state of the artifact. Artifacts that have been resolved or deployed will usually have the meta version expanded.
        Returns:
        The version, never null.
      • getClassifier

        public java.lang.String getClassifier()
        Description copied from interface: Artifact
        Gets the classifier of this artifact, for example "sources".
        Returns:
        The classifier or an empty string if none, never null.
      • getExtension

        public java.lang.String getExtension()
        Description copied from interface: Artifact
        Gets the (file) extension of this artifact, for example "jar" or "tar.gz".
        Returns:
        The file extension (without leading period), never null.
      • getFile

        public java.io.File getFile()
        Description copied from interface: Artifact
        Gets the file of this artifact. Note that only resolved artifacts have a file associated with them. In general, callers must not assume any relationship between an artifact's filename and its coordinates.
        Returns:
        The file or null if the artifact isn't resolved.
      • getProperties

        public java.util.Map<java.lang.String,​java.lang.String> getProperties()
        Description copied from interface: Artifact
        Gets the properties of this artifact. Clients may use these properties to associate non-persistent values with an artifact that help later processing when the artifact gets passed around within the application.
        Returns:
        The (read-only) properties, never null.
        See Also:
        ArtifactProperties