org.sonatype.aether.util.artifact
Class DefaultArtifact

java.lang.Object
  extended by org.sonatype.aether.util.artifact.AbstractArtifact
      extended by org.sonatype.aether.util.artifact.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.

Author:
Benjamin Bentmann

Constructor Summary
DefaultArtifact(String coords)
          Creates a new artifact with the specified coordinates.
DefaultArtifact(String coords, Map<String,String> properties)
          Creates a new artifact with the specified coordinates and properties.
DefaultArtifact(String groupId, String artifactId, String extension, String version)
          Creates a new artifact with the specified coordinates and no classifier.
DefaultArtifact(String groupId, String artifactId, String classifier, String extension, String version)
          Creates a new artifact with the specified coordinates.
DefaultArtifact(String groupId, String artifactId, String classifier, String extension, String version, ArtifactType type)
          Creates a new artifact with the specified coordinates.
DefaultArtifact(String groupId, String artifactId, String classifier, String extension, String version, Map<String,String> properties, ArtifactType type)
          Creates a new artifact with the specified coordinates and properties.
DefaultArtifact(String groupId, String artifactId, String classifier, String extension, String version, Map<String,String> properties, File file)
          Creates a new artifact with the specified coordinates, properties and file.
 
Method Summary
 String getArtifactId()
          Gets the artifact identifier of this artifact, for example "maven-model".
 String getBaseVersion()
          Gets the base version of this artifact, for example "1.0-SNAPSHOT".
 String getClassifier()
          Gets the classifier of this artifact, for example "sources".
 String getExtension()
          Gets the (file) extension of this artifact, for example "jar".
 File getFile()
          Gets the file of this artifact.
 String getGroupId()
          Gets the group identifier of this artifact, for example "org.apache.maven".
 Map<String,String> getProperties()
          Gets the properties of this artifact.
 String getProperty(String key, String defaultValue)
          Gets the specified property.
 String getVersion()
          Gets the version of this artifact, for example "1.0-20100529-1213".
 boolean isSnapshot()
          Determines whether this artifact uses a snapshot version.
 Artifact setFile(File file)
          Sets the file of the artifact.
 Artifact setProperties(Map<String,String> properties)
          Sets the properties for the artifact.
 Artifact setVersion(String version)
          Sets the version of this artifact.
 
Methods inherited from class org.sonatype.aether.util.artifact.AbstractArtifact
equals, hashCode, isSnapshot, newInstance, toBaseVersion, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultArtifact

public DefaultArtifact(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.

DefaultArtifact

public DefaultArtifact(String coords,
                       Map<String,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.

DefaultArtifact

public DefaultArtifact(String groupId,
                       String artifactId,
                       String extension,
                       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(String groupId,
                       String artifactId,
                       String classifier,
                       String extension,
                       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(String groupId,
                       String artifactId,
                       String classifier,
                       String extension,
                       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(String groupId,
                       String artifactId,
                       String classifier,
                       String extension,
                       String version,
                       Map<String,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(String groupId,
                       String artifactId,
                       String classifier,
                       String extension,
                       String version,
                       Map<String,String> properties,
                       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.
Method Detail

getGroupId

public 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 String getArtifactId()
Description copied from interface: Artifact
Gets the artifact identifier of this artifact, for example "maven-model".

Returns:
The artifact identifier, never null.

getBaseVersion

public String getBaseVersion()
Description copied from interface: Artifact
Gets the base version of this artifact, for example "1.0-SNAPSHOT". In contrast to the Artifact.getVersion(), the base version will always refer to the unresolved meta version.

Returns:
The base version, never null.

getVersion

public 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 have the meta version expanded.

Returns:
The version, never null.

setVersion

public Artifact setVersion(String version)
Description copied from interface: Artifact
Sets the version of this artifact.

Specified by:
setVersion in interface Artifact
Overrides:
setVersion in class AbstractArtifact
Parameters:
version - The version of this artifact, may be null or empty.
Returns:
The new artifact, never null.

isSnapshot

public boolean isSnapshot()
Description copied from interface: Artifact
Determines whether this artifact uses a snapshot version.

Returns:
true if the artifact is a snapshot, false otherwise.

getClassifier

public 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 String getExtension()
Description copied from interface: Artifact
Gets the (file) extension of this artifact, for example "jar".

Returns:
The file extension, never null.

getFile

public File getFile()
Description copied from interface: Artifact
Gets the file of this artifact. Note that only resolved artifacts have a file associated with them.

Returns:
The file or null if the artifact isn't resolved.

setFile

public Artifact setFile(File file)
Description copied from interface: Artifact
Sets the file of the artifact.

Specified by:
setFile in interface Artifact
Overrides:
setFile in class AbstractArtifact
Parameters:
file - The file of the artifact, may be null
Returns:
The new artifact, never null.

getProperty

public String getProperty(String key,
                          String defaultValue)
Description copied from interface: Artifact
Gets the specified property.

Parameters:
key - The name of the property, must not be null.
defaultValue - The default value to return in case the property is not set, may be null.

getProperties

public Map<String,String> getProperties()
Description copied from interface: Artifact
Gets the properties of this artifact. While the exact set of available properties is undefined, the following properties are considered to be common:
type
A high-level characterization of the artifact, e.g. "maven-plugin" or "test-jar".
language
The programming language this artifact is relevant for, e.g. "java" or "none".
includesDependencies
A boolean flag indicating whether the artifact presents some kind of bundle that physically includes its dependencies, e.g. a fat WAR.
constitutesBuildPath
A boolean flag indicating whether the artifact is meant to be used for the compile/runtime/test build path of a consumer project.
localPath
The (expected) path to the artifact on the local filesystem. An artifact which has this property set is assumed to be not present in any regular repository and likewise has no artifact descriptor.

Returns:
The (read-only) properties, never null.

setProperties

public Artifact setProperties(Map<String,String> properties)
Description copied from interface: Artifact
Sets the properties for the artifact.

Specified by:
setProperties in interface Artifact
Overrides:
setProperties in class AbstractArtifact
Parameters:
properties - The properties for the artifact, may be null.
Returns:
The new artifact, never null.


Copyright © 2010-2013. All Rights Reserved.