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 org.apache.commons.lang3.Validate;
22 import org.apache.maven.model.Build;
23 import org.apache.maven.model.Model;
24 import org.apache.maven.model.Plugin;
25 import org.apache.maven.model.PluginExecution;
26 import org.apache.maven.model.PluginManagement;
27 import org.codehaus.plexus.util.StringUtils;
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 (StringUtils.isNotEmpty(pluginExecutionId)) {
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 Validate.notBlank(groupId, "groupId can neither be null, empty nor blank");
108 Validate.notBlank(artifactId, "artifactId can neither be null, empty nor blank");
109
110 if (model != null) {
111 Build build = model.getBuild();
112 if (build != null) {
113 for (Plugin plugin : build.getPlugins()) {
114 if (groupId.equals(plugin.getGroupId()) && artifactId.equals(plugin.getArtifactId())) {
115 return plugin;
116 }
117 }
118
119 PluginManagement mgmt = build.getPluginManagement();
120 if (mgmt != null) {
121 for (Plugin plugin : mgmt.getPlugins()) {
122 if (groupId.equals(plugin.getGroupId()) && artifactId.equals(plugin.getArtifactId())) {
123 return plugin;
124 }
125 }
126 }
127 }
128 }
129
130 return null;
131 }
132
133 public ClassLoader getClassLoader() {
134 return classLoader;
135 }
136
137 public DefaultBeanConfigurationRequest setClassLoader(ClassLoader classLoader) {
138 this.classLoader = classLoader;
139 return this;
140 }
141
142 public BeanConfigurationValuePreprocessor getValuePreprocessor() {
143 return valuePreprocessor;
144 }
145
146 public DefaultBeanConfigurationRequest setValuePreprocessor(BeanConfigurationValuePreprocessor valuePreprocessor) {
147 this.valuePreprocessor = valuePreprocessor;
148 return this;
149 }
150
151 public BeanConfigurationPathTranslator getPathTranslator() {
152 return pathTranslator;
153 }
154
155 public DefaultBeanConfigurationRequest setPathTranslator(BeanConfigurationPathTranslator pathTranslator) {
156 this.pathTranslator = pathTranslator;
157 return this;
158 }
159 }