Commit cf00a951 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Update development mode to not require classes dir. It's not needed in all cases.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3849 b35dd754-fafc-0310-a699-88a17e54d16e
parent 628cd368
...@@ -24,7 +24,18 @@ import java.io.File; ...@@ -24,7 +24,18 @@ import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
...@@ -171,10 +182,10 @@ public class PluginManager { ...@@ -171,10 +182,10 @@ public class PluginManager {
String requiredVersion = minServerVersion.getTextTrim(); String requiredVersion = minServerVersion.getTextTrim();
Version version = XMPPServer.getInstance().getServerInfo().getVersion(); Version version = XMPPServer.getInstance().getServerInfo().getVersion();
String hasVersion = version.getMajor() + "." + version.getMinor() + "." + String hasVersion = version.getMajor() + "." + version.getMinor() + "." +
version.getMicro(); version.getMicro();
if (hasVersion.compareTo(requiredVersion) < 0) { if (hasVersion.compareTo(requiredVersion) < 0) {
String msg = "Ignoring plugin " + pluginDir.getName() + ": requires " + String msg = "Ignoring plugin " + pluginDir.getName() + ": requires " +
"server version " + requiredVersion; "server version " + requiredVersion;
Log.warn(msg); Log.warn(msg);
System.out.println(msg); System.out.println(msg);
return; return;
...@@ -192,10 +203,9 @@ public class PluginManager { ...@@ -192,10 +203,9 @@ public class PluginManager {
String classesDirKey = pluginName + ".classes"; String classesDirKey = pluginName + ".classes";
String webRoot = System.getProperty(webRootKey); String webRoot = System.getProperty(webRootKey);
String classesDir = System.getProperty(classesDirKey); String classesDir = System.getProperty(classesDirKey);
boolean inDevelopmentMode = webRoot != null && classesDir != null; if (webRoot != null) {
if(inDevelopmentMode){
final File compilationClassesDir = new File(pluginDir, "classes"); final File compilationClassesDir = new File(pluginDir, "classes");
if(!compilationClassesDir.exists()){ if (!compilationClassesDir.exists()) {
compilationClassesDir.mkdir(); compilationClassesDir.mkdir();
} }
} }
...@@ -206,7 +216,7 @@ public class PluginManager { ...@@ -206,7 +216,7 @@ public class PluginManager {
// See if the parent is already loaded. // See if the parent is already loaded.
if (plugins.containsKey(parentPlugin)) { if (plugins.containsKey(parentPlugin)) {
pluginLoader = classloaders.get(getPlugin(parentPlugin)); pluginLoader = classloaders.get(getPlugin(parentPlugin));
pluginLoader.addDirectory(pluginDir, inDevelopmentMode); pluginLoader.addDirectory(pluginDir, classesDir != null);
} }
else { else {
...@@ -230,7 +240,7 @@ public class PluginManager { ...@@ -230,7 +240,7 @@ public class PluginManager {
} }
else { else {
String msg = "Ignoring plugin " + pluginDir.getName() + ": parent plugin " + String msg = "Ignoring plugin " + pluginDir.getName() + ": parent plugin " +
parentPlugin + " not present."; parentPlugin + " not present.";
Log.warn(msg); Log.warn(msg);
System.out.println(msg); System.out.println(msg);
return; return;
...@@ -249,35 +259,40 @@ public class PluginManager { ...@@ -249,35 +259,40 @@ public class PluginManager {
// This is not a child plugin, so create a new class loader. // This is not a child plugin, so create a new class loader.
else { else {
pluginLoader = new PluginClassLoader(); pluginLoader = new PluginClassLoader();
pluginLoader.addDirectory(pluginDir, inDevelopmentMode); pluginLoader.addDirectory(pluginDir, classesDir != null);
} }
// Check to see if development mode is turned on for the plugin. If it is, // Check to see if development mode is turned on for the plugin. If it is,
// configure dev mode. // configure dev mode.
PluginDevEnvironment dev = null; PluginDevEnvironment dev = null;
if (inDevelopmentMode) { if (webRoot != null || classesDir != null) {
dev = new PluginDevEnvironment(); dev = new PluginDevEnvironment();
File webRootDir = new File(webRoot); System.out.println(pluginName + " is running in development mode.");
if (!webRootDir.exists()) { if (webRoot != null) {
// ok, let's try it relative from this plugin dir? File webRootDir = new File(webRoot);
webRootDir = new File(pluginDir, webRoot); if (!webRootDir.exists()) {
} // ok, let's try it relative from this plugin dir?
webRootDir = new File(pluginDir, webRoot);
}
if (webRootDir.exists()) { if (webRootDir.exists()) {
dev.setWebRoot(webRootDir); dev.setWebRoot(webRootDir);
}
} }
File classes = new File(classesDir); if (classesDir != null) {
if (!classes.exists()) { File classes = new File(classesDir);
// ok, let's try it relative from this plugin dir? if (!classes.exists()) {
classes = new File(pluginDir, classesDir); // ok, let's try it relative from this plugin dir?
} classes = new File(pluginDir, classesDir);
}
if (classes.exists()) { if (classes.exists()) {
dev.setClassesDir(classes); dev.setClassesDir(classes);
pluginLoader.addURL(classes.getAbsoluteFile().toURL()); pluginLoader.addURL(classes.getAbsoluteFile().toURL());
}
} }
} }
...@@ -285,7 +300,7 @@ public class PluginManager { ...@@ -285,7 +300,7 @@ public class PluginManager {
String className = pluginXML.selectSingleNode("/plugin/class").getText(); String className = pluginXML.selectSingleNode("/plugin/class").getText();
plugin = (Plugin)pluginLoader.loadClass(className).newInstance(); plugin = (Plugin)pluginLoader.loadClass(className).newInstance();
if(parentPluginNode != null){ if (parentPluginNode != null) {
String parentPlugin = parentPluginNode.getTextTrim(); String parentPlugin = parentPluginNode.getTextTrim();
// See if the parent is already loaded. // See if the parent is already loaded.
if (plugins.containsKey(parentPlugin)) { if (plugins.containsKey(parentPlugin)) {
...@@ -318,13 +333,13 @@ public class PluginManager { ...@@ -318,13 +333,13 @@ public class PluginManager {
// Load any JSP's defined by the plugin. // Load any JSP's defined by the plugin.
File webXML = new File(pluginDir, "web" + File.separator + "WEB-INF" + File webXML = new File(pluginDir, "web" + File.separator + "WEB-INF" +
File.separator + "web.xml"); File.separator + "web.xml");
if (webXML.exists()) { if (webXML.exists()) {
PluginServlet.registerServlets(this, plugin, webXML); PluginServlet.registerServlets(this, plugin, webXML);
} }
// Load any custom-defined servlets. // Load any custom-defined servlets.
File customWebXML = new File(pluginDir, "web" + File.separator + "WEB-INF" + File customWebXML = new File(pluginDir, "web" + File.separator + "WEB-INF" +
File.separator + "web-custom.xml"); File.separator + "web-custom.xml");
if (customWebXML.exists()) { if (customWebXML.exists()) {
PluginServlet.registerServlets(this, plugin, customWebXML); PluginServlet.registerServlets(this, plugin, customWebXML);
} }
...@@ -336,14 +351,13 @@ public class PluginManager { ...@@ -336,14 +351,13 @@ public class PluginManager {
// If there a <adminconsole> section defined, register it. // If there a <adminconsole> section defined, register it.
Element adminElement = (Element)pluginXML.selectSingleNode("/plugin/adminconsole"); Element adminElement = (Element)pluginXML.selectSingleNode("/plugin/adminconsole");
if (adminElement != null) { if (adminElement != null) {
if(parentPluginNode != null){ if (parentPluginNode != null) {
pluginName = parentPluginNode.getTextTrim(); pluginName = parentPluginNode.getTextTrim();
} }
// If global images are specified, override their URL. // If global images are specified, override their URL.
Element imageEl = (Element)adminElement.selectSingleNode( Element imageEl = (Element)adminElement.selectSingleNode(
"/plugin/adminconsole/global/logo-image"); "/plugin/adminconsole/global/logo-image");
if (imageEl != null) { if (imageEl != null) {
imageEl.setText("plugins/" + pluginName + "/" + imageEl.getText()); imageEl.setText("plugins/" + pluginName + "/" + imageEl.getText());
} }
...@@ -355,7 +369,7 @@ public class PluginManager { ...@@ -355,7 +369,7 @@ public class PluginManager {
// the plugin servlet correctly. // the plugin servlet correctly.
List urls = adminElement.selectNodes("//@url"); List urls = adminElement.selectNodes("//@url");
for (Object url : urls) { for (Object url : urls) {
Attribute attr = (Attribute) url; Attribute attr = (Attribute)url;
attr.setValue("plugins/" + pluginName + "/" + attr.getValue()); attr.setValue("plugins/" + pluginName + "/" + attr.getValue());
} }
AdminConsole.addModel(pluginName, adminElement); AdminConsole.addModel(pluginName, adminElement);
...@@ -400,13 +414,13 @@ public class PluginManager { ...@@ -400,13 +414,13 @@ public class PluginManager {
} }
File webXML = new File(pluginDirectory, pluginName + File.separator + "web" + File.separator + "WEB-INF" + File webXML = new File(pluginDirectory, pluginName + File.separator + "web" + File.separator + "WEB-INF" +
File.separator + "web.xml"); File.separator + "web.xml");
if (webXML.exists()) { if (webXML.exists()) {
AdminConsole.removeModel(pluginName); AdminConsole.removeModel(pluginName);
PluginServlet.unregisterServlets(webXML); PluginServlet.unregisterServlets(webXML);
} }
File customWebXML = new File(pluginDirectory, pluginName + File.separator + "web" + File.separator + "WEB-INF" + File customWebXML = new File(pluginDirectory, pluginName + File.separator + "web" + File.separator + "WEB-INF" +
File.separator + "web-custom.xml"); File.separator + "web-custom.xml");
if (customWebXML.exists()) { if (customWebXML.exists()) {
PluginServlet.unregisterServlets(customWebXML); PluginServlet.unregisterServlets(customWebXML);
} }
...@@ -432,7 +446,7 @@ public class PluginManager { ...@@ -432,7 +446,7 @@ public class PluginManager {
/** /**
* Loads a class from the classloader of a plugin. * Loads a class from the classloader of a plugin.
* *
* @param plugin the plugin. * @param plugin the plugin.
* @param className the name of the class to load. * @param className the name of the class to load.
* @return the class. * @return the class.
* @throws ClassNotFoundException if the class was not found. * @throws ClassNotFoundException if the class was not found.
...@@ -440,8 +454,7 @@ public class PluginManager { ...@@ -440,8 +454,7 @@ public class PluginManager {
* @throws InstantiationException if the class could not be created. * @throws InstantiationException if the class could not be created.
*/ */
public Class loadClass(Plugin plugin, String className) throws ClassNotFoundException, public Class loadClass(Plugin plugin, String className) throws ClassNotFoundException,
IllegalAccessException, InstantiationException IllegalAccessException, InstantiationException {
{
PluginClassLoader loader = classloaders.get(plugin); PluginClassLoader loader = classloaders.get(plugin);
return loader.loadClass(className); return loader.loadClass(className);
} }
...@@ -452,7 +465,7 @@ public class PluginManager { ...@@ -452,7 +465,7 @@ public class PluginManager {
* *
* @param plugin the plugin. * @param plugin the plugin.
* @return the plugin dev environment, or <tt>null</tt> if development * @return the plugin dev environment, or <tt>null</tt> if development
* mode is not enabled for the plugin. * mode is not enabled for the plugin.
*/ */
public PluginDevEnvironment getDevEnvironment(Plugin plugin) { public PluginDevEnvironment getDevEnvironment(Plugin plugin) {
return pluginDevelopment.get(plugin); return pluginDevelopment.get(plugin);
...@@ -511,10 +524,11 @@ public class PluginManager { ...@@ -511,10 +524,11 @@ public class PluginManager {
/** /**
* Returns the classloader of a plugin. * Returns the classloader of a plugin.
*
* @param plugin the plugin. * @param plugin the plugin.
* @return the classloader of the plugin. * @return the classloader of the plugin.
*/ */
public PluginClassLoader getPluginClassloader(Plugin plugin){ public PluginClassLoader getPluginClassloader(Plugin plugin) {
return classloaders.get(plugin); return classloaders.get(plugin);
} }
...@@ -583,7 +597,7 @@ public class PluginManager { ...@@ -583,7 +597,7 @@ public class PluginManager {
for (File jarFile : jars) { for (File jarFile : jars) {
String pluginName = jarFile.getName().substring(0, String pluginName = jarFile.getName().substring(0,
jarFile.getName().length() - 4).toLowerCase(); jarFile.getName().length() - 4).toLowerCase();
// See if the JAR has already been exploded. // See if the JAR has already been exploded.
File dir = new File(pluginDirectory, pluginName); File dir = new File(pluginDirectory, pluginName);
// If the JAR hasn't been exploded, do so. // If the JAR hasn't been exploded, do so.
...@@ -599,7 +613,7 @@ public class PluginManager { ...@@ -599,7 +613,7 @@ public class PluginManager {
int count = 0; int count = 0;
while (!deleteDir(dir) && count < 5) { while (!deleteDir(dir) && count < 5) {
Log.error("Error unloading plugin " + pluginName + ". " + Log.error("Error unloading plugin " + pluginName + ". " +
"Will attempt again momentarily."); "Will attempt again momentarily.");
Thread.sleep(5000); Thread.sleep(5000);
count++; count++;
} }
...@@ -658,7 +672,7 @@ public class PluginManager { ...@@ -658,7 +672,7 @@ public class PluginManager {
File dir = new File(pluginDirectory, pluginName); File dir = new File(pluginDirectory, pluginName);
while (!deleteDir(dir) && count < 5) { while (!deleteDir(dir) && count < 5) {
Log.error("Error unloading plugin " + pluginName + ". " + Log.error("Error unloading plugin " + pluginName + ". " +
"Will attempt again momentarily."); "Will attempt again momentarily.");
Thread.sleep(5000); Thread.sleep(5000);
count++; count++;
} }
...@@ -682,8 +696,8 @@ public class PluginManager { ...@@ -682,8 +696,8 @@ public class PluginManager {
* isn't a plugin, this method will do nothing. * isn't a plugin, this method will do nothing.
* *
* @param pluginName the name of the plugin. * @param pluginName the name of the plugin.
* @param file the JAR file * @param file the JAR file
* @param dir the directory to extract the plugin to. * @param dir the directory to extract the plugin to.
*/ */
private void unzipPlugin(String pluginName, File file, File dir) { private void unzipPlugin(String pluginName, File file, File dir) {
try { try {
......
...@@ -20,14 +20,6 @@ import org.jivesoftware.util.Log; ...@@ -20,14 +20,6 @@ import org.jivesoftware.util.Log;
import org.jivesoftware.util.StringUtils; import org.jivesoftware.util.StringUtils;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.GenericServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServlet;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -40,6 +32,14 @@ import java.util.List; ...@@ -40,6 +32,14 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.GenericServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/** /**
* The plugin servlet acts as a proxy for web requests (in the admin console) * The plugin servlet acts as a proxy for web requests (in the admin console)
* to plugins. Since plugins can be dynamically loaded and live in a different place * to plugins. Since plugins can be dynamically loaded and live in a different place
...@@ -75,8 +75,7 @@ public class PluginServlet extends HttpServlet { ...@@ -75,8 +75,7 @@ public class PluginServlet extends HttpServlet {
} }
public void service(HttpServletRequest request, HttpServletResponse response) public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException throws ServletException, IOException {
{
String pathInfo = request.getPathInfo(); String pathInfo = request.getPathInfo();
if (pathInfo == null) { if (pathInfo == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setStatus(HttpServletResponse.SC_NOT_FOUND);
...@@ -118,7 +117,7 @@ public class PluginServlet extends HttpServlet { ...@@ -118,7 +117,7 @@ public class PluginServlet extends HttpServlet {
pluginManager = manager; pluginManager = manager;
if (!webXML.exists()) { if (!webXML.exists()) {
Log.error("Could not register plugin servlets, file " + webXML.getAbsolutePath() + Log.error("Could not register plugin servlets, file " + webXML.getAbsolutePath() +
" does not exist."); " does not exist.");
return; return;
} }
// Find the name of the plugin directory given that the webXML file // Find the name of the plugin directory given that the webXML file
...@@ -130,7 +129,7 @@ public class PluginServlet extends HttpServlet { ...@@ -130,7 +129,7 @@ public class PluginServlet extends HttpServlet {
SAXReader saxReader = new SAXReader(false); SAXReader saxReader = new SAXReader(false);
try { try {
saxReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", saxReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",
false); false);
} }
catch (SAXException e) { catch (SAXException e) {
Log.warn("Error setting SAXReader feature", e); Log.warn("Error setting SAXReader feature", e);
...@@ -178,7 +177,7 @@ public class PluginServlet extends HttpServlet { ...@@ -178,7 +177,7 @@ public class PluginServlet extends HttpServlet {
public static void unregisterServlets(File webXML) { public static void unregisterServlets(File webXML) {
if (!webXML.exists()) { if (!webXML.exists()) {
Log.error("Could not unregister plugin servlets, file " + webXML.getAbsolutePath() + Log.error("Could not unregister plugin servlets, file " + webXML.getAbsolutePath() +
" does not exist."); " does not exist.");
return; return;
} }
// Find the name of the plugin directory given that the webXML file // Find the name of the plugin directory given that the webXML file
...@@ -187,7 +186,7 @@ public class PluginServlet extends HttpServlet { ...@@ -187,7 +186,7 @@ public class PluginServlet extends HttpServlet {
try { try {
SAXReader saxReader = new SAXReader(false); SAXReader saxReader = new SAXReader(false);
saxReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", saxReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",
false); false);
Document doc = saxReader.read(webXML); Document doc = saxReader.read(webXML);
// Find all <servelt-mapping> entries to discover name to URL mapping. // Find all <servelt-mapping> entries to discover name to URL mapping.
List names = doc.selectNodes("//servlet-mapping"); List names = doc.selectNodes("//servlet-mapping");
...@@ -433,7 +432,7 @@ public class PluginServlet extends HttpServlet { ...@@ -433,7 +432,7 @@ public class PluginServlet extends HttpServlet {
try { try {
Object servletInstance = pluginManager.loadClass(plugin, "org.apache.jsp." + Object servletInstance = pluginManager.loadClass(plugin, "org.apache.jsp." +
relativeDir + filename).newInstance(); relativeDir + filename).newInstance();
HttpServlet servlet = (HttpServlet)servletInstance; HttpServlet servlet = (HttpServlet)servletInstance;
servlet.init(servletConfig); servlet.init(servletConfig);
servlet.service(request, response); servlet.service(request, response);
...@@ -490,8 +489,10 @@ public class PluginServlet extends HttpServlet { ...@@ -490,8 +489,10 @@ public class PluginServlet extends HttpServlet {
classpath.append(wildfireLib.getAbsolutePath()).append("//wildfire.jar;"); classpath.append(wildfireLib.getAbsolutePath()).append("//wildfire.jar;");
classpath.append(wildfireLib.getAbsolutePath()).append("//jasper-compiler.jar;"); classpath.append(wildfireLib.getAbsolutePath()).append("//jasper-compiler.jar;");
classpath.append(wildfireLib.getAbsolutePath()).append("//jasper-runtime.jar;"); classpath.append(wildfireLib.getAbsolutePath()).append("//jasper-runtime.jar;");
classpath.append(pluginEnv.getClassesDir().getAbsolutePath()).append(";");
if (pluginEnv.getClassesDir() != null) {
classpath.append(pluginEnv.getClassesDir().getAbsolutePath()).append(";");
}
return classpath.toString(); return classpath.toString();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment