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
021import javax.annotation.Nonnull;
022
023import java.util.List;
024import java.util.Map;
025import java.util.function.Supplier;
026
027import org.apache.maven.plugin.logging.Log;
028import org.codehaus.plexus.PlexusContainer;
029import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
030import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
031
032/**
033 * This is the interface that all helpers will use. This
034 * provides access to the log, session and components to the
035 * rules.
036 *
037 * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
038 * @deprecated Please see
039 *         <a href="https://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html">Writing a custom rule</a>
040 */
041@Deprecated
042public interface EnforcerRuleHelper extends ExpressionEvaluator {
043
044    /**
045     * Gets the log.
046     *
047     * @return the log
048     */
049    @Nonnull
050    Log getLog();
051
052    /**
053     * Gets the component.
054     *
055     * @param clazz the clazz
056     * @param <T> a class type
057     * @return the component
058     * @throws ComponentLookupException the component lookup exception
059     */
060    @Nonnull
061    <T> T getComponent(Class<T> clazz) throws ComponentLookupException;
062
063    /**
064     * Gets the component.
065     *
066     * @param componentKey the component key
067     * @return the component
068     * @throws ComponentLookupException the component lookup exception
069     */
070    @Nonnull
071    Object getComponent(String componentKey) throws ComponentLookupException;
072
073    /**
074     * Gets the component.
075     *
076     * @param role     the role
077     * @param roleHint the role hint
078     * @return the component
079     * @throws ComponentLookupException the component lookup exception
080     */
081    Object getComponent(String role, String roleHint) throws ComponentLookupException;
082
083    /**
084     * Gets the component.
085     *
086     * @param clazz    the clazz
087     * @param roleHint the role hint
088     * @param <T> a class type
089     * @return the component
090     * @throws ComponentLookupException the component lookup exception
091     */
092    <T> T getComponent(Class<T> clazz, String roleHint) throws ComponentLookupException;
093
094    /**
095     * Gets the component map.
096     *
097     * @param role the role
098     * @return the component map
099     * @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}