1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.basepom.mojo.propertyhelper.groups;
16
17 import org.basepom.mojo.propertyhelper.FieldContext;
18 import org.basepom.mojo.propertyhelper.IgnoreWarnFail;
19 import org.basepom.mojo.propertyhelper.definitions.PropertyDefinition;
20 import org.basepom.mojo.propertyhelper.definitions.PropertyGroupDefinition;
21
22 import java.util.Map;
23 import java.util.Optional;
24 import java.util.Set;
25
26 import com.google.common.collect.ImmutableSet;
27
28 public class PropertyGroup {
29
30 private final PropertyGroupDefinition propertyGroupDefinition;
31 private final FieldContext context;
32
33 public PropertyGroup(PropertyGroupDefinition propertyGroupDefinition, FieldContext context) {
34 this.propertyGroupDefinition = propertyGroupDefinition;
35 this.context = context;
36 }
37
38 public String getId() {
39 return propertyGroupDefinition.getId();
40 }
41
42 public boolean checkActive(boolean isSnapshot) {
43 return (propertyGroupDefinition.isActiveOnRelease() && !isSnapshot)
44 || (propertyGroupDefinition.isActiveOnSnapshot() && isSnapshot);
45 }
46
47 public IgnoreWarnFail getOnDuplicateProperty() {
48 return propertyGroupDefinition.getOnDuplicateProperty();
49 }
50
51 public String getPropertyValue(final PropertyDefinition propertyDefinition, final Map<String, String> propElements) {
52
53 return Optional.ofNullable(propertyDefinition.getValue())
54 .map(context.getInterpolatorFactory().interpolate(propertyDefinition.getName(), propertyGroupDefinition.getOnMissingField(), propElements))
55 .map(context.getTransformerRegistry().applyTransformers(propertyDefinition.getTransformers()))
56 .orElse("");
57 }
58
59 public Set<PropertyResult> createProperties(final Map<String, String> values) {
60 return propertyGroupDefinition.getPropertyDefinitions().stream()
61 .map(propertyDefinition -> new PropertyResult(propertyDefinition.getName(),
62 getPropertyValue(propertyDefinition, values)))
63 .collect(ImmutableSet.toImmutableSet());
64 }
65 }