jvanzyl     2002/07/14 11:01:38

  Modified:    src/java/org/apache/maven/app PluginManager.java
  Log:
  o We must unpack all the plugin jars, then re-read the directory so that
    we can then pickup new plugins without invoking maven twice.
  
  Revision  Changes    Path
  1.10      +52 -14    
jakarta-turbine-maven/src/java/org/apache/maven/app/PluginManager.java
  
  Index: PluginManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/app/PluginManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PluginManager.java        14 Jul 2002 15:58:42 -0000      1.9
  +++ PluginManager.java        14 Jul 2002 18:01:38 -0000      1.10
  @@ -63,9 +63,12 @@
   import java.net.URLClassLoader;
   
   import java.util.Enumeration;
  +import java.util.Iterator;
   import java.util.Properties;
   
   import org.apache.commons.jelly.JellyContext;
  +import org.apache.commons.jelly.expression.CompositeExpression;
  +
   import org.apache.commons.jelly.XMLOutput;
   import org.apache.commons.jelly.expression.Expression;
   import org.apache.commons.jelly.expression.CompositeExpression;
  @@ -78,6 +81,10 @@
   
   import com.werken.forehead.Forehead;
   
  +import org.apache.maven.MavenUtils;
  +import org.apache.maven.project.Dependency;
  +import org.apache.maven.project.Project;
  +
   /**
    * Plugin manager for Maven. <p>
    *
  @@ -91,22 +98,22 @@
       /**
        * Plug-in main script name.
        */
  -    public static final String PLUGIN_SCRIPT_NAME = "plugin.jelly";
  +    public final static String PLUGIN_SCRIPT_NAME = "plugin.jelly";
   
       /**
        * Plug-in default properties name.
        */
  -    public static final String PLUGIN_PROPERTIES_NAME = "plugin.properties";
  +    public final static String PLUGIN_PROPERTIES_NAME = "plugin.properties";
   
       /**
        * Plug-in descriptor.
        */
  -    public static final String PLUGIN_DESCRIPTOR = "plugin.xml";
  +    public final static String PLUGIN_DESCRIPTOR = "plugin.xml";
   
       /**
        * Log.
        */
  -    private static final Log log = LogFactory.getLog(Maven.class);
  +    private final static Log log = LogFactory.getLog(Maven.class);
   
       /**
        * ${maven.home}/bin/plugins directory.
  @@ -150,18 +157,23 @@
           // First we expand any JARs that contain plugins.
           for (int i = 0; i < files.length; ++i)
           {
  -            if (files[i].getName().endsWith(".jar"))
  +            if (files[i].getName().endsWith("plugin.jar"))
               {
                   Expand unzipper = new Expand();
                   unzipper.setSrc(files[i]);
                   String directory = files[i].getName();
  -                directory = directory.substring(0, directory.indexOf(".jar"));
  +                directory = directory.substring(0, 
directory.indexOf("plugin.jar")-1);
                   File unzipDir = new File(getPluginsDir(), directory);
                   unzipper.setDest(unzipDir);
                   unzipper.execute();
               }
           }
  -    
  +        
  +        // We need to get the directory listing again so that we
  +        // can process plugins that were just unpacked by the
  +        // above process.
  +        files = pluginsDir.listFiles();
  +
           // Process each of the directorties.
           for (int i = 0; i < files.length; ++i)
           {
  @@ -203,8 +215,7 @@
   
           ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
   
  -        ClassLoader cl = new URLClassLoader(new URL[]{
  -            getPluginDir(name).toURL()},
  +        ClassLoader cl = new URLClassLoader(new URL[]{getPluginDir(name).toURL()},
               getAntProject().getClass().getClassLoader());
   
           // Thread.currentThread().setContextClassLoader(cl);
  @@ -212,21 +223,48 @@
           log.debug("plugin: " + name + " -> " + getPluginDir(name));
           
           // Let the classloader know where the classes provided by
  -        // the plugin live.
  -        Forehead.getInstance().getClassLoader("root.maven")
  -            .addURL(getPluginDir(name).toURL());
  +        // the plugin live. We could probably make a classes dir
  +        // or actually put the classes in a JAR.
  +        // The jar will be package up so that inside the plugin jar there
  +        // will be a jar named <name>.jar so that might be, say,
  +        // jxr-1.0.jar which contains java classes for the plugin.
  +        File pluginJar = new File(getPluginDir(name), name + ".jar");
  +        
  +        if (pluginJar.exists())
  +        {
  +            log.debug("Adding " + pluginJar + " to root.maven");
  +            
Forehead.getInstance().getClassLoader("root.maven").addURL(pluginJar.toURL());
  +        }            
           
           // Now for each plugin we have to let the classloader know about
           // the JARs that this plugin needs.
  +        File p  = new File(getPluginDir(name),name);
           
  +        // Most plugins aren't real plugins yet.
  +        if (p.exists())
  +        {
  +        
  +        Project pluginProject = MavenUtils.getProject(p);
           
  +        for (Iterator i = pluginProject.getDependencies().iterator(); i.hasNext();)
  +        {
  +            Dependency d = (Dependency) i.next();
  +            String classloader = d.getMetaEntry("classloader");            
  +            // Retrieve the dependency if necessary
  +            
  +            // Add the dependency to the specified classloader
  +            // if it isn't present already.
  +        }
  +
  +        }            
  +
  +
           // For each plugin we create a new MavenJellyContext so that we
           // can push in commonly named elements like ${plugin.dir} without
           // the elements clobbering one another. Make sure to set inheritence
           // to true so that the outter context has access to variables and
           // taglibs set in the parent.
  -        MavenJellyContext pluginJellyContext = new MavenJellyContext(
  -            getJellyContext());
  +        MavenJellyContext pluginJellyContext = new 
MavenJellyContext(getJellyContext());
           pluginJellyContext.setInherit(true);
           pluginJellyContext.setVariable("plugin.dir", getPluginDir(name));
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to