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