001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014 015package org.basepom.mojo.propertyhelper.macros; 016 017import static com.google.common.base.Preconditions.checkNotNull; 018 019import org.basepom.mojo.propertyhelper.FieldContext; 020import org.basepom.mojo.propertyhelper.ValueProvider; 021import org.basepom.mojo.propertyhelper.definitions.MacroDefinition; 022 023import java.util.Objects; 024import java.util.Optional; 025 026import org.codehaus.plexus.component.annotations.Component; 027 028@Component(role = MacroType.class, hint = "demo") 029public class DemoMacro 030 implements MacroType { 031 032 @Override 033 public Optional<String> getValue(final MacroDefinition macroDefinition, 034 final ValueProvider valueProvider, 035 final FieldContext context) { 036 checkNotNull(valueProvider, "valueProvider is null"); 037 checkNotNull(context, "context is null"); 038 039 final String type = Objects.requireNonNullElse(macroDefinition.getProperties().get("type"), "static"); 040 if ("static".equals(type)) { 041 return Optional.of("static-value"); 042 } else if ("property".equals(type)) { 043 return valueProvider.getValue(); 044 } else { 045 return Optional.ofNullable(macroDefinition.getProperties().get("value")); 046 } 047 } 048}