1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.toolchain;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
25 import org.codehaus.plexus.component.configurator.ConfigurationListener;
26 import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter;
27 import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
28 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
29 import org.codehaus.plexus.configuration.PlexusConfiguration;
30
31
32
33
34
35
36
37 public class ToolchainConverter extends AbstractConfigurationConverter {
38
39
40
41
42 @Override
43 public boolean canConvert(Class type) {
44 return ToolchainsRequirement.class.isAssignableFrom(type);
45 }
46
47
48
49
50 @Override
51 public Object fromConfiguration(
52 ConverterLookup converterLookup,
53 PlexusConfiguration configuration,
54 Class type,
55 Class baseType,
56 ClassLoader classLoader,
57 ExpressionEvaluator expressionEvaluator,
58 ConfigurationListener listener)
59 throws ComponentConfigurationException {
60 ToolchainsRequirement retValue = new ToolchainsRequirement();
61
62 processConfiguration(retValue, configuration, expressionEvaluator);
63
64 return retValue;
65 }
66
67 private void processConfiguration(
68 ToolchainsRequirement requirement,
69 PlexusConfiguration configuration,
70 ExpressionEvaluator expressionEvaluator)
71 throws ComponentConfigurationException {
72 Map<String, Map<String, String>> map = new HashMap<>();
73
74 PlexusConfiguration[] tools = configuration.getChildren();
75 for (PlexusConfiguration tool : tools) {
76 String type = tool.getName();
77 PlexusConfiguration[] params = tool.getChildren();
78
79 Map<String, String> parameters = new HashMap<>();
80 for (PlexusConfiguration param : params) {
81 parameters.put(param.getName(), param.getValue());
82 }
83 map.put(type, parameters);
84 }
85
86 requirement.toolchains = map;
87 }
88 }