Package org.apache.maven.plugin.testing
Class ArtifactStubFactory
java.lang.Object
org.apache.maven.plugin.testing.ArtifactStubFactory
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
ConstructorDescriptionDefault constructor.ArtifactStubFactory
(File workingDir, boolean createFiles) This constructor is to be used if files are needed and to set a working dir -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.maven.artifact.Artifact
createArtifact
(String groupId, String artifactId, String version) org.apache.maven.artifact.Artifact
createArtifact
(String groupId, String artifactId, String version, String scope) org.apache.maven.artifact.Artifact
createArtifact
(String groupId, String artifactId, String version, String scope, String type, String classifier) org.apache.maven.artifact.Artifact
createArtifact
(String groupId, String artifactId, org.apache.maven.artifact.versioning.VersionRange versionRange, String scope, String type, String classifier, boolean optional) void
createUnpackableFile
(org.apache.maven.artifact.Artifact artifact, File destFile) Set<org.apache.maven.artifact.Artifact>
Set<org.apache.maven.artifact.Artifact>
static String
getFormattedFileName
(org.apache.maven.artifact.Artifact artifact, boolean removeVersion) Builds the file name.Set<org.apache.maven.artifact.Artifact>
Set<org.apache.maven.artifact.Artifact>
Set<org.apache.maven.artifact.Artifact>
org.apache.maven.artifact.Artifact
Set<org.apache.maven.artifact.Artifact>
org.apache.maven.artifact.Artifact
Set<org.apache.maven.artifact.Artifact>
Set<org.apache.maven.artifact.Artifact>
static String
getUnpackableFileName
(org.apache.maven.artifact.Artifact artifact) boolean
void
setArtifactFile
(org.apache.maven.artifact.Artifact artifact, File workingDir) Creates a new empty file and attaches it to the artifact.void
setArtifactFile
(org.apache.maven.artifact.Artifact artifact, File workingDir, File srcFile) Copyies the srcFile to the workingDir and then attaches it to the artifact.void
setCreateFiles
(boolean createFiles) void
setSrcFile
(File srcFile) void
setUnpackableArtifactFile
(org.apache.maven.artifact.Artifact artifact, File workingDir) Creates an unpackable file (zip,jar etc) containing an empty file.void
setUnpackableArtifactFile
(org.apache.maven.artifact.Artifact artifact, File workingDir, 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
(Object object, String variable, Object value) Convenience method to set values to variables in objects that don't have settersvoid
setWorkingDir
(File workingDir)
-
Constructor Details
-
ArtifactStubFactory
public ArtifactStubFactory()Default constructor. This should be used only if real files aren't needed...just the artifact objects -
ArtifactStubFactory
This constructor is to be used if files are needed and to set a working dir- Parameters:
workingDir
-createFiles
-
-
-
Method Details
-
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(String groupId, String artifactId, String version) throws IOException - Parameters:
groupId
-artifactId
-version
-- Returns:
- a
DefaultArtifact
instance for the given parameters - Throws:
IOException
- if any- See Also:
-
createArtifact
public org.apache.maven.artifact.Artifact createArtifact(String groupId, String artifactId, String version, String scope) throws IOException - Parameters:
groupId
-artifactId
-version
-scope
-- Returns:
- a
DefaultArtifact
instance for the given parameters - Throws:
IOException
- if any- See Also:
-
createArtifact
public org.apache.maven.artifact.Artifact createArtifact(String groupId, String artifactId, String version, String scope, String type, String classifier) throws IOException - Parameters:
groupId
-artifactId
-version
-scope
-type
-classifier
-- Returns:
- a
DefaultArtifact
instance for the given parameters - Throws:
IOException
- if any- See Also:
-
createArtifact
public org.apache.maven.artifact.Artifact createArtifact(String groupId, String artifactId, org.apache.maven.artifact.versioning.VersionRange versionRange, String scope, String type, String classifier, boolean optional) throws IOException - Parameters:
groupId
- not nullartifactId
- not nullversionRange
- not nullscope
- not nulltype
- not nullclassifier
-optional
- not null- Returns:
- a
DefaultArtifact
instance - Throws:
IOException
- if any
-
setArtifactFile
public void setArtifactFile(org.apache.maven.artifact.Artifact artifact, File workingDir) throws 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:
IOException
-
setArtifactFile
public void setArtifactFile(org.apache.maven.artifact.Artifact artifact, File workingDir, File srcFile) throws 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:
IOException
-
setUnpackableArtifactFile
public void setUnpackableArtifactFile(org.apache.maven.artifact.Artifact artifact, File workingDir) throws IOException Creates an unpackable file (zip,jar etc) containing an empty file.- Parameters:
artifact
- to attachworkingDir
- where to create the file.- Throws:
IOException
-
setUnpackableArtifactFile
public void setUnpackableArtifactFile(org.apache.maven.artifact.Artifact artifact, File workingDir, File srcFile) throws 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:
IOException
- if any
-
getUnpackableFileName
- Parameters:
artifact
-- Returns:
-
createUnpackableFile
public void createUnpackableFile(org.apache.maven.artifact.Artifact artifact, File destFile) throws org.codehaus.plexus.archiver.manager.NoSuchArchiverException, org.codehaus.plexus.archiver.ArchiverException, IOException - Parameters:
artifact
-destFile
-- Throws:
org.codehaus.plexus.archiver.manager.NoSuchArchiverException
org.codehaus.plexus.archiver.ArchiverException
- if anyIOException
- if any
-
getReleaseArtifact
- Returns:
- a
DefaultArtifact
instance fortestGroupId:release:jar:1.0
- Throws:
IOException
- if any
-
getSnapshotArtifact
- Returns:
- a default
DefaultArtifact
instance fortestGroupId:snapshot:jar:2.0-SNAPSHOT
- Throws:
IOException
- if any
-
getReleaseAndSnapshotArtifacts
- Returns:
- a default set of release and snapshot
DefaultArtifact
, i.e.:testGroupId:snapshot:jar:2.0-SNAPSHOT, testGroupId:release:jar:1.0
- Throws:
IOException
- if any- See Also:
-
getScopedArtifacts
- 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:
IOException
- if any
-
getTypedArtifacts
- 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:
IOException
- if any
-
getClassifiedArtifacts
- 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:
IOException
- if any
-
getTypedArchiveArtifacts
- 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:
IOException
- if any
-
getArtifactArtifacts
- 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:
IOException
- if any
-
getGroupIdArtifacts
- 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:
IOException
- if any
-
getMixedArtifacts
- Returns:
- a set of
DefaultArtifact
- Throws:
IOException
- if any- See Also:
-
isCreateFiles
public boolean isCreateFiles()- Returns:
- Returns the createFiles.
-
setCreateFiles
public void setCreateFiles(boolean createFiles) - Parameters:
createFiles
- The createFiles to set.
-
getWorkingDir
- Returns:
- Returns the workingDir.
-
setWorkingDir
- Parameters:
workingDir
- The workingDir to set.
-
getSrcFile
- Returns:
- Returns the srcFile.
-
setSrcFile
- Parameters:
srcFile
- The srcFile to set.
-
setVariableValueToObject
public static void setVariableValueToObject(Object object, String variable, Object value) throws IllegalAccessException Convenience method to set values to variables in objects that don't have setters- Parameters:
object
-variable
-value
-- Throws:
IllegalAccessException
-
getFormattedFileName
public static 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]
-