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.enforcer.rule.api;
20  
21  import javax.annotation.Nonnull;
22  import javax.annotation.Nullable;
23  
24  /**
25   * Interface to be implemented by any rules executed by the enforcer.
26   *
27   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
28   * @deprecated Please see
29   *         <a href="https://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html">Writing a custom rule</a>
30   */
31  @Deprecated
32  public interface EnforcerRule extends EnforcerRuleBase {
33  
34      /**
35       * This is the interface into the rule. This method should throw an exception
36       * containing a reason message if the rule fails the check. The plugin will
37       * then decide based on the fail flag if it should stop or just log the
38       * message as a warning.
39       *
40       * @param helper The helper provides access to the log, MavenSession and has
41       *               helpers to get common components. It is also able to lookup components
42       *               by class name.
43       * @throws EnforcerRuleException the enforcer rule exception
44       */
45      void execute(@Nonnull EnforcerRuleHelper helper) throws EnforcerRuleException;
46  
47      /**
48       * This method tells the enforcer if the rule results may be cached. If the result is true,
49       * the results will be remembered for future executions in the same build (ie children). Subsequent
50       * iterations of the rule will be queried to see if they are also cacheable. This will allow the rule to be
51       * uncached further down the tree if needed.
52       *
53       * @return <code>true</code> if rule is cacheable
54       */
55      boolean isCacheable();
56  
57      /**
58       * If the rule is cacheable and the same id is found in the cache, the stored results are passed to this method to
59       * allow double checking of the results. Most of the time this can be done by generating unique ids, but sometimes
60       * the results of objects returned by the helper need to be queried. You may for example, store certain objects in
61       * your rule and then query them later.
62       *
63       * @param cachedRule the last cached instance of the rule. This is to be used by the rule to
64       *                   potentially determine if the results are still valid (ie if the configuration has been
65       *                   overridden)
66       * @return <code>true</code> if the stored results are valid for the same id.
67       */
68      boolean isResultValid(@Nonnull EnforcerRule cachedRule);
69  
70      /**
71       * If the rule is to be cached, this id is used as part of the key. This can allow rules to take parameters
72       * that allow multiple results of the same rule to be cached.
73       *
74       * @return id to be used by the enforcer to determine uniqueness of cache results. The ids only need to be unique
75       *         within a given rule implementation as the full key will be [classname]-[id]
76       */
77      @Nullable
78      String getCacheId();
79  }