1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.configuration;
20
21 import java.util.Objects;
22
23 import org.apache.maven.model.Build;
24 import org.apache.maven.model.Model;
25 import org.apache.maven.model.Plugin;
26 import org.apache.maven.model.PluginExecution;
27 import org.apache.maven.model.PluginManagement;
28
29
30
31
32
33
34 public class DefaultBeanConfigurationRequest implements BeanConfigurationRequest {
35
36 private Object bean;
37
38 private Object configuration;
39
40 private String configurationElement;
41
42 private ClassLoader classLoader;
43
44 private BeanConfigurationValuePreprocessor valuePreprocessor;
45
46 private BeanConfigurationPathTranslator pathTranslator;
47
48 public Object getBean() {
49 return bean;
50 }
51
52 public DefaultBeanConfigurationRequest setBean(Object bean) {
53 this.bean = bean;
54 return this;
55 }
56
57 public Object getConfiguration() {
58 return configuration;
59 }
60
61 public String getConfigurationElement() {
62 return configurationElement;
63 }
64
65 public DefaultBeanConfigurationRequest setConfiguration(Object configuration) {
66 return setConfiguration(configuration, null);
67 }
68
69 public DefaultBeanConfigurationRequest setConfiguration(Object configuration, String element) {
70 this.configuration = configuration;
71 this.configurationElement = element;
72 return this;
73 }
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 public DefaultBeanConfigurationRequest setConfiguration(
89 Model model, String pluginGroupId, String pluginArtifactId, String pluginExecutionId) {
90 Plugin plugin = findPlugin(model, pluginGroupId, pluginArtifactId);
91 if (plugin != null) {
92 if (pluginExecutionId != null && !pluginExecutionId.isEmpty()) {
93 for (PluginExecution execution : plugin.getExecutions()) {
94 if (pluginExecutionId.equals(execution.getId())) {
95 setConfiguration(execution.getConfiguration());
96 break;
97 }
98 }
99 } else {
100 setConfiguration(plugin.getConfiguration());
101 }
102 }
103 return this;
104 }
105
106 private Plugin findPlugin(Model model, String groupId, String artifactId) {
107 if (Objects.requireNonNull(groupId, "groupId cannot be null").isEmpty()) {
108 throw new IllegalArgumentException("groupId cannot be empty");
109 }
110 if (Objects.requireNonNull(artifactId, "artifactId cannot be null").isEmpty()) {
111 throw new IllegalArgumentException("artifactId cannot be empty");
112 }
113
114 if (model != null) {
115 Build build = model.getBuild();
116 if (build != null) {
117 for (Plugin plugin : build.getPlugins()) {
118 if (groupId.equals(plugin.getGroupId()) && artifactId.equals(plugin.getArtifactId())) {
119 return plugin;
120 }
121 }
122
123 PluginManagement mgmt = build.getPluginManagement();
124 if (mgmt != null) {
125 for (Plugin plugin : mgmt.getPlugins()) {
126 if (groupId.equals(plugin.getGroupId()) && artifactId.equals(plugin.getArtifactId())) {
127 return plugin;
128 }
129 }
130 }
131 }
132 }
133
134 return null;
135 }
136
137 public ClassLoader getClassLoader() {
138 return classLoader;
139 }
140
141 public DefaultBeanConfigurationRequest setClassLoader(ClassLoader classLoader) {
142 this.classLoader = classLoader;
143 return this;
144 }
145
146 public BeanConfigurationValuePreprocessor getValuePreprocessor() {
147 return valuePreprocessor;
148 }
149
150 public DefaultBeanConfigurationRequest setValuePreprocessor(BeanConfigurationValuePreprocessor valuePreprocessor) {
151 this.valuePreprocessor = valuePreprocessor;
152 return this;
153 }
154
155 public BeanConfigurationPathTranslator getPathTranslator() {
156 return pathTranslator;
157 }
158
159 public DefaultBeanConfigurationRequest setPathTranslator(BeanConfigurationPathTranslator pathTranslator) {
160 this.pathTranslator = pathTranslator;
161 return this;
162 }
163 }