Author: toad
Date: 2006-12-13 21:41:51 +0000 (Wed, 13 Dec 2006)
New Revision: 11383

Added:
   trunk/freenet/src/freenet/oldplugins/
   trunk/freenet/src/freenet/oldplugins/plugin/
   trunk/freenet/src/freenet/oldplugins/plugin/HttpPlugin.java
   trunk/freenet/src/freenet/oldplugins/plugin/Plugin.java
   trunk/freenet/src/freenet/oldplugins/plugin/PluginManager.java
   trunk/freenet/src/freenet/oldplugins/plugin/TestHttpPlugin.java
   trunk/freenet/src/freenet/oldplugins/plugin/TestPlugin.java
Removed:
   trunk/freenet/src/freenet/plugin/HttpPlugin.java
   trunk/freenet/src/freenet/plugin/Plugin.java
   trunk/freenet/src/freenet/plugin/PluginManager.java
   trunk/freenet/src/freenet/plugin/TestHttpPlugin.java
   trunk/freenet/src/freenet/plugin/TestPlugin.java
Modified:
   trunk/freenet/src/freenet/clients/http/NinjaSpider.java
   trunk/freenet/src/freenet/clients/http/PluginToadlet.java
   trunk/freenet/src/freenet/clients/http/Spider.java
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/pluginmanager/PluginManager.java
Log:
Move plugin/ out of the way.

Modified: trunk/freenet/src/freenet/clients/http/NinjaSpider.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/NinjaSpider.java     2006-12-13 
20:53:44 UTC (rev 11382)
+++ trunk/freenet/src/freenet/clients/http/NinjaSpider.java     2006-12-13 
21:41:51 UTC (rev 11383)
@@ -46,8 +46,8 @@
 import freenet.keys.FreenetURI;
 import freenet.node.NodeClientCore;
 import freenet.node.RequestStarter;
-import freenet.plugin.HttpPlugin;
-import freenet.plugin.PluginManager;
+import freenet.oldplugins.plugin.HttpPlugin;
+import freenet.oldplugins.plugin.PluginManager;
 import freenet.support.HTMLNode;
 import freenet.support.Logger;
 import freenet.support.MultiValueTable;
@@ -531,7 +531,7 @@
        }

        /**
-        * @see 
freenet.plugin.HttpPlugin#handleGet(freenet.clients.http.HTTPRequest, 
freenet.clients.http.ToadletContext)
+        * @see 
freenet.oldplugins.plugin.HttpPlugin#handleGet(freenet.clients.http.HTTPRequest,
 freenet.clients.http.ToadletContext)
         */
        public void handleGet(HTTPRequest request, ToadletContext context) 
throws IOException, ToadletContextClosedException {
                String action = request.getParam("action");
@@ -603,7 +603,7 @@
        }

        /**
-        * @see 
freenet.plugin.HttpPlugin#handlePost(freenet.clients.http.HTTPRequest, 
freenet.clients.http.ToadletContext)
+        * @see 
freenet.oldplugins.plugin.HttpPlugin#handlePost(freenet.clients.http.HTTPRequest,
 freenet.clients.http.ToadletContext)
         */
        public void handlePost(HTTPRequest request, ToadletContext context) 
throws IOException {
        }
