001package org.apache.maven.plugins.enforcer;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.enforcer.rule.api.EnforcerRule;
023import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
024import org.apache.maven.plugins.annotations.LifecyclePhase;
025import org.apache.maven.plugins.annotations.Mojo;
026import org.apache.maven.plugins.annotations.Parameter;
027
028/**
029 * This goal executes the defined enforcer-recommendations once per module. In contrast to {@link EnforceMojo} it will
030 * never fail the build, i.e. it will only warn.
031 * 
032 * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
033 * @author Mirko Friedenhagen
034 * @version $Id: RecommendMojo.html 937567 2015-01-24 21:47:25Z khmarbaise $
035 */
036@Mojo( name = "recommend", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true )
037public class RecommendMojo
038    extends AbstractEnforceMojo
039{
040
041    /**
042     * Array of objects that implement the EnforcerRule interface to execute.
043     */
044    @Parameter( required = true )
045    private EnforcerRule[] recommendations;
046
047    /**
048     * @return the recommendedRules
049     */
050    @Override
051    public EnforcerRule[] getRules()
052    {
053        return this.recommendations;
054    }
055
056    /**
057     * @param theRules the recommendedRules to set
058     */
059    @Override
060    public void setRules( EnforcerRule[] theRules )
061    {
062        this.recommendations = theRules;
063    }
064
065    /**
066     * @param theFailFast the failFast to set
067     */
068    @Override
069    public void setFailFast( boolean theFailFast )
070    {
071        // intentionally blank
072    }
073
074    /**
075     * Always return false, as this Mojo should never fail the build.
076     * 
077     * @return false
078     */
079    @Override
080    public boolean isFail()
081    {
082        return false;
083    }
084
085    /**
086     * Always return false, as this Mojo should never fail the build.
087     * 
088     * @return false
089     */
090    @Override
091    public boolean isFailFast()
092    {
093        return false;
094    }
095
096    @Override
097    protected String createRuleMessage( int i, String currentRule, EnforcerRuleException e )
098    {
099        return "Recommendation " + i + ": " + currentRule + " failed with message:\n" + e.getMessage();
100    }
101}