mirror of https://github.com/apache/maven.git
MNG-4910 Use BeanConfigurator for configuration sub-elements
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1037741 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2c935ddff8
commit
38ced22fda
|
@ -52,12 +52,34 @@ public interface BeanConfigurationRequest
|
|||
/**
|
||||
* Sets the configuration to unmarshal into the bean. The configuration should be taken from
|
||||
* {@link org.apache.maven.model.ConfigurationContainer#getConfiguration()} or a similar source.
|
||||
* Fully equivalent to {@code setConfiguration(configuration, null)}.
|
||||
*
|
||||
* @param configuration The configuration to unmarshal, may be {@code null}.
|
||||
* @return This request for chaining, never {@code null}.
|
||||
*/
|
||||
BeanConfigurationRequest setConfiguration( Object configuration );
|
||||
|
||||
/**
|
||||
* Sets the configuration to unmarshal into the bean. The configuration should be taken from
|
||||
* {@link org.apache.maven.model.ConfigurationContainer#getConfiguration()} or a similar source.
|
||||
* If {@code element} is not {@code null}, child configuration element with the specified name will
|
||||
* be unmarshaled.
|
||||
*
|
||||
* @param configuration The configuration to unmarshal, may be {@code null}.
|
||||
* @param element Configuration element name to unmarshal or {@code null} to unmarshal entire configuration.
|
||||
* @return This request for chaining, never {@code null}.
|
||||
*/
|
||||
BeanConfigurationRequest setConfiguration( Object configuration, String element );
|
||||
|
||||
/**
|
||||
* Returns configuration element name or {@code null}.
|
||||
*
|
||||
* @see {@link #setConfiguration(Object, String)}
|
||||
*
|
||||
* @return Configuration element name or {@code null}
|
||||
*/
|
||||
String getConfigurationElement();
|
||||
|
||||
/**
|
||||
* Gets the class loader from which to load any types referenced by the configuration. If unset, the class loader of
|
||||
* the bean class will be used.
|
||||
|
|
|
@ -39,6 +39,8 @@ public class DefaultBeanConfigurationRequest
|
|||
|
||||
private Object configuration;
|
||||
|
||||
private String configurationElement;
|
||||
|
||||
private ClassLoader classLoader;
|
||||
|
||||
private BeanConfigurationValuePreprocessor valuePreprocessor;
|
||||
|
@ -61,9 +63,20 @@ public class DefaultBeanConfigurationRequest
|
|||
return configuration;
|
||||
}
|
||||
|
||||
public String getConfigurationElement()
|
||||
{
|
||||
return configurationElement;
|
||||
}
|
||||
|
||||
public DefaultBeanConfigurationRequest setConfiguration( Object configuration )
|
||||
{
|
||||
return setConfiguration( configuration, null );
|
||||
}
|
||||
|
||||
public DefaultBeanConfigurationRequest setConfiguration( Object configuration, String element )
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.configurationElement = element;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -84,6 +84,11 @@ public class DefaultBeanConfigurator
|
|||
+ configuration.getClass().getName() + ")" );
|
||||
}
|
||||
|
||||
if ( request.getConfigurationElement() != null )
|
||||
{
|
||||
plexusConfig = plexusConfig.getChild( request.getConfigurationElement() );
|
||||
}
|
||||
|
||||
ClassLoader classLoader = request.getClassLoader();
|
||||
if ( classLoader == null )
|
||||
{
|
||||
|
|
|
@ -123,6 +123,21 @@ public class DefaultBeanConfiguratorTest
|
|||
assertEquals( new File( "base/test" ).getAbsoluteFile(), bean.file );
|
||||
}
|
||||
|
||||
public void testChildConfigurationElement()
|
||||
throws BeanConfigurationException
|
||||
{
|
||||
SomeBean bean = new SomeBean();
|
||||
|
||||
Xpp3Dom config = toConfig( "<wrapper><file>test</file></wrapper>" );
|
||||
|
||||
DefaultBeanConfigurationRequest request = new DefaultBeanConfigurationRequest();
|
||||
request.setBean( bean ).setConfiguration( config, "wrapper" );
|
||||
|
||||
configurator.configureBean( request );
|
||||
|
||||
assertEquals( new File( "test" ), bean.file );
|
||||
}
|
||||
|
||||
static class SomeBean
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in New Issue