Package org.apache.maven.plugin.testing
Class ArtifactStubFactory
- java.lang.Object
-
- 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.- Version:
- $Id$
-
-
Field Summary
Fields Modifier and Type Field Description private org.codehaus.plexus.archiver.manager.ArchiverManager
archiverManager
private boolean
createFiles
private boolean
createUnpackableFile
private java.io.File
srcFile
private java.io.File
workingDir
-
Constructor Summary
Constructors Constructor Description 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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<org.apache.maven.artifact.Artifact>
getArtifactArtifacts()
java.util.Set<org.apache.maven.artifact.Artifact>
getClassifiedArtifacts()
static java.lang.String
getFormattedFileName(org.apache.maven.artifact.Artifact artifact, boolean removeVersion)
Builds the file name.java.util.Set<org.apache.maven.artifact.Artifact>
getGroupIdArtifacts()
java.util.Set<org.apache.maven.artifact.Artifact>
getMixedArtifacts()
java.util.Set<org.apache.maven.artifact.Artifact>
getReleaseAndSnapshotArtifacts()
org.apache.maven.artifact.Artifact
getReleaseArtifact()
java.util.Set<org.apache.maven.artifact.Artifact>
getScopedArtifacts()
org.apache.maven.artifact.Artifact
getSnapshotArtifact()
java.io.File
getSrcFile()
java.util.Set<org.apache.maven.artifact.Artifact>
getTypedArchiveArtifacts()
java.util.Set<org.apache.maven.artifact.Artifact>
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, java.io.File workingDir)
Creates a new empty file and attaches it to the artifact.void
setArtifactFile(org.apache.maven.artifact.Artifact artifact, java.io.File workingDir, java.io.File srcFile)
Copyies the srcFile to the workingDir and then attaches it to the artifact.private void
setArtifactFile(org.apache.maven.artifact.Artifact artifact, java.io.File workingDir, java.io.File srcFile, boolean createUnpackableFile)
Creates a file that can be copied or unpacked based on the passed in artifactvoid
setCreateFiles(boolean createFiles)
void
setSrcFile(java.io.File srcFile)
void
setUnpackableArtifactFile(org.apache.maven.artifact.Artifact artifact, java.io.File workingDir)
Creates an unpackable file (zip,jar etc) containing an empty file.void
setUnpackableArtifactFile(org.apache.maven.artifact.Artifact artifact, java.io.File workingDir, java.io.File srcFile)
Creates an unpackable file (zip,jar etc) containing the 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)
Convenience method to set values to variables in objects that don't have settersvoid
setWorkingDir(java.io.File workingDir)
-
-
-
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
- Parameters:
groupId
-artifactId
-version
-- Returns:
- a
DefaultArtifact
instance for the given parameters - Throws:
java.io.IOException
- if any- See Also:
createArtifact(String, String, String, String, String, String)
-
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
- Parameters:
groupId
-artifactId
-version
-scope
-- Returns:
- a
DefaultArtifact
instance for the given parameters - Throws:
java.io.IOException
- if any- See Also:
createArtifact(String, String, String, String, String, String)
-
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
- Parameters:
groupId
-artifactId
-version
-scope
-type
-classifier
-- Returns:
- a
DefaultArtifact
instance for the given parameters - Throws:
java.io.IOException
- if any- See Also:
createArtifact(String, String, VersionRange, String, String, String, boolean)
-
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
- Parameters:
groupId
- not nullartifactId
- not nullversionRange
- not nullscope
- not nulltype
- not nullclassifier
-optional
- not null- Returns:
- a
DefaultArtifact
instance - Throws:
java.io.IOException
- if any
-
setArtifactFile
public void setArtifactFile(org.apache.maven.artifact.Artifact artifact, java.io.File workingDir) throws java.io.IOException
Creates a new empty file and attaches it to the artifact.- Parameters:
artifact
- to attach the file to.workingDir
- where to locate the new file- Throws:
java.io.IOException
-
setArtifactFile
public void setArtifactFile(org.apache.maven.artifact.Artifact artifact, java.io.File workingDir, java.io.File srcFile) throws java.io.IOException
Copyies the srcFile to the workingDir and then attaches it to the artifact. If srcFile is null, a new empty file will be created.- Parameters:
artifact
- to attachworkingDir
- where to copy the srcFile.srcFile
- file to be attached.- Throws:
java.io.IOException
-
setUnpackableArtifactFile
public void setUnpackableArtifactFile(org.apache.maven.artifact.Artifact artifact, java.io.File workingDir) throws java.io.IOException
Creates an unpackable file (zip,jar etc) containing an empty file.- Parameters:
artifact
- to attachworkingDir
- where to create the file.- Throws:
java.io.IOException
-
setUnpackableArtifactFile
public void setUnpackableArtifactFile(org.apache.maven.artifact.Artifact artifact, java.io.File workingDir, java.io.File srcFile) throws java.io.IOException
Creates an unpackable file (zip,jar etc) containing the srcFile. If srcFile is null, a new empty file will be created.- Parameters:
artifact
- to attachworkingDir
- where to create the file.srcFile
-- Throws:
java.io.IOException
- if any
-
setArtifactFile
private void setArtifactFile(org.apache.maven.artifact.Artifact artifact, java.io.File workingDir, java.io.File srcFile, boolean createUnpackableFile) throws java.io.IOException
Creates a file that can be copied or unpacked based on the passed in artifact- Parameters:
artifact
-workingDir
-srcFile
-createUnpackableFile
-- Throws:
java.io.IOException
- if any
-
getUnpackableFileName
public static java.lang.String getUnpackableFileName(org.apache.maven.artifact.Artifact artifact)
- Parameters:
artifact
-- Returns:
-
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
- Parameters:
artifact
-destFile
-- Throws:
org.codehaus.plexus.archiver.manager.NoSuchArchiverException
org.codehaus.plexus.archiver.ArchiverException
- if anyjava.io.IOException
- if any
-
getReleaseArtifact
public org.apache.maven.artifact.Artifact getReleaseArtifact() throws java.io.IOException
- Returns:
- a
DefaultArtifact
instance fortestGroupId:release:jar:1.0
- Throws:
java.io.IOException
- if any
-
getSnapshotArtifact
public org.apache.maven.artifact.Artifact getSnapshotArtifact() throws java.io.IOException
- Returns:
- a default
DefaultArtifact
instance fortestGroupId:snapshot:jar:2.0-SNAPSHOT
- Throws:
java.io.IOException
- if any
-
getReleaseAndSnapshotArtifacts
public java.util.Set<org.apache.maven.artifact.Artifact> getReleaseAndSnapshotArtifacts() throws java.io.IOException
- Returns:
- a default set of release and snapshot
DefaultArtifact
, i.e.:testGroupId:snapshot:jar:2.0-SNAPSHOT, testGroupId:release:jar:1.0
- Throws:
java.io.IOException
- if any- See Also:
getReleaseArtifact()
,getSnapshotArtifact()
-
getScopedArtifacts
public java.util.Set<org.apache.maven.artifact.Artifact> getScopedArtifacts() throws java.io.IOException
- Returns:
- a default set of
DefaultArtifact
, i.e.:g:provided:jar:1.0, g:compile:jar:1.0, g:system:jar:1.0, g:test:jar:1.0, g:runtime:jar:1.0
- Throws:
java.io.IOException
- if any
-
getTypedArtifacts
public java.util.Set<org.apache.maven.artifact.Artifact> getTypedArtifacts() throws java.io.IOException
- Returns:
- a set of
DefaultArtifact
, i.e.:g:d:zip:1.0, g:a:war:1.0, g:b:jar:1.0, g:c:sources:1.0, g:e:rar:1.0
- Throws:
java.io.IOException
- if any
-
getClassifiedArtifacts
public java.util.Set<org.apache.maven.artifact.Artifact> getClassifiedArtifacts() throws java.io.IOException
- Returns:
- a set of
DefaultArtifact
, i.e.:g:c:jar:three:1.0, g:b:jar:two:1.0, g:d:jar:four:1.0, g:a:jar:one:1.0
- Throws:
java.io.IOException
- if any
-
getTypedArchiveArtifacts
public java.util.Set<org.apache.maven.artifact.Artifact> getTypedArchiveArtifacts() throws java.io.IOException
- Returns:
- a set of
DefaultArtifact
, i.e.:g:d:zip:1.0, g:a:war:1.0, g:b:jar:1.0, g:e:rar:1.0
- Throws:
java.io.IOException
- if any
-
getArtifactArtifacts
public java.util.Set<org.apache.maven.artifact.Artifact> getArtifactArtifacts() throws java.io.IOException
- Returns:
- a set of
DefaultArtifact
, i.e.:g:one:jar:a:1.0, g:two:jar:a:1.0, g:four:jar:a:1.0, g:three:jar:a:1.0
- Throws:
java.io.IOException
- if any
-
getGroupIdArtifacts
public java.util.Set<org.apache.maven.artifact.Artifact> getGroupIdArtifacts() throws java.io.IOException
- Returns:
- a set of
DefaultArtifact
, i.e.:one:group-one:jar:a:1.0, three:group-three:jar:a:1.0, four:group-four:jar:a:1.0, two:group-two:jar:a:1.0
- Throws:
java.io.IOException
- if any
-
getMixedArtifacts
public java.util.Set<org.apache.maven.artifact.Artifact> getMixedArtifacts() throws java.io.IOException
- Returns:
- a set of
DefaultArtifact
- Throws:
java.io.IOException
- if any- See Also:
getTypedArtifacts()
,getScopedArtifacts()
,getReleaseAndSnapshotArtifacts()
-
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
Convenience 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]
-
-