001package org.apache.maven.enforcer.rule.api;
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 java.util.List;
023import java.util.Map;
024import java.util.function.Supplier;
025
026import javax.annotation.Nonnull;
027
028import org.apache.maven.plugin.logging.Log;
029import org.codehaus.plexus.PlexusContainer;
030import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
031import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
032
033
034/**
035 * This is the interface that all helpers will use. This
036 * provides access to the log, session and components to the
037 * rules.
038 *
039 * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
040 */
041public interface EnforcerRuleHelper
042    extends ExpressionEvaluator
043{
044
045    /**
046     * Gets the log.
047     *
048     * @return the log
049     */
050    @Nonnull
051    Log getLog ();
052
053    /**
054     * Gets the component.
055     *
056     * @param clazz the clazz
057     *
058     * @return the component
059     *
060     * @throws ComponentLookupException the component lookup exception
061     */
062    @Nonnull
063    <T> T getComponent ( Class<T> clazz )
064        throws ComponentLookupException;
065
066    /**
067     * Gets the component.
068     *
069     * @param componentKey the component key
070     *
071     * @return the component
072     *
073     * @throws ComponentLookupException the component lookup exception
074     */
075    @Nonnull
076    Object getComponent ( String componentKey )
077        throws ComponentLookupException;
078
079    /**
080     * Gets the component.
081     *
082     * @param role the role
083     * @param roleHint the role hint
084     *
085     * @return the component
086     *
087     * @throws ComponentLookupException the component lookup exception
088     */
089    Object getComponent ( String role, String roleHint )
090        throws ComponentLookupException;
091
092    /**
093     * Gets the component.
094     *
095     * @param clazz the clazz
096     * @param roleHint the role hint
097     *
098     * @return the component
099     *
100     * @throws ComponentLookupException the component lookup exception
101     */
102    <T> T getComponent ( Class<T> clazz, String roleHint )
103        throws ComponentLookupException;
104    
105    /**
106     * Gets the component map.
107     *
108     * @param role the role
109     *
110     * @return the component map
111     *
112     * @throws ComponentLookupException the component lookup exception
113     */
114    Map<String, ?> getComponentMap ( String role )
115        throws ComponentLookupException;
116
117    /**
118     * Gets the component list.
119     *
120     * @param role the role
121     *
122     * @return the component list
123     *
124     * @throws ComponentLookupException the component lookup exception
125     */
126    List<?> getComponentList ( String role )
127        throws ComponentLookupException;
128
129    /**
130     * Gets the container.
131     *
132     * @return the container
133     */
134    PlexusContainer getContainer();
135
136    /**
137     * Gets a cached value, or uses the provided producer to compute it.
138     *
139     * @param key a key to identify the value stored
140     * @param producer a supplier for the value if it's not already present
141     * @return a previously-cached or freshly-computed value
142     */
143    Object getCache( String key, Supplier<?> producer );
144}