Package org.apache.maven.plugins.invoker
Class AbstractInvokerMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.apache.maven.plugins.invoker.AbstractInvokerMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
IntegrationTestMojo,InvokerMojo
public abstract class AbstractInvokerMojo extends org.apache.maven.plugin.AbstractMojoProvides common code for mojos invoking sub builds.- Since:
- 15-Aug-2009 09:09:29
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classAbstractInvokerMojo.ExecutionResultprivate static classAbstractInvokerMojo.OrdinalComparator(package private) static classAbstractInvokerMojo.ToolchainPrivateManager
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringactualMavenVersionThe version of Maven which is used to run the buildsprivate booleanaddTestClassPathA flag whether the test class path of the project under test should be included in the class path of the pre-/post-build scripts.private booleancloneAllFilesSome files are normally excluded when copying the IT projects from the directory specified by the parameter projectsDirectory to the directory given by cloneProjectsTo (e.g.private booleancloneCleanEnsure thecloneProjectsTodirectory is not polluted with files from earlier invoker runs.private java.io.FilecloneProjectsToDirectory to which projects should be cloned prior to execution.private booleandebugWhether to show debug statements in the build output.private booleandisableReportsA flag to disable the generation of build reports.private java.lang.StringencodingThe file encoding for the pre-/post-build scripts and the list files for goals and profiles.private java.util.Map<java.lang.String,java.lang.String>environmentVariablesAdditional environment variables to set on the command line.private java.lang.StringfilteredPomPrefixA string used to prefix the file name of the filtered POMs in case the POMs couldn't be filtered in-place (i.e.private java.util.Map<java.lang.String,java.lang.String>filterPropertiesA list of additional properties which will be used to filter tokens in POMs and goal files.private java.util.List<java.lang.String>goalsThe list of goals to execute on each project.private org.apache.maven.shared.invoker.Invokerinvokerprivate java.lang.StringinvokerPropertiesFileThe name of an optional project-specific file that contains properties used to specify settings for an individual Maven invocation.private java.lang.StringinvokerTestA comma separated list of projectname patterns to run.private java.io.FilejavaHomeTheJAVA_HOMEenvironment variable to use for forked Maven invocations.private java.lang.StringjunitPackageNameThe package name use in junit reportprivate java.io.FilelocalRepositoryPathThe local repository for caching artifacts.private java.io.FilelogDirectoryBy default abuild.logis created in the root of the project.private java.lang.StringmavenExecutablemavenExecutable can either be a file relative to${maven.home}/bin/or an absolute file.private java.io.FilemavenHomeThe home directory of the Maven installation to use for the forked builds.private java.lang.StringmavenOptsTheMAVEN_OPTSenvironment variable to use when invoking Maven.private booleanmergeUserSettingsIf enable and if you have a settings file configured for the execution, it will be merged with your user settings.private org.apache.maven.plugin.MojoExecutionmojoExecutionprivate booleannoLogSuppress logging to thebuild.logfile.private intparallelThreadsnumber of threads for running tests in parallel.private java.util.List<org.apache.maven.artifact.Artifact>pluginArtifactsprivate java.io.FilepomA single POM to build, skipping any scanning parameters and behavior.private java.util.List<java.lang.String>pomExcludesExclude patterns for searching the integration test directory.private java.util.List<java.lang.String>pomIncludesInclude patterns for searching the integration test directory for projects.private java.lang.StringpostBuildHookScriptRelative path of a cleanup/verification hook script to run after executing the build.private java.lang.StringpreBuildHookScriptRelative path of a pre-build hook script to run prior to executing the build.private java.util.List<java.lang.String>profilesList of profile identifiers to explicitly trigger in the build.private org.apache.maven.project.MavenProjectprojectThe Maven Project Objectprivate java.io.FileprojectsDirectoryDirectory to search for integration tests.private java.util.Map<java.lang.String,java.lang.String>propertiesCommon set of properties to pass in on each project's command line, via -D parameters.private java.io.FilereportsDirectoryBase directory where all build reports are written to.private static intRESULT_COLUMNThe zero-based column index where to print the invoker result.private org.apache.maven.shared.scriptinterpreter.ScriptRunnerscriptRunnerThe scripter runner that is responsible to execute hook scripts.private java.util.Map<java.lang.String,java.lang.String>scriptVariablesAdditional variables for use in the hook scripts.private java.text.DecimalFormatsecFormatThe format for elapsed build time.private java.lang.StringselectorScriptRelative path of a selector script to run prior in order to decide if the build should be executed.private org.apache.maven.execution.MavenSessionsessionprivate org.apache.maven.settings.SettingssettingsThe current user system settings for use in Maven.private org.apache.maven.settings.building.SettingsBuildersettingsBuilderprivate java.io.FilesettingsFilePath to an alternatesettings.xmlto use for Maven invocation with all ITs.private java.util.List<java.lang.String>setupIncludesInclude patterns for searching the projects directory for projects that need to be run before the other projects.private booleanshowErrorsWhether to show errors in the build output.private booleanshowVersionflag to enable show mvn version used for running its (cli option : -V,--show-version )private booleanskipInvocationFlag used to suppress certain invocations.private booleanstreamLogsFlag used to determine whether the build logs should be output to the normal mojo log.protected booleansuppressSummariesFlag used to suppress the summary output notifying of successes and failures.private java.util.List<java.lang.String>testClassPathThe test class path of the project under test.private java.lang.StringtestPropertiesFileLocation of a properties file that defines CLI properties for the test.private inttimeoutInSecondsprivate org.apache.maven.toolchain.ToolchainManagerPrivatetoolchainManagerPrivateprivate booleanwriteJunitReportWrite test result in junit format.
-
Constructor Summary
Constructors Constructor Description AbstractInvokerMojo()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) static booleanalreadyCloned(java.lang.String subpath, java.util.List<java.lang.String> clonedSubpaths)Determines whether the specified sub path has already been cloned, i.e.(package private) voidbuildInterpolatedFile(java.io.File originalFile, java.io.File interpolatedFile)Interpolates the specified POM/settings file to a temporary file.private java.util.List<java.lang.String>calculateExcludes()private voidcloneProjects(java.util.Collection<java.lang.String> projectPaths)Copies the specified projects to the directory given bycloneProjectsTo.private org.apache.maven.settings.SettingscloneSettings()private java.util.List<java.lang.String>collectListFromCSV(java.lang.String csv)Gets a list of comma separated tokens from the specified line.private voidcollectProjects(java.io.File projectsDir, java.lang.String projectPath, java.util.Collection<java.lang.String> projectPaths, boolean included)Collects all projects locally reachable from the specified project.private voidcopyDirectoryStructure(java.io.File sourceDir, java.io.File destDir)Copied a directory structure with default exclusions (.svn, CVS, etc)private voiddeleteInterpolatedPomFile(java.io.File interpolatedPomFile)Delete the interpolated pom file if it has been created before.protected voiddoFailIfNoProjects()voidexecute()Invokes Maven on the configured test projects.private java.lang.StringformatTime(double seconds)Formats the specified build duration time.private java.nio.file.PathgetAncestorFolder(java.nio.file.Path p)(package private) java.util.List<BuildJob>getBuildJobs()Gets the build jobs that should be processed.(package private) java.util.List<java.lang.String>getGoals(java.io.File basedir)Gets the goal list for the specified project.private java.util.Map<java.lang.String,java.lang.Object>getInterpolationValueSource(boolean escapeXml)Returns the map-based value source used to interpolate POMs and other stuff.private InvokerPropertiesgetInvokerProperties(java.io.File projectDirectory, java.util.Properties globalInvokerProperties)Gets the (interpolated) invoker properties for an integration test.private java.util.List<BuildJob>getNonSetupJobs(java.util.List<BuildJob> buildJobs)private java.lang.StringgetParentPath(java.lang.String path)Gets the parent path of the specified relative path.(package private) java.util.List<java.lang.String>getProfiles(java.io.File basedir)Gets the profile list for the specified project.private intgetSelection(InvokerProperties invokerProperties, java.lang.CharSequence actualJreVersion)Determines whether selector conditions of the specified invoker properties match the current environment.private java.util.List<BuildJob>getSetupBuildJobsFromFolders()private java.util.PropertiesgetSystemProperties(java.io.File basedir, java.lang.String filename)Gets the system properties to use for the specified project.private java.util.List<java.lang.String>getTokens(java.io.File basedir, java.lang.String filename, java.util.List<java.lang.String> defaultTokens)Gets goal/profile names for the specified project, either directly from the plugin configuration or from an external token file.private AbstractInvokerMojo.ToolchainPrivateManagergetToolchainPrivateManager()private voidhandleScriptRunnerWithScriptClassPath()private java.io.FileinterpolatePomFile(java.io.File pomFile, java.io.File basedir)Interpolate the pom file.private java.io.FileinterpolateSettings(java.io.File settingsFile)Interpolate settings.xml file.protected booleanisParallelRun()private java.io.FilemergeSettings(java.io.File interpolatedSettingsFile)Merge the settings fileprivate java.io.ReadernewReader(java.io.File file)Creates a new reader for the specified file, using the plugin'sencodingparameter.private org.apache.maven.shared.utils.logging.MessageBuilderpad(BuildJob buildJob)(package private) abstract voidprocessResults(InvokerSession invokerSession)Processes the results of invoking the build jobs.private java.util.List<java.lang.String>readTokens(java.io.File tokenFile)Reads the tokens from the specified file.private java.lang.StringrelativizePath(java.io.File path, java.lang.String basedir)Relativizes the specified path against the given base directory.private voidrelativizeProjectPaths(java.util.List<BuildJob> buildJobs)Relativizes the project paths of the specified build jobs against the directory specified byprojectsDirectory(if possible).private voidresetSourceLevelSet(org.apache.maven.settings.TrackableBase trackable)private java.lang.CharSequenceresolveExternalJreVersion()private AbstractInvokerMojo.ExecutionResultrunBuild(java.io.File basedir, java.io.File pomFile, java.io.File settingsFile, java.io.File actualJavaHome, InvokerProperties invokerProperties)Runs the specified project.private voidrunBuild(java.io.File projectsDir, BuildJob buildJob, java.io.File settingsFile, java.io.File actualJavaHome, java.lang.CharSequence actualJreVersion, java.util.Properties globalInvokerProperties)Runs the specified project.private voidrunBuilds(java.io.File projectsDir, java.util.List<BuildJob> buildJobs, int runWithParallelThreads)Runs the specified build jobs.private voidrunPostBuildHook(java.io.File basedir, java.util.Map<java.lang.String,java.lang.Object> context, FileLogger logger)private java.util.List<BuildJob>scanProjectsDirectory(java.util.List<java.lang.String> includes, java.util.List<java.lang.String> excludes, java.lang.String type)Scans the projects directory for projects to build.private FileLoggersetupBuildLogFile(java.io.File basedir)Initializes the build logger for the specified project.private voidsetupLoggerForBuildJob(FileLogger logger, org.apache.maven.shared.invoker.InvocationRequest request)private voidsetupReportsFolder()This will create the necessary folders for the reports.private static java.lang.StringtoUrl(java.lang.String filename)Converts the specified filesystem path to a URL.private voidverify(org.apache.maven.shared.invoker.InvocationResult result, int invocationIndex, InvokerProperties invokerProperties, FileLogger logger)Verifies the invocation result.private voidwriteBuildReport(BuildJob buildJob, AbstractInvokerMojo.ExecutionResult executionResult)Writes the XML report for the specified build job unless report generation has been disabled.private voidwriteJunitReport(BuildJob buildJob, java.lang.String safeFileName, AbstractInvokerMojo.ExecutionResult executionResult)private java.io.FilewriteMergedSettingsFile(org.apache.maven.settings.Settings mergedSettings)private voidwriteSummaryFile(java.util.List<BuildJob> buildJobs)
-
-
-
Field Detail
-
RESULT_COLUMN
private static final int RESULT_COLUMN
The zero-based column index where to print the invoker result.- See Also:
- Constant Field Values
-
skipInvocation
@Parameter(property="invoker.skip", defaultValue="false") private boolean skipInvocationFlag used to suppress certain invocations. This is useful in tailoring the build using profiles.- Since:
- 1.1
-
suppressSummaries
@Parameter(defaultValue="false") protected boolean suppressSummaries
Flag used to suppress the summary output notifying of successes and failures. If set totrue, the only indication of the build's success or failure will be the effect it has on the main build (if it fails, the main build should fail as well). IfstreamLogsis enabled, the sub-build summary will also provide an indication.
-
streamLogs
@Parameter(property="invoker.streamLogs", defaultValue="false") private boolean streamLogsFlag used to determine whether the build logs should be output to the normal mojo log.
-
localRepositoryPath
@Parameter(property="invoker.localRepositoryPath", defaultValue="${settings.localRepository}") private java.io.File localRepositoryPathThe local repository for caching artifacts. It is strongly recommended to specify a path to an isolated repository like${project.build.directory}/it-repo. Otherwise, your ordinary local repository will be used, potentially soiling it with broken artifacts.
-
projectsDirectory
@Parameter(property="invoker.projectsDirectory", defaultValue="${basedir}/src/it/") private java.io.File projectsDirectoryDirectory to search for integration tests.
-
reportsDirectory
@Parameter(property="invoker.reportsDirectory", defaultValue="${project.build.directory}/invoker-reports") private java.io.File reportsDirectoryBase directory where all build reports are written to. Every execution of an integration test will produce an XML file which contains the information about success or failure of that particular build job. The format of the resulting XML file is documented in the given build-job reference.- Since:
- 1.4
-
disableReports
@Parameter(property="invoker.disableReports", defaultValue="false") private boolean disableReportsA flag to disable the generation of build reports.- Since:
- 1.4
-
cloneProjectsTo
@Parameter(property="invoker.cloneProjectsTo") private java.io.File cloneProjectsTo
Directory to which projects should be cloned prior to execution. If set tonull, each integration test will be run in the directory in which the corresponding IT POM was found. In this case, you most likely want to configure your SCM to ignoretargetandbuild.login the test's base directory.- Since:
- 1.1
-
cloneAllFiles
@Parameter(defaultValue="false") private boolean cloneAllFiles
Some files are normally excluded when copying the IT projects from the directory specified by the parameter projectsDirectory to the directory given by cloneProjectsTo (e.g..svn,CVS,*~, etc: see reference for full list). Setting this parameter totruewill cause all files to be copied to thecloneProjectsTodirectory.- Since:
- 1.2
-
cloneClean
@Parameter(defaultValue="true") private boolean cloneClean
Ensure thecloneProjectsTodirectory is not polluted with files from earlier invoker runs.- Since:
- 1.6
-
pom
@Parameter(property="invoker.pom") private java.io.File pom
A single POM to build, skipping any scanning parameters and behavior.
-
pomIncludes
@Parameter private java.util.List<java.lang.String> pomIncludes
Include patterns for searching the integration test directory for projects. This parameter is meant to be set from the POM. If this parameter is not set, the plugin will search for allpom.xmlfiles one directory belowprojectsDirectory(i.e.*/pom.xml).
Starting with version 1.3, mere directories can also be matched by these patterns. For example, the include pattern*will run Maven builds on all immediate sub directories ofprojectsDirectory, regardless if they contain apom.xml. This allows to perform builds that need/should not depend on the existence of a POM.
-
pomExcludes
@Parameter private java.util.List<java.lang.String> pomExcludes
Exclude patterns for searching the integration test directory. This parameter is meant to be set from the POM. By default, no POM files are excluded. For the convenience of using an include pattern like*, the custom settings file specified by the parametersettingsFilewill always be excluded automatically.
-
setupIncludes
@Parameter private java.util.List<java.lang.String> setupIncludes
Include patterns for searching the projects directory for projects that need to be run before the other projects. This parameter allows to declare projects that perform setup tasks like installing utility artifacts into the local repository. Projects matched by these patterns are implicitly excluded from the scan for ordinary projects. Also, the exclusions defined by the parameterpomExcludesapply to the setup projects, too. Default value is:setup*/pom.xml.- Since:
- 1.3
-
goals
@Parameter private java.util.List<java.lang.String> goals
The list of goals to execute on each project. Default value is:package.
-
invoker
@Component private org.apache.maven.shared.invoker.Invoker invoker
-
settingsBuilder
@Component private org.apache.maven.settings.building.SettingsBuilder settingsBuilder
-
toolchainManagerPrivate
@Component private org.apache.maven.toolchain.ToolchainManagerPrivate toolchainManagerPrivate
-
selectorScript
@Parameter(property="invoker.selectorScript", defaultValue="selector") private java.lang.String selectorScriptRelative path of a selector script to run prior in order to decide if the build should be executed. This script may be written with either BeanShell or Groovy. If the file extension is omitted (e.g.selector), 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 fromtrue, the corresponding build is flagged as skipped. In this case, none of the pre-build hook script, Maven nor the post-build hook script will be invoked. If this script throws an exception, the corresponding build is flagged as in error, and none of the pre-build hook script, Maven not the post-build hook script will be invoked.- Since:
- 1.5
-
preBuildHookScript
@Parameter(property="invoker.preBuildHookScript", defaultValue="prebuild") private java.lang.String preBuildHookScriptRelative path of a pre-build hook script to run prior to executing the build. This script may be written with either BeanShell or Groovy (since 1.3). If the file extension is omitted (e.g.prebuild), 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. In this case, neither Maven nor the post-build hook script will be invoked.
-
postBuildHookScript
@Parameter(property="invoker.postBuildHookScript", defaultValue="postbuild") private java.lang.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 (since 1.3). 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.
-
testPropertiesFile
@Parameter(property="invoker.testPropertiesFile", defaultValue="test.properties") private java.lang.String testPropertiesFileLocation of a properties file that defines CLI properties for the test.
-
properties
@Parameter 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.- Since:
- 1.1
-
showErrors
@Parameter(property="invoker.showErrors", defaultValue="false") private boolean showErrorsWhether to show errors in the build output.
-
debug
@Parameter(property="invoker.debug", defaultValue="false") private boolean debugWhether to show debug statements in the build output.
-
noLog
@Parameter(property="invoker.noLog", defaultValue="false") private boolean noLogSuppress logging to thebuild.logfile.
-
logDirectory
@Parameter private java.io.File logDirectory
By default abuild.logis created in the root of the project. By setting this folder files are written to a different folder, respecting the structure of the projectsDirectory.- Since:
- 3.2.0
-
profiles
@Parameter private java.util.List<java.lang.String> profiles
List of profile identifiers to explicitly trigger in the build.- Since:
- 1.1
-
filterProperties
@Parameter private java.util.Map<java.lang.String,java.lang.String> filterProperties
A list of additional properties which will be used to filter tokens in POMs and goal files.- Since:
- 1.3
-
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject projectThe Maven Project Object- Since:
- 1.1
-
session
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session
-
mojoExecution
@Parameter(defaultValue="${mojoExecution}", readonly=true, required=true) private org.apache.maven.plugin.MojoExecution mojoExecution
-
invokerTest
@Parameter(property="invoker.test") private java.lang.String invokerTest
A comma separated list of projectname patterns to run. Specify this parameter to run individual tests by file name, overriding thesetupIncludes,pomIncludesandpomExcludesparameters. Each pattern you specify here will be used to create an include/exclude pattern formatted like${projectsDirectory}/pattern. To exclude a test, prefix the pattern with a '!'. So you can just type to run builds in-Dinvoker.test=SimpleTest,Comp*Test,!Compare*${projectsDirectory}/SimpleTestand${projectsDirectory}/ComplexTest, but not${projectsDirectory}/CompareTest- Since:
- 1.1 (exclusion since 1.8)
-
settingsFile
@Parameter(property="invoker.settingsFile") private java.io.File 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:
- 1.2
-
mavenOpts
@Parameter(property="invoker.mavenOpts") private java.lang.String mavenOpts
TheMAVEN_OPTSenvironment variable to use when invoking Maven. This value can be overridden for individual integration tests by usinginvokerPropertiesFile.- Since:
- 1.2
-
mavenHome
@Parameter(property="invoker.mavenHome") private java.io.File mavenHome
The home directory of the Maven installation to use for the forked builds. Defaults to the current Maven installation.- Since:
- 1.3
-
mavenExecutable
@Parameter(property="invoker.mavenExecutable") private java.lang.String mavenExecutable
mavenExecutable can either be a file relative to${maven.home}/bin/or an absolute file.- Since:
- 1.8
- See Also:
Invoker.setMavenExecutable(File)
-
javaHome
@Parameter(property="invoker.javaHome") private java.io.File javaHome
TheJAVA_HOMEenvironment variable to use for forked Maven invocations. Defaults to the current Java home directory.- Since:
- 1.3
-
encoding
@Parameter(property="encoding", defaultValue="${project.build.sourceEncoding}") private java.lang.String encodingThe file encoding for the pre-/post-build scripts and the list files for goals and profiles.- Since:
- 1.2
-
settings
@Parameter(defaultValue="${settings}", readonly=true, required=true) private org.apache.maven.settings.Settings settingsThe current user system settings for use in Maven.- Since:
- 1.2
-
addTestClassPath
@Parameter(property="invoker.addTestClassPath", defaultValue="false") private boolean addTestClassPathA flag whether the test class path of the project under test should be included in the class path of the pre-/post-build scripts. If set tofalse, the class path of script interpreter consists only of the runtime dependencies of the Maven Invoker Plugin. If set thetrue, the project's test class path will be prepended to the interpreter class path. Among others, this feature allows the scripts to access utility classes from the test sources of your project.- Since:
- 1.2
-
testClassPath
@Parameter(defaultValue="${project.testClasspathElements}", readonly=true) private java.util.List<java.lang.String> testClassPathThe test class path of the project under test.
-
invokerPropertiesFile
@Parameter(property="invoker.invokerPropertiesFile", defaultValue="invoker.properties") private java.lang.String invokerPropertiesFileThe name of an optional project-specific file that contains properties used to specify settings for an individual Maven invocation. Any property present in the file will override the corresponding setting from the plugin configuration. The values of the properties are filtered and may use expressions like${project.version}to reference project properties or values from the parameterfilterProperties.As of 3.2.0 it is possible to put this folder in any of the ancestor folders, where properties will be inherited. This way you can provide a single properties file for a group of projects
The snippet below describes the supported properties:# A comma or space separated list of goals/phases to execute, may # specify an empty list to execute the default goal of the IT project. # Environment variables used by maven plugins can be added here invoker.goals = clean install -Dplugin.variable=value # Or you can give things like this if you need. invoker.goals = -T2 clean verify # Optionally, a list of goals to run during further invocations of Maven invoker.goals.2 = ${project.groupId}:${project.artifactId}:${project.version}:run # A comma or space separated list of profiles to activate invoker.profiles = its,jdk15 # The path to an alternative POM or base directory to invoke Maven on, defaults to the # project that was originally specified in the plugin configuration # Since plugin version 1.4 invoker.project = sub-module # The value for the environment variable MAVEN_OPTS invoker.mavenOpts = -Dfile.encoding=UTF-16 -Xms32m -Xmx256m # Possible values are "fail-fast" (default), "fail-at-end" and "fail-never" invoker.failureBehavior = fail-never # The expected result of the build, possible values are "success" (default) and "failure" invoker.buildResult = failure # A boolean value controlling the aggregator mode of Maven, defaults to "false" invoker.nonRecursive = true # A boolean value controlling the network behavior of Maven, defaults to "false" # Since plugin version 1.4 invoker.offline = true # The path to the properties file from which to load system properties, defaults to the # filename given by the plugin parameter testPropertiesFile # Since plugin version 1.4 invoker.systemPropertiesFile = test.properties # An optional human friendly name for this build job to be included in the build reports. # Since plugin version 1.4 invoker.name = Test Build 01 # An optional description for this build job to be included in the build reports. # Since plugin version 1.4 invoker.description = Checks the support for build reports. # A comma separated list of JRE versions on which this build job should be run. # Since plugin version 1.4 invoker.java.version = 1.4+, !1.4.1, 1.7- # A comma separated list of OS families on which this build job should be run. # Since plugin version 1.4 invoker.os.family = !windows, unix, mac # A comma separated list of Maven versions on which this build should be run. # Since plugin version 1.5 invoker.maven.version = 2.0.10+, !2.1.0, !2.2.0 # A mapping for toolchain to ensure it exists # Since plugin version 3.2.0 invoker.toolchain.<type>.<provides> = value invoker.toolchain.jdk.version = 11 # For java.version, maven.version, os.family and toolchain it is possible to define multiple selectors. # If one of the indexed selectors matches, the test is executed. # With the invoker.x.y equivalents you can specify global matchers. selector.1.java.version = 1.8+ selector.1.maven.version = 3.2.5+ selector.1.os.family = !windows selector.2.maven.version = 3.0+ selector.3.java.version = 9+ # A boolean value controlling the debug logging level of Maven, , defaults to "false" # Since plugin version 1.8 invoker.debug = true # Path to an alternatesettings.xmlto use for Maven invocation with this IT. # Since plugin version 3.0.1 invoker.settingsFile = ../ # An integer value to control run order of projects. sorted in the descending order of the ordinal. In other words, the BuildJobs with the highest numbers will be executed first # Since plugin version 3.2.1 invoker.ordinal = 3 invoker.ordinal = 1- Since:
- 1.2
-
showVersion
@Parameter(property="invoker.showVersion", defaultValue="false") private boolean showVersionflag to enable show mvn version used for running its (cli option : -V,--show-version )- Since:
- 1.4
-
parallelThreads
@Parameter(property="invoker.parallelThreads", defaultValue="1") private int parallelThreadsnumber of threads for running tests in parallel. This will be the number of maven forked process in parallel.- Since:
- 1.6
-
pluginArtifacts
@Parameter(property="plugin.artifacts", required=true, readonly=true) private java.util.List<org.apache.maven.artifact.Artifact> pluginArtifacts- Since:
- 1.6
-
mergeUserSettings
@Parameter(property="invoker.mergeUserSettings", defaultValue="false") private boolean mergeUserSettingsIf enable and if you have a settings file configured for the execution, it will be merged with your user settings.- Since:
- 1.6
-
environmentVariables
@Parameter private java.util.Map<java.lang.String,java.lang.String> environmentVariables
Additional environment variables to set on the command line.- Since:
- 1.8
-
scriptVariables
@Parameter private java.util.Map<java.lang.String,java.lang.String> scriptVariables
Additional variables for use in the hook scripts.- Since:
- 1.9
-
timeoutInSeconds
@Parameter(defaultValue="0", property="invoker.timeoutInSeconds") private int timeoutInSeconds- Since:
- 3.0.2
-
writeJunitReport
@Parameter(defaultValue="false", property="invoker.writeJunitReport") private boolean writeJunitReportWrite test result in junit format.- Since:
- 3.1.2
-
junitPackageName
@Parameter(defaultValue="maven.invoker.it", property="invoker.junitPackageName") private java.lang.String junitPackageNameThe package name use in junit report- Since:
- 3.1.2
-
scriptRunner
private org.apache.maven.shared.scriptinterpreter.ScriptRunner scriptRunner
The scripter runner that is responsible to execute hook scripts.
-
filteredPomPrefix
private java.lang.String filteredPomPrefix
A string used to prefix the file name of the filtered POMs in case the POMs couldn't be filtered in-place (i.e. the projects were not cloned to a temporary directory), can benull. This will be set tonullif the POMs have already been filtered during cloning.
-
secFormat
private final java.text.DecimalFormat secFormat
The format for elapsed build time.
-
actualMavenVersion
private java.lang.String actualMavenVersion
The version of Maven which is used to run the builds
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureExceptionInvokes Maven on the configured test projects.- Throws:
org.apache.maven.plugin.MojoExecutionException- If the goal encountered severe errors.org.apache.maven.plugin.MojoFailureException- If any of the Maven builds failed.
-
setupReportsFolder
private void setupReportsFolder() throws org.apache.maven.plugin.MojoExecutionExceptionThis will create the necessary folders for the reports.- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of failure during creation of the reports folder.
-
getNonSetupJobs
private java.util.List<BuildJob> getNonSetupJobs(java.util.List<BuildJob> buildJobs)
-
handleScriptRunnerWithScriptClassPath
private void handleScriptRunnerWithScriptClassPath()
-
writeSummaryFile
private void writeSummaryFile(java.util.List<BuildJob> buildJobs) throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
doFailIfNoProjects
protected void doFailIfNoProjects() throws org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoFailureException
-
processResults
abstract void processResults(InvokerSession invokerSession) throws org.apache.maven.plugin.MojoFailureException
Processes the results of invoking the build jobs.- Parameters:
invokerSession- The session with the build jobs, must not benull.- Throws:
org.apache.maven.plugin.MojoFailureException- If the mojo had failed as a result of invoking the build jobs.- Since:
- 1.4
-
newReader
private java.io.Reader newReader(java.io.File file) throws java.io.IOExceptionCreates a new reader for the specified file, using the plugin'sencodingparameter.- Parameters:
file- The file to create a reader for, must not benull.- Returns:
- The reader for the file, never
null. - Throws:
java.io.IOException- If the specified file was not found or the configured encoding is not supported.
-
collectProjects
private void collectProjects(java.io.File projectsDir, java.lang.String projectPath, java.util.Collection<java.lang.String> projectPaths, boolean included) throws org.apache.maven.plugin.MojoExecutionExceptionCollects all projects locally reachable from the specified project. The method will as such try to read the POM and recursively follow its parent/module elements.- Parameters:
projectsDir- The base directory of all projects, must not benull.projectPath- The relative path of the current project, can denote either the POM or its base directory, must not benull.projectPaths- The set of already collected projects to add new projects to, must not benull. This set will hold the relative paths to either a POM file or a project base directory.included- A flag indicating whether the specified project has been explicitly included via the parameterpomIncludes. Such projects will always be added to the result set even if there is no corresponding POM.- Throws:
org.apache.maven.plugin.MojoExecutionException- If the project tree could not be traversed.
-
cloneProjects
private void cloneProjects(java.util.Collection<java.lang.String> projectPaths) throws org.apache.maven.plugin.MojoExecutionExceptionCopies the specified projects to the directory given bycloneProjectsTo. A project may either be denoted by a path to a POM file or merely by a path to a base directory. During cloning, the POM files will be filtered.- Parameters:
projectPaths- The paths to the projects to clone, relative to the projects directory, must not benullnor containnullelements.- Throws:
org.apache.maven.plugin.MojoExecutionException- If the the projects could not be copied/filtered.
-
getParentPath
private java.lang.String getParentPath(java.lang.String path)
Gets the parent path of the specified relative path.- Parameters:
path- The relative path whose parent should be retrieved, must not benull.- Returns:
- The parent path or "." if the specified path has no parent, never
null.
-
copyDirectoryStructure
private void copyDirectoryStructure(java.io.File sourceDir, java.io.File destDir) throws java.io.IOExceptionCopied a directory structure with default exclusions (.svn, CVS, etc)- Parameters:
sourceDir- The source directory to copy, must not benull.destDir- The target directory to copy to, must not benull.- Throws:
java.io.IOException- If the directory structure could not be copied.
-
alreadyCloned
static boolean alreadyCloned(java.lang.String subpath, java.util.List<java.lang.String> clonedSubpaths)Determines whether the specified sub path has already been cloned, i.e. whether one of its ancestor directories was already cloned.- Parameters:
subpath- The sub path to check, must not benull.clonedSubpaths- The list of already cloned paths, must not benullnor containnullelements.- Returns:
trueif the specified path has already been cloned,falseotherwise.
-
runBuilds
private void runBuilds(java.io.File projectsDir, java.util.List<BuildJob> buildJobs, int runWithParallelThreads) throws org.apache.maven.plugin.MojoExecutionExceptionRuns the specified build jobs.- Parameters:
projectsDir- The base directory of all projects, must not benull.buildJobs- The build jobs to run must not benullnor containnullelements.- Throws:
org.apache.maven.plugin.MojoExecutionException- If any build could not be launched.
-
getAncestorFolder
private java.nio.file.Path getAncestorFolder(java.nio.file.Path p)
-
interpolateSettings
private java.io.File interpolateSettings(java.io.File settingsFile) throws org.apache.maven.plugin.MojoExecutionExceptionInterpolate settings.xml file.- Parameters:
settingsFile- a settings file- Returns:
- The interpolated settings.xml file.
- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of a problem.
-
mergeSettings
private java.io.File mergeSettings(java.io.File interpolatedSettingsFile) throws org.apache.maven.plugin.MojoExecutionExceptionMerge the settings file- Parameters:
interpolatedSettingsFile- The interpolated settings file.- Returns:
- The merged settings file.
- Throws:
org.apache.maven.plugin.MojoExecutionException- Fail the build in case the merged settings file can't be created.
-
writeMergedSettingsFile
private java.io.File writeMergedSettingsFile(org.apache.maven.settings.Settings mergedSettings) throws java.io.IOException- Throws:
java.io.IOException
-
cloneSettings
private org.apache.maven.settings.Settings cloneSettings()
-
resetSourceLevelSet
private void resetSourceLevelSet(org.apache.maven.settings.TrackableBase trackable)
-
resolveExternalJreVersion
private java.lang.CharSequence resolveExternalJreVersion()
-
interpolatePomFile
private java.io.File interpolatePomFile(java.io.File pomFile, java.io.File basedir) throws org.apache.maven.plugin.MojoExecutionExceptionInterpolate the pom file.- Parameters:
pomFile- The pom file.basedir- The base directory.- Returns:
- interpolated pom file location in case we have interpolated the pom file otherwise the original pom file will be returned.
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
runBuild
private void runBuild(java.io.File projectsDir, BuildJob buildJob, java.io.File settingsFile, java.io.File actualJavaHome, java.lang.CharSequence actualJreVersion, java.util.Properties globalInvokerProperties) throws org.apache.maven.plugin.MojoExecutionExceptionRuns the specified project.- Parameters:
projectsDir- The base directory of all projects, must not benull.buildJob- The build job to run, must not benull.settingsFile- The (already interpolated) user settings file for the build, may benullto use the current user settings.globalInvokerProperties-- Throws:
org.apache.maven.plugin.MojoExecutionException- If the project could not be launched.
-
pad
private org.apache.maven.shared.utils.logging.MessageBuilder pad(BuildJob buildJob)
-
deleteInterpolatedPomFile
private void deleteInterpolatedPomFile(java.io.File interpolatedPomFile)
Delete the interpolated pom file if it has been created before.- Parameters:
interpolatedPomFile- The interpolated pom file.
-
getSelection
private int getSelection(InvokerProperties invokerProperties, java.lang.CharSequence actualJreVersion)
Determines whether selector conditions of the specified invoker properties match the current environment.- Parameters:
invokerProperties- The invoker properties to check, must not benull.- Returns:
0if the job corresponding to the properties should be run, otherwise a bitwise value representing the reason why it should be skipped.
-
getToolchainPrivateManager
private AbstractInvokerMojo.ToolchainPrivateManager getToolchainPrivateManager()
-
writeBuildReport
private void writeBuildReport(BuildJob buildJob, AbstractInvokerMojo.ExecutionResult executionResult) throws org.apache.maven.plugin.MojoExecutionException
Writes the XML report for the specified build job unless report generation has been disabled.- Parameters:
buildJob- The build job whose report should be written, must not benull.- Throws:
org.apache.maven.plugin.MojoExecutionException- If the report could not be written.
-
writeJunitReport
private void writeJunitReport(BuildJob buildJob, java.lang.String safeFileName, AbstractInvokerMojo.ExecutionResult executionResult) throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
formatTime
private java.lang.String formatTime(double seconds)
Formats the specified build duration time.- Parameters:
seconds- The duration of the build.- Returns:
- The formatted time, never
null.
-
runBuild
private AbstractInvokerMojo.ExecutionResult runBuild(java.io.File basedir, java.io.File pomFile, java.io.File settingsFile, java.io.File actualJavaHome, InvokerProperties invokerProperties) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.shared.scriptinterpreter.RunFailureException
Runs the specified project.- Parameters:
basedir- The base directory of the project, must not benull.pomFile- The (already interpolated) POM file, may benullfor a POM-less Maven invocation.settingsFile- The (already interpolated) user settings file for the build, may benull. Will be merged with the settings file of the invoking Maven process.invokerProperties- The properties to use.- Returns:
trueif the project was launched orfalseif the selector script indicated that the project should be skipped.- Throws:
org.apache.maven.plugin.MojoExecutionException- If the project could not be launched.org.apache.maven.shared.scriptinterpreter.RunFailureException- If either a hook script or the build itself failed.
-
runPostBuildHook
private void runPostBuildHook(java.io.File basedir, java.util.Map<java.lang.String,java.lang.Object> context, FileLogger logger) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.shared.scriptinterpreter.RunFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.shared.scriptinterpreter.RunFailureException
-
setupLoggerForBuildJob
private void setupLoggerForBuildJob(FileLogger logger, org.apache.maven.shared.invoker.InvocationRequest request)
-
setupBuildLogFile
private FileLogger setupBuildLogFile(java.io.File basedir) throws org.apache.maven.plugin.MojoExecutionException
Initializes the build logger for the specified project. This will write the logging information intobuild.log.- Parameters:
basedir- The base directory of the project, must not benull.- Returns:
- The build logger or
nullif logging has been disabled. - Throws:
org.apache.maven.plugin.MojoExecutionException- If the log file could not be created.
-
getSystemProperties
private java.util.Properties getSystemProperties(java.io.File basedir, java.lang.String filename) throws org.apache.maven.plugin.MojoExecutionExceptionGets the system properties to use for the specified project.- Parameters:
basedir- The base directory of the project, must not benull.filename- The filename to the properties file to load, may benullto use the default path given bytestPropertiesFile.- Returns:
- The system properties to use, may be empty but never
null. - Throws:
org.apache.maven.plugin.MojoExecutionException- If the properties file exists but could not be read.
-
verify
private void verify(org.apache.maven.shared.invoker.InvocationResult result, int invocationIndex, InvokerProperties invokerProperties, FileLogger logger) throws org.apache.maven.shared.scriptinterpreter.RunFailureExceptionVerifies the invocation result.- Parameters:
result- The invocation result to check, must not benull.invocationIndex- The index of the invocation for which to check the exit code, must not be negative.invokerProperties- The invoker properties used to check the exit code, must not benull.logger- The build logger, may benullif logging is disabled.- Throws:
org.apache.maven.shared.scriptinterpreter.RunFailureException- If the invocation result indicates a build failure.
-
getGoals
java.util.List<java.lang.String> getGoals(java.io.File basedir) throws org.apache.maven.plugin.MojoExecutionExceptionGets the goal list for the specified project.- Parameters:
basedir- The base directory of the project, must not benull.- Returns:
- The list of goals to run when building the project, may be empty but never
null. - Throws:
org.apache.maven.plugin.MojoExecutionException- If the profile file could not be read.
-
getProfiles
java.util.List<java.lang.String> getProfiles(java.io.File basedir) throws org.apache.maven.plugin.MojoExecutionExceptionGets the profile list for the specified project.- Parameters:
basedir- The base directory of the project, must not benull.- Returns:
- The list of profiles to activate when building the project, may be empty but never
null. - Throws:
org.apache.maven.plugin.MojoExecutionException- If the profile file could not be read.
-
calculateExcludes
private java.util.List<java.lang.String> calculateExcludes() throws java.io.IOException- Throws:
java.io.IOException
-
getSetupBuildJobsFromFolders
private java.util.List<BuildJob> getSetupBuildJobsFromFolders() throws java.io.IOException, org.apache.maven.plugin.MojoExecutionException
- Returns:
- The list of setupUp jobs.
- Throws:
java.io.IOExceptionorg.apache.maven.plugin.MojoExecutionException
-
getBuildJobs
java.util.List<BuildJob> getBuildJobs() throws java.io.IOException, org.apache.maven.plugin.MojoExecutionException
Gets the build jobs that should be processed. Note that the order of the returned build jobs is significant.- Returns:
- The build jobs to process, may be empty but never
null. - Throws:
java.io.IOException- If the projects directory could not be scanned.org.apache.maven.plugin.MojoExecutionException
-
scanProjectsDirectory
private java.util.List<BuildJob> scanProjectsDirectory(java.util.List<java.lang.String> includes, java.util.List<java.lang.String> excludes, java.lang.String type) throws java.io.IOException, org.apache.maven.plugin.MojoExecutionException
Scans the projects directory for projects to build. Both (POM) files and mere directories will be matched by the scanner patterns. If the patterns match a directory which contains a file named "pom.xml", the results will include the path to this file rather than the directory path in order to avoid duplicate invocations of the same project.- Parameters:
includes- The include patterns for the scanner, may benull.excludes- The exclude patterns for the scanner, may benullto exclude nothing.type- The type to assign to the resulting build jobs, must not benull.- Returns:
- The build jobs matching the patterns, never
null. - Throws:
java.io.IOException- If the project directory could not be scanned.org.apache.maven.plugin.MojoExecutionException
-
relativizeProjectPaths
private void relativizeProjectPaths(java.util.List<BuildJob> buildJobs) throws java.io.IOException
Relativizes the project paths of the specified build jobs against the directory specified byprojectsDirectory(if possible). If a project path does not denote a sub path of the projects directory, it is returned as is.- Parameters:
buildJobs- The build jobs whose project paths should be relativized, must not benullnor containnullelements.- Throws:
java.io.IOException- If any path could not be relativized.
-
relativizePath
private java.lang.String relativizePath(java.io.File path, java.lang.String basedir) throws java.io.IOExceptionRelativizes the specified path against the given base directory. Besides relativization, the returned path will also be normalized, e.g. directory references like ".." will be removed.- Parameters:
path- The path to relativize, must not benull.basedir- The (canonical path of the) base directory to relativize against, must not benull.- Returns:
- The relative path in normal form or
nullif the input path does not denote a sub path of the base directory. - Throws:
java.io.IOException- If the path could not be relativized.
-
getInterpolationValueSource
private java.util.Map<java.lang.String,java.lang.Object> getInterpolationValueSource(boolean escapeXml)
Returns the map-based value source used to interpolate POMs and other stuff.- Parameters:
escapeXml-true, to escape any XML special characters in the property values;false, to not escape any property values.- Returns:
- The map-based value source for interpolation, never
null.
-
toUrl
private static java.lang.String toUrl(java.lang.String filename)
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.
-
getTokens
private java.util.List<java.lang.String> getTokens(java.io.File basedir, java.lang.String filename, java.util.List<java.lang.String> defaultTokens) throws java.io.IOExceptionGets goal/profile names for the specified project, either directly from the plugin configuration or from an external token file.- Parameters:
basedir- The base directory of the test project, must not benull.filename- The (simple) name of an optional file in the project base directory from which to read goals/profiles, may benull.defaultTokens- The list of tokens to return in case the specified token file does not exist, may benull.- Returns:
- The list of goal/profile names, may be empty but never
null. - Throws:
java.io.IOException- If the token file exists but could not be parsed.
-
readTokens
private java.util.List<java.lang.String> readTokens(java.io.File tokenFile) throws java.io.IOExceptionReads the tokens from the specified file. Tokens are separated either by line terminators or commas. During parsing, the file contents will be interpolated.- Parameters:
tokenFile- The file to read the tokens from, must not benull.- Returns:
- The list of tokens, may be empty but never
null. - Throws:
java.io.IOException- If the token file could not be read.
-
collectListFromCSV
private java.util.List<java.lang.String> collectListFromCSV(java.lang.String csv)
Gets a list of comma separated tokens from the specified line.- Parameters:
csv- The line with comma separated tokens, may benull.- Returns:
- The list of tokens from the line, may be empty but never
null.
-
buildInterpolatedFile
void buildInterpolatedFile(java.io.File originalFile, java.io.File interpolatedFile) throws org.apache.maven.plugin.MojoExecutionExceptionInterpolates the specified POM/settings file to a temporary file. The destination file may be same as the input file, i.e. interpolation can be performed in-place.Note:This methods expects the file to be a XML file and applies special XML escaping during interpolation.
- Parameters:
originalFile- The XML file to interpolate, must not benull.interpolatedFile- The target file to write the interpolated contents of the original file to, must not benull.- Throws:
org.apache.maven.plugin.MojoExecutionException- If the target file could not be created.
-
getInvokerProperties
private InvokerProperties getInvokerProperties(java.io.File projectDirectory, java.util.Properties globalInvokerProperties) throws org.apache.maven.plugin.MojoExecutionException
Gets the (interpolated) invoker properties for an integration test.- Parameters:
projectDirectory- The base directory of the IT project, must not benull.- Returns:
- The invoker properties, may be empty but never
null. - Throws:
org.apache.maven.plugin.MojoExecutionException- If an I/O error occurred during reading the properties.
-
isParallelRun
protected boolean isParallelRun()
-
-