View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.invoker;
20  
21  import org.apache.maven.plugin.MojoFailureException;
22  import org.apache.maven.plugins.annotations.LifecyclePhase;
23  import org.apache.maven.plugins.annotations.Mojo;
24  import org.apache.maven.plugins.annotations.Parameter;
25  import org.apache.maven.plugins.annotations.ResolutionScope;
26  
27  /**
28   * Searches for integration test Maven projects, and executes each, collecting a log in the project directory, and
29   * outputting the results to the command line.
30   *
31   * @since 1.0
32   * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
33   * @author <a href="mailto:jdcasey@apache.org">John Casey</a>
34   */
35  // CHECKSTYLE_OFF: LineLength
36  @Mojo(
37          name = "run",
38          defaultPhase = LifecyclePhase.INTEGRATION_TEST,
39          requiresDependencyResolution = ResolutionScope.TEST,
40          threadSafe = true)
41  // CHECKSTYLE_ON: LineLength
42  public class InvokerMojo extends AbstractInvokerMojo {
43  
44      /**
45       * A flag controlling whether failures of the sub builds should fail the main build, too. If set to
46       * <code>true</code>, the main build will proceed even if one or more sub builds failed.
47       *
48       * @since 1.3
49       */
50      @Parameter(property = "maven.test.failure.ignore", defaultValue = "false")
51      private boolean ignoreFailures;
52  
53      /**
54       * Set this to <code>true</code> to cause a failure if there are no projects to invoke.
55       *
56       * @since 1.9
57       */
58      @Parameter(property = "invoker.failIfNoProjects")
59      private Boolean failIfNoProjects;
60  
61      /**
62       * Set to <code>true</code> to output build.log to mojo log in case of failed jobs.
63       *
64       * @since 3.2.2
65       */
66      @Parameter(property = "invoker.streamLogsOnFailures", defaultValue = "false")
67      private boolean streamLogsOnFailures;
68  
69      void processResults(InvokerSession invokerSession) throws MojoFailureException {
70          if (streamLogsOnFailures) {
71              invokerSession.logFailedBuildLog(getLog(), ignoreFailures);
72          }
73  
74          if (!suppressSummaries) {
75              invokerSession.logSummary(getLog(), ignoreFailures);
76          }
77  
78          invokerSession.handleFailures(getLog(), ignoreFailures);
79      }
80  
81      @Override
82      protected void doFailIfNoProjects() throws MojoFailureException {
83          if (Boolean.TRUE.equals(failIfNoProjects)) {
84              throw new MojoFailureException("No projects to invoke!");
85          }
86      }
87  }