Class IntegrationTestMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
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:
- a
goal.txtfile, containing a list of goals to run against the generated project (can be empty, content ignored before maven-archetype-plugin 2.1), - an
archetype.propertiesfile, containing properties for project generation, - an optional
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ArchetypeGenerationConfiguratorprivate ArchetypeGeneratorprivate booleanWhether to show debug statements in the build output.private Downloaderprivate StringThe file encoding for the post-build script.A list of additional properties which will be used to filter tokens in settings.xmlprivate booleanIgnores the EOL encoding for comparing files (default and original behaviour is false).private org.apache.maven.shared.invoker.Invokerprivate FileThe local repository to run maven instance.private booleanSuppress logging to thebuild.logfile.private StringRelative path of a cleanup/verification hook script to run after executing the build.private org.apache.maven.project.MavenProjectThe archetype project to execute the integration tests on.Common set of properties to pass in on each project's command line, via -D parameters.private org.apache.maven.execution.MavenSessionprivate org.apache.maven.settings.SettingsThe current user system settings for use in Maven.private FilePath to an alternatesettings.xmlto use for Maven invocation with all ITs.private booleanflag to enable show mvn version used for running its (cli option : -V,--show-version )private booleanSkip the integration test.private booleanFlag used to determine whether the build logs should be output to the normal mojo log.private FileDirectory of test projectsFields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
ConstructorsConstructorDescriptionIntegrationTestMojo(ArchetypeGenerator archetypeGenerator, Downloader downloader, org.apache.maven.shared.invoker.Invoker invoker, ArchetypeGenerationConfigurator archetypeGenerationConfigurator) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidassertDirectoryEquals(File reference, File actual) Checks that actual directory content is the same as reference.protected voidbuildInterpolatedFile(File originalFile, File interpolatedFile) private booleancontentEquals(File referenceFile, File actualFile) Uses theignoreEOLStyleattribute to compare the two files.voidexecute()private ArchetypeGenerationRequestgenerate(String archetypeGroupId, String archetypeArtifactId, String archetypeVersion, File archetypeFile, Properties properties, String basedir) private FilegetArchetypeFile(String groupId, String artifactId, String version) Returns the map-based value source used to interpolate settings and other stuff.private PropertiesgetProperties(File goalFile) private voidinvokePostArchetypeGenerationGoals(String goals, File basedir, File goalFile) private PropertiesloadProperties(File propertiesFile) private voidprocessIntegrationTest(File goalFile, File archetypeFile) private FileLoggersetupLogger(File basedir) private FilesetupParentProjects(File configFolder, File buildFolder) private static StringConverts the specified filesystem path to a URL.Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
archetypeGenerator
-
downloader
-
invoker
private org.apache.maven.shared.invoker.Invoker invoker -
archetypeGenerationConfigurator
-
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject projectThe archetype project to execute the integration tests on. -
session
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session -
skip
@Parameter(property="archetype.test.skip") private boolean skipSkip the integration test. -
testProjectsDirectory
@Parameter(property="archetype.test.projectsDirectory", defaultValue="${project.build.testOutputDirectory}/projects", required=true) private File testProjectsDirectoryDirectory of test projects- Since:
- 2.2
-
postBuildHookScript
@Parameter(property="archetype.test.verifyScript", defaultValue="verify") private String postBuildHookScriptRelative path of a cleanup/verification hook script to run after executing the build. This script may be written with either BeanShell or Groovy. If the file extension is omitted (e.g.verify), the plugin searches for the file by trying out the well-known extensions.bshand.groovy. If this script exists for a particular project but returns any non-null value different fromtrueor throws an exception, the corresponding build is flagged as a failure.- Since:
- 2.2
-
noLog
@Parameter(property="archetype.test.noLog", defaultValue="false") private boolean noLogSuppress logging to thebuild.logfile.- Since:
- 2.2
-
streamLogs
@Parameter(property="archetype.test.streamLogs", defaultValue="true") private boolean streamLogsFlag used to determine whether the build logs should be output to the normal mojo log.- Since:
- 2.2
-
encoding
@Parameter(property="encoding", defaultValue="${project.build.sourceEncoding}") private String encodingThe file encoding for the post-build script.- Since:
- 2.2
-
localRepositoryPath
@Parameter(property="archetype.test.localRepositoryPath", defaultValue="${settings.localRepository}", required=true) private File localRepositoryPathThe local repository to run maven instance.- Since:
- 2.2
-
showVersion
@Parameter(property="archetype.test.showVersion", defaultValue="false") private boolean showVersionflag to enable show mvn version used for running its (cli option : -V,--show-version )- Since:
- 2.2
-
ignoreEOLStyle
@Parameter(property="archetype.test.ignoreEOLStyle", defaultValue="false") private boolean ignoreEOLStyleIgnores the EOL encoding for comparing files (default and original behaviour is false).- Since:
- 2.3
-
debug
@Parameter(property="archetype.test.debug", defaultValue="false") private boolean debugWhether to show debug statements in the build output.- Since:
- 2.2
-
filterProperties
-
settings
@Parameter(defaultValue="${settings}", required=true, readonly=true) private org.apache.maven.settings.Settings settingsThe current user system settings for use in Maven.- Since:
- 2.2
-
settingsFile
Path to an alternatesettings.xmlto 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 parameterlocalRepositoryPathis dominant.- Since:
- 2.2
-
properties
-
-
Constructor Details
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
assertDirectoryEquals
private void assertDirectoryEquals(File reference, File actual) throws IntegrationTestMojo.IntegrationTestFailure, IOException Checks that actual directory content is the same as reference.- Parameters:
reference- the reference directoryactual- the actual directory to compare with the reference- Throws:
IntegrationTestMojo.IntegrationTestFailure- if content differsIOException
-
contentEquals
Uses theignoreEOLStyleattribute to compare the two files. IfignoreEOLStyleis true, then the comparison does not take care about the EOL (aka newline) character.- Throws:
IOException
-
loadProperties
- Throws:
IOException
-
processIntegrationTest
private void processIntegrationTest(File goalFile, File archetypeFile) throws IntegrationTestMojo.IntegrationTestFailure, org.apache.maven.plugin.MojoExecutionException - Throws:
IntegrationTestMojo.IntegrationTestFailureorg.apache.maven.plugin.MojoExecutionException
-
generate
private ArchetypeGenerationRequest generate(String archetypeGroupId, String archetypeArtifactId, String archetypeVersion, File archetypeFile, Properties properties, String basedir) throws IntegrationTestMojo.IntegrationTestFailure, org.apache.maven.plugin.MojoExecutionException - Throws:
IntegrationTestMojo.IntegrationTestFailureorg.apache.maven.plugin.MojoExecutionException
-
setupParentProjects
private File setupParentProjects(File configFolder, File buildFolder) throws IOException, org.apache.maven.plugin.MojoExecutionException, IntegrationTestMojo.IntegrationTestFailure - Throws:
IOExceptionorg.apache.maven.plugin.MojoExecutionExceptionIntegrationTestMojo.IntegrationTestFailure
-
getArchetypeFile
private File getArchetypeFile(String groupId, String artifactId, String version) throws DownloadException - Throws:
DownloadException
-
getProperties
- Throws:
IOException
-
invokePostArchetypeGenerationGoals
private void invokePostArchetypeGenerationGoals(String goals, File basedir, File goalFile) throws IntegrationTestMojo.IntegrationTestFailure, IOException, org.apache.maven.plugin.MojoExecutionException - Throws:
IntegrationTestMojo.IntegrationTestFailureIOExceptionorg.apache.maven.plugin.MojoExecutionException
-
setupLogger
- Throws:
IOException
-
getInterpolationValueSource
-
buildInterpolatedFile
-
toUrl
Converts the specified filesystem path to a URL. The resulting URL has no trailing slash regardless whether the path denotes a file or a directory.- Parameters:
filename- The filesystem path to convert, must not benull.- Returns:
- The
file:URL for the specified path, nevernull.
-