Coverage Report - org.apache.maven.plugin.failsafe.IntegrationTestMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
IntegrationTestMojo
0%
0/243
0%
0/38
1.142
 
 1  
 package org.apache.maven.plugin.failsafe;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *     http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.maven.artifact.factory.ArtifactFactory;
 23  
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
 24  
 import org.apache.maven.artifact.repository.ArtifactRepository;
 25  
 import org.apache.maven.artifact.resolver.ArtifactResolver;
 26  
 import org.apache.maven.execution.MavenSession;
 27  
 import org.apache.maven.plugin.MojoExecutionException;
 28  
 import org.apache.maven.plugin.MojoFailureException;
 29  
 import org.apache.maven.plugin.surefire.AbstractSurefireMojo;
 30  
 import org.apache.maven.plugin.surefire.ProviderInfo;
 31  
 import org.apache.maven.plugin.surefire.SurefireExecutionParameters;
 32  
 import org.apache.maven.plugin.surefire.booterclient.ForkConfiguration;
 33  
 import org.apache.maven.plugin.surefire.booterclient.ForkStarter;
 34  
 import org.apache.maven.project.MavenProject;
 35  
 import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
 36  
 import org.apache.maven.surefire.booter.ProviderConfiguration;
 37  
 import org.apache.maven.surefire.booter.SurefireBooterForkException;
 38  
 import org.apache.maven.surefire.booter.SurefireExecutionException;
 39  
 import org.apache.maven.surefire.failsafe.model.FailsafeSummary;
 40  
 import org.apache.maven.surefire.failsafe.model.io.xpp3.FailsafeSummaryXpp3Writer;
 41  
 import org.apache.maven.toolchain.ToolchainManager;
 42  
 import org.codehaus.plexus.util.ReaderFactory;
 43  
 import org.codehaus.plexus.util.StringUtils;
 44  
 
 45  
 import java.io.BufferedOutputStream;
 46  
 import java.io.File;
 47  
 import java.io.FileOutputStream;
 48  
 import java.io.IOException;
 49  
 import java.io.OutputStreamWriter;
 50  
 import java.io.Writer;
 51  
 import java.util.HashMap;
 52  
 import java.util.Iterator;
 53  
 import java.util.List;
 54  
 import java.util.Map;
 55  
 import java.util.Properties;
 56  
 
 57  
 /**
 58  
  * Run integration tests using Surefire.
 59  
  *
 60  
  * @author Jason van Zyl
 61  
  * @author Stephen Connolly
 62  
  * @requiresProject true
 63  
  * @requiresDependencyResolution test
 64  
  * @goal integration-test
 65  
  * @phase integration-test
 66  
  * @threadSafe
 67  
  * @noinspection JavaDoc
 68  
  */
 69  0
 public class IntegrationTestMojo
 70  
     extends AbstractSurefireMojo
 71  
     implements SurefireExecutionParameters
 72  
 {
 73  
 
 74  
     /**
 75  
      * Set this to 'true' to skip running tests, but still compile them. Its use is NOT RECOMMENDED, but quite
 76  
      * convenient on occasion.
 77  
      *
 78  
      * @parameter default-value="false" expression="${skipTests}"
 79  
      * @since 2.4
 80  
      */
 81  
     private boolean skipTests;
 82  
 
 83  
     /**
 84  
      * Set this to 'true' to skip running integration tests, but still compile them. Its use is NOT RECOMMENDED, but quite
 85  
      * convenient on occasion.
 86  
      *
 87  
      * @parameter expression="${skipITs}"
 88  
      * @since 2.4.3-alpha-2
 89  
      */
 90  
     private boolean skipITs;
 91  
 
 92  
     /**
 93  
      * This old parameter is just like skipTests, but bound to the old property maven.test.skip.exec.
 94  
      *
 95  
      * @parameter expression="${maven.test.skip.exec}"
 96  
      * @since 2.3
 97  
      * @deprecated Use -DskipTests instead.
 98  
      */
 99  
     private boolean skipExec;
 100  
 
 101  
     /**
 102  
      * Set this to 'true' to bypass unit tests entirely. Its use is NOT RECOMMENDED, especially if you
 103  
      * enable it using the "maven.test.skip" property, because maven.test.skip disables both running the
 104  
      * tests and compiling the tests.  Consider using the skipTests parameter instead.
 105  
      *
 106  
      * @parameter default-value="false" expression="${maven.test.skip}"
 107  
      */
 108  
     private boolean skip;
 109  
 
 110  
     /**
 111  
      * The base directory of the project being tested. This can be obtained in your unit test by
 112  
      * System.getProperty("basedir").
 113  
      *
 114  
      * @parameter default-value="${basedir}"
 115  
      */
 116  
     private File basedir;
 117  
 
 118  
     /**
 119  
      * The directory containing generated test classes of the project being tested.
 120  
      * This will be included at the beginning the test classpath.
 121  
      *
 122  
      * @parameter default-value="${project.build.testOutputDirectory}"
 123  
      */
 124  
     private File testClassesDirectory;
 125  
 
 126  
     /**
 127  
      * The directory containing generated classes of the project being tested.
 128  
      * This will be included after the test classes in the test classpath.
 129  
      *
 130  
      * @parameter default-value="${project.build.outputDirectory}"
 131  
      */
 132  
     private File classesDirectory;
 133  
 
 134  
     /**
 135  
      * The Maven Project Object
 136  
      *
 137  
      * @parameter default-value="${project}"
 138  
      * @readonly
 139  
      */
 140  
     private MavenProject project;
 141  
 
 142  
     /**
 143  
      * List of dependencies to exclude from the test classpath.
 144  
      * Each dependency string must follow the format <i>groupId:artifactId</i>.
 145  
      * For example: <i>org.acme:project-a</i>
 146  
      *
 147  
      * @parameter
 148  
      * @since 2.6
 149  
      */
 150  
     private List classpathDependencyExcludes;
 151  
 
 152  
     /**
 153  
      * A dependency scope to exclude from the test classpath
 154  
      * The scope should be one of the scopes defined by org.apache.maven.artifact.Artifact.
 155  
      * This includes the following
 156  
      * <p/>
 157  
      * <ul>
 158  
      * <li><i>compile</i> - system, provided, compile
 159  
      * <li><i>runtime</i> - compile, runtime
 160  
      * <li><i>compile+runtime</i> - system, provided, compile, runtime
 161  
      * <li><i>runtime+system</i> - system, compile, runtime
 162  
      * <li><i>test</i> - system, provided, compile, runtime, test
 163  
      * </ul>
 164  
      *
 165  
      * @parameter default-value=""
 166  
      * @since 2.6
 167  
      */
 168  
     private String classpathDependencyScopeExclude;
 169  
 
 170  
     /**
 171  
      * Additional elements to be appended to the classpath.
 172  
      *
 173  
      * @parameter
 174  
      * @since 2.4
 175  
      */
 176  
     private List additionalClasspathElements;
 177  
 
 178  
     /**
 179  
      * Base directory where all reports are written to.
 180  
      *
 181  
      * @parameter default-value="${project.build.directory}/failsafe-reports"
 182  
      */
 183  
     private File reportsDirectory;
 184  
 
 185  
     /**
 186  
      * The test source directory containing test class sources.
 187  
      *
 188  
      * @parameter default-value="${project.build.testSourceDirectory}"
 189  
      * @required
 190  
      * @since 2.2
 191  
      */
 192  
     private File testSourceDirectory;
 193  
 
 194  
     /**
 195  
      * Specify this parameter to run individual tests by file name, overriding the <code>includes/excludes</code>
 196  
      * parameters.  Each pattern you specify here will be used to create an
 197  
      * include pattern formatted like <code>**&#47;${test}.java</code>, so you can just type "-Dtest=MyTest"
 198  
      * to run a single test called "foo/MyTest.java".  This parameter will override the TestNG suiteXmlFiles
 199  
      * parameter.
 200  
      *
 201  
      * @parameter expression="${it.test}"
 202  
      */
 203  
     private String test;
 204  
 
 205  
     /**
 206  
      * List of patterns (separated by commas) used to specify the tests that should be included in testing. When not
 207  
      * specified and when the <code>test</code> parameter is not specified, the default includes will be
 208  
      * <code>**&#47;IT*.java   **&#47;*IT.java   **&#47;*ITCase.java</code>.  This parameter is ignored if
 209  
      * TestNG suiteXmlFiles are specified.
 210  
      *
 211  
      * @parameter
 212  
      */
 213  
     private List includes;
 214  
 
 215  
     /**
 216  
      * List of patterns (separated by commas) used to specify the tests that should be excluded in testing. When not
 217  
      * specified and when the <code>test</code> parameter is not specified, the default excludes will be
 218  
      * <code>**&#47;*$*</code> (which excludes all inner classes).  This parameter is ignored if
 219  
      * TestNG suiteXmlFiles are specified.
 220  
      *
 221  
      * @parameter
 222  
      */
 223  
     private List excludes;
 224  
 
 225  
     /**
 226  
      * ArtifactRepository of the localRepository. To obtain the directory of localRepository in unit tests use
 227  
      * System.setProperty( "localRepository").
 228  
      *
 229  
      * @parameter expression="${localRepository}"
 230  
      * @required
 231  
      * @readonly
 232  
      */
 233  
     private ArtifactRepository localRepository;
 234  
 
 235  
     /**
 236  
      * List of System properties to pass to the JUnit tests.
 237  
      *
 238  
      * @parameter
 239  
      * @deprecated Use systemPropertyVariables instead.
 240  
      */
 241  
     private Properties systemProperties;
 242  
 
 243  
     /**
 244  
      * List of System properties to pass to the JUnit tests.
 245  
      *
 246  
      * @parameter
 247  
      * @since 2.5
 248  
      */
 249  
     private Map systemPropertyVariables;
 250  
 
 251  
     /**
 252  
      * List of properties for configuring all TestNG related configurations. This is the new
 253  
      * preferred method of configuring TestNG.
 254  
      *
 255  
      * @parameter
 256  
      * @since 2.4
 257  
      */
 258  
     private Properties properties;
 259  
 
 260  
     /**
 261  
      * Map of of plugin artifacts.
 262  
      *
 263  
      * @parameter expression="${plugin.artifactMap}"
 264  
      * @required
 265  
      * @readonly
 266  
      */
 267  
     private Map pluginArtifactMap;
 268  
 
 269  
     /**
 270  
      * Map of of project artifacts.
 271  
      *
 272  
      * @parameter expression="${project.artifactMap}"
 273  
      * @required
 274  
      * @readonly
 275  
      */
 276  
     private Map projectArtifactMap;
 277  
 
 278  
     /**
 279  
      * The summary file to write integration test results to.
 280  
      *
 281  
      * @parameter expression="${project.build.directory}/failsafe-reports/failsafe-summary.xml"
 282  
      * @required
 283  
      */
 284  
     private File summaryFile;
 285  
 
 286  
     /**
 287  
      * Option to print summary of test suites or just print the test cases that has errors.
 288  
      *
 289  
      * @parameter expression="${failsafe.printSummary}" default-value="true"
 290  
      */
 291  
     private boolean printSummary;
 292  
 
 293  
     /**
 294  
      * Selects the formatting for the test report to be generated. Can be set as brief or plain.
 295  
      *
 296  
      * @parameter expression="${failsafe.reportFormat}" default-value="brief"
 297  
      */
 298  
     private String reportFormat;
 299  
 
 300  
     /**
 301  
      * Option to generate a file test report or just output the test report to the console.
 302  
      *
 303  
      * @parameter expression="${failsafe.useFile}" default-value="true"
 304  
      */
 305  
     private boolean useFile;
 306  
 
 307  
     /**
 308  
      * When forking, set this to true to redirect the unit test standard output to a file (found in
 309  
      * reportsDirectory/testName-output.txt).
 310  
      *
 311  
      * @parameter expression="${maven.test.redirectTestOutputToFile}" default-value="false"
 312  
      * @since 2.3
 313  
      */
 314  
     private boolean redirectTestOutputToFile;
 315  
 
 316  
     /**
 317  
      * Set this to "true" to cause a failure if there are no tests to run. Defaults to false.
 318  
      *
 319  
      * @parameter expression="${failIfNoTests}"
 320  
      * @since 2.4
 321  
      */
 322  
     private Boolean failIfNoTests;
 323  
 
 324  
     /**
 325  
      * Option to specify the forking mode. Can be "never", "once" or "always". "none" and "pertest" are also accepted
 326  
      * for backwards compatibility.
 327  
      *
 328  
      * @parameter expression="${forkMode}" default-value="once"
 329  
      * @since 2.1
 330  
      */
 331  
     private String forkMode;
 332  
 
 333  
     /**
 334  
       * Option to specify the jvm (or path to the java executable) to use with the forking options. For the default, the
 335  
       * jvm will be a new instance of the same VM as the one used to run Maven. JVM settings are not inherited from
 336  
       * MAVEN_OPTS
 337  
      *
 338  
      * @parameter expression="${jvm}"
 339  
      * @since 2.1
 340  
      */
 341  
     private String jvm;
 342  
 
 343  
     /**
 344  
      * Arbitrary JVM options to set on the command line.
 345  
      *
 346  
      * @parameter expression="${argLine}"
 347  
      * @since 2.1
 348  
      */
 349  
     private String argLine;
 350  
 
 351  
     /**
 352  
      * Attach a debugger to the forked JVM.  If set to "true", the process will suspend and
 353  
      * wait for a debugger to attach on port 5005.  If set to some other string, that
 354  
      * string will be appended to the argLine, allowing you to configure arbitrary
 355  
      * debuggability options (without overwriting the other options specified in the argLine).
 356  
      *
 357  
      * @parameter expression="${maven.failsafe.debug}"
 358  
      * @since 2.4
 359  
      */
 360  
     private String debugForkedProcess;
 361  
 
 362  
     /**
 363  
      * Kill the forked test process after a certain number of seconds.  If set to 0,
 364  
      * wait forever for the process, never timing out.
 365  
      *
 366  
      * @parameter expression="${failsafe.timeout}"
 367  
      * @since 2.4
 368  
      */
 369  
     private int forkedProcessTimeoutInSeconds;
 370  
 
 371  
     /**
 372  
      * Additional environments to set on the command line.
 373  
      *
 374  
      * @parameter
 375  
      * @since 2.1.3
 376  
      */
 377  0
     private Map environmentVariables = new HashMap();
 378  
 
 379  
     /**
 380  
      * Command line working directory.
 381  
      *
 382  
      * @parameter expression="${basedir}"
 383  
      * @since 2.1.3
 384  
      */
 385  
     private File workingDirectory;
 386  
 
 387  
     /**
 388  
      * When false it makes tests run using the standard classloader delegation instead of the default Maven isolated
 389  
      * classloader. Only used when forking (forkMode is not "none").<br/> Setting it to false helps with some problems
 390  
      * caused by conflicts between xml parsers in the classpath and the Java 5 provider parser.
 391  
      *
 392  
      * @parameter expression="${childDelegation}" default-value="false"
 393  
      * @since 2.1
 394  
      */
 395  
     private boolean childDelegation;
 396  
 
 397  
     /**
 398  
      * (TestNG only) Groups for this test. Only classes/methods/etc decorated with one of the groups specified here will be included
 399  
      * in test run, if specified.  This parameter is overridden if suiteXmlFiles are specified.
 400  
      *
 401  
      * @parameter expression="${groups}"
 402  
      * @since 2.2
 403  
      */
 404  
     private String groups;
 405  
 
 406  
     /**
 407  
      * (TestNG only) Excluded groups. Any methods/classes/etc with one of the groups specified in this list will specifically not be
 408  
      * run.  This parameter is overridden if suiteXmlFiles are specified.
 409  
      *
 410  
      * @parameter expression="${excludedGroups}"
 411  
      * @since 2.2
 412  
      */
 413  
     private String excludedGroups;
 414  
 
 415  
     /**
 416  
      * (TestNG only) List of TestNG suite xml file locations, seperated by commas. Note that suiteXmlFiles is incompatible
 417  
      * with several other parameters on this plugin, like includes/excludes.  This parameter is ignored if
 418  
      * the "test" parameter is specified (allowing you to run a single test instead of an entire suite).
 419  
      *
 420  
      * @parameter
 421  
      * @since 2.2
 422  
      */
 423  
     private File[] suiteXmlFiles;
 424  
 
 425  
     /**
 426  
      * Allows you to specify the name of the JUnit artifact. If not set, <code>junit:junit</code> will be used.
 427  
      *
 428  
      * @parameter expression="${junitArtifactName}" default-value="junit:junit"
 429  
      * @since 2.3.1
 430  
      */
 431  
     private String junitArtifactName;
 432  
 
 433  
     /**
 434  
      * Allows you to specify the name of the TestNG artifact. If not set, <code>org.testng:testng</code> will be used.
 435  
      *
 436  
      * @parameter expression="${testNGArtifactName}" default-value="org.testng:testng"
 437  
      * @since 2.3.1
 438  
      */
 439  
     private String testNGArtifactName;
 440  
 
 441  
     /**
 442  
      * (TestNG/JUnit 4.7 provider only) The attribute thread-count allows you to specify how many threads should be allocated for this execution. Only
 443  
      * makes sense to use in conjunction with parallel.
 444  
      *
 445  
      * @parameter expression="${threadCount}"
 446  
      * @since 2.2
 447  
      */
 448  
     private int threadCount;
 449  
 
 450  
     /**
 451  
      * (JUnit 4.7 provider) Indicates that threadCount is per cpu core. Defaults to true
 452  
      *
 453  
      * @parameter expression="${perCoreThreadCount}"
 454  
      * @since 2.5
 455  
      */
 456  
     private String perCoreThreadCount;
 457  
 
 458  
     /**
 459  
      * (JUnit 4.7 provider) Indicates that the thread pool will be unlimited. The parallel parameter and the actual number of classes/methods
 460  
      * will decide. Setting this to true effectively disables perCoreThreadCount and threadCount.
 461  
      *
 462  
      * @parameter expression="${useUnlimitedThreads}"
 463  
      * @since 2.5
 464  
      */
 465  
     private String useUnlimitedThreads;
 466  
 
 467  
     /**
 468  
      * (TestNG only) When you use the parallel attribute, TestNG will try to run all your test methods in separate threads, except for
 469  
      * methods that depend on each other, which will be run in the same thread in order to respect their order of
 470  
      * execution.
 471  
      * <p/>
 472  
      * (JUnit 4.7 provider) Supports values classes/methods/both to run in separate threads, as controlled by threadCount.
 473  
      *
 474  
      * @parameter expression="${parallel}"
 475  
      * @todo test how this works with forking, and console/file output parallelism
 476  
      * @since 2.2
 477  
      */
 478  
     private String parallel;
 479  
 
 480  
     /**
 481  
      * Whether to trim the stack trace in the reports to just the lines within the test, or show the full trace.
 482  
      *
 483  
      * @parameter expression="${trimStackTrace}" default-value="true"
 484  
      * @since 2.2
 485  
      */
 486  
     private boolean trimStackTrace;
 487  
 
 488  
     /**
 489  
      * Resolves the artifacts needed.
 490  
      *
 491  
      * @component
 492  
      */
 493  
     private ArtifactResolver artifactResolver;
 494  
 
 495  
     /**
 496  
      * Creates the artifact
 497  
      *
 498  
      * @component
 499  
      */
 500  
     private ArtifactFactory artifactFactory;
 501  
 
 502  
     /**
 503  
      * The plugin remote repositories declared in the POM.
 504  
      *
 505  
      * @parameter expression="${project.pluginArtifactRepositories}"
 506  
      * @since 2.2
 507  
      */
 508  
     private List remoteRepositories;
 509  
 
 510  
     /**
 511  
      * For retrieval of artifact's metadata.
 512  
      *
 513  
      * @component
 514  
      */
 515  
     private ArtifactMetadataSource metadataSource;
 516  
 
 517  
     private static final String BRIEF_REPORT_FORMAT = "brief";
 518  
 
 519  
     private static final String PLAIN_REPORT_FORMAT = "plain";
 520  
 
 521  
     private Properties originalSystemProperties;
 522  
 
 523  
     /**
 524  
      * systemPropertyVariables + systemProperties
 525  
      */
 526  0
     private Properties internalSystemProperties = new Properties();
 527  
 
 528  
     /**
 529  
      * Flag to disable the generation of report files in xml format.
 530  
      *
 531  
      * @parameter expression="${disableXmlReport}" default-value="false"
 532  
      * @since 2.2
 533  
      */
 534  
     private boolean disableXmlReport;
 535  
 
 536  
     /**
 537  
      * Option to pass dependencies to the system's classloader instead of using an isolated class loader when forking.
 538  
      * Prevents problems with JDKs which implement the service provider lookup mechanism by using the system's
 539  
      * classloader.  Default value is "true".
 540  
      *
 541  
      * @parameter expression="${failsafe.useSystemClassLoader}"
 542  
      * @since 2.3
 543  
      */
 544  
     private Boolean useSystemClassLoader;
 545  
 
 546  
     /**
 547  
      * By default, Surefire forks your tests using a manifest-only JAR; set this parameter
 548  
      * to "false" to force it to launch your tests with a plain old Java classpath.
 549  
      * (See http://maven.apache.org/plugins/maven-surefire-plugin/examples/class-loading.html
 550  
      * for a more detailed explanation of manifest-only JARs and their benefits.)
 551  
      * <p/>
 552  
      * Beware, setting this to "false" may cause your tests to
 553  
      * fail on Windows if your classpath is too long.
 554  
      *
 555  
      * @parameter expression="${failsafe.useManifestOnlyJar}" default-value="true"
 556  
      * @since 2.4.3
 557  
      */
 558  
     private boolean useManifestOnlyJar;
 559  
 
 560  
     /**
 561  
      * By default, Surefire enables JVM assertions for the execution of your test cases. To disable the assertions, set
 562  
      * this flag to <code>false</code>.
 563  
      *
 564  
      * @parameter expression="${enableAssertions}" default-value="true"
 565  
      * @since 2.3.1
 566  
      */
 567  
     private boolean enableAssertions;
 568  
 
 569  
     /**
 570  
      * The current build session instance.
 571  
      *
 572  
      * @parameter expression="${session}"
 573  
      * @required
 574  
      * @readonly
 575  
      */
 576  
     private MavenSession session;
 577  
 
 578  
     /**
 579  
      * (TestNG only) Define the factory class used to create all test instances
 580  
      *
 581  
      * @parameter expression="${objectFactory}"
 582  
      * @since 2.5
 583  
      */
 584  
     private String objectFactory;
 585  
 
 586  
     /**
 587  
      * The character encoding scheme to be applied.
 588  
      *
 589  
      * @parameter expression="${encoding}" default-value="${project.reporting.outputEncoding}"
 590  
      */
 591  
     private String encoding;
 592  
 
 593  
     /**
 594  
      * @parameter default-value="${session.parallel}"
 595  
      * @readonly
 596  
      */
 597  
     private Boolean parallelMavenExecution;
 598  
 
 599  
     /**
 600  
      * Defines the order the tests will be run in. Supported values are alphabetical, reversealphabetical
 601  
      * random, hourly (alphabetical on even hours, reverse alphabetical on odd hours) and filesystem.
 602  
      * <p/>
 603  
      * Not supplying a value for this setting will run tests in filesystem order.
 604  
      * <p/>
 605  
      * Odd/Even for hourly is determined at the time the of scanning the classpath, meaning it could change during
 606  
      * a multi-module build.
 607  
      *
 608  
      * @parameter
 609  
      * @since 2.7
 610  
      */
 611  
      private String runOrder;
 612  
 
 613  
     /**
 614  
      * @component
 615  
      */
 616  
     private ToolchainManager toolchainManager;
 617  
 
 618  
 
 619  
     public void execute()
 620  
         throws MojoExecutionException, MojoFailureException
 621  
     {
 622  0
         if ( verifyParameters() )
 623  
         {
 624  0
             logReportsDirectory();
 625  
 
 626  0
             final List providers = initialize();
 627  0
             String exceptionMessage = null;
 628  0
             FailsafeSummary result = new FailsafeSummary();
 629  
 
 630  0
             ForkConfiguration forkConfiguration = null;
 631  0
             for ( Iterator iter = providers.iterator(); iter.hasNext(); )
 632  
             {
 633  0
                 ProviderInfo provider = (ProviderInfo) iter.next();
 634  0
                 forkConfiguration = getForkConfiguration();
 635  0
                 ClassLoaderConfiguration classLoaderConfiguration = getClassLoaderConfiguration( forkConfiguration );
 636  0
                 ForkStarter forkStarter = createForkStarter( provider, forkConfiguration, classLoaderConfiguration );
 637  
                 try
 638  
                 {
 639  0
                     result.setResult( forkStarter.run() );
 640  
                 }
 641  0
                 catch ( SurefireBooterForkException e )
 642  
                 {
 643  0
                     if ( exceptionMessage == null )
 644  
                     {
 645  0
                         exceptionMessage = e.getMessage();
 646  
                     }
 647  
                 }
 648  0
                 catch ( SurefireExecutionException e )
 649  
                 {
 650  0
                     if ( exceptionMessage == null )
 651  
                     {
 652  0
                         exceptionMessage = e.getMessage();
 653  
                     }
 654  0
                 }
 655  0
             }
 656  
 
 657  0
             if ( exceptionMessage != null )
 658  
             {
 659  
                 // Fail no matter what as long as any provider failed
 660  0
                 result.setResult( ProviderConfiguration.TESTS_FAILED_EXIT_CODE );
 661  0
                 result.setException( exceptionMessage );
 662  
             }
 663  
 
 664  0
             if ( getOriginalSystemProperties() != null && forkConfiguration != null && !forkConfiguration.isForking() )
 665  
             {
 666  
                 // restore system properties, only makes sense when not forking..
 667  0
                 System.setProperties( getOriginalSystemProperties() );
 668  
             }
 669  
 
 670  0
             if ( !getSummaryFile().getParentFile().isDirectory() )
 671  
             {
 672  0
                 getSummaryFile().getParentFile().mkdirs();
 673  
             }
 674  
 
 675  
             try
 676  
             {
 677  
                 String encoding;
 678  0
                 if ( StringUtils.isEmpty( this.encoding ) )
 679  
                 {
 680  0
                     getLog().warn(
 681  
                         "File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING +
 682  
                             ", i.e. build is platform dependent!" );
 683  0
                     encoding = ReaderFactory.FILE_ENCODING;
 684  
                 }
 685  
                 else
 686  
                 {
 687  0
                     encoding = this.encoding;
 688  
                 }
 689  
 
 690  0
                 FileOutputStream fileOutputStream = new FileOutputStream( getSummaryFile() );
 691  0
                 BufferedOutputStream bufferedOutputStream = new BufferedOutputStream( fileOutputStream );
 692  0
                 Writer writer = new OutputStreamWriter( bufferedOutputStream, encoding );
 693  0
                 FailsafeSummaryXpp3Writer xpp3Writer = new FailsafeSummaryXpp3Writer();
 694  0
                 xpp3Writer.write( writer, result );
 695  0
                 writer.close();
 696  0
                 bufferedOutputStream.close();
 697  0
                 fileOutputStream.close();
 698  
             }
 699  0
             catch ( IOException e )
 700  
             {
 701  0
                 throw new MojoExecutionException( e.getMessage(), e );
 702  0
             }
 703  
         }
 704  0
     }
 705  
 
 706  
     protected boolean verifyParameters()
 707  
         throws MojoFailureException
 708  
     {
 709  0
         if ( isSkip() || isSkipTests() || isSkipITs() || isSkipExec() )
 710  
         {
 711  0
             getLog().info( "Tests are skipped." );
 712  0
             return false;
 713  
         }
 714  
 
 715  0
         if ( !getTestClassesDirectory().exists() )
 716  
         {
 717  0
             if ( getFailIfNoTests() != null && getFailIfNoTests().booleanValue() )
 718  
             {
 719  0
                 throw new MojoFailureException( "No tests to run!" );
 720  
             }
 721  0
             getLog().info( "No tests to run." );
 722  0
             return false;
 723  
         }
 724  
 
 725  0
         ensureWorkingDirectoryExists();
 726  
 
 727  0
         ensureParallelRunningCompatibility();
 728  
 
 729  0
         warnIfUselessUseSystemClassLoaderParameter();
 730  
 
 731  0
         return true;
 732  
     }
 733  
 
 734  
     protected String getPluginName()
 735  
     {
 736  0
         return "failsafe";
 737  
     }
 738  
 
 739  
     protected String[] getDefaultIncludes()
 740  
     {
 741  0
         return new String[]{ "**/IT*.java", "**/*IT.java", "**/*ITCase.java" };
 742  
     }
 743  
 
 744  
     public boolean isSkipTests()
 745  
     {
 746  0
         return skipTests;
 747  
     }
 748  
 
 749  
     public void setSkipTests( boolean skipTests )
 750  
     {
 751  0
         this.skipTests = skipTests;
 752  0
     }
 753  
 
 754  
     public boolean isSkipITs()
 755  
     {
 756  0
         return skipITs;
 757  
     }
 758  
 
 759  
     public void setSkipITs( boolean skipITs )
 760  
     {
 761  0
         this.skipITs = skipITs;
 762  0
     }
 763  
 
 764  
     public boolean isSkipExec()
 765  
     {
 766  0
         return skipExec;
 767  
     }
 768  
 
 769  
     public void setSkipExec( boolean skipExec )
 770  
     {
 771  0
         this.skipExec = skipExec;
 772  0
     }
 773  
 
 774  
     public boolean isSkip()
 775  
     {
 776  0
         return skip;
 777  
     }
 778  
 
 779  
     public void setSkip( boolean skip )
 780  
     {
 781  0
         this.skip = skip;
 782  0
     }
 783  
 
 784  
     public File getBasedir()
 785  
     {
 786  0
         return basedir;
 787  
     }
 788  
 
 789  
     public void setBasedir( File basedir )
 790  
     {
 791  0
         this.basedir = basedir;
 792  0
     }
 793  
 
 794  
     public File getTestClassesDirectory()
 795  
     {
 796  0
         return testClassesDirectory;
 797  
     }
 798  
 
 799  
     public void setTestClassesDirectory( File testClassesDirectory )
 800  
     {
 801  0
         this.testClassesDirectory = testClassesDirectory;
 802  0
     }
 803  
 
 804  
     public File getClassesDirectory()
 805  
     {
 806  0
         return classesDirectory;
 807  
     }
 808  
 
 809  
     public void setClassesDirectory( File classesDirectory )
 810  
     {
 811  0
         this.classesDirectory = classesDirectory;
 812  0
     }
 813  
 
 814  
     public MavenProject getProject()
 815  
     {
 816  0
         return project;
 817  
     }
 818  
 
 819  
     public void setProject( MavenProject project )
 820  
     {
 821  0
         this.project = project;
 822  0
     }
 823  
 
 824  
     public List getClasspathDependencyExcludes()
 825  
     {
 826  0
         return classpathDependencyExcludes;
 827  
     }
 828  
 
 829  
     public void setClasspathDependencyExcludes( List classpathDependencyExcludes )
 830  
     {
 831  0
         this.classpathDependencyExcludes = classpathDependencyExcludes;
 832  0
     }
 833  
 
 834  
     public String getClasspathDependencyScopeExclude()
 835  
     {
 836  0
         return classpathDependencyScopeExclude;
 837  
     }
 838  
 
 839  
     public void setClasspathDependencyScopeExclude( String classpathDependencyScopeExclude )
 840  
     {
 841  0
         this.classpathDependencyScopeExclude = classpathDependencyScopeExclude;
 842  0
     }
 843  
 
 844  
     public List getAdditionalClasspathElements()
 845  
     {
 846  0
         return additionalClasspathElements;
 847  
     }
 848  
 
 849  
     public void setAdditionalClasspathElements( List additionalClasspathElements )
 850  
     {
 851  0
         this.additionalClasspathElements = additionalClasspathElements;
 852  0
     }
 853  
 
 854  
     public File getReportsDirectory()
 855  
     {
 856  0
         return reportsDirectory;
 857  
     }
 858  
 
 859  
     public void setReportsDirectory( File reportsDirectory )
 860  
     {
 861  0
         this.reportsDirectory = reportsDirectory;
 862  0
     }
 863  
 
 864  
     public File getTestSourceDirectory()
 865  
     {
 866  0
         return testSourceDirectory;
 867  
     }
 868  
 
 869  
     public void setTestSourceDirectory( File testSourceDirectory )
 870  
     {
 871  0
         this.testSourceDirectory = testSourceDirectory;
 872  0
     }
 873  
 
 874  
     public String getTest()
 875  
     {
 876  0
         return test;
 877  
     }
 878  
 
 879  
     public void setTest( String test )
 880  
     {
 881  0
         this.test = test;
 882  0
     }
 883  
 
 884  
     public List getIncludes()
 885  
     {
 886  0
         return includes;
 887  
     }
 888  
 
 889  
     public void setIncludes( List includes )
 890  
     {
 891  0
         this.includes = includes;
 892  0
     }
 893  
 
 894  
     public List getExcludes()
 895  
     {
 896  0
         return excludes;
 897  
     }
 898  
 
 899  
     public void setExcludes( List excludes )
 900  
     {
 901  0
         this.excludes = excludes;
 902  0
     }
 903  
 
 904  
     public ArtifactRepository getLocalRepository()
 905  
     {
 906  0
         return localRepository;
 907  
     }
 908  
 
 909  
     public void setLocalRepository( ArtifactRepository localRepository )
 910  
     {
 911  0
         this.localRepository = localRepository;
 912  0
     }
 913  
 
 914  
     public Properties getSystemProperties()
 915  
     {
 916  0
         return systemProperties;
 917  
     }
 918  
 
 919  
     public void setSystemProperties( Properties systemProperties )
 920  
     {
 921  0
         this.systemProperties = systemProperties;
 922  0
     }
 923  
 
 924  
     public Map getSystemPropertyVariables()
 925  
     {
 926  0
         return systemPropertyVariables;
 927  
     }
 928  
 
 929  
     public void setSystemPropertyVariables( Map systemPropertyVariables )
 930  
     {
 931  0
         this.systemPropertyVariables = systemPropertyVariables;
 932  0
     }
 933  
 
 934  
     public Properties getProperties()
 935  
     {
 936  0
         return properties;
 937  
     }
 938  
 
 939  
     public void setProperties( Properties properties )
 940  
     {
 941  0
         this.properties = properties;
 942  0
     }
 943  
 
 944  
     public Map getPluginArtifactMap()
 945  
     {
 946  0
         return pluginArtifactMap;
 947  
     }
 948  
 
 949  
     public void setPluginArtifactMap( Map pluginArtifactMap )
 950  
     {
 951  0
         this.pluginArtifactMap = pluginArtifactMap;
 952  0
     }
 953  
 
 954  
     public Map getProjectArtifactMap()
 955  
     {
 956  0
         return projectArtifactMap;
 957  
     }
 958  
 
 959  
     public void setProjectArtifactMap( Map projectArtifactMap )
 960  
     {
 961  0
         this.projectArtifactMap = projectArtifactMap;
 962  0
     }
 963  
 
 964  
     public File getSummaryFile()
 965  
     {
 966  0
         return summaryFile;
 967  
     }
 968  
 
 969  
     public void setSummaryFile( File summaryFile )
 970  
     {
 971  0
         this.summaryFile = summaryFile;
 972  0
     }
 973  
 
 974  
     public boolean isPrintSummary()
 975  
     {
 976  0
         return printSummary;
 977  
     }
 978  
 
 979  
     public void setPrintSummary( boolean printSummary )
 980  
     {
 981  0
         this.printSummary = printSummary;
 982  0
     }
 983  
 
 984  
     public String getReportFormat()
 985  
     {
 986  0
         return reportFormat;
 987  
     }
 988  
 
 989  
     public void setReportFormat( String reportFormat )
 990  
     {
 991  0
         this.reportFormat = reportFormat;
 992  0
     }
 993  
 
 994  
     public boolean isUseFile()
 995  
     {
 996  0
         return useFile;
 997  
     }
 998  
 
 999  
     public void setUseFile( boolean useFile )
 1000  
     {
 1001  0
         this.useFile = useFile;
 1002  0
     }
 1003  
 
 1004  
     public boolean isRedirectTestOutputToFile()
 1005  
     {
 1006  0
         return redirectTestOutputToFile;
 1007  
     }
 1008  
 
 1009  
     public void setRedirectTestOutputToFile( boolean redirectTestOutputToFile )
 1010  
     {
 1011  0
         this.redirectTestOutputToFile = redirectTestOutputToFile;
 1012  0
     }
 1013  
 
 1014  
     public Boolean getFailIfNoTests()
 1015  
     {
 1016  0
         return failIfNoTests;
 1017  
     }
 1018  
 
 1019  
     public void setFailIfNoTests( Boolean failIfNoTests )
 1020  
     {
 1021  0
         this.failIfNoTests = failIfNoTests;
 1022  0
     }
 1023  
 
 1024  
     public String getForkMode()
 1025  
     {
 1026  0
         return forkMode;
 1027  
     }
 1028  
 
 1029  
     public void setForkMode( String forkMode )
 1030  
     {
 1031  0
         this.forkMode = forkMode;
 1032  0
     }
 1033  
 
 1034  
     public String getJvm()
 1035  
     {
 1036  0
         return jvm;
 1037  
     }
 1038  
 
 1039  
     public void setJvm( String jvm )
 1040  
     {
 1041  0
         this.jvm = jvm;
 1042  0
     }
 1043  
 
 1044  
     public String getArgLine()
 1045  
     {
 1046  0
         return argLine;
 1047  
     }
 1048  
 
 1049  
     public void setArgLine( String argLine )
 1050  
     {
 1051  0
         this.argLine = argLine;
 1052  0
     }
 1053  
 
 1054  
     public String getDebugForkedProcess()
 1055  
     {
 1056  0
         return debugForkedProcess;
 1057  
     }
 1058  
 
 1059  
     public void setDebugForkedProcess( String debugForkedProcess )
 1060  
     {
 1061  0
         this.debugForkedProcess = debugForkedProcess;
 1062  0
     }
 1063  
 
 1064  
     public int getForkedProcessTimeoutInSeconds()
 1065  
     {
 1066  0
         return forkedProcessTimeoutInSeconds;
 1067  
     }
 1068  
 
 1069  
     public void setForkedProcessTimeoutInSeconds( int forkedProcessTimeoutInSeconds )
 1070  
     {
 1071  0
         this.forkedProcessTimeoutInSeconds = forkedProcessTimeoutInSeconds;
 1072  0
     }
 1073  
 
 1074  
     public Map getEnvironmentVariables()
 1075  
     {
 1076  0
         return environmentVariables;
 1077  
     }
 1078  
 
 1079  
     public void setEnvironmentVariables( Map environmentVariables )
 1080  
     {
 1081  0
         this.environmentVariables = environmentVariables;
 1082  0
     }
 1083  
 
 1084  
     public File getWorkingDirectory()
 1085  
     {
 1086  0
         return workingDirectory;
 1087  
     }
 1088  
 
 1089  
     public void setWorkingDirectory( File workingDirectory )
 1090  
     {
 1091  0
         this.workingDirectory = workingDirectory;
 1092  0
     }
 1093  
 
 1094  
     public boolean isChildDelegation()
 1095  
     {
 1096  0
         return childDelegation;
 1097  
     }
 1098  
 
 1099  
     public void setChildDelegation( boolean childDelegation )
 1100  
     {
 1101  0
         this.childDelegation = childDelegation;
 1102  0
     }
 1103  
 
 1104  
     public String getGroups()
 1105  
     {
 1106  0
         return groups;
 1107  
     }
 1108  
 
 1109  
     public void setGroups( String groups )
 1110  
     {
 1111  0
         this.groups = groups;
 1112  0
     }
 1113  
 
 1114  
     public String getExcludedGroups()
 1115  
     {
 1116  0
         return excludedGroups;
 1117  
     }
 1118  
 
 1119  
     public void setExcludedGroups( String excludedGroups )
 1120  
     {
 1121  0
         this.excludedGroups = excludedGroups;
 1122  0
     }
 1123  
 
 1124  
     public File[] getSuiteXmlFiles()
 1125  
     {
 1126  0
         return suiteXmlFiles;
 1127  
     }
 1128  
 
 1129  
     public void setSuiteXmlFiles( File[] suiteXmlFiles )
 1130  
     {
 1131  0
         this.suiteXmlFiles = suiteXmlFiles;
 1132  0
     }
 1133  
 
 1134  
     public String getJunitArtifactName()
 1135  
     {
 1136  0
         return junitArtifactName;
 1137  
     }
 1138  
 
 1139  
     public void setJunitArtifactName( String junitArtifactName )
 1140  
     {
 1141  0
         this.junitArtifactName = junitArtifactName;
 1142  0
     }
 1143  
 
 1144  
     public String getTestNGArtifactName()
 1145  
     {
 1146  0
         return testNGArtifactName;
 1147  
     }
 1148  
 
 1149  
     public void setTestNGArtifactName( String testNGArtifactName )
 1150  
     {
 1151  0
         this.testNGArtifactName = testNGArtifactName;
 1152  0
     }
 1153  
 
 1154  
     public int getThreadCount()
 1155  
     {
 1156  0
         return threadCount;
 1157  
     }
 1158  
 
 1159  
     public void setThreadCount( int threadCount )
 1160  
     {
 1161  0
         this.threadCount = threadCount;
 1162  0
     }
 1163  
 
 1164  
     public String getPerCoreThreadCount()
 1165  
     {
 1166  0
         return perCoreThreadCount;
 1167  
     }
 1168  
 
 1169  
     public void setPerCoreThreadCount( String perCoreThreadCount )
 1170  
     {
 1171  0
         this.perCoreThreadCount = perCoreThreadCount;
 1172  0
     }
 1173  
 
 1174  
     public String getUseUnlimitedThreads()
 1175  
     {
 1176  0
         return useUnlimitedThreads;
 1177  
     }
 1178  
 
 1179  
     public void setUseUnlimitedThreads( String useUnlimitedThreads )
 1180  
     {
 1181  0
         this.useUnlimitedThreads = useUnlimitedThreads;
 1182  0
     }
 1183  
 
 1184  
     public String getParallel()
 1185  
     {
 1186  0
         return parallel;
 1187  
     }
 1188  
 
 1189  
     public void setParallel( String parallel )
 1190  
     {
 1191  0
         this.parallel = parallel;
 1192  0
     }
 1193  
 
 1194  
     public boolean isTrimStackTrace()
 1195  
     {
 1196  0
         return trimStackTrace;
 1197  
     }
 1198  
 
 1199  
     public void setTrimStackTrace( boolean trimStackTrace )
 1200  
     {
 1201  0
         this.trimStackTrace = trimStackTrace;
 1202  0
     }
 1203  
 
 1204  
     public ArtifactResolver getArtifactResolver()
 1205  
     {
 1206  0
         return artifactResolver;
 1207  
     }
 1208  
 
 1209  
     public void setArtifactResolver( ArtifactResolver artifactResolver )
 1210  
     {
 1211  0
         this.artifactResolver = artifactResolver;
 1212  0
     }
 1213  
 
 1214  
     public ArtifactFactory getArtifactFactory()
 1215  
     {
 1216  0
         return artifactFactory;
 1217  
     }
 1218  
 
 1219  
     public void setArtifactFactory( ArtifactFactory artifactFactory )
 1220  
     {
 1221  0
         this.artifactFactory = artifactFactory;
 1222  0
     }
 1223  
 
 1224  
     public List getRemoteRepositories()
 1225  
     {
 1226  0
         return remoteRepositories;
 1227  
     }
 1228  
 
 1229  
     public void setRemoteRepositories( List remoteRepositories )
 1230  
     {
 1231  0
         this.remoteRepositories = remoteRepositories;
 1232  0
     }
 1233  
 
 1234  
     public ArtifactMetadataSource getMetadataSource()
 1235  
     {
 1236  0
         return metadataSource;
 1237  
     }
 1238  
 
 1239  
     public void setMetadataSource( ArtifactMetadataSource metadataSource )
 1240  
     {
 1241  0
         this.metadataSource = metadataSource;
 1242  0
     }
 1243  
 
 1244  
     public Properties getOriginalSystemProperties()
 1245  
     {
 1246  0
         return originalSystemProperties;
 1247  
     }
 1248  
 
 1249  
     public void setOriginalSystemProperties( Properties originalSystemProperties )
 1250  
     {
 1251  0
         this.originalSystemProperties = originalSystemProperties;
 1252  0
     }
 1253  
 
 1254  
     public Properties getInternalSystemProperties()
 1255  
     {
 1256  0
         return internalSystemProperties;
 1257  
     }
 1258  
 
 1259  
     public void setInternalSystemProperties( Properties internalSystemProperties )
 1260  
     {
 1261  0
         this.internalSystemProperties = internalSystemProperties;
 1262  0
     }
 1263  
 
 1264  
     public boolean isDisableXmlReport()
 1265  
     {
 1266  0
         return disableXmlReport;
 1267  
     }
 1268  
 
 1269  
     public void setDisableXmlReport( boolean disableXmlReport )
 1270  
     {
 1271  0
         this.disableXmlReport = disableXmlReport;
 1272  0
     }
 1273  
 
 1274  
     public Boolean getUseSystemClassLoader()
 1275  
     {
 1276  0
         return useSystemClassLoader;
 1277  
     }
 1278  
 
 1279  
     public void setUseSystemClassLoader( Boolean useSystemClassLoader )
 1280  
     {
 1281  0
         this.useSystemClassLoader = useSystemClassLoader;
 1282  0
     }
 1283  
 
 1284  
     public boolean isUseManifestOnlyJar()
 1285  
     {
 1286  0
         return useManifestOnlyJar;
 1287  
     }
 1288  
 
 1289  
     public void setUseManifestOnlyJar( boolean useManifestOnlyJar )
 1290  
     {
 1291  0
         this.useManifestOnlyJar = useManifestOnlyJar;
 1292  0
     }
 1293  
 
 1294  
     public boolean isEnableAssertions()
 1295  
     {
 1296  0
         return enableAssertions;
 1297  
     }
 1298  
 
 1299  
     public void setEnableAssertions( boolean enableAssertions )
 1300  
     {
 1301  0
         this.enableAssertions = enableAssertions;
 1302  0
     }
 1303  
 
 1304  
     public MavenSession getSession()
 1305  
     {
 1306  0
         return session;
 1307  
     }
 1308  
 
 1309  
     public void setSession( MavenSession session )
 1310  
     {
 1311  0
         this.session = session;
 1312  0
     }
 1313  
 
 1314  
     public String getObjectFactory()
 1315  
     {
 1316  0
         return objectFactory;
 1317  
     }
 1318  
 
 1319  
     public void setObjectFactory( String objectFactory )
 1320  
     {
 1321  0
         this.objectFactory = objectFactory;
 1322  0
     }
 1323  
 
 1324  
     public ToolchainManager getToolchainManager()
 1325  
     {
 1326  0
         return toolchainManager;
 1327  
     }
 1328  
 
 1329  
     public void setToolchainManager( ToolchainManager toolchainManager )
 1330  
     {
 1331  0
         this.toolchainManager = toolchainManager;
 1332  0
     }
 1333  
 
 1334  
     // the following will be refactored out once the common code is all in one place
 1335  
 
 1336  
     public boolean isTestFailureIgnore()
 1337  
     {
 1338  0
         return true; // ignore
 1339  
     }
 1340  
 
 1341  
     public void setTestFailureIgnore( boolean testFailureIgnore )
 1342  
     {
 1343  
         // ignore
 1344  0
     }
 1345  
 
 1346  
     public boolean isMavenParallel()
 1347  
     {
 1348  0
         return parallelMavenExecution != null && parallelMavenExecution.booleanValue();
 1349  
     }
 1350  
 
 1351  
     public String getRunOrder()
 1352  
     {
 1353  0
         return runOrder;
 1354  
     }
 1355  
 
 1356  
     public void setRunOrder( String runOrder )
 1357  
     {
 1358  0
         this.runOrder = runOrder;
 1359  0
     }
 1360  
 }