org.apache.maven.plugin.testing
Class ArtifactStubFactory

java.lang.Object
  extended by org.apache.maven.plugin.testing.ArtifactStubFactory

public class ArtifactStubFactory
extends Object

This class creates artifacts to be used for testing purposes. It can optionally create actual files on the local disk for things like copying. It can create these files as archives with named files inside to be used for testing things like unpack. Also provided are some utility methods to quickly get a set of artifacts distinguished by various things like group,artifact,type,scope, etc It was originally developed for the dependency plugin, but can be useful in other plugins that need to simulate artifacts for unit tests.

Author:
Brian Fox

Constructor Summary
ArtifactStubFactory()
          Default constructor.
ArtifactStubFactory(File workingDir, boolean createFiles)
          This constructor is to be used if files are needed and to set a working dir
 
Method Summary
 Artifact createArtifact(String groupId, String artifactId, String version)
           
 Artifact createArtifact(String groupId, String artifactId, String version, String scope)
           
 Artifact createArtifact(String groupId, String artifactId, String version, String scope, String type, String classifier)
           
 Artifact createArtifact(String groupId, String artifactId, VersionRange versionRange, String scope, String type, String classifier, boolean optional)
           
 void createUnpackableFile(Artifact artifact, File destFile)
           
 Set getArtifactArtifacts()
           
 Set getClassifiedArtifacts()
           
static String getFormattedFileName(Artifact artifact, boolean removeVersion)
          Builds the file name.
 Set getGroupIdArtifacts()
           
 Set getMixedArtifacts()
           
 Set getReleaseAndSnapshotArtifacts()
           
 Artifact getReleaseArtifact()
           
 Set getScopedArtifacts()
           
 Artifact getSnapshotArtifact()
           
 File getSrcFile()
           
 Set getTypedArchiveArtifacts()
           
 Set getTypedArtifacts()
           
static String getUnpackableFileName(Artifact artifact)
           
 File getWorkingDir()
           
 boolean isCreateFiles()
           
 void setArtifactFile(Artifact artifact)
           
 void setCreateFiles(boolean createFiles)
           
 void setSrcFile(File srcFile)
           
 void setUnpackableFile(org.codehaus.plexus.archiver.manager.ArchiverManager archiverManager)
          If set, the file will be created as a zip/jar/war with a file inside that can be checked to exist after unpacking.
static void setVariableValueToObject(Object object, String variable, Object value)
          convience method to set values to variables in objects that don't have setters
 void setWorkingDir(File workingDir)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArtifactStubFactory

public ArtifactStubFactory()
Default constructor. This should be used only if real files aren't needed...just the artifact objects


ArtifactStubFactory

public ArtifactStubFactory(File workingDir,
                           boolean createFiles)
This constructor is to be used if files are needed and to set a working dir

Parameters:
workingDir -
createFiles -
Method Detail

setUnpackableFile

public void setUnpackableFile(org.codehaus.plexus.archiver.manager.ArchiverManager archiverManager)
If set, the file will be created as a zip/jar/war with a file inside that can be checked to exist after unpacking.

Parameters:
archiverManager -

createArtifact

public Artifact createArtifact(String groupId,
                               String artifactId,
                               String version)
                        throws IOException
Throws:
IOException

createArtifact

public Artifact createArtifact(String groupId,
                               String artifactId,
                               String version,
                               String scope)
                        throws IOException
Throws:
IOException

createArtifact

public Artifact createArtifact(String groupId,
                               String artifactId,
                               String version,
                               String scope,
                               String type,
                               String classifier)
                        throws IOException
Throws:
IOException

createArtifact

public Artifact createArtifact(String groupId,
                               String artifactId,
                               VersionRange versionRange,
                               String scope,
                               String type,
                               String classifier,
                               boolean optional)
                        throws IOException
Throws:
IOException

setArtifactFile

public void setArtifactFile(Artifact artifact)
                     throws IOException
Throws:
IOException

getUnpackableFileName

public static String getUnpackableFileName(Artifact artifact)

createUnpackableFile

public void createUnpackableFile(Artifact artifact,
                                 File destFile)
                          throws org.codehaus.plexus.archiver.manager.NoSuchArchiverException,
                                 org.codehaus.plexus.archiver.ArchiverException,
                                 IOException
Throws:
org.codehaus.plexus.archiver.manager.NoSuchArchiverException
org.codehaus.plexus.archiver.ArchiverException
IOException

getReleaseArtifact

public Artifact getReleaseArtifact()
                            throws IOException
Throws:
IOException

getSnapshotArtifact

public Artifact getSnapshotArtifact()
                             throws IOException
Throws:
IOException

getReleaseAndSnapshotArtifacts

public Set getReleaseAndSnapshotArtifacts()
                                   throws IOException
Throws:
IOException

getScopedArtifacts

public Set getScopedArtifacts()
                       throws IOException
Throws:
IOException

getTypedArtifacts

public Set getTypedArtifacts()
                      throws IOException
Throws:
IOException

getClassifiedArtifacts

public Set getClassifiedArtifacts()
                           throws IOException
Throws:
IOException

getTypedArchiveArtifacts

public Set getTypedArchiveArtifacts()
                             throws IOException
Throws:
IOException

getArtifactArtifacts

public Set getArtifactArtifacts()
                         throws IOException
Throws:
IOException

getGroupIdArtifacts

public Set getGroupIdArtifacts()
                        throws IOException
Throws:
IOException

getMixedArtifacts

public Set getMixedArtifacts()
                      throws IOException
Throws:
IOException

isCreateFiles

public boolean isCreateFiles()
Returns:
Returns the createFiles.

setCreateFiles

public void setCreateFiles(boolean createFiles)
Parameters:
createFiles - The createFiles to set.

getWorkingDir

public File getWorkingDir()
Returns:
Returns the workingDir.

setWorkingDir

public void setWorkingDir(File workingDir)
Parameters:
workingDir - The workingDir to set.

getSrcFile

public File getSrcFile()
Returns:
Returns the srcFile.

setSrcFile

public void setSrcFile(File srcFile)
Parameters:
srcFile - The srcFile to set.

setVariableValueToObject

public static void setVariableValueToObject(Object object,
                                            String variable,
                                            Object value)
                                     throws IllegalAccessException
convience method to set values to variables in objects that don't have setters

Parameters:
object -
variable -
value -
Throws:
IllegalAccessException

getFormattedFileName

public static String getFormattedFileName(Artifact artifact,
                                          boolean removeVersion)
Builds the file name. If removeVersion is set, then the file name must be reconstructed from the artifactId, Classifier (if used) and Type. Otherwise, this method returns the artifact file name.

Parameters:
artifact - File to be formatted.
removeVersion - Specifies if the version should be removed from the file name.
Returns:
Formatted file name in the format artifactId-[version]-[classifier].[type]


Copyright © 2002-2011 Apache Software Foundation. All Rights Reserved.