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  
23  import java.util.List;
24  import java.util.Map;
25  import java.util.function.Supplier;
26  
27  import org.apache.maven.plugin.logging.Log;
28  import org.codehaus.plexus.PlexusContainer;
29  import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
30  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
31  
32  /**
33   * This is the interface that all helpers will use. This
34   * provides access to the log, session and components to the
35   * rules.
36   *
37   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
38   * @deprecated Please see
39   *         <a href="https://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html">Writing a custom rule</a>
40   */
41  @Deprecated
42  public interface EnforcerRuleHelper extends ExpressionEvaluator {
43  
44      /**
45       * Gets the log.
46       *
47       * @return the log
48       */
49      @Nonnull
50      Log getLog();
51  
52      /**
53       * Gets the component.
54       *
55       * @param clazz the clazz
56       * @param <T> a class type
57       * @return the component
58       * @throws ComponentLookupException the component lookup exception
59       */
60      @Nonnull
61      <T> T getComponent(Class<T> clazz) throws ComponentLookupException;
62  
63      /**
64       * Gets the component.
65       *
66       * @param componentKey the component key
67       * @return the component
68       * @throws ComponentLookupException the component lookup exception
69       */
70      @Nonnull
71      Object getComponent(String componentKey) throws ComponentLookupException;
72  
73      /**
74       * Gets the component.
75       *
76       * @param role     the role
77       * @param roleHint the role hint
78       * @return the component
79       * @throws ComponentLookupException the component lookup exception
80       */
81      Object getComponent(String role, String roleHint) throws ComponentLookupException;
82  
83      /**
84       * Gets the component.
85       *
86       * @param clazz    the clazz
87       * @param roleHint the role hint
88       * @param <T> a class type
89       * @return the component
90       * @throws ComponentLookupException the component lookup exception
91       */
92      <T> T getComponent(Class<T> clazz, String roleHint) throws ComponentLookupException;
93  
94      /**
95       * Gets the component map.
96       *
97       * @param role the role
98       * @return the component map
99       * @throws ComponentLookupException the component lookup exception
100      */
101     Map<String, ?> getComponentMap(String role) throws ComponentLookupException;
102 
103     /**
104      * Gets the component list.
105      *
106      * @param role the role
107      * @return the component list
108      * @throws ComponentLookupException the component lookup exception
109      */
110     List<?> getComponentList(String role) throws ComponentLookupException;
111 
112     /**
113      * Gets the container.
114      *
115      * @return the container
116      */
117     PlexusContainer getContainer();
118 
119     /**
120      * Gets a cached value, or uses the provided producer to compute it.
121      *
122      * @param key      a key to identify the value stored
123      * @param producer a supplier for the value if it's not already present
124      * @return a previously-cached or freshly-computed value
125      */
126     Object getCache(String key, Supplier<?> producer);
127 }