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