[MNG-3012] Adding an import for Xpp3Dom from plexus-utils in maven-core to plugin realms, to prevent ClassCastException when they call plugin.getConfiguration() from maven-model objects.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@543187 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-05-31 17:28:23 +00:00
parent 4c175033e8
commit dc2f469a10
1 changed files with 78 additions and 31 deletions

View File

@ -66,6 +66,7 @@ import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.ComponentConfigurator;
import org.codehaus.plexus.component.configurator.ConfigurationListener;
@ -272,7 +273,7 @@ public class DefaultPluginManager
String version = plugin.getVersion();
if ( groupId == null || artifactId == null || version == null )
if ( ( groupId == null ) || ( artifactId == null ) || ( version == null ) )
{
throw new PluginNotFoundException( e );
}
@ -308,7 +309,7 @@ public class DefaultPluginManager
MavenProject project =
mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository, false );
// if we don't have the required Maven version, then ignore an update
if ( project.getPrerequisites() != null && project.getPrerequisites().getMaven() != null )
if ( ( project.getPrerequisites() != null ) && ( project.getPrerequisites().getMaven() != null ) )
{
DefaultArtifactVersion requiredVersion =
new DefaultArtifactVersion( project.getPrerequisites().getMaven() );
@ -383,10 +384,26 @@ public class DefaultPluginManager
// POM), we need to undo this somehow.
ClassRealm pluginRealm = container.getComponentRealm( projectPlugin.getKey() );
if ( pluginRealm != null && pluginRealm != container.getContainerRealm() )
getLogger().debug( "Realm for " + projectPlugin.getKey() + " is: " + pluginRealm );
if ( ( pluginRealm != null ) && ( pluginRealm != container.getContainerRealm() ) )
{
getLogger().debug( "Realm already exists for: " + projectPlugin.getKey() + ". Skipping addition..." );
// we've already discovered this plugin, and configured it, so skip it this time.
// StringBuffer debugMessage = new StringBuffer();
// debugMessage.append( "Realm for plugin: " ).append( projectPlugin.getKey() );
// debugMessage.append( " with classpath:\n" ).append( String.valueOf( Arrays.asList( pluginRealm.getURLs() ) ).replace( ',', '\n' ) );
// debugMessage.append( "\nClass realm is: " )
// .append( pluginRealm.getId() )
// .append( " with parent: " )
// .append( pluginRealm.getParentRealm().getId() );
// debugMessage.append( "\nParent classpath:\n" )
// .append(
// String.valueOf( Arrays.asList( pluginRealm.getParentRealm().getURLs() ) )
// .replace( ',', '\n' ) );
// getLogger().debug( debugMessage.toString() );
return;
}
@ -412,11 +429,33 @@ public class DefaultPluginManager
// Now here we need the artifact coreArtifactFilter stuff
componentRealm = container.createComponentRealm( projectPlugin.getKey(), jars );
// adding for MNG-3012 to try to work around problems with Xpp3Dom (from plexus-utils)
// spawning a ClassCastException when a mojo calls plugin.getConfiguration() from maven-model...
getLogger().info( "\n\n\n\n***** Adding import for " + Xpp3Dom.class.getName() + "\nPlugin: " + projectPlugin.getKey() + " *****\n\n\n\n" );
componentRealm.importFrom( componentRealm.getParentRealm().getId(), Xpp3Dom.class.getName() );
// StringBuffer debugMessage = new StringBuffer();
// debugMessage.append( "Creating realm for plugin: " ).append( projectPlugin.getKey() );
// debugMessage.append( " with classpath:\n" ).append( String.valueOf( jars ).replace( ',', '\n' ) );
// debugMessage.append( "\nClass realm is: " )
// .append( componentRealm.getId() )
// .append( " with parent: " )
// .append( componentRealm.getParentRealm().getId() );
// debugMessage.append( "\nParent classpath:\n" )
// .append(
// String.valueOf( Arrays.asList( componentRealm.getParentRealm().getURLs() ) )
// .replace( ',', '\n' ) );
// getLogger().debug( debugMessage.toString() );
}
catch ( PlexusContainerException e )
{
throw new PluginManagerException( "Failed to create realm for plugin '" + projectPlugin + ".", e );
}
catch ( NoSuchRealmException e )
{
throw new PluginManagerException( "Failed to import Xpp3Dom from parent realm for plugin: '" + projectPlugin + ".", e );
}
// ----------------------------------------------------------------------------
// The PluginCollector will now know about the plugin we are trying to load
@ -605,7 +644,7 @@ public class DefaultPluginManager
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
Xpp3Dom dom = (Xpp3Dom) mojoExecution.getConfiguration();
Xpp3Dom dom = mojoExecution.getConfiguration();
if ( dom != null )
{
// make a defensive copy, to keep things from getting polluted.
@ -759,9 +798,13 @@ public class DefaultPluginManager
plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint(), realm );
if ( plugin != null )
{
getLogger().debug( "Looked up - " + plugin + " - " + plugin.getClass().getClassLoader() );
else// not needed i guess.
}
else
{
getLogger().warn("No luck.");
}
container.setLookupRealm( oldRealm );
}
@ -772,9 +815,13 @@ public class DefaultPluginManager
plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() );
if ( plugin != null )
{
getLogger().info( "Looked up - " + plugin + " - " + plugin.getClass().getClassLoader() );
else// not needed i guess.
}
else
{
getLogger().warn("No luck.");
}
}
@ -922,7 +969,7 @@ public class DefaultPluginManager
}
}
if ( fieldValue == null && StringUtils.isNotEmpty( parameter.getAlias() ) )
if ( ( fieldValue == null ) && StringUtils.isNotEmpty( parameter.getAlias() ) )
{
value = configuration.getChild( parameter.getAlias(), false );
if ( value != null )
@ -942,7 +989,7 @@ public class DefaultPluginManager
}
// only mark as invalid if there are no child nodes
if ( fieldValue == null && ( value == null || value.getChildCount() == 0 ) )
if ( ( fieldValue == null ) && ( ( value == null ) || ( value.getChildCount() == 0 ) ) )
{
parameter.setExpression( expression );
invalidParameters.add( parameter );
@ -976,7 +1023,7 @@ public class DefaultPluginManager
PlexusConfiguration value = pomConfiguration.getChild( key, false );
if ( value == null && StringUtils.isNotEmpty( parameter.getAlias() ) )
if ( ( value == null ) && StringUtils.isNotEmpty( parameter.getAlias() ) )
{
key = parameter.getAlias();
value = pomConfiguration.getChild( key, false );
@ -1050,20 +1097,20 @@ public class DefaultPluginManager
{
pomConfig = buildTopDownMergedConfiguration( pomConfig, mojoConfig );
if ( StringUtils.isNotEmpty( pomConfig.getValue( null ) ) || pomConfig.getChildCount() > 0 )
if ( StringUtils.isNotEmpty( pomConfig.getValue( null ) ) || ( pomConfig.getChildCount() > 0 ) )
{
toAdd = pomConfig;
}
}
if ( toAdd == null && mojoConfig != null )
if ( ( toAdd == null ) && ( mojoConfig != null ) )
{
toAdd = copyConfiguration( mojoConfig );
}
if ( toAdd != null )
{
if ( implementation != null && toAdd.getAttribute( "implementation", null ) == null )
if ( ( implementation != null ) && ( toAdd.getAttribute( "implementation", null ) == null ) )
{
XmlPlexusConfiguration implementationConf = new XmlPlexusConfiguration( paramName );
@ -1087,7 +1134,7 @@ public class DefaultPluginManager
String value = dominant.getValue( null );
if ( StringUtils.isEmpty( value ) && recessive != null )
if ( StringUtils.isEmpty( value ) && ( recessive != null ) )
{
value = recessive.getValue( null );
}