jvanzyl 2002/07/11 22:52:16
Modified: src/java/org/apache/maven/app PluginManager.java
Log:
o Added handling to expand JARs in the plugin directory and add the
the contents of the directory to the root.maven classloader using
the forhead instance. This needs to be further refined so that
a plugin can specify which classloader a specific resources needs
to be pushed into. For example the clover plugin needs to be added
to the root classloader in order to work. Right now I have the
JXR stuff working as a plugin in a JAR.
This shouldn't affect anyone because it looks for JARs in the plugins
directory and I doubt anyone else has any ;-)
Revision Changes Path
1.7 +160 -113
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PluginManager.java 12 Jul 2002 03:48:16 -0000 1.6
+++ PluginManager.java 12 Jul 2002 05:52:16 -0000 1.7
@@ -55,7 +55,6 @@
*
* ====================================================================
*/
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -79,75 +78,110 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-/** Plugin manager for Maven.
- *
- * <p>
- * The <code>PluginManager</code> deals with all aspects of a plugins
- * lifecycle.
+import com.werken.forehead.Forehead;
+
+/**
+ * Plugin manager for Maven. <p>
+ *
+ * The <code>PluginManager</code> deals with all aspects of a plugins lifecycle.
* </p>
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
*/
public class PluginManager
{
- /** Plug-in main script name. */
- public static final String PLUGIN_SCRIPT_NAME = "plugin.jelly";
+ /**
+ * Plug-in main script name.
+ */
+ public final static String PLUGIN_SCRIPT_NAME = "plugin.jelly";
- /** Plug-in default properties name. */
- public static final String PLUGIN_PROPERTIES_NAME = "plugin.properties";
+ /**
+ * Plug-in default properties name.
+ */
+ public final static String PLUGIN_PROPERTIES_NAME = "plugin.properties";
- /** Plug-in descriptor. */
- public static final String PLUGIN_DESCRIPTOR = "plugin.xml";
+ /**
+ * Plug-in descriptor.
+ */
+ public final static String PLUGIN_DESCRIPTOR = "plugin.xml";
- /** Log. */
- private static final Log log = LogFactory.getLog(Maven.class);
-
- /** ${maven.home}/bin/plugins directory. */
+ /**
+ * Log.
+ */
+ private final static Log log = LogFactory.getLog(Maven.class);
+
+ /**
+ * ${maven.home}/bin/plugins directory.
+ */
private File pluginsDir;
- /** Jelly's output. */
+ /**
+ * Jelly's output.
+ */
private XMLOutput output;
- /** Jelly conext. */
+ /**
+ * Jelly conext.
+ */
private MavenJellyContext jellyContext;
- /** The Ant project. */
+ /**
+ * The Ant project.
+ */
private GrantProject antProject;
- /** ${maven.home}/ directory. */
+ /**
+ * ${maven.home}/ directory.
+ */
private File mavenHome;
- /** Initialize all plugins.
+ /**
+ * Initialize all plugins.
*
- * @throws Exception If an error occurs while initializing
- * any plugin.
+ * @throws Exception If an error occurs while initializing any plugin.
*/
- public void initializePlugins()
+ public void initializePlugins()
throws Exception
{
- setPluginsDir( new File( getMavenHome(), "plugins" ) );
-
- File pluginsDir = getPluginsDir();
+ setPluginsDir(new File(getMavenHome(), "plugins"));
- File[] pluginDirs = pluginsDir.listFiles();
+ File pluginsDir = getPluginsDir();
- for (int i = 0; i < pluginDirs.length; ++i)
+ File[] files = pluginsDir.listFiles();
+
+ // First we expand any JARs that contain plugins.
+ for (int i = 0; i < files.length; ++i)
{
- if (pluginDirs[i].isDirectory())
+ if (files[i].getName().endsWith(".jar"))
{
- loadPlugin(pluginDirs[i].getName());
+ Expand unzipper = new Expand();
+ unzipper.setSrc(files[i]);
+ String directory = files[i].getName();
+ directory = directory.substring(0, directory.indexOf(".jar"));
+ File unzipDir = new File(getPluginsDir(), directory);
+ unzipper.setDest(unzipDir);
+ unzipper.execute();
+ }
+ }
+
+ // Process each of the directorties.
+ for (int i = 0; i < files.length; ++i)
+ {
+ if (files[i].isDirectory())
+ {
+ loadPlugin(files[i].getName());
}
}
}
- /** Load the specified plugin.
- *
- * @param name The name of the plugin to load.
+ /**
+ * Load the specified plugin.
*
- * @throws Exception If an error occurs while initializing
- * the plugin.
+ * @param name The name of the plugin to load.
+ * @throws Exception If an error occurs while initializing the plugin.
*/
- private void loadPlugin(String name) throws Exception
+ private void loadPlugin(String name)
+ throws Exception
{
File pluginScript = getPluginScript(name);
@@ -168,93 +202,92 @@
// jelly. Don't forget to set it back to how it
// was. Leave nothing but footprints, take nothing
// but photographs.
-
+
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
ClassLoader cl = new URLClassLoader(new URL[]{getPluginDir(name).toURL()},
-
getAntProject().getClass().getClassLoader());
+ getAntProject().getClass().getClassLoader());
// Thread.currentThread().setContextClassLoader(cl);
+
+ log.debug("plugin: " + name + " -> " + getPluginDir(name));
- log.debug( "plugin: " + name + " -> " + getPluginDir( name ) );
+
Forehead.getInstance().getClassLoader("root.maven").addURL(getPluginDir(name).toURL());
// 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 ) );
-
- //System.out.println(">> " + pluginJellyContext);
- //System.out.println(">> " + getJellyContext());
-
+ pluginJellyContext.setVariable("plugin.dir", getPluginDir(name));
+
JellyUtils.runScript(pluginScript,
- getPluginDir(name).toURL(),
- pluginJellyContext,
- getXMLOutput());
+ getPluginDir(name).toURL(),
+ pluginJellyContext,
+ getXMLOutput());
// Thread.currentThread().setContextClassLoader(oldCl);
}
- /** Load the properties for the specified plugin.
+ /**
+ * Load the properties for the specified plugin.
*
- * @param name The name of the plugin to load.
- *
- * @throws IOException If an error occurs while initializing
- * the plugin's properties.
+ * @param name The name of the plugin to load.
+ * @throws IOException If an error occurs while initializing the plugin's
+ * properties.
*/
- private void loadPluginProperties(String name) throws IOException
+ private void loadPluginProperties(String name)
+ throws IOException
{
Properties props = getPluginProperties(name);
- integrateProps( props );
+ integrateProps(props);
}
- /** Retrieve the directory for the specified
- * plugin.
- *
- * @param pluginName The name of the plugin.
+ /**
+ * Retrieve the directory for the specified plugin.
*
- * @return The directory for the plugin, or
- * <code>null</code> if no such plugin.
+ * @param pluginName The name of the plugin.
+ * @return The directory for the plugin, or <code>null</code> if no such
+ * plugin.
*/
public File getPluginDir(String pluginName)
{
return new File(getPluginsDir(),
- pluginName);
+ pluginName);
}
- /** Retrieve the plugin's entry-point jelly script.
- *
- * @param pluginName The name of the plugin.
+ /**
+ * Retrieve the plugin's entry-point jelly script.
*
- * @return The entry-point script for the plugin, or
- * <code>null</code> if no such plugin.
+ * @param pluginName The name of the plugin.
+ * @return The entry-point script for the plugin, or <code>null</code> if no
+ * such plugin.
*/
public File getPluginScript(String pluginName)
{
return new File(getPluginDir(pluginName),
- PLUGIN_SCRIPT_NAME);
+ PLUGIN_SCRIPT_NAME);
}
- /** Retrieve the plugin's default properties.
+ /**
+ * Retrieve the plugin's default properties.
*
- * @param pluginName The name of the plugin.
- *
- * @return The default properties file for the plugin, or
- * <code>null</code> if no such plugin.
- *
- * @throws IOException If an IO error occurs while attempting
- * to read the plugin's properties.
+ * @param pluginName The name of the plugin.
+ * @return The default properties file for the plugin, or <code>null</code>
+ * if no such plugin.
+ * @throws IOException If an IO error occurs while attempting to read the
+ * plugin's properties.
*/
- public Properties getPluginProperties(String pluginName) throws IOException
+ public Properties getPluginProperties(String pluginName)
+ throws IOException
{
File propsFile = new File(getPluginDir(pluginName),
- PLUGIN_PROPERTIES_NAME);
+ PLUGIN_PROPERTIES_NAME);
if (!propsFile.exists())
{
@@ -264,7 +297,7 @@
Properties props = new Properties();
FileInputStream in = new FileInputStream(propsFile);
-
+
props.load(in);
in.close();
@@ -272,20 +305,23 @@
return props;
}
- private void integrateProps(Properties props)
+ /**
+ * Description of the Method
+ */
+ private void integrateProps(Properties props)
{
if (props == null)
{
return;
}
-
+
JellyContext context = getJellyContext();
Enumeration propNames = props.propertyNames();
String eachName = null;
String propText = null;
- Object propVal = null;
+ Object propVal = null;
JexlExpressionFactory factory = new JexlExpressionFactory();
@@ -300,7 +336,7 @@
try
{
Expression expr = CompositeExpression.parse(propText,
- factory);
+ factory);
if (expr != null)
{
@@ -310,9 +346,9 @@
{
propVal = propText;
}
-
+
context.setVariable(eachName,
- propVal);
+ propVal);
}
catch (Exception e)
{
@@ -321,80 +357,91 @@
}
}
}
-
- /** Set Maven home.
- *
+
+ /**
+ * Set Maven home.
*/
- public void setMavenHome( File mavenHome )
+ public void setMavenHome(File mavenHome)
{
this.mavenHome = mavenHome;
}
- /** Retrieve Maven home.
+ /**
+ * Retrieve Maven home.
*
- * @return The ant project.
+ * @return The ant project.
*/
public File getMavenHome()
{
return mavenHome;
}
- /** Set Ant project.
- *
+ /**
+ * Set Ant project.
*/
- public void setAntProject( GrantProject antProject )
+ public void setAntProject(GrantProject antProject)
{
this.antProject = antProject;
- }
+ }
- /** Retrieve the Ant project.
+ /**
+ * Retrieve the Ant project.
*
- * @return The ant project.
+ * @return The ant project.
*/
public GrantProject getAntProject()
{
return this.antProject;
}
- /** Set Jelly context.
- *
+ /**
+ * Set Jelly context.
*/
- public void setJellyContext( MavenJellyContext jellyContext )
+ public void setJellyContext(MavenJellyContext jellyContext)
{
this.jellyContext = jellyContext;
- }
+ }
- /** Retrieve the Jelly context.
+ /**
+ * Retrieve the Jelly context.
*
- * @return The Jelly context.
+ * @return The Jelly context.
*/
public MavenJellyContext getJellyContext()
{
return this.jellyContext;
}
- public void setXMLOutput( XMLOutput output )
+ /**
+ * Sets the xMLOutput attribute of the PluginManager object
+ */
+ public void setXMLOutput(XMLOutput output)
{
this.output = output;
- }
+ }
- /** Retrieve the XML execution output sink.
+ /**
+ * Retrieve the XML execution output sink.
*
- * @return The output sink.
+ * @return The output sink.
*/
public XMLOutput getXMLOutput()
{
return this.output;
}
- public void setPluginsDir( File pluginsDir )
+ /**
+ * Sets the pluginsDir attribute of the PluginManager object
+ */
+ public void setPluginsDir(File pluginsDir)
{
this.pluginsDir = pluginsDir;
- }
+ }
- /** Retrieve the directory containing all plugins.
+ /**
+ * Retrieve the directory containing all plugins.
*
- * @return The directory containing all plugins.
+ * @return The directory containing all plugins.
*/
public File getPluginsDir()
{
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>