View Javadoc
1   package org.apache.maven.plugins.enforcer;
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.enforcer.rule.api.EnforcerRule;
23  import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
24  import org.apache.maven.plugins.annotations.LifecyclePhase;
25  import org.apache.maven.plugins.annotations.Mojo;
26  import org.apache.maven.plugins.annotations.Parameter;
27  
28  /**
29   * This goal executes the defined enforcer-recommendations once per module. In contrast to {@link EnforceMojo} it will
30   * never fail the build, i.e. it will only warn.
31   * 
32   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
33   * @author Mirko Friedenhagen
34   * @version $Id: RecommendMojo.html 937567 2015-01-24 21:47:25Z khmarbaise $
35   */
36  @Mojo( name = "recommend", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true )
37  public class RecommendMojo
38      extends AbstractEnforceMojo
39  {
40  
41      /**
42       * Array of objects that implement the EnforcerRule interface to execute.
43       */
44      @Parameter( required = true )
45      private EnforcerRule[] recommendations;
46  
47      /**
48       * @return the recommendedRules
49       */
50      @Override
51      public EnforcerRule[] getRules()
52      {
53          return this.recommendations;
54      }
55  
56      /**
57       * @param theRules the recommendedRules to set
58       */
59      @Override
60      public void setRules( EnforcerRule[] theRules )
61      {
62          this.recommendations = theRules;
63      }
64  
65      /**
66       * @param theFailFast the failFast to set
67       */
68      @Override
69      public void setFailFast( boolean theFailFast )
70      {
71          // intentionally blank
72      }
73  
74      /**
75       * Always return false, as this Mojo should never fail the build.
76       * 
77       * @return false
78       */
79      @Override
80      public boolean isFail()
81      {
82          return false;
83      }
84  
85      /**
86       * Always return false, as this Mojo should never fail the build.
87       * 
88       * @return false
89       */
90      @Override
91      public boolean isFailFast()
92      {
93          return false;
94      }
95  
96      @Override
97      protected String createRuleMessage( int i, String currentRule, EnforcerRuleException e )
98      {
99          return "Recommendation " + i + ": " + currentRule + " failed with message:\n" + e.getMessage();
100     }
101 }