1 package org.apache.maven.enforcer.rule.api; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.util.List; 23 import java.util.Map; 24 import java.util.function.Supplier; 25 26 import javax.annotation.Nonnull; 27 28 import org.apache.maven.plugin.logging.Log; 29 import org.codehaus.plexus.PlexusContainer; 30 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; 31 import org.codehaus.plexus.component.repository.exception.ComponentLookupException; 32 33 34 /** 35 * This is the interface that all helpers will use. This 36 * provides access to the log, session and components to the 37 * rules. 38 * 39 * @author <a href="mailto:brianf@apache.org">Brian Fox</a> 40 */ 41 public interface EnforcerRuleHelper 42 extends ExpressionEvaluator 43 { 44 45 /** 46 * Gets the log. 47 * 48 * @return the log 49 */ 50 @Nonnull 51 Log getLog (); 52 53 /** 54 * Gets the component. 55 * 56 * @param clazz the clazz 57 * 58 * @return the component 59 * 60 * @throws ComponentLookupException the component lookup exception 61 */ 62 @Nonnull 63 <T> T getComponent ( Class<T> clazz ) 64 throws ComponentLookupException; 65 66 /** 67 * Gets the component. 68 * 69 * @param componentKey the component key 70 * 71 * @return the component 72 * 73 * @throws ComponentLookupException the component lookup exception 74 */ 75 @Nonnull 76 Object getComponent ( String componentKey ) 77 throws ComponentLookupException; 78 79 /** 80 * Gets the component. 81 * 82 * @param role the role 83 * @param roleHint the role hint 84 * 85 * @return the component 86 * 87 * @throws ComponentLookupException the component lookup exception 88 */ 89 Object getComponent ( String role, String roleHint ) 90 throws ComponentLookupException; 91 92 /** 93 * Gets the component. 94 * 95 * @param clazz the clazz 96 * @param roleHint the role hint 97 * 98 * @return the component 99 * 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 }