maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r604685 - in /maven/components/trunk/maven-core/src/main: aspect/org/apache/maven/CoreDebuggingAspect.aj java/org/apache/maven/execution/MavenSession.java java/org/apache/maven/plugin/DefaultPluginManager.java
Date Sun, 16 Dec 2007 20:09:44 GMT
Author: jdcasey
Date: Sun Dec 16 12:09:43 2007
New Revision: 604685

URL: http://svn.apache.org/viewvc?rev=604685&view=rev
Log:
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.

Modified:
    maven/components/trunk/maven-core/src/main/aspect/org/apache/maven/CoreDebuggingAspect.aj
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java

Modified: maven/components/trunk/maven-core/src/main/aspect/org/apache/maven/CoreDebuggingAspect.aj
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/aspect/org/apache/maven/CoreDebuggingAspect.aj?rev=604685&r1=604684&r2=604685&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/aspect/org/apache/maven/CoreDebuggingAspect.aj
(original)
+++ maven/components/trunk/maven-core/src/main/aspect/org/apache/maven/CoreDebuggingAspect.aj
Sun Dec 16 12:09:43 2007
@@ -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
@@ -12,6 +19,53 @@
 //        && args( request )
 //    {
 //        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" );
 //    }
 
 }

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java?rev=604685&r1=604684&r2=604685&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
(original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
Sun Dec 16 12:09:43 2007
@@ -30,11 +30,13 @@
 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 List getReports()
     {
+        if ( reports == null )
+        {
+            return Collections.EMPTY_LIST;
+        }
+
         return new ArrayList( reports.values() );
     }
 
@@ -230,7 +237,17 @@
      */
     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();
     }
 
 }

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=604685&r1=604684&r2=604685&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
(original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
Sun Dec 16 12:09:43 2007
@@ -265,7 +265,7 @@
 
         PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( plugin );
 
-        setDescriptorClassAndArtifactInfo( pluginDescriptor, project, session );
+        setDescriptorClassAndArtifactInfo( pluginDescriptor, project, session, new ArrayList()
);
 
         return pluginDescriptor;
     }
@@ -583,13 +583,13 @@
 
         // 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 @@
             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 @@
             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 @@
                                     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 @@
 
     private void setDescriptorClassAndArtifactInfo( PluginDescriptor pluginDescriptor,
                                                     MavenProject project,
-                                                    MavenSession session )
+                                                    MavenSession session,
+                                                    List realmActions )
     {
         MavenRealmManager realmManager = session.getRealmManager();
 
@@ -894,10 +909,12 @@
             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 );
@@ -1438,6 +1455,35 @@
                                  artifactFactory.createArtifact( "org.codehaus.plexus",
                                                                  "plexus-utils", "1.1",
                                                                  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 );
+            }
         }
     }
 }



Mime
View raw message