@@ -672,14 +672,14 @@
        }

        /**
-        * @see freenet.plugin.Plugin#getPluginName()
+        * @see freenet.oldplugins.plugin.Plugin#getPluginName()
         */
        public String getPluginName() {
                return pluginName;
        }

        /**
-        * @see 
freenet.plugin.Plugin#setPluginManager(freenet.plugin.PluginManager)
+        * @see 
freenet.oldplugins.plugin.Plugin#setPluginManager(freenet.oldplugins.plugin.PluginManager)
         */
        public void setPluginManager(PluginManager pluginManager) {
                this.core = pluginManager.getClientCore();
@@ -693,7 +693,7 @@


        /**
-        * @see freenet.plugin.Plugin#startPlugin()
+        * @see freenet.oldplugins.plugin.Plugin#startPlugin()
         */
        public void startPlugin() {
                FreenetURI[] initialURIs = 
core.bookmarkManager.getBookmarkURIs();
@@ -710,7 +710,7 @@
        }

        /**
-        * @see freenet.plugin.Plugin#stopPlugin()
+        * @see freenet.oldplugins.plugin.Plugin#stopPlugin()
         */
        public void stopPlugin() {
                synchronized (this) {

Modified: trunk/freenet/src/freenet/clients/http/PluginToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/PluginToadlet.java   2006-12-13 
20:53:44 UTC (rev 11382)
+++ trunk/freenet/src/freenet/clients/http/PluginToadlet.java   2006-12-13 
21:41:51 UTC (rev 11383)
@@ -8,9 +8,9 @@

 import freenet.client.HighLevelSimpleClient;
 import freenet.node.NodeClientCore;
-import freenet.plugin.HttpPlugin;
-import freenet.plugin.Plugin;
-import freenet.plugin.PluginManager;
+import freenet.oldplugins.plugin.HttpPlugin;
+import freenet.oldplugins.plugin.Plugin;
+import freenet.oldplugins.plugin.PluginManager;
 import freenet.support.HTMLNode;
 import freenet.support.MultiValueTable;
 import freenet.support.io.Bucket;

Modified: trunk/freenet/src/freenet/clients/http/Spider.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/Spider.java  2006-12-13 20:53:44 UTC 
(rev 11382)
+++ trunk/freenet/src/freenet/clients/http/Spider.java  2006-12-13 21:41:51 UTC 
(rev 11383)
@@ -36,8 +36,8 @@
 import freenet.keys.FreenetURI;
 import freenet.node.NodeClientCore;
 import freenet.node.RequestStarter;
-import freenet.plugin.HttpPlugin;
-import freenet.plugin.PluginManager;
+import freenet.oldplugins.plugin.HttpPlugin;
+import freenet.oldplugins.plugin.PluginManager;
 import freenet.support.HTMLNode;
 import freenet.support.Logger;
 import freenet.support.MultiValueTable;
@@ -274,7 +274,7 @@
        }

        /**
-        * @see 
freenet.plugin.HttpPlugin#handleGet(freenet.clients.http.HTTPRequest, 
freenet.clients.http.ToadletContext)
+        * @see 
freenet.oldplugins.plugin.HttpPlugin#handleGet(freenet.clients.http.HTTPRequest,
 freenet.clients.http.ToadletContext)
         */
        public void handleGet(HTTPRequest request, ToadletContext context) 
throws IOException, ToadletContextClosedException {
                String action = request.getParam("action");
@@ -342,7 +342,7 @@
        }

        /**
-        * @see 
freenet.plugin.HttpPlugin#handlePost(freenet.clients.http.HTTPRequest, 
freenet.clients.http.ToadletContext)
+        * @see 
freenet.oldplugins.plugin.HttpPlugin#handlePost(freenet.clients.http.HTTPRequest,
 freenet.clients.http.ToadletContext)
         */
        public void handlePost(HTTPRequest request, ToadletContext context) 
throws IOException {
        }
@@ -409,14 +409,14 @@
        }

        /**
-        * @see freenet.plugin.Plugin#getPluginName()
+        * @see freenet.oldplugins.plugin.Plugin#getPluginName()
         */
        public String getPluginName() {
                return "The Definitive Spider";
        }

        /**
-        * @see 
freenet.plugin.Plugin#setPluginManager(freenet.plugin.PluginManager)
+        * @see 
freenet.oldplugins.plugin.Plugin#setPluginManager(freenet.oldplugins.plugin.PluginManager)
         */
        public void setPluginManager(PluginManager pluginManager) {
                this.core = pluginManager.getClientCore();
@@ -430,7 +430,7 @@


        /**
-        * @see freenet.plugin.Plugin#startPlugin()
+        * @see freenet.oldplugins.plugin.Plugin#startPlugin()
         */
        public void startPlugin() {
                stopped = false;
@@ -444,7 +444,7 @@
        }

        /**
-        * @see freenet.plugin.Plugin#stopPlugin()
+        * @see freenet.oldplugins.plugin.Plugin#stopPlugin()
         */
        public void stopPlugin() {
                synchronized (this) {

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2006-12-13 20:53:44 UTC (rev 
11382)
+++ trunk/freenet/src/freenet/node/Node.java    2006-12-13 21:41:51 UTC (rev 
11383)
@@ -476,7 +476,7 @@

        // Things that's needed to keep track of
        public final PluginManager pluginManager;
-       public freenet.plugin.PluginManager pluginManager2;
+       public freenet.oldplugins.plugin.PluginManager pluginManager2;

        // Helpers
        public final InetAddress localhostAddress;
@@ -1280,7 +1280,7 @@
                Logger.normal(this, "Initializing Plugin Manager");
                System.out.println("Initializing Plugin Manager");
                pluginManager = new PluginManager(this);
-               pluginManager2 = new freenet.plugin.PluginManager(this);
+               pluginManager2 = new 
freenet.oldplugins.plugin.PluginManager(this);

                FetcherContext ctx = clientCore.makeClient((short)0, 
true).getFetcherContext();


Copied: trunk/freenet/src/freenet/oldplugins/plugin/HttpPlugin.java (from rev 
11380, trunk/freenet/src/freenet/plugin/HttpPlugin.java)
===================================================================
--- trunk/freenet/src/freenet/oldplugins/plugin/HttpPlugin.java                 
        (rev 0)
+++ trunk/freenet/src/freenet/oldplugins/plugin/HttpPlugin.java 2006-12-13 
21:41:51 UTC (rev 11383)
@@ -0,0 +1,48 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.oldplugins.plugin;
+
+import java.io.IOException;
+
+import freenet.clients.http.HTTPRequest;
+import freenet.clients.http.ToadletContext;
+import freenet.clients.http.ToadletContextClosedException;
+
+/**
+ * Interface for plugins that support HTTP interaction.
+ * 
+ * @author David 'Bombe' Roden <bombe at freenetproject.org>
+ * @version $Id$
+ */
+public interface HttpPlugin extends Plugin {
+
+       /**
+        * Handles the GET request.
+        * 
+        * @param request
+        *            The request used to interact with this plugin
+        * @param context
+        *            The context of the HTTP request
+        * @throws IOException
+        *             if an I/O error occurs
+        * @throws ToadletContextClosedException
+        *             if the context has already been closed.
+        */
+       public void handleGet(HTTPRequest request, ToadletContext context) 
throws IOException, ToadletContextClosedException;
+
+       /**
+        * Handles the POST request.
+        * 
+        * @param request
+        *            The request used to interact with this plugin
+        * @param context
+        *            The context of the HTTP request
+        * @throws IOException
+        *             if an I/O error occurs
+        * @throws ToadletContextClosedException
+        *             if the context has already been closed.
+        */
+       public void handlePost(HTTPRequest request, ToadletContext context) 
throws IOException, ToadletContextClosedException;
+
+}


Property changes on: trunk/freenet/src/freenet/oldplugins/plugin/HttpPlugin.java
___________________________________________________________________
Name: svn:keywords
   + Id

Copied: trunk/freenet/src/freenet/oldplugins/plugin/Plugin.java (from rev 
11380, trunk/freenet/src/freenet/plugin/Plugin.java)
===================================================================
--- trunk/freenet/src/freenet/oldplugins/plugin/Plugin.java                     
        (rev 0)
+++ trunk/freenet/src/freenet/oldplugins/plugin/Plugin.java     2006-12-13 
21:41:51 UTC (rev 11383)
@@ -0,0 +1,40 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.oldplugins.plugin;
+
+/**
+ * Interface for Fred plugins.
+ * 
+ * @author David 'Bombe' Roden <bombe at freenetproject.org>
+ * @version $Id$
+ */
+public interface Plugin {
+
+       /**
+        * Returns the name of the plugin.
+        * 
+        * @return The name of the plugin
+        */
+       public String getPluginName();
+
+       /**
+        * Sets the plugin manager that manages this plugin.
+        * 
+        * @param pluginManager
+        *            The plugin manager
+        */
+       public void setPluginManager(PluginManager pluginManager);
+
+       /**
+        * Starts the plugin. If the plugin needs threads they have to be 
started
+        * here.
+        */
+       public void startPlugin();
+
+       /**
+        * Stops the plugin.
+        */
+       public void stopPlugin();
+
+}


Property changes on: trunk/freenet/src/freenet/oldplugins/plugin/Plugin.java
___________________________________________________________________
Name: svn:keywords
   + Id

Copied: trunk/freenet/src/freenet/oldplugins/plugin/PluginManager.java (from 
rev 11380, trunk/freenet/src/freenet/plugin/PluginManager.java)
===================================================================
--- trunk/freenet/src/freenet/oldplugins/plugin/PluginManager.java              
                (rev 0)
+++ trunk/freenet/src/freenet/oldplugins/plugin/PluginManager.java      
2006-12-13 21:41:51 UTC (rev 11383)
@@ -0,0 +1,241 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.oldplugins.plugin;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import freenet.config.InvalidConfigValueException;
+import freenet.config.StringArrCallback;
+import freenet.config.StringArrOption;
+import freenet.config.SubConfig;
+import freenet.node.Node;
+import freenet.node.NodeClientCore;
+import freenet.support.Logger;
+
+/**
+ * Manages plugins.
+ * 
+ * @author David 'Bombe' Roden <bombe at freenetproject.org>
+ * @version $Id$
+ */
+public class PluginManager {
+
+       /** Object used for synchronization. */
+       private final Object syncObject = new Object();
+
+       /** The node. */
+       private final Node node;
+
+       /** The configuration of this plugin manager. */
+       private final SubConfig config;
+
+       /** Currently loaded plugins. */
+       private List plugins = new ArrayList();
+
+       /**
+        * Creates a new plugin manager.
+        * 
+        * @param node
+        *            The node
+        */
+       public PluginManager(Node node) {
+               this.node = node;
+
+               config = new SubConfig("pluginmanager2", node.config);
+               config.register("loadedPlugins", new String[0], 9, true, true, 
"Plugins to load on start up", "A list of plugins that are started when the 
node starts", new StringArrCallback() {
+
+                       /**
+                        * Returns the current value of this option.
+                        * 
+                        * @see freenet.config.StringArrCallback#get()
+                        * @return The current value of this option
+                        */
+                       public String get() {
+                               if(plugins.size() == 0) return "";
+                               StringBuffer optionValue = new StringBuffer();
+                               synchronized (syncObject) {
+                                       Iterator pluginIterator = 
plugins.iterator();
+                                       while (pluginIterator.hasNext()) {
+                                               Plugin plugin = (Plugin) 
pluginIterator.next();
+                                               if (optionValue.length() != 0) {
+                                                       
optionValue.append(StringArrOption.delimiter);
+                                               }
+                                               
optionValue.append(StringArrOption.encode(plugin.getClass().getName()));
+                                       }
+                               }
+                               if(Logger.shouldLog(Logger.MINOR, this))
+                                       Logger.minor(this, "Plugin list: 
"+optionValue.toString());
+                               return optionValue.toString();
+                       };
+
+                       /**
+                        * Sets the new value of this option.
+                        * 
+                        * @see 
freenet.config.StringArrCallback#set(java.lang.String)
+                        * @param val
+                        *            The new value
+                        * @throws InvalidConfigValueException
+                        *             if setting the value is not allowed, or 
the new value
+                        *             is not valid
+                        */
+                       public void set(String val) throws 
InvalidConfigValueException {
+                               if(val == null || get().indexOf(val) >= 0) 
return;
+                               // it's probably silly as it won't allow more 
than 1 plugin to be loaded
+                               addPlugin(val, true);
+                       };
+               });
+
+               String[] loadedPluginNames = 
config.getStringArr("loadedPlugins");
+               if (loadedPluginNames != null && loadedPluginNames.length > 0) {
+                       for (int pluginIndex = 0, pluginCount = 
loadedPluginNames.length; pluginIndex < pluginCount; pluginIndex++) {
+                               String pluginName = 
StringArrOption.decode(loadedPluginNames[pluginIndex]);
+                               try {
+                                       addPlugin(pluginName, false);
+                               } catch (Throwable t) {
+                                       Logger.error(this, "Failed to load 
plugin "+pluginName+" : "+t, t);
+                               }
+                       }
+               }
+
+               config.finishedInitialization();
+       }
+
+       /**
+        * Returns the node that created this plugin manager.
+        * 
+        * @return The node that created this plugin manager
+        */
+       public Node getNode() {
+               return node;
+       }
+
+       /**
+        * Returns all currently loaded plugins. The array is returned in no
+        * particular order.
+        * 
+        * @return All currently loaded plugins
+        */
+       public Plugin[] getPlugins() {
+               synchronized (syncObject) {
+                       return (Plugin[]) plugins.toArray(new 
Plugin[plugins.size()]);
+               }
+       }
+
+       /**
+        * Adds a plugin to the plugin manager. The name can contain a URL for 
a jar
+        * file from which the plugin is then loaded. If it does the URL and the
+        * plugin name are separated by a '@', e.g.
+        * 'plugin.TestPlugin at http://www.example.com/test.jar'. URLs can 
contain
+        * every protocol your VM understands.
+        * 
+        * @see URL
+        * @param pluginName
+        *            The name of the plugin
+        */
+       public void addPlugin(String pluginName, final boolean store) throws 
IllegalArgumentException {
+               if(Logger.shouldLog(Logger.MINOR, this)) 
+                       Logger.minor(this, "Loading plugin 
"+pluginName+(store?"" : " (don't store afterwards)"));
+               final Plugin newPlugin = createPlugin(pluginName);
+               if (newPlugin == null) {
+                       throw new IllegalArgumentException();
+               }
+               newPlugin.setPluginManager(this);
+               synchronized (syncObject) {
+                       plugins.add(newPlugin);
+               }
+               node.ps.queueTimedJob(new Runnable() {
+                       public void run() {
+                               try{
+                                       while(!node.isHasStarted())
+                                               Thread.sleep(1000);
+                               }catch (InterruptedException e) {}
+                               newPlugin.startPlugin();
+                               if(store)
+                                       node.clientCore.storeConfig();
+                       }
+               }, 0);
+               
+       }
+
+       /**
+        * Remoes the plugin from the list of running plugins. The plugin is 
stopped
+        * before removing it.
+        * 
+        * @param plugin
+        *            The plugin to remove
+        */
+       public void removePlugin(Plugin plugin, boolean store) {
+               plugin.stopPlugin();
+               synchronized (syncObject) {
+                       plugins.remove(plugin);
+               }
+               if(store)
+                       node.clientCore.storeConfig();
+       }
+
+       /**
+        * Creates a plugin from a name. The name can contain a URL for a jar 
file
+        * from which the plugin is then loaded. If it does the URL and the 
plugin
+        * name are separated by a '@', e.g.
+        * 'plugin.TestPlugin at http://www.example.com/test.jar'. URLs can 
contain
+        * every protocol your VM understands.
+        * <p>
+        * <b>WARNING:</b> The code to load JAR files from URLs has <b>not</b>
+        * been tested.
+        * 
+        * @see URL
+        * @param pluginName
+        *            The name of the plugin
+        * @return The created plugin, or <code>null</code> if the plugin could
+        *         not be created
+        */
+       private Plugin createPlugin(String pluginName) {
+               int p = pluginName.indexOf('@');
+               String pluginSource = null;
+               
+               /* split up */
+               if (p > -1) {
+                       pluginSource = pluginName.substring(p + 1);
+                       pluginName = pluginName.substring(0, p);
+               }
+
+               /* load jar file */
+               ClassLoader classLoader = getClass().getClassLoader();
+               if (pluginSource != null) {
+                       try {
+                               URL pluginSourceUrl = new URL(pluginSource);
+                               classLoader = new URLClassLoader(new URL[] { 
pluginSourceUrl });
+                       } catch (MalformedURLException mue1) {
+                               Logger.normal(this, "could not create class 
loader", mue1);
+                               return null;
+                       }
+               }
+
+               /* load class from class loader */
+               try {
+                       Class pluginClass = classLoader.loadClass(pluginName);
+                       if (Plugin.class.isAssignableFrom(pluginClass)) {
+                               Plugin plugin = (Plugin) 
pluginClass.newInstance();
+                               return plugin;
+                       }
+               } catch (ClassNotFoundException e) {
+                       Logger.normal(this, "could not find plugin class: " + 
pluginName+" : "+e, e);
+               } catch (InstantiationException e) {
+                       Logger.normal(this, "could not instantiate plugin 
class: " + pluginName+" : "+e, e);
+               } catch (IllegalAccessException e) {
+                       Logger.normal(this, "could not instantiate plugin 
class: " + pluginName+" : "+e, e);
+               }
+               return null;
+       }
+
+       public NodeClientCore getClientCore() {
+               return node.clientCore;
+       }
+
+}


Property changes on: 
trunk/freenet/src/freenet/oldplugins/plugin/PluginManager.java
___________________________________________________________________
Name: svn:keywords
   + Id

Copied: trunk/freenet/src/freenet/oldplugins/plugin/TestHttpPlugin.java (from 
rev 11380, trunk/freenet/src/freenet/plugin/TestHttpPlugin.java)
===================================================================
--- trunk/freenet/src/freenet/oldplugins/plugin/TestHttpPlugin.java             
                (rev 0)
+++ trunk/freenet/src/freenet/oldplugins/plugin/TestHttpPlugin.java     
2006-12-13 21:41:51 UTC (rev 11383)
@@ -0,0 +1,62 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.oldplugins.plugin;
+
+import java.io.IOException;
+
+import freenet.clients.http.HTTPRequest;
+import freenet.clients.http.ToadletContext;
+import freenet.clients.http.ToadletContextClosedException;
+import freenet.support.MultiValueTable;
+
+/**
+ * Test HTTP plugin. Outputs "Plugin works" to the browser.
+ * 
+ * @author David 'Bombe' Roden &lt;bombe at freenetproject.org&gt;
+ * @version $Id$
+ */
+public class TestHttpPlugin implements HttpPlugin {
+
+       /**
+        * @throws ToadletContextClosedException
+        * @see 
freenet.oldplugins.plugin.HttpPlugin#handleGet(freenet.clients.http.HTTPRequest)
+        */
+       public void handleGet(HTTPRequest request, ToadletContext context) 
throws IOException, ToadletContextClosedException {
+               byte[] messageBytes = "Plugin works.".getBytes("UTF-8");
+               context.sendReplyHeaders(200, "OK", new MultiValueTable(), 
"text/html; charset=utf-8", messageBytes.length);
+               context.writeData(messageBytes, 0, messageBytes.length);
+       }
+
+       /**
+        * @see 
freenet.oldplugins.plugin.HttpPlugin#handlePost(freenet.clients.http.HTTPRequest)
+        */
+       public void handlePost(HTTPRequest request, ToadletContext context) 
throws IOException, ToadletContextClosedException {
+       }
+
+       /**
+        * @see freenet.oldplugins.plugin.Plugin#getPluginName()
+        */
+       public String getPluginName() {
+               return "Simple HTTP Test Plugin";
+       }
+
+       /**
+        * @see 
freenet.oldplugins.plugin.Plugin#setPluginManager(freenet.oldplugins.plugin.PluginManager)
+        */
+       public void setPluginManager(PluginManager pluginManager) {
+       }
+
+       /**
+        * @see freenet.oldplugins.plugin.Plugin#startPlugin()
+        */
+       public void startPlugin() {
+       }
+
+       /**
+        * @see freenet.oldplugins.plugin.Plugin#stopPlugin()
+        */
+       public void stopPlugin() {
+       }
+
+}


Property changes on: 
trunk/freenet/src/freenet/oldplugins/plugin/TestHttpPlugin.java
___________________________________________________________________
Name: svn:keywords
   + Id

Copied: trunk/freenet/src/freenet/oldplugins/plugin/TestPlugin.java (from rev 
11380, trunk/freenet/src/freenet/plugin/TestPlugin.java)
===================================================================
--- trunk/freenet/src/freenet/oldplugins/plugin/TestPlugin.java                 
        (rev 0)
+++ trunk/freenet/src/freenet/oldplugins/plugin/TestPlugin.java 2006-12-13 
21:41:51 UTC (rev 11383)
@@ -0,0 +1,39 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.oldplugins.plugin;
+
+/**
+ * Test plugin. Does absolutely nothing.
+ * 
+ * @author David 'Bombe' Roden &lt;bombe at freenetproject.org&gt;
+ * @version $Id$
+ */
+public class TestPlugin implements Plugin {
+
+       /**
+        * @see freenet.oldplugins.plugin.Plugin#getPluginName()
+        */
+       public String getPluginName() {
+               return "Simple Test Plugin";
+       }
+
+       /**
+        * @see 
freenet.oldplugins.plugin.Plugin#setPluginManager(freenet.oldplugins.plugin.PluginManager)
+        */
+       public void setPluginManager(PluginManager pluginManager) {
+       }
+
+       /**
+        * @see freenet.oldplugins.plugin.Plugin#startPlugin()
+        */
+       public void startPlugin() {
+       }
+
+       /**
+        * @see freenet.oldplugins.plugin.Plugin#stopPlugin()
+        */
+       public void stopPlugin() {
+       }
+
+}


Property changes on: trunk/freenet/src/freenet/oldplugins/plugin/TestPlugin.java
___________________________________________________________________
Name: svn:keywords
   + Id

Deleted: trunk/freenet/src/freenet/plugin/HttpPlugin.java
===================================================================
--- trunk/freenet/src/freenet/plugin/HttpPlugin.java    2006-12-13 20:53:44 UTC 
(rev 11382)
+++ trunk/freenet/src/freenet/plugin/HttpPlugin.java    2006-12-13 21:41:51 UTC 
(rev 11383)
@@ -1,48 +0,0 @@
-/* This code is part of Freenet. It is distributed under the GNU General
- * Public License, version 2 (or at your option any later version). See
- * http://www.gnu.org/ for further details of the GPL. */
-package freenet.plugin;
-
-import java.io.IOException;
-
-import freenet.clients.http.HTTPRequest;
-import freenet.clients.http.ToadletContext;
-import freenet.clients.http.ToadletContextClosedException;
-
-/**
- * Interface for plugins that support HTTP interaction.
- * 
- * @author David 'Bombe' Roden &lt;bombe at freenetproject.org&gt;
- * @version $Id$
- */
-public interface HttpPlugin extends Plugin {
-
-       /**
-        * Handles the GET request.
-        * 
-        * @param request
-        *            The request used to interact with this plugin
-        * @param context
-        *            The context of the HTTP request
-        * @throws IOException
-        *             if an I/O error occurs
-        * @throws ToadletContextClosedException
-        *             if the context has already been closed.
-        */
-       public void handleGet(HTTPRequest request, ToadletContext context) 
throws IOException, ToadletContextClosedException;
-
-       /**
-        * Handles the POST request.
-        * 
-        * @param request
-        *            The request used to interact with this plugin
-        * @param context
-        *            The context of the HTTP request
-        * @throws IOException
-        *             if an I/O error occurs
-        * @throws ToadletContextClosedException
-        *             if the context has already been closed.
-        */
-       public void handlePost(HTTPRequest request, ToadletContext context) 
throws IOException, ToadletContextClosedException;
-
-}

Deleted: trunk/freenet/src/freenet/plugin/Plugin.java
===================================================================
--- trunk/freenet/src/freenet/plugin/Plugin.java        2006-12-13 20:53:44 UTC 
(rev 11382)
+++ trunk/freenet/src/freenet/plugin/Plugin.java        2006-12-13 21:41:51 UTC 
(rev 11383)
@@ -1,40 +0,0 @@
-/* This code is part of Freenet. It is distributed under the GNU General
- * Public License, version 2 (or at your option any later version). See
- * http://www.gnu.org/ for further details of the GPL. */
-package freenet.plugin;
-
-/**
- * Interface for Fred plugins.
- * 
- * @author David 'Bombe' Roden &lt;bombe at freenetproject.org&gt;
- * @version $Id$
- */
-public interface Plugin {
-
-       /**
-        * Returns the name of the plugin.
-        * 
-        * @return The name of the plugin
-        */
-       public String getPluginName();
-
-       /**
-        * Sets the plugin manager that manages this plugin.
-        * 
-        * @param pluginManager
-        *            The plugin manager
-        */
-       public void setPluginManager(PluginManager pluginManager);
-
-       /**
-        * Starts the plugin. If the plugin needs threads they have to be 
started
-        * here.
-        */
-       public void startPlugin();
-
-       /**
-        * Stops the plugin.
-        */
-       public void stopPlugin();
-
-}

Deleted: trunk/freenet/src/freenet/plugin/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/plugin/PluginManager.java 2006-12-13 20:53:44 UTC 
(rev 11382)
+++ trunk/freenet/src/freenet/plugin/PluginManager.java 2006-12-13 21:41:51 UTC 
(rev 11383)
@@ -1,241 +0,0 @@
-/* This code is part of Freenet. It is distributed under the GNU General
- * Public License, version 2 (or at your option any later version). See
- * http://www.gnu.org/ for further details of the GPL. */
-package freenet.plugin;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import freenet.config.InvalidConfigValueException;
-import freenet.config.StringArrCallback;
-import freenet.config.StringArrOption;
-import freenet.config.SubConfig;
-import freenet.node.Node;
-import freenet.node.NodeClientCore;
-import freenet.support.Logger;
-
-/**
- * Manages plugins.
- * 
- * @author David 'Bombe' Roden &lt;bombe at freenetproject.org&gt;
- * @version $Id$
- */
-public class PluginManager {
-
-       /** Object used for synchronization. */
-       private final Object syncObject = new Object();
-
-       /** The node. */
-       private final Node node;
-
-       /** The configuration of this plugin manager. */
-       private final SubConfig config;
-
-       /** Currently loaded plugins. */
-       private List plugins = new ArrayList();
-
-       /**
-        * Creates a new plugin manager.
-        * 
-        * @param node
-        *            The node
-        */
-       public PluginManager(Node node) {
-               this.node = node;
-
-               config = new SubConfig("pluginmanager2", node.config);
-               config.register("loadedPlugins", new String[0], 9, true, true, 
"Plugins to load on start up", "A list of plugins that are started when the 
node starts", new StringArrCallback() {
-
-                       /**
-                        * Returns the current value of this option.
-                        * 
-                        * @see freenet.config.StringArrCallback#get()
-                        * @return The current value of this option
-                        */
-                       public String get() {
-                               if(plugins.size() == 0) return "";
-                               StringBuffer optionValue = new StringBuffer();
-                               synchronized (syncObject) {
-                                       Iterator pluginIterator = 
plugins.iterator();
-                                       while (pluginIterator.hasNext()) {
-                                               Plugin plugin = (Plugin) 
pluginIterator.next();
-                                               if (optionValue.length() != 0) {
-                                                       
optionValue.append(StringArrOption.delimiter);
-                                               }
-                                               
optionValue.append(StringArrOption.encode(plugin.getClass().getName()));
-                                       }
-                               }
-                               if(Logger.shouldLog(Logger.MINOR, this))
-                                       Logger.minor(this, "Plugin list: 
"+optionValue.toString());
-                               return optionValue.toString();
-                       };
-
-                       /**
-                        * Sets the new value of this option.
-                        * 
-                        * @see 
freenet.config.StringArrCallback#set(java.lang.String)
-                        * @param val
-                        *            The new value
-                        * @throws InvalidConfigValueException
-                        *             if setting the value is not allowed, or 
the new value
-                        *             is not valid
-                        */
-                       public void set(String val) throws 
InvalidConfigValueException {
-                               if(val == null || get().indexOf(val) >= 0) 
return;
-                               // it's probably silly as it won't allow more 
than 1 plugin to be loaded
-                               addPlugin(val, true);
-                       };
-               });
-
-               String[] loadedPluginNames = 
config.getStringArr("loadedPlugins");
-               if (loadedPluginNames != null && loadedPluginNames.length > 0) {
-                       for (int pluginIndex = 0, pluginCount = 
loadedPluginNames.length; pluginIndex < pluginCount; pluginIndex++) {
-                               String pluginName = 
StringArrOption.decode(loadedPluginNames[pluginIndex]);
-                               try {
-                                       addPlugin(pluginName, false);
-                               } catch (Throwable t) {
-                                       Logger.error(this, "Failed to load 
plugin "+pluginName+" : "+t, t);
-                               }
-                       }
-               }
-
-               config.finishedInitialization();
-       }
-
-       /**
-        * Returns the node that created this plugin manager.
-        * 
-        * @return The node that created this plugin manager
-        */
-       public Node getNode() {
-               return node;
-       }
-
-       /**
-        * Returns all currently loaded plugins. The array is returned in no
-        * particular order.
-        * 
-        * @return All currently loaded plugins
-        */
-       public Plugin[] getPlugins() {
-               synchronized (syncObject) {
-                       return (Plugin[]) plugins.toArray(new 
Plugin[plugins.size()]);
-               }
-       }
-
-       /**
-        * Adds a plugin to the plugin manager. The name can contain a URL for 
a jar
-        * file from which the plugin is then loaded. If it does the URL and the
-        * plugin name are separated by a '@', e.g.
-        * 'plugin.TestPlugin at http://www.example.com/test.jar'. URLs can 
contain
-        * every protocol your VM understands.
-        * 
-        * @see URL
-        * @param pluginName
-        *            The name of the plugin
-        */
-       public void addPlugin(String pluginName, final boolean store) throws 
IllegalArgumentException {
-               if(Logger.shouldLog(Logger.MINOR, this)) 
-                       Logger.minor(this, "Loading plugin 
"+pluginName+(store?"" : " (don't store afterwards)"));
-               final Plugin newPlugin = createPlugin(pluginName);
-               if (newPlugin == null) {
-                       throw new IllegalArgumentException();
-               }
-               newPlugin.setPluginManager(this);
-               synchronized (syncObject) {
-                       plugins.add(newPlugin);
-               }
-               node.ps.queueTimedJob(new Runnable() {
-                       public void run() {
-                               try{
-                                       while(!node.isHasStarted())
-                                               Thread.sleep(1000);
-                               }catch (InterruptedException e) {}
-                               newPlugin.startPlugin();
-                               if(store)
-                                       node.clientCore.storeConfig();
-                       }
-               }, 0);
-               
-       }
-
-       /**
-        * Remoes the plugin from the list of running plugins. The plugin is 
stopped
-        * before removing it.
-        * 
-        * @param plugin
-        *            The plugin to remove
-        */
-       public void removePlugin(Plugin plugin, boolean store) {
-               plugin.stopPlugin();
-               synchronized (syncObject) {
-                       plugins.remove(plugin);
-               }
-               if(store)
-                       node.clientCore.storeConfig();
-       }
-
-       /**
-        * Creates a plugin from a name. The name can contain a URL for a jar 
file
-        * from which the plugin is then loaded. If it does the URL and the 
plugin
-        * name are separated by a '@', e.g.
-        * 'plugin.TestPlugin at http://www.example.com/test.jar'. URLs can 
contain
-        * every protocol your VM understands.
-        * <p>
-        * <b>WARNING:</b> The code to load JAR files from URLs has <b>not</b>
-        * been tested.
-        * 
-        * @see URL
-        * @param pluginName
-        *            The name of the plugin
-        * @return The created plugin, or <code>null</code> if the plugin could
-        *         not be created
-        */
-       private Plugin createPlugin(String pluginName) {
-               int p = pluginName.indexOf('@');
-               String pluginSource = null;
-               
-               /* split up */
-               if (p > -1) {
-                       pluginSource = pluginName.substring(p + 1);
-                       pluginName = pluginName.substring(0, p);
-               }
-
-               /* load jar file */
-               ClassLoader classLoader = getClass().getClassLoader();
-               if (pluginSource != null) {
-                       try {
-                               URL pluginSourceUrl = new URL(pluginSource);
-                               classLoader = new URLClassLoader(new URL[] { 
pluginSourceUrl });
-                       } catch (MalformedURLException mue1) {
-                               Logger.normal(this, "could not create class 
loader", mue1);
-                               return null;
-                       }
-               }
-
-               /* load class from class loader */
-               try {
-                       Class pluginClass = classLoader.loadClass(pluginName);
-                       if (Plugin.class.isAssignableFrom(pluginClass)) {
-                               Plugin plugin = (Plugin) 
pluginClass.newInstance();
-                               return plugin;
-                       }
-               } catch (ClassNotFoundException e) {
-                       Logger.normal(this, "could not find plugin class: " + 
pluginName+" : "+e, e);
-               } catch (InstantiationException e) {
-                       Logger.normal(this, "could not instantiate plugin 
class: " + pluginName+" : "+e, e);
-               } catch (IllegalAccessException e) {
-                       Logger.normal(this, "could not instantiate plugin 
class: " + pluginName+" : "+e, e);
-               }
-               return null;
-       }
-
-       public NodeClientCore getClientCore() {
-               return node.clientCore;
-       }
-
-}

Deleted: trunk/freenet/src/freenet/plugin/TestHttpPlugin.java
===================================================================
--- trunk/freenet/src/freenet/plugin/TestHttpPlugin.java        2006-12-13 
20:53:44 UTC (rev 11382)
+++ trunk/freenet/src/freenet/plugin/TestHttpPlugin.java        2006-12-13 
21:41:51 UTC (rev 11383)
@@ -1,62 +0,0 @@
-/* This code is part of Freenet. It is distributed under the GNU General
- * Public License, version 2 (or at your option any later version). See
- * http://www.gnu.org/ for further details of the GPL. */
-package freenet.plugin;
-
-import java.io.IOException;
-
-import freenet.clients.http.HTTPRequest;
-import freenet.clients.http.ToadletContext;
-import freenet.clients.http.ToadletContextClosedException;
-import freenet.support.MultiValueTable;
-
-/**
- * Test HTTP plugin. Outputs "Plugin works" to the browser.
- * 
- * @author David 'Bombe' Roden &lt;bombe at freenetproject.org&gt;
- * @version $Id$
- */
-public class TestHttpPlugin implements HttpPlugin {
-
-       /**
-        * @throws ToadletContextClosedException
-        * @see 
freenet.plugin.HttpPlugin#handleGet(freenet.clients.http.HTTPRequest)
-        */
-       public void handleGet(HTTPRequest request, ToadletContext context) 
throws IOException, ToadletContextClosedException {
-               byte[] messageBytes = "Plugin works.".getBytes("UTF-8");
-               context.sendReplyHeaders(200, "OK", new MultiValueTable(), 
"text/html; charset=utf-8", messageBytes.length);
-               context.writeData(messageBytes, 0, messageBytes.length);
-       }
-
-       /**
-        * @see 
freenet.plugin.HttpPlugin#handlePost(freenet.clients.http.HTTPRequest)
-        */
-       public void handlePost(HTTPRequest request, ToadletContext context) 
throws IOException, ToadletContextClosedException {
-       }
-
-       /**
-        * @see freenet.plugin.Plugin#getPluginName()
-        */
-       public String getPluginName() {
-               return "Simple HTTP Test Plugin";
-       }
-
-       /**
-        * @see 
freenet.plugin.Plugin#setPluginManager(freenet.plugin.PluginManager)
-        */
-       public void setPluginManager(PluginManager pluginManager) {
-       }
-
-       /**
-        * @see freenet.plugin.Plugin#startPlugin()
-        */
-       public void startPlugin() {
-       }
-
-       /**
-        * @see freenet.plugin.Plugin#stopPlugin()
-        */
-       public void stopPlugin() {
-       }
-
-}

Deleted: trunk/freenet/src/freenet/plugin/TestPlugin.java
===================================================================
--- trunk/freenet/src/freenet/plugin/TestPlugin.java    2006-12-13 20:53:44 UTC 
(rev 11382)
+++ trunk/freenet/src/freenet/plugin/TestPlugin.java    2006-12-13 21:41:51 UTC 
(rev 11383)
@@ -1,39 +0,0 @@
-/* This code is part of Freenet. It is distributed under the GNU General
- * Public License, version 2 (or at your option any later version). See
- * http://www.gnu.org/ for further details of the GPL. */
-package freenet.plugin;
-
-/**
- * Test plugin. Does absolutely nothing.
- * 
- * @author David 'Bombe' Roden &lt;bombe at freenetproject.org&gt;
- * @version $Id$
- */
-public class TestPlugin implements Plugin {
-
-       /**
-        * @see freenet.plugin.Plugin#getPluginName()
-        */
-       public String getPluginName() {
-               return "Simple Test Plugin";
-       }
-
-       /**
-        * @see 
freenet.plugin.Plugin#setPluginManager(freenet.plugin.PluginManager)
-        */
-       public void setPluginManager(PluginManager pluginManager) {
-       }
-
-       /**
-        * @see freenet.plugin.Plugin#startPlugin()
-        */
-       public void startPlugin() {
-       }
-
-       /**
-        * @see freenet.plugin.Plugin#stopPlugin()
-        */
-       public void stopPlugin() {
-       }
-
-}

Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2006-12-13 
20:53:44 UTC (rev 11382)
+++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2006-12-13 
21:41:51 UTC (rev 11383)
@@ -350,6 +350,8 @@

                                        URL url = new URL("jar:"+realURL+"!/");
                                        JarURLConnection jarConnection = 
(JarURLConnection)url.openConnection();
+                                       // Java seems to cache even file: 
urls...
+                                       jarConnection.setUseCaches(false);
                                        JarFile jf = jarConnection.getJarFile();
                                        //URLJarFile jf = new URLJarFile(new 
File(liburi));
                                        //is = 
jf.getInputStream(jf.getJarEntry("META-INF/MANIFEST.MF"));


Reply via email to