org.apache.maven.plugin.testing
Class ArtifactStubFactory

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

public class ArtifactStubFactory
extends java.lang.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(java.io.File workingDir, boolean createFiles)
          This constructor is to be used if files are needed and to set a working dir
 
Method Summary
 org.apache.maven.artifact.Artifact createArtifact(java.lang.String groupId, java.lang.String artifactId, java.lang.String version)
           
 org.apache.maven.artifact.Artifact createArtifact(java.lang.String groupId, java.lang.String artifactId, java.lang.String version, java.lang.String scope)
           
 org.apache.maven.artifact.Artifact createArtifact(java.lang.String groupId, java.lang.String artifactId, java.lang.String version, java.lang.String scope, java.lang.String type, java.lang.String classifier)
           
 org.apache.maven.artifact.Artifact createArtifact(java.lang.String groupId, java.lang.String artifactId, org.apache.maven.artifact.versioning.VersionRange versionRange, java.lang.String scope, java.lang.String type, java.lang.String classifier, boolean optional)
           
 void createUnpackableFile(org.apache.maven.artifact.Artifact artifact, java.io.File destFile)
           
 java.util.Set getArtifactArtifacts()
           
 java.util.Set getClassifiedArtifacts()
           
static java.lang.String getFormattedFileName(org.apache.maven.artifact.Artifact artifact, boolean removeVersion)
          Builds the file name.
 java.util.Set getGroupIdArtifacts()
           
 java.util.Set getMixedArtifacts()
           
 java.util.Set getReleaseAndSnapshotArtifacts()
           
 org.apache.maven.artifact.Artifact getReleaseArtifact()
           
 java.util.Set getScopedArtifacts()
           
 org.apache.maven.artifact.Artifact getSnapshotArtifact()
           
 java.io.File getSrcFile()
           
 java.util.Set getTypedArchiveArtifacts()
           
 java.util.Set getTypedArtifacts()
           
static java.lang.String getUnpackableFileName(org.apache.maven.artifact.Artifact artifact)
           
 java.io.File getWorkingDir()
           
 boolean isCreateFiles()
           
 void setArtifactFile(org.apache.maven.artifact.Artifact artifact)
           
 void setCreateFiles(boolean createFiles)
           
 void setSrcFile(java.io.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(java.lang.Object object, java.lang.String variable, java.lang.Object value)
          convience method to set values to variables in objects that don't have setters
 void setWorkingDir(java.io.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(java.io.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 org.apache.maven.artifact.Artifact createArtifact(java.lang.String groupId,
                                                         java.lang.String artifactId,
                                                         java.lang.String version)
                                                  throws java.io.IOException
Throws:
java.io.IOException

createArtifact

public org.apache.maven.artifact.Artifact createArtifact(java.lang.String groupId,
                                                         java.lang.String artifactId,
                                                         java.lang.String version,
                                                         java.lang.String scope)
                                                  throws java.io.IOException
Throws:
java.io.IOException

createArtifact

public org.apache.maven.artifact.Artifact createArtifact(java.lang.String groupId,
                                                         java.lang.String artifactId,
                                                         java.lang.String version,
                                                         java.lang.String scope,
                                                         java.lang.String type,
                                                         java.lang.String classifier)
                                                  throws java.io.IOException
Throws:
java.io.IOException

createArtifact

public org.apache.maven.artifact.Artifact createArtifact(java.lang.String groupId,
                                                         java.lang.String artifactId,
                                                         org.apache.maven.artifact.versioning.VersionRange versionRange,
                                                         java.lang.String scope,
                                                         java.lang.String type,
                                                         java.lang.String classifier,
                                                         boolean optional)
                                                  throws java.io.IOException
Throws:
java.io.IOException

setArtifactFile

public void setArtifactFile(org.apache.maven.artifact.Artifact artifact)
                     throws java.io.IOException
Throws:
java.io.IOException

getUnpackableFileName

public static java.lang.String getUnpackableFileName(org.apache.maven.artifact.Artifact artifact)

createUnpackableFile

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

getReleaseArtifact

public org.apache.maven.artifact.Artifact getReleaseArtifact()
                                                      throws java.io.IOException
Throws:
java.io.IOException

getSnapshotArtifact

public org.apache.maven.artifact.Artifact getSnapshotArtifact()
                                                       throws java.io.IOException
Throws:
java.io.IOException

getReleaseAndSnapshotArtifacts

public java.util.Set getReleaseAndSnapshotArtifacts()
                                             throws java.io.IOException
Throws:
java.io.IOException

getScopedArtifacts

public java.util.Set getScopedArtifacts()
                                 throws java.io.IOException
Throws:
java.io.IOException

getTypedArtifacts

public java.util.Set getTypedArtifacts()
                                throws java.io.IOException
Throws:
java.io.IOException

getClassifiedArtifacts

public java.util.Set getClassifiedArtifacts()
                                     throws java.io.IOException
Throws:
java.io.IOException

getTypedArchiveArtifacts

public java.util.Set getTypedArchiveArtifacts()
                                       throws java.io.IOException
Throws:
java.io.IOException

getArtifactArtifacts

public java.util.Set getArtifactArtifacts()
                                   throws java.io.IOException
Throws:
java.io.IOException

getGroupIdArtifacts

public java.util.Set getGroupIdArtifacts()
                                  throws java.io.IOException
Throws:
java.io.IOException

getMixedArtifacts

public java.util.Set getMixedArtifacts()
                                throws java.io.IOException
Throws:
java.io.IOException

isCreateFiles

public boolean isCreateFiles()
Returns:
Returns the createFiles.

setCreateFiles

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

getWorkingDir

public java.io.File getWorkingDir()
Returns:
Returns the workingDir.

setWorkingDir

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

getSrcFile

public java.io.File getSrcFile()
Returns:
Returns the srcFile.

setSrcFile

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

setVariableValueToObject

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

Parameters:
object -
variable -
value -
Throws:
java.lang.IllegalAccessException

getFormattedFileName

public static java.lang.String getFormattedFileName(org.apache.maven.artifact.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-2009 Apache Software Foundation. All Rights Reserved.