1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
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 * Centralized class for feature information
28 *
29 * @author Robert Scholte
30 * @since 4.0.0
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 * Represents some feature
54 *
55 * @author Robert Scholte
56 * @since 4.0.0
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 }