@Mojo(name="integration-test",
requiresProject=true)
public class IntegrationTestMojo
extends org.apache.maven.plugin.AbstractMojo
Execute the archetype integration tests, consisting in generating projects from the current archetype and optionally comparing generated projects with reference copy.
Each IT consists of a sub-directory in src/test/resources/projects
containing:
goal.txt
file, containing a list of goals to run against the generated project (can be empty,
content ignored before maven-archetype-plugin 2.1),archetype.properties
file, containing properties for project generation,reference/
directory containing a reference copy of the expected project created from
the IT.To let the IT create a Maven module below some other Maven project (being generated from another archetype)
one can additionally specify an optional archetype.pom.properties
file in the parent directory,
specifying the archetype's groupId
, artifactId
and version
along with its
archetype.properties
file, containing properties for project generation. Both files are leveraged
to create the parent project for this IT. Parent projects can be nested.
An example structure for such an integration test looks like this
File/Directory | Description |
---|---|
src/test/resources/projects/it1 |
Directory for integration test 1 |
src/test/resources/projects/it1/archetype.pom.properties |
GAV for the archetype from which to generate the parent |
src/test/resources/projects/it1/archetype.properties |
All required properties for the archetype being specified by archetype.pom.properties on this level |
src/test/resources/projects/it1/child |
Directory for maven module within integration test 1 (this folder's name is not relevant) |
src/test/resources/projects/it1/child/goal.txt |
The file containing the list of goals to be executed against the generated project |
src/test/resources/projects/it1/child/archetype.properties |
All required properties for this project's archetype |
Notice that it is expected to be run as part as of a build after the package
phase and not directly as a
goal from CLI.
Modifier and Type | Class and Description |
---|---|
private static class |
IntegrationTestMojo.CompositeMap |
(package private) class |
IntegrationTestMojo.IntegrationTestFailure |
Modifier and Type | Field and Description |
---|---|
private ArchetypeGenerator |
archetypeGenerator |
private org.apache.maven.shared.artifact.resolve.ArtifactResolver |
artifactResolver |
private boolean |
debug
Whether to show debug statements in the build output.
|
private java.lang.String |
encoding
The file encoding for the post-build script.
|
private java.util.Map<java.lang.String,java.lang.String> |
filterProperties
A list of additional properties which will be used to filter tokens in settings.xml
|
private boolean |
ignoreEOLStyle
Ignores the EOL encoding for comparing files (default and original behaviour is false).
|
private org.apache.maven.shared.invoker.Invoker |
invoker |
protected org.apache.maven.artifact.repository.ArtifactRepository |
localRepository |
private java.io.File |
localRepositoryPath
The local repository to run maven instance.
|
private boolean |
noLog
Suppress logging to the
build.log file. |
private java.lang.String |
postBuildHookScript
Relative path of a cleanup/verification hook script to run after executing the build.
|
private org.apache.maven.project.MavenProject |
project
The archetype project to execute the integration tests on.
|
private java.util.Map<java.lang.String,java.lang.String> |
properties
Common set of properties to pass in on each project's command line, via -D parameters.
|
protected java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> |
remoteRepositories |
private org.apache.maven.execution.MavenSession |
session |
private org.apache.maven.settings.Settings |
settings
The current user system settings for use in Maven.
|
private java.io.File |
settingsFile
Path to an alternate
settings.xml to use for Maven invocation with all ITs. |
private boolean |
showVersion
flag to enable show mvn version used for running its (cli option : -V,--show-version )
|
private boolean |
skip
Skip the integration test.
|
private boolean |
streamLogs
Flag used to determine whether the build logs should be output to the normal mojo log.
|
private java.io.File |
testProjectsDirectory
Directory of test projects
|
Constructor and Description |
---|
IntegrationTestMojo() |
Modifier and Type | Method and Description |
---|---|
private void |
assertDirectoryEquals(java.io.File reference,
java.io.File actual)
Checks that actual directory content is the same as reference.
|
protected void |
buildInterpolatedFile(java.io.File originalFile,
java.io.File interpolatedFile) |
private boolean |
contentEquals(java.io.File referenceFile,
java.io.File actualFile)
Uses the
ignoreEOLStyle attribute to compare the two files. |
void |
execute() |
private ArchetypeGenerationRequest |
generate(java.lang.String archetypeGroupId,
java.lang.String archetypeArtifactId,
java.lang.String archetypeVersion,
java.io.File archetypeFile,
java.util.Properties properties,
java.lang.String basedir) |
private java.io.File |
getArchetypeFile(java.lang.String groupId,
java.lang.String artifactId,
java.lang.String version) |
private java.util.Map<java.lang.String,java.lang.Object> |
getInterpolationValueSource()
Returns the map-based value source used to interpolate settings and other stuff.
|
private java.util.Properties |
getProperties(java.io.File goalFile) |
private void |
invokePostArchetypeGenerationGoals(java.lang.String goals,
java.io.File basedir,
java.io.File goalFile) |
private java.util.Properties |
loadProperties(java.io.File propertiesFile) |
private void |
processIntegrationTest(java.io.File goalFile,
java.io.File archetypeFile) |
private FileLogger |
setupLogger(java.io.File basedir) |
private java.io.File |
setupParentProjects(java.io.File configFolder,
java.io.File buildFolder) |
private static java.lang.String |
toUrl(java.lang.String filename)
Converts the specified filesystem path to a URL.
|
@Component private ArchetypeGenerator archetypeGenerator
@Component private org.apache.maven.shared.invoker.Invoker invoker
@Component private org.apache.maven.shared.artifact.resolve.ArtifactResolver artifactResolver
@Parameter(defaultValue="${project.remoteArtifactRepositories}", readonly=true, required=true) protected java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositories
@Parameter(defaultValue="${localRepository}", readonly=true, required=true) protected org.apache.maven.artifact.repository.ArtifactRepository localRepository
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject project
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session
@Parameter(property="archetype.test.skip") private boolean skip
@Parameter(property="archetype.test.projectsDirectory", defaultValue="${project.build.testOutputDirectory}/projects", required=true) private java.io.File testProjectsDirectory
@Parameter(property="archetype.test.verifyScript", defaultValue="verify") private java.lang.String postBuildHookScript
verify
), the
plugin searches for the file by trying out the well-known extensions .bsh
and .groovy
.
If this script exists for a particular project but returns any non-null value different from true
or
throws an exception, the corresponding build is flagged as a failure.@Parameter(property="archetype.test.noLog", defaultValue="false") private boolean noLog
build.log
file.@Parameter(property="archetype.test.streamLogs", defaultValue="true") private boolean streamLogs
@Parameter(property="encoding", defaultValue="${project.build.sourceEncoding}") private java.lang.String encoding
@Parameter(property="archetype.test.localRepositoryPath", defaultValue="${settings.localRepository}", required=true) private java.io.File localRepositoryPath
@Parameter(property="archetype.test.showVersion", defaultValue="false") private boolean showVersion
@Parameter(property="archetype.test.ignoreEOLStyle", defaultValue="false") private boolean ignoreEOLStyle
@Parameter(property="archetype.test.debug", defaultValue="false") private boolean debug
@Parameter private java.util.Map<java.lang.String,java.lang.String> filterProperties
@Parameter(defaultValue="${settings}", required=true, readonly=true) private org.apache.maven.settings.Settings settings
@Parameter(property="archetype.test.settingsFile") private java.io.File settingsFile
settings.xml
to use for Maven invocation with all ITs. Note that the
<localRepository>
element of this settings file is always ignored, i.e. the path given by the
parameter localRepositoryPath
is dominant.@Parameter private java.util.Map<java.lang.String,java.lang.String> properties
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoFailureException
private void assertDirectoryEquals(java.io.File reference, java.io.File actual) throws IntegrationTestMojo.IntegrationTestFailure, java.io.IOException
reference
- the reference directoryactual
- the actual directory to compare with the referenceIntegrationTestMojo.IntegrationTestFailure
- if content differsjava.io.IOException
private boolean contentEquals(java.io.File referenceFile, java.io.File actualFile) throws java.io.IOException
ignoreEOLStyle
attribute to compare the two files. If ignoreEOLStyle
is true,
then the comparison does not take care about the EOL (aka newline) character.java.io.IOException
private java.util.Properties loadProperties(java.io.File propertiesFile) throws java.io.IOException
java.io.IOException
private void processIntegrationTest(java.io.File goalFile, java.io.File archetypeFile) throws IntegrationTestMojo.IntegrationTestFailure, org.apache.maven.plugin.MojoExecutionException
IntegrationTestMojo.IntegrationTestFailure
org.apache.maven.plugin.MojoExecutionException
private ArchetypeGenerationRequest generate(java.lang.String archetypeGroupId, java.lang.String archetypeArtifactId, java.lang.String archetypeVersion, java.io.File archetypeFile, java.util.Properties properties, java.lang.String basedir) throws IntegrationTestMojo.IntegrationTestFailure
private java.io.File setupParentProjects(java.io.File configFolder, java.io.File buildFolder) throws java.io.IOException, org.apache.maven.plugin.MojoExecutionException, IntegrationTestMojo.IntegrationTestFailure
java.io.IOException
org.apache.maven.plugin.MojoExecutionException
IntegrationTestMojo.IntegrationTestFailure
private java.io.File getArchetypeFile(java.lang.String groupId, java.lang.String artifactId, java.lang.String version) throws org.apache.maven.shared.artifact.resolve.ArtifactResolverException
org.apache.maven.shared.artifact.resolve.ArtifactResolverException
private java.util.Properties getProperties(java.io.File goalFile) throws java.io.IOException
java.io.IOException
private void invokePostArchetypeGenerationGoals(java.lang.String goals, java.io.File basedir, java.io.File goalFile) throws IntegrationTestMojo.IntegrationTestFailure, java.io.IOException, org.apache.maven.plugin.MojoExecutionException
IntegrationTestMojo.IntegrationTestFailure
java.io.IOException
org.apache.maven.plugin.MojoExecutionException
private FileLogger setupLogger(java.io.File basedir) throws java.io.IOException
java.io.IOException
private java.util.Map<java.lang.String,java.lang.Object> getInterpolationValueSource()
null
.protected void buildInterpolatedFile(java.io.File originalFile, java.io.File interpolatedFile) throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
private static java.lang.String toUrl(java.lang.String filename)
filename
- The filesystem path to convert, must not be null
.file:
URL for the specified path, never null
.