1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.basepom.mojo.propertyhelper.macros;
16
17 import static com.google.common.base.Preconditions.checkNotNull;
18
19 import org.basepom.mojo.propertyhelper.FieldContext;
20 import org.basepom.mojo.propertyhelper.ValueProvider;
21 import org.basepom.mojo.propertyhelper.definitions.MacroDefinition;
22
23 import java.util.Objects;
24 import java.util.Optional;
25
26 import org.codehaus.plexus.component.annotations.Component;
27
28 @Component(role = MacroType.class, hint = "demo")
29 public class DemoMacro
30 implements MacroType {
31
32 @Override
33 public Optional<String> getValue(final MacroDefinition macroDefinition,
34 final ValueProvider valueProvider,
35 final FieldContext context) {
36 checkNotNull(valueProvider, "valueProvider is null");
37 checkNotNull(context, "context is null");
38
39 final String type = Objects.requireNonNullElse(macroDefinition.getProperties().get("type"), "static");
40 if ("static".equals(type)) {
41 return Optional.of("static-value");
42 } else if ("property".equals(type)) {
43 return valueProvider.getValue();
44 } else {
45 return Optional.ofNullable(macroDefinition.getProperties().get("value"));
46 }
47 }
48 }