1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.basepom.mojo.propertyhelper.definitions;
16
17 import static com.google.common.collect.ImmutableSet.toImmutableSet;
18
19 import org.basepom.mojo.propertyhelper.FieldContext;
20 import org.basepom.mojo.propertyhelper.IgnoreWarnFail;
21 import org.basepom.mojo.propertyhelper.groups.PropertyGroup;
22
23 import java.util.Arrays;
24 import java.util.Set;
25
26 import com.google.common.annotations.VisibleForTesting;
27 import com.google.common.collect.ImmutableSet;
28
29 public class PropertyGroupDefinition {
30
31
32
33
34 String id;
35
36
37
38
39 boolean activeOnRelease = true;
40
41
42
43
44 boolean activeOnSnapshot = true;
45
46
47
48
49 private IgnoreWarnFail onDuplicateProperty = IgnoreWarnFail.FAIL;
50
51 public void setOnDuplicateProperty(String onDuplicateProperty) {
52 this.onDuplicateProperty = IgnoreWarnFail.forString(onDuplicateProperty);
53 }
54
55
56
57
58 private IgnoreWarnFail onMissingField = IgnoreWarnFail.FAIL;
59
60 public void setOnMissingField(String onMissingField) {
61 this.onMissingField = IgnoreWarnFail.forString(onMissingField);
62 }
63
64
65
66
67 Set<PropertyDefinition> propertyDefinitions = Set.of();
68
69
70 public void setProperties(PropertyDefinition... propertyDefinitions) {
71 this.propertyDefinitions = ImmutableSet.copyOf(Arrays.asList(propertyDefinitions));
72
73 this.propertyDefinitions.forEach(PropertyDefinition::check);
74 }
75
76 public PropertyGroupDefinition() {
77 }
78
79 @VisibleForTesting
80 PropertyGroupDefinition(String id) {
81 this.id = id;
82 }
83
84 public String getId() {
85 return id;
86 }
87
88 public boolean isActiveOnRelease() {
89 return activeOnRelease;
90 }
91
92 public boolean isActiveOnSnapshot() {
93 return activeOnSnapshot;
94 }
95
96 public IgnoreWarnFail getOnDuplicateProperty() {
97 return onDuplicateProperty;
98 }
99
100 public IgnoreWarnFail getOnMissingField() {
101 return onMissingField;
102 }
103
104 public Set<PropertyDefinition> getPropertyDefinitions() {
105 return propertyDefinitions;
106 }
107
108 public PropertyGroup createGroup(FieldContext context) {
109 return new PropertyGroup(this, context);
110 }
111
112 public Set<String> getPropertyNames() {
113 return propertyDefinitions.stream()
114 .map(PropertyDefinition::getName)
115 .collect(toImmutableSet());
116 }
117 }