jvanzyl 2002/07/16 19:54:12
Modified: src/java/org/apache/maven/app PluginManager.java
Log:
o Only process a plugin once. We will assume for now that new plugins
will have a different version. But we can add some timestamp goodness
if required. I'm just getting sick of watching the plugins get processed
over and over again.
Revision Changes Path
1.15 +80 -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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- PluginManager.java 16 Jul 2002 22:03:10 -0000 1.14
+++ PluginManager.java 17 Jul 2002 02:54:12 -0000 1.15
@@ -55,7 +55,9 @@
*
* ====================================================================
*/
+
import java.io.File;
+import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
@@ -63,6 +65,8 @@
import java.net.URLClassLoader;
import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Iterator;
import java.util.Properties;
@@ -117,7 +121,7 @@
/**
* Log.
*/
- private final static Log log = LogFactory.getLog(Maven.class);
+ private final static Log log = LogFactory.getLog(PluginManager.class);
/**
* ${maven.home}/bin/plugins directory.
@@ -150,6 +154,11 @@
private ProjectVerifier projectVerifier;
/**
+ * classloaders
+ */
+ private HashMap classloaders = new HashMap();
+
+ /**
* Initialize all plugins.
*
* @throws Exception If an error occurs while initializing any plugin.
@@ -166,7 +175,8 @@
// First we expand any JARs that contain plugins.
for (int i = 0; i < files.length; ++i)
{
- if (files[i].getName().endsWith(".jar"))
+ // Only unpack the JAR if it hasn't been already.
+ if (files[i].getName().endsWith(".jar") &&
!getPluginDir(files[i].getName()).exists())
{
Expand unzipper = new Expand();
unzipper.setSrc(files[i]);
@@ -194,6 +204,59 @@
}
/**
+ * Retrieve the plugin processed marker.
+ */
+ private File getPluginProcessedMarker(String pluginName)
+ {
+ return new File(new File(getPluginsDir(),pluginName), ".processed");
+ }
+
+ /**
+ * Plugin processed state.
+ */
+ private boolean isPluginProcessed(String pluginName)
+ {
+ return getPluginProcessedMarker(pluginName).exists();
+ }
+
+ /**
+ * Emulation of File.createNewFile for JDK 1.1. <p>
+ *
+ * This method does <strong>not</strong> guarantee that the operation is
+ * atomic.</p>
+ *
+ * @since 1.21, Ant 1.5
+ */
+ public boolean createNewFile(File f)
+ throws IOException
+ {
+ if (f != null)
+ {
+ if (f.exists())
+ {
+ return false;
+ }
+
+ FileOutputStream fos = null;
+ try
+ {
+ fos = new FileOutputStream(f);
+ fos.write(new byte[0]);
+ }
+ finally
+ {
+ if (fos != null)
+ {
+ fos.close();
+ }
+ }
+
+ return true;
+ }
+ return false;
+ }
+
+ /**
* Load the specified plugin.
*
* @param name The name of the plugin to load.
@@ -212,20 +275,26 @@
loadPluginProperties(name);
log.debug("plugin: " + name + " -> " + getPluginDir(name));
-
Forehead.getInstance().getClassLoader("root.maven").addURL(getPluginDir(name).toURL());
-
- // Retrieve the dependencies that this plugin requires.
+
Project pluginProject = MavenUtils.getProject(new
File(getPluginDir(name),"project.xml"));
- getProjectVerifier().setMavenProject(pluginProject);
- getProjectVerifier().clearFailedDependencies();
- getProjectVerifier().doExecute();
+
+ if (!isPluginProcessed(name))
+ {
+ // Retrieve the dependencies that this plugin requires.
+ getProjectVerifier().setMavenProject(pluginProject);
+ getProjectVerifier().clearFailedDependencies();
+ getProjectVerifier().doExecute();
+
+ // Mark the plugin as processed.
+ createNewFile(getPluginProcessedMarker(name));
+ }
log.debug("Loading plugin dependencies:");
for (Iterator i = pluginProject.getDependencies().iterator(); i.hasNext();)
{
Dependency dependency = (Dependency) i.next();
- log.debug("dependency: " + dependency);
+ log.debug("dependency: " + dependency.getId());
String classloader = dependency.getMetaEntry("classloader");
log.debug("classloader: " + classloader);
@@ -266,16 +335,13 @@
// Now we want to make available to the plugins the [root.maven]
// classloader for convenience.
-
getJellyContext().setClassLoader(Forehead.getInstance().getClassLoader("root.maven"));
- ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
-
Thread.currentThread().setContextClassLoader(Forehead.getInstance().getClassLoader("root.maven"));
+ //System.out.println(">>>> " + getJellyContext().getClassLoader());
+
//getJellyContext().setClassLoader(Forehead.getInstance().getClassLoader("root.maven"));
JellyUtils.runScript(pluginScript,
getPluginDir(name).toURL(),
pluginJellyContext,
getXMLOutput());
-
- Thread.currentThread().setContextClassLoader(currentCL);
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>