001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.enforcer.rule.api;
020
021/**
022 * Entry point for custom {@code Enforcer Rule}.
023 * <p>
024 * Please see
025 * <a href="https://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html">Writing a custom rule</a>
026 *
027 * @author Slawomir Jaranowski
028 * @since 3.2.1
029 */
030public abstract class AbstractEnforcerRule extends AbstractEnforcerRuleBase {
031
032    /**
033     * Enforcer Rule execution level
034     */
035    private EnforcerLevel level = EnforcerLevel.ERROR;
036
037    /**
038     * Current Enforcer execution level
039     *
040     * @return an Enforcer execution level
041     */
042    @Override
043    public EnforcerLevel getLevel() {
044        return level;
045    }
046
047    /**
048     * If the rule is to be cached during session scope, whole executing of Maven build,
049     * this id is used as part of the key.
050     * <p>
051     * Rule of the same class and the same cache id will be executed once.
052     *
053     * @return id to be used by the Enforcer to determine uniqueness of cache results.
054     *         Return {@code null} disable cache of rule executing.
055     */
056    public String getCacheId() {
057        return null;
058    }
059
060    /**
061     * This is the interface into the rule. This method should throw an exception
062     * containing a reason message if the rule fails the check. The plugin will
063     * then decide based on the fail flag and rule level if it should stop or just log the
064     * message as a warning.
065     *
066     * @throws EnforcerRuleException the enforcer rule exception
067     * @throws EnforcerRuleError     in order to brake a build immediately
068     */
069    public abstract void execute() throws EnforcerRuleException;
070}