1 package org.apache.maven.configuration;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.lang3.Validate;
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 import org.codehaus.plexus.util.StringUtils;
29
30
31
32
33
34
35 public class DefaultBeanConfigurationRequest
36 implements BeanConfigurationRequest
37 {
38
39 private Object bean;
40
41 private Object configuration;
42
43 private String configurationElement;
44
45 private ClassLoader classLoader;
46
47 private BeanConfigurationValuePreprocessor valuePreprocessor;
48
49 private BeanConfigurationPathTranslator pathTranslator;
50
51 public Object getBean()
52 {
53 return bean;
54 }
55
56 public DefaultBeanConfigurationRequest setBean( Object bean )
57 {
58 this.bean = bean;
59 return this;
60 }
61
62 public Object getConfiguration()
63 {
64 return configuration;
65 }
66
67 public String getConfigurationElement()
68 {
69 return configurationElement;
70 }
71
72 public DefaultBeanConfigurationRequest setConfiguration( Object configuration )
73 {
74 return setConfiguration( configuration, null );
75 }
76
77 public DefaultBeanConfigurationRequest setConfiguration( Object configuration, String element )
78 {
79 this.configuration = configuration;
80 this.configurationElement = element;
81 return this;
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 public DefaultBeanConfigurationRequest setConfiguration( Model model, String pluginGroupId,
98 String pluginArtifactId, String pluginExecutionId )
99 {
100 Plugin plugin = findPlugin( model, pluginGroupId, pluginArtifactId );
101 if ( plugin != null )
102 {
103 if ( StringUtils.isNotEmpty( pluginExecutionId ) )
104 {
105 for ( PluginExecution execution : plugin.getExecutions() )
106 {
107 if ( pluginExecutionId.equals( execution.getId() ) )
108 {
109 setConfiguration( execution.getConfiguration() );
110 break;
111 }
112 }
113 }
114 else
115 {
116 setConfiguration( plugin.getConfiguration() );
117 }
118 }
119 return this;
120 }
121
122 private Plugin findPlugin( Model model, String groupId, String artifactId )
123 {
124 Validate.notBlank( groupId, "groupId can neither be null, empty nor blank" );
125 Validate.notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
126
127 if ( model != null )
128 {
129 Build build = model.getBuild();
130 if ( build != null )
131 {
132 for ( Plugin plugin : build.getPlugins() )
133 {
134 if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
135 {
136 return plugin;
137 }
138 }
139
140 PluginManagement mgmt = build.getPluginManagement();
141 if ( mgmt != null )
142 {
143 for ( Plugin plugin : mgmt.getPlugins() )
144 {
145 if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
146 {
147 return plugin;
148 }
149 }
150 }
151 }
152 }
153
154 return null;
155 }
156
157 public ClassLoader getClassLoader()
158 {
159 return classLoader;
160 }
161
162 public DefaultBeanConfigurationRequest setClassLoader( ClassLoader classLoader )
163 {
164 this.classLoader = classLoader;
165 return this;
166 }
167
168 public BeanConfigurationValuePreprocessor getValuePreprocessor()
169 {
170 return valuePreprocessor;
171 }
172
173 public DefaultBeanConfigurationRequest setValuePreprocessor( BeanConfigurationValuePreprocessor valuePreprocessor )
174 {
175 this.valuePreprocessor = valuePreprocessor;
176 return this;
177 }
178
179 public BeanConfigurationPathTranslator getPathTranslator()
180 {
181 return pathTranslator;
182 }
183
184 public DefaultBeanConfigurationRequest setPathTranslator( BeanConfigurationPathTranslator pathTranslator )
185 {
186 this.pathTranslator = pathTranslator;
187 return this;
188 }
189
190 }