@Test public void testProfile2() { System.setProperty("seedstack.profiles", "profile2"); profileProcessor.process(config); assertThat(config.get("a").get()).isEqualTo(new ValueNode("1")); assertThat(config.get("b").isPresent()).isFalse(); assertThat(config.get("c").isPresent()).isTrue(); assertThat(config.get("c.ca").get()).isEqualTo(new ValueNode("3")); assertThat(config.get("c.cb").isPresent()).isFalse(); assertThat(config.get("c.cc").isPresent()).isFalse(); System.clearProperty("seedstack.profiles"); }
@Override public void process(MapNode configuration) { Set<String> activeProfiles = activeProfiles(); Map<MapNode, List<String>> toRemove = new HashMap<>(); Map<TreeNode, Map<String, String>> moves = new HashMap<>(); configuration.walk() .filter(node -> node instanceof MapNode) .map(MapNode.class::cast) .forEach(mapNode -> mapNode.namedNodes().forEach(namedNode -> { Matcher matcher = keyWithProfilePattern.matcher(namedNode.name()); if (matcher.matches()) { if (parseProfiles(matcher.group(2)).stream().noneMatch(activeProfiles::contains)) { toRemove.computeIfAbsent(mapNode, k -> new ArrayList<>()).add(namedNode.name()); } else { moves.computeIfAbsent(mapNode, k -> new HashMap<>()) .put(matcher.group(0), matcher.group(1)); } } })); toRemove.forEach((node, list) -> list.forEach(node::remove)); for (Map.Entry<TreeNode, Map<String, String>> movesEntry : moves.entrySet()) { for (Map.Entry<String, String> moveEntry : movesEntry.getValue().entrySet()) { movesEntry.getKey().move(moveEntry.getKey(), moveEntry.getValue()); } } }
ProfileProcessor implements ConfigurationProcessor { @Override public void process(MapNode configuration) { Set<String> activeProfiles = activeProfiles(); Map<MapNode, List<String>> toRemove = new HashMap<>(); Map<TreeNode, Map<String, String>> moves = new HashMap<>(); configuration.walk() .filter(node -> node instanceof MapNode) .map(MapNode.class::cast) .forEach(mapNode -> mapNode.namedNodes().forEach(namedNode -> { Matcher matcher = keyWithProfilePattern.matcher(namedNode.name()); if (matcher.matches()) { if (parseProfiles(matcher.group(2)).stream().noneMatch(activeProfiles::contains)) { toRemove.computeIfAbsent(mapNode, k -> new ArrayList<>()).add(namedNode.name()); } else { moves.computeIfAbsent(mapNode, k -> new HashMap<>()) .put(matcher.group(0), matcher.group(1)); } } })); toRemove.forEach((node, list) -> list.forEach(node::remove)); for (Map.Entry<TreeNode, Map<String, String>> movesEntry : moves.entrySet()) { for (Map.Entry<String, String> moveEntry : movesEntry.getValue().entrySet()) { movesEntry.getKey().move(moveEntry.getKey(), moveEntry.getValue()); } } } }
ProfileProcessor implements ConfigurationProcessor { @Override public void process(MapNode configuration) { Set<String> activeProfiles = activeProfiles(); Map<MapNode, List<String>> toRemove = new HashMap<>(); Map<TreeNode, Map<String, String>> moves = new HashMap<>(); configuration.walk() .filter(node -> node instanceof MapNode) .map(MapNode.class::cast) .forEach(mapNode -> mapNode.namedNodes().forEach(namedNode -> { Matcher matcher = keyWithProfilePattern.matcher(namedNode.name()); if (matcher.matches()) { if (parseProfiles(matcher.group(2)).stream().noneMatch(activeProfiles::contains)) { toRemove.computeIfAbsent(mapNode, k -> new ArrayList<>()).add(namedNode.name()); } else { moves.computeIfAbsent(mapNode, k -> new HashMap<>()) .put(matcher.group(0), matcher.group(1)); } } })); toRemove.forEach((node, list) -> list.forEach(node::remove)); for (Map.Entry<TreeNode, Map<String, String>> movesEntry : moves.entrySet()) { for (Map.Entry<String, String> moveEntry : movesEntry.getValue().entrySet()) { movesEntry.getKey().move(moveEntry.getKey(), moveEntry.getValue()); } } }  }
ProfileProcessor implements ConfigurationProcessor { @Override public void process(MapNode configuration) { Set<String> activeProfiles = activeProfiles(); Map<MapNode, List<String>> toRemove = new HashMap<>(); Map<TreeNode, Map<String, String>> moves = new HashMap<>(); configuration.walk() .filter(node -> node instanceof MapNode) .map(MapNode.class::cast) .forEach(mapNode -> mapNode.namedNodes().forEach(namedNode -> { Matcher matcher = keyWithProfilePattern.matcher(namedNode.name()); if (matcher.matches()) { if (parseProfiles(matcher.group(2)).stream().noneMatch(activeProfiles::contains)) { toRemove.computeIfAbsent(mapNode, k -> new ArrayList<>()).add(namedNode.name()); } else { moves.computeIfAbsent(mapNode, k -> new HashMap<>()) .put(matcher.group(0), matcher.group(1)); } } })); toRemove.forEach((node, list) -> list.forEach(node::remove)); for (Map.Entry<TreeNode, Map<String, String>> movesEntry : moves.entrySet()) { for (Map.Entry<String, String> moveEntry : movesEntry.getValue().entrySet()) { movesEntry.getKey().move(moveEntry.getKey(), moveEntry.getValue()); } } }  @Override void process(MapNode configuration); }
ProfileProcessor implements ConfigurationProcessor { @Override public void process(MapNode configuration) { Set<String> activeProfiles = activeProfiles(); Map<MapNode, List<String>> toRemove = new HashMap<>(); Map<TreeNode, Map<String, String>> moves = new HashMap<>(); configuration.walk() .filter(node -> node instanceof MapNode) .map(MapNode.class::cast) .forEach(mapNode -> mapNode.namedNodes().forEach(namedNode -> { Matcher matcher = keyWithProfilePattern.matcher(namedNode.name()); if (matcher.matches()) { if (parseProfiles(matcher.group(2)).stream().noneMatch(activeProfiles::contains)) { toRemove.computeIfAbsent(mapNode, k -> new ArrayList<>()).add(namedNode.name()); } else { moves.computeIfAbsent(mapNode, k -> new HashMap<>()) .put(matcher.group(0), matcher.group(1)); } } })); toRemove.forEach((node, list) -> list.forEach(node::remove)); for (Map.Entry<TreeNode, Map<String, String>> movesEntry : moves.entrySet()) { for (Map.Entry<String, String> moveEntry : movesEntry.getValue().entrySet()) { movesEntry.getKey().move(moveEntry.getKey(), moveEntry.getValue()); } } }  @Override void process(MapNode configuration);  }