mirror of https://github.com/apache/maven.git
Fixing issues with reports used from the site plugin, where the reports' classloaders had been disconnected from the project/core parent realms, and so couldn't use maven libraries.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@604685 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fa0cce4fdb
commit
b511c734a6
|
@ -1,7 +1,14 @@
|
|||
package org.apache.maven;
|
||||
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugin.PluginParameterExpressionEvaluator;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.apache.maven.plugin.Mojo;
|
||||
import org.apache.maven.plugin.DefaultPluginManager;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public aspect CoreDebuggingAspect
|
||||
|
@ -14,4 +21,51 @@ public aspect CoreDebuggingAspect
|
|||
// System.out.println( "Got projects-list of size " + ( projects == null ? "null" : "" + projects.size() ) + ":\n\n" + projects );
|
||||
// }
|
||||
|
||||
// private ClassRealm pluginRealm;
|
||||
//
|
||||
// after() returning( ClassRealm realm ):
|
||||
// call( ClassRealm PluginDescriptor.getClassRealm() )
|
||||
// && cflow( execution( * DefaultPluginManager.executeMojo( .. ) ) )
|
||||
// {
|
||||
// pluginRealm = realm;
|
||||
// }
|
||||
//
|
||||
// after():
|
||||
// execution( * DefaultPluginManager.executeMojo( .. ) )
|
||||
// {
|
||||
// pluginRealm = null;
|
||||
// }
|
||||
//
|
||||
// void around():
|
||||
// call( void Mojo+.execute( .. ) )
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// proceed();
|
||||
// }
|
||||
// catch( Error err )
|
||||
// {
|
||||
// System.out.println( "Plugin realm was " + pluginRealm + ":\n\n\n" );
|
||||
// pluginRealm.display();
|
||||
//
|
||||
// throw err;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// after() returning( List reports ):
|
||||
// cflow( execution( * PluginParameterExpressionEvaluator.evaluate( .. ) ) )
|
||||
// && call( List MavenSession.getReports() )
|
||||
// {
|
||||
// System.out.println( "Injecting reports for ${reports} expression.\n\n" );
|
||||
// if ( reports != null && !reports.isEmpty() )
|
||||
// {
|
||||
// for ( Iterator it = reports.iterator(); it.hasNext(); )
|
||||
// {
|
||||
// Object report = it.next();
|
||||
// System.out.println( "Report: " + report + " has classloader:\n" + report.getClass().getClassLoader() );
|
||||
// }
|
||||
// }
|
||||
// System.out.println( "\n\n" );
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -30,11 +30,13 @@ import org.codehaus.plexus.PlexusContainer;
|
|||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
|
@ -213,6 +215,11 @@ public class MavenSession
|
|||
*/
|
||||
public List getReports()
|
||||
{
|
||||
if ( reports == null )
|
||||
{
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
return new ArrayList( reports.values() );
|
||||
}
|
||||
|
||||
|
@ -230,7 +237,17 @@ public class MavenSession
|
|||
*/
|
||||
public void addReport( MojoDescriptor mojoDescriptor, MavenReport report )
|
||||
{
|
||||
reports.put( mojoDescriptor.getId(), report );
|
||||
reports.put( mojoDescriptor, report );
|
||||
}
|
||||
|
||||
public Set getReportMojoDescriptors()
|
||||
{
|
||||
if ( reports == null )
|
||||
{
|
||||
return Collections.EMPTY_SET;
|
||||
}
|
||||
|
||||
return reports.keySet();
|
||||
}
|
||||
|
||||
}
|
|
@ -265,7 +265,7 @@ public class DefaultPluginManager
|
|||
|
||||
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( plugin );
|
||||
|
||||
setDescriptorClassAndArtifactInfo( pluginDescriptor, project, session );
|
||||
setDescriptorClassAndArtifactInfo( pluginDescriptor, project, session, new ArrayList() );
|
||||
|
||||
return pluginDescriptor;
|
||||
}
|
||||
|
@ -583,13 +583,13 @@ public class DefaultPluginManager
|
|||
|
||||
// by this time, the pluginDescriptor has had the correct realm setup from getConfiguredMojo(..)
|
||||
ClassRealm pluginRealm = null;
|
||||
ClassRealm projectRealm = session.getRealmManager().getProjectRealm( project.getGroupId(), project.getArtifactId(), project.getVersion() );
|
||||
ClassRealm oldLookupRealm = container.getLookupRealm();
|
||||
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
List realmActions = new ArrayList();
|
||||
try
|
||||
{
|
||||
mojo = getConfiguredMojo( session, dom, project, false, mojoExecution );
|
||||
mojo = getConfiguredMojo( session, dom, project, false, mojoExecution, realmActions );
|
||||
|
||||
dispatcher.dispatchStart( event, goalExecId );
|
||||
|
||||
|
@ -639,10 +639,10 @@ public class DefaultPluginManager
|
|||
pluginDescriptor.setClassRealm( null );
|
||||
pluginDescriptor.setArtifacts( null );
|
||||
|
||||
if ( ( pluginRealm != null ) && ( pluginRealm != container.getContainerRealm() )
|
||||
&& ( pluginRealm != projectRealm ) )
|
||||
for ( Iterator it = realmActions.iterator(); it.hasNext(); )
|
||||
{
|
||||
pluginRealm.setParentRealm( null );
|
||||
PluginRealmAction action = (PluginRealmAction) it.next();
|
||||
action.undo();
|
||||
}
|
||||
|
||||
if ( oldLookupRealm != null )
|
||||
|
@ -680,7 +680,7 @@ public class DefaultPluginManager
|
|||
dom = Xpp3Dom.mergeXpp3Dom( dom, mojoExecution.getConfiguration() );
|
||||
}
|
||||
|
||||
return (MavenReport) getConfiguredMojo( session, dom, project, true, mojoExecution );
|
||||
return (MavenReport) getConfiguredMojo( session, dom, project, true, mojoExecution, new ArrayList() );
|
||||
}
|
||||
|
||||
public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin,
|
||||
|
@ -715,21 +715,35 @@ public class DefaultPluginManager
|
|||
Xpp3Dom dom,
|
||||
MavenProject project,
|
||||
boolean report,
|
||||
MojoExecution mojoExecution )
|
||||
MojoExecution mojoExecution,
|
||||
List realmActions )
|
||||
throws PluginConfigurationException, PluginManagerException
|
||||
{
|
||||
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
|
||||
|
||||
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
||||
|
||||
setDescriptorClassAndArtifactInfo( pluginDescriptor, project, session );
|
||||
setDescriptorClassAndArtifactInfo( pluginDescriptor, project, session, realmActions );
|
||||
|
||||
ClassRealm pluginRealm = pluginDescriptor.getClassRealm();
|
||||
|
||||
if ( mojoDescriptor.isRequiresReports() )
|
||||
{
|
||||
Set reportDescriptors = session.getReportMojoDescriptors();
|
||||
|
||||
if ( ( reportDescriptors != null ) && !reportDescriptors.isEmpty() )
|
||||
{
|
||||
for ( Iterator it = reportDescriptors.iterator(); it.hasNext(); )
|
||||
{
|
||||
MojoDescriptor reportDescriptor = (MojoDescriptor) it.next();
|
||||
setDescriptorClassAndArtifactInfo( reportDescriptor.getPluginDescriptor(), project, session, realmActions );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We are forcing the use of the plugin realm for all lookups that might occur during
|
||||
// the lifecycle that is part of the lookup. Here we are specifically trying to keep
|
||||
// lookups that occur in contextualize calls in line with the right realm.
|
||||
|
||||
container.setLookupRealm( pluginRealm );
|
||||
|
||||
getLogger().debug(
|
||||
|
@ -869,7 +883,8 @@ public class DefaultPluginManager
|
|||
|
||||
private void setDescriptorClassAndArtifactInfo( PluginDescriptor pluginDescriptor,
|
||||
MavenProject project,
|
||||
MavenSession session )
|
||||
MavenSession session,
|
||||
List realmActions )
|
||||
{
|
||||
MavenRealmManager realmManager = session.getRealmManager();
|
||||
|
||||
|
@ -894,10 +909,12 @@ public class DefaultPluginManager
|
|||
getLogger().debug( "Realm for plugin: " + pluginDescriptor.getId() + " not found. Using project realm instead." );
|
||||
|
||||
pluginRealm = projectRealm;
|
||||
realmActions.add( new PluginRealmAction( pluginDescriptor ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
pluginRealm.setParentRealm( projectRealm );
|
||||
realmActions.add( new PluginRealmAction( pluginDescriptor, pluginRealm ) );
|
||||
}
|
||||
|
||||
getLogger().debug( "Setting realm for plugin descriptor: " + pluginDescriptor.getId() + " to: " + pluginRealm );
|
||||
|
@ -1440,4 +1457,33 @@ public class DefaultPluginManager
|
|||
Artifact.SCOPE_RUNTIME, "jar" ) );
|
||||
}
|
||||
}
|
||||
|
||||
private static final class PluginRealmAction
|
||||
{
|
||||
private final PluginDescriptor pluginDescriptor;
|
||||
private final ClassRealm realmWithTransientParent;
|
||||
|
||||
PluginRealmAction( PluginDescriptor pluginDescriptor )
|
||||
{
|
||||
this.pluginDescriptor = pluginDescriptor;
|
||||
realmWithTransientParent = null;
|
||||
}
|
||||
|
||||
PluginRealmAction( PluginDescriptor pluginDescriptor, ClassRealm realmWithTransientParent )
|
||||
{
|
||||
this.pluginDescriptor = pluginDescriptor;
|
||||
this.realmWithTransientParent = realmWithTransientParent;
|
||||
}
|
||||
|
||||
void undo()
|
||||
{
|
||||
pluginDescriptor.setArtifacts( null );
|
||||
pluginDescriptor.setClassRealm( null );
|
||||
|
||||
if ( realmWithTransientParent != null )
|
||||
{
|
||||
realmWithTransientParent.setParentRealm( null );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue