1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.feature;
20
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.Properties;
24 import java.util.stream.Collectors;
25
26
27
28
29
30
31
32 public final class Features {
33 private Features() {}
34
35 public static Feature buildConsumer(Properties userProperties) {
36 return buildConsumer(toMap(userProperties));
37 }
38
39 public static Feature buildConsumer(Map<String, String> userProperties) {
40 return new Feature(userProperties, "maven.experimental.buildconsumer", "true");
41 }
42
43 private static Map<String, String> toMap(Properties properties) {
44 return properties.entrySet().stream()
45 .collect(Collectors.toMap(
46 e -> String.valueOf(e.getKey()),
47 e -> String.valueOf(e.getValue()),
48 (prev, next) -> next,
49 HashMap::new));
50 }
51
52
53
54
55
56
57
58 public static class Feature {
59 private final boolean active;
60
61 private final String name;
62
63 Feature(Map<String, String> userProperties, String name, String defaultValue) {
64 this.name = name;
65 this.active = "true".equals(userProperties.getOrDefault(name, defaultValue));
66 }
67
68 public boolean isActive() {
69 return active;
70 }
71
72 public String propertyName() {
73 return name;
74 }
75 }
76 }