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 (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 java.util.List<java.lang.String>collectedProjectsProjects that are cloned undergo some filtering.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 InterpolatorUtilsinterpolatorUtilsprivate 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/, test project workspace 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 static floatONE_SECONDprivate java.lang.StringparallelThreadsNumber 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.MavenProjectprojectprivate 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 booleanquietWhether to execute Maven in quiet mode.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.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.Settingssettingsprivate 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>testClassPathprivate java.lang.StringtestPropertiesFileLocation of a properties file that defines CLI properties for the test.private inttimeoutInSecondsprivate org.apache.maven.toolchain.ToolchainManagerPrivatetoolchainManagerPrivateprivate booleanupdateOnlyOnly invoke maven projects if their sources have been modified since they were last built.private booleanupdateSnapshotsForce a check for missing releases and updated snapshots on remote repositories.private booleanwriteJunitReportWrite test result in junit format.
-
Constructor Summary
Constructors Constructor Description AbstractInvokerMojo(org.apache.maven.shared.invoker.Invoker invoker, org.apache.maven.settings.building.SettingsBuilder settingsBuilder, org.apache.maven.toolchain.ToolchainManagerPrivate toolchainManagerPrivate, InterpolatorUtils interpolatorUtils)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private voidaddMissingDotMvnDirectory(java.io.File projectsDir, java.util.List<BuildJob> buildJobs)We need add missing.mnvndirectories for executing projects(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 java.util.List<java.lang.String>calculateIncludes()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 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.StringformatElapsedTime(float time)Formats the specified elapsed 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.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)(package private) intgetParallelThreadsCount()private java.lang.StringgetParentPath(java.lang.String path)Gets the parent path of the specified relative path.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>getSetupJobs(java.util.List<BuildJob> buildJobs)private AbstractInvokerMojo.ToolchainPrivateManagergetToolchainPrivateManager()private java.util.PropertiesgetUserProperties(java.io.File basedir, java.lang.String filename)Gets the system properties to use for the specified project.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.private booleanisNotEmpty(java.lang.String s)private longlastModifiedRecursive(java.io.File file)Find the latest lastModified recursively within a directory structure.private java.io.FilemergeSettings(java.io.File interpolatedSettingsFile)Merge the settings fileprivate 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.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 booleanrunBuild(java.io.File basedir, java.io.File pomFile, java.io.File settingsFile, java.io.File actualJavaHome, InvokerProperties invokerProperties, FileLogger logger)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 voidrunPreBuildHook(java.io.File basedir, java.util.Map<java.lang.String,java.lang.Object> context, FileLogger logger)private booleanrunSelectorHook(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)Scans the projects directory for projects to build.private voidsetupActualMavenVersion()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)Writes the XML report for the specified build job unless report generation has been disabled.private voidwriteJunitReport(BuildJob buildJob, java.lang.String safeFileName)private java.io.FilewriteMergedSettingsFile(org.apache.maven.settings.Settings mergedSettings)private voidwriteSummaryFile(java.util.List<BuildJob> buildJobs)
-
-
-
Field Detail
-
ONE_SECOND
private static final float ONE_SECOND
- See Also:
- Constant Field Values
-
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.- Since:
- 1.0
-
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.- Since:
- 1.0
-
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.- Since:
- 1.0
-
projectsDirectory
@Parameter(property="invoker.projectsDirectory", defaultValue="${basedir}/src/it/") private java.io.File projectsDirectoryDirectory to search for integration tests.- Since:
- 1.0
-
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. (Exception when project using invoker plugin is of maven-plugin packaging: In such case IT projects will be cloned to and executed intarget/itsby default.) Note: cloning needs to be enabled for properties filtering to work.- 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.- Since:
- 1.0
-
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.- Since:
- 1.0
-
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.- Since:
- 1.0
-
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.- Since:
- 1.0
-
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.- Since:
- 1.0
-
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.- Since:
- 1.0
-
testPropertiesFile
@Parameter(property="invoker.testPropertiesFile", defaultValue="test.properties") private java.lang.String testPropertiesFileLocation of a properties file that defines CLI properties for the test.- Since:
- 1.0
-
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.- Since:
- 1.0
-
debug
@Parameter(property="invoker.debug", defaultValue="false") private boolean debugWhether to show debug statements in the build output.- Since:
- 1.0
-
quiet
@Parameter(property="invoker.quiet", defaultValue="false") private boolean quietWhether to execute Maven in quiet mode.- Since:
- 3.3.0
-
noLog
@Parameter(property="invoker.noLog", defaultValue="false") private boolean noLogSuppress logging to thebuild.logfile.- Since:
- 1.0
-
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
-
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 the version 3.7.0 using an alternate syntax for mavenOpts,@{...}allows late replacement of properties when the plugin is executed, so properties that have been modified by other plugins will be picked up correctly.- 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/, test project workspace or an absolute file.- Since:
- 1.8
-
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
-
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
-
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 # can be indexed 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 # can be indexed invoker.project = sub-module # The maven executable can either be a file relative to${maven.home}/bin/, test project workspace # or an absolute file. # Since plugin version 3.3.0 # can be indexed invoker.mavenExecutable = mvnw # The value for the environment variable MAVEN_OPTS # can be indexed invoker.mavenOpts = -Dfile.encoding=UTF-16 -Xms32m -Xmx256m # Possible values are "fail-fast" (default), "fail-at-end" and "fail-never" # can be indexed invoker.failureBehavior = fail-never # The expected result of the build, possible values are "success" (default) and "failure" # can be indexed invoker.buildResult = failure # A boolean value controlling the aggregator mode of Maven, defaults to "false" # can be indexed invoker.nonRecursive = true # A boolean value controlling the network behavior of Maven, defaults to "false" # Since plugin version 1.4 # can be indexed invoker.offline = true # The path to the properties file from which to load user properties, defaults to the # filename given by the plugin parameter testPropertiesFile # Since plugin version 1.4 # can be indexed invoker.userPropertiesFile = test.properties # An optional human friendly name and description for this build job. # Both name and description have to be set to be included in the build reports. # Since plugin version 1.4 invoker.name = Test Build 01 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 # can be indexed invoker.debug = true # Whether to execute Maven in quiet mode # Since plugin version 3.3.0 # can be indexed invoker.quiet = true The execution timeout in seconds. # Since plugin version 3.0.2 # can be indexed invoker.timeoutInSeconds = 5 # Path to an alternate settings.xml to use for Maven invocation with this IT. # Since plugin version 3.0.1 # can be indexed 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 # Default value is 0 (zero) # Since plugin version 3.2.1 invoker.ordinal = 3 # The additional value for the environment variable. # Since plugin version 3.2.2 invoker.environmentVariables.<variableName> = variableValue invoker.environmentVariables.MY_ENV_NAME = myEnvValue # A boolean value indicating a check for missing releases and updated snapshots on remote repositories to be done # Passed to the invoker. Same as passing -U, --update-snapshots flag on the command line # Since plugin version 3.4.0 invoker.updateSnapshots = true- 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 java.lang.String parallelThreadsNumber of threads for running tests in parallel. This will be the number of maven forked process in parallel. When terminated with "C", the number part is multiplied by the number of processors (cores) available to the Java virtual machine. Floating point value are only accepted together with "C".
Example values: "1.5C", "4"
- 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
-
updateOnly
@Parameter(defaultValue="false", property="invoker.updateOnly") private boolean updateOnlyOnly invoke maven projects if their sources have been modified since they were last built. Only works in conjunction withcloneProjectsTo.- Since:
- 3.2.2
-
updateSnapshots
@Parameter(defaultValue="false", property="invoker.updateSnapshots") private boolean updateSnapshotsForce a check for missing releases and updated snapshots on remote repositories. This is passed to the invoked maven projects (it is the same as if you were to use the -U, --update-snapshots flag on the command line).- Since:
- 3.4.0
-
collectedProjects
@Parameter private java.util.List<java.lang.String> collectedProjects
Projects that are cloned undergo some filtering. In order to grab all projects and make sure they are all filtered, projects are read and parsed. In some cases, this may not be a desired behavior (especially when some pom.xml cannot be parsed by Maven directly). In such cases, the exact list of projects can be set using this field, avoiding the parsing of all pom.xml files found.- Since:
- 3.9.0
-
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.
-
actualMavenVersion
private java.lang.String actualMavenVersion
The version of Maven which is used to run the builds
-
pluginArtifacts
@Parameter(property="plugin.artifacts", required=true, readonly=true) private java.util.List<org.apache.maven.artifact.Artifact> pluginArtifacts
-
testClassPath
@Parameter(defaultValue="${project.testClasspathElements}", readonly=true) private java.util.List<java.lang.String> testClassPath
-
mojoExecution
@Parameter(defaultValue="${mojoExecution}", readonly=true, required=true) private org.apache.maven.plugin.MojoExecution mojoExecution
-
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject project
-
session
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session
-
settings
@Parameter(defaultValue="${settings}", readonly=true, required=true) private org.apache.maven.settings.Settings settings
-
invoker
private final org.apache.maven.shared.invoker.Invoker invoker
-
settingsBuilder
private final org.apache.maven.settings.building.SettingsBuilder settingsBuilder
-
toolchainManagerPrivate
private final org.apache.maven.toolchain.ToolchainManagerPrivate toolchainManagerPrivate
-
interpolatorUtils
private final InterpolatorUtils interpolatorUtils
-
-
Constructor Detail
-
AbstractInvokerMojo
public AbstractInvokerMojo(org.apache.maven.shared.invoker.Invoker invoker, org.apache.maven.settings.building.SettingsBuilder settingsBuilder, org.apache.maven.toolchain.ToolchainManagerPrivate toolchainManagerPrivate, InterpolatorUtils interpolatorUtils)
-
-
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 errorsorg.apache.maven.plugin.MojoFailureException- if any of the Maven builds failed
-
addMissingDotMvnDirectory
private void addMissingDotMvnDirectory(java.io.File projectsDir, java.util.List<BuildJob> buildJobs) throws org.apache.maven.plugin.MojoExecutionExceptionWe need add missing.mnvndirectories for executing projects- Parameters:
projectsDir- base of projectsbuildJobs- list of discovered jobs- Throws:
org.apache.maven.plugin.MojoExecutionException
-
setupActualMavenVersion
private void setupActualMavenVersion() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
lastModifiedRecursive
private long lastModifiedRecursive(java.io.File file)
Find the latest lastModified recursively within a directory structure.- Parameters:
file- the root file to check.- Returns:
- the latest lastModified time found.
-
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
-
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.
-
isNotEmpty
private boolean isNotEmpty(java.lang.String s)
-
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 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) 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) throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
formatElapsedTime
private java.lang.String formatElapsedTime(float time)
Formats the specified elapsed time.- Parameters:
time- The eapsed time of the build.- Returns:
- The formatted time, never
null.
-
runBuild
private boolean runBuild(java.io.File basedir, java.io.File pomFile, java.io.File settingsFile, java.io.File actualJavaHome, InvokerProperties invokerProperties, FileLogger logger) throws org.apache.maven.plugin.MojoExecutionException, RunFailureExceptionRuns 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.logger- file logger to write execution build.log- 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.RunFailureException- If either a hook script or the build itself failed.
-
getParallelThreadsCount
int getParallelThreadsCount()
-
runSelectorHook
private boolean runSelectorHook(java.io.File basedir, java.util.Map<java.lang.String,java.lang.Object> context, FileLogger logger) throws org.apache.maven.plugin.MojoExecutionException, RunFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionRunFailureException
-
runPreBuildHook
private void runPreBuildHook(java.io.File basedir, java.util.Map<java.lang.String,java.lang.Object> context, FileLogger logger) throws org.apache.maven.plugin.MojoExecutionException, RunFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionRunFailureException
-
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, RunFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionRunFailureException
-
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.
-
getUserProperties
private java.util.Properties getUserProperties(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 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:
RunFailureException
-
calculateIncludes
private java.util.List<java.lang.String> calculateIncludes()
-
calculateExcludes
private java.util.List<java.lang.String> calculateExcludes() throws java.io.IOException- Throws:
java.io.IOException
-
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) throws java.io.IOException
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.- Returns:
- The build jobs matching the patterns, never
null. - Throws:
java.io.IOException- If the project directory could not be scanned.
-
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.
-
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.
-
-