Author: cyberdo
Date: 2006-02-22 23:28:55 +0000 (Wed, 22 Feb 2006)
New Revision: 8122

Modified:
   trunk/freenet/src/freenet/node/TextModeClientInterface.java
   trunk/freenet/src/freenet/node/Version.java
   trunk/freenet/src/freenet/pluginmanager/PluginManager.java
Log:
471:
Added additional help for "PLUGLOAD:"
PLUGLOAD: now handles redirecting URLs (textfiles containing other urls)
This is done by looking at the end of the url (".url" == redirect).
No recursive redirect though.


Modified: trunk/freenet/src/freenet/node/TextModeClientInterface.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterface.java 2006-02-22 
23:18:54 UTC (rev 8121)
+++ trunk/freenet/src/freenet/node/TextModeClientInterface.java 2006-02-22 
23:28:55 UTC (rev 8122)
@@ -103,7 +103,8 @@
         System.out.println("MAKESSK - Create an SSK keypair.");
         System.out.println("PUTSSK:<insert uri>;<url to redirect to> - Insert 
an SSK redirect to a file already inserted.");
         System.out.println("PUTSSKDIR:<insert uri>#<path>[#<defaultfile>] - 
Insert an entire directory to an SSK.");
-        System.out.println("PLUGLOAD: <pkg.classname>[@file:<jarfile.jar>] - 
Load plugin.");
+        System.out.println("PLUGLOAD: - Load plugin. (use \"PLUGLOAD:?\" for 
more info)");
+        //System.out.println("PLUGLOAD: <pkg.classname>[(@<URI to 
jarfile.jar>|<<URI to file containing real URI>|* (will load from freenets 
pluginpool))] - Load plugin.");
         System.out.println("PLUGLIST - List all loaded plugins.");
         System.out.println("PLUGKILL: <pluginID> - Unload the plugin with the 
given ID (see PLUGLIST).");
 //        System.out.println("PUBLISH:<name> - create a publish/subscribe 
stream called <name>");
@@ -510,7 +511,20 @@
                disconnect(ipAndPort.trim());

         } else if(uline.startsWith("PLUGLOAD:")) {
-               
n.pluginManager.startPlugin(line.substring("PLUGLOAD:".length()).trim());
+               if (line.substring("PLUGLOAD:".length()).trim().equals("?")) {
+                       System.out.println("  PLUGLOAD: pkg.Class               
         - Load plugin from current classpath");                        
+                       System.out.println("  PLUGLOAD: pkg.Class at 
file:<filename>        - Load plugin from file");
+                       System.out.println("  PLUGLOAD: pkg.Class at http://... 
            - Load plugin from online file");
+                       System.out.println("");
+                       System.out.println("If the filename/url ends with 
\".url\", it" +
+                                       " is treated as a link, meaning that 
the first line is" +
+                                       " the accual URL. Else it is loaded as 
classpath and" +
+                                       " the class it loaded from it (meaning 
the file could" +
+                                       " be either a jar-file or a 
class-file).");
+                       
+               } else
+                       
n.pluginManager.startPlugin(line.substring("PLUGLOAD:".length()).trim());
+            //System.out.println("PLUGLOAD: <pkg.classname>[(@<URI to 
jarfile.jar>|<<URI to file containing real URI>|* (will load from freenets 
pluginpool))] - Load plugin.");
         } else if(uline.startsWith("PLUGLIST")) {
                System.out.println(n.pluginManager.dumpPlugins());
         } else if(uline.startsWith("PLUGKILL:")) {

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-02-22 23:18:54 UTC (rev 
8121)
+++ trunk/freenet/src/freenet/node/Version.java 2006-02-22 23:28:55 UTC (rev 
8122)
@@ -20,7 +20,7 @@
        public static final String protocolVersion = "1.0";

        /** The build number of the current revision */
-       private static final int buildNumber = 470;
+       private static final int buildNumber = 471;

        /** Oldest build of Fred we will talk to */
        private static final int lastGoodBuild = 403;

Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2006-02-22 
23:18:54 UTC (rev 8121)
+++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2006-02-22 
23:28:55 UTC (rev 8122)
@@ -1,7 +1,10 @@
 package freenet.pluginmanager;

+import java.io.BufferedReader;
+import java.io.InputStreamReader;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.net.URLConnection;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -141,28 +144,51 @@
         */
        private FredPlugin LoadPlugin(String filename) throws 
PluginNotFoundException {
         Class cls = null;
+        if (filename.endsWith("*")) {
+               filename = filename.substring(0,filename.length()-1) + 
+               "<http://downloads.freenetproject.org/alpha/plugins/"; + 
+               filename.substring(filename.lastIndexOf(".")+1, 
filename.length()-1) +
+               ".jar.url";
+               System.out.println(filename);
+        }

-        if (filename.indexOf("@file:") >= 0) {
-            // Open from extern file
+        if ((filename.indexOf("@") >= 0)) {
+            // Open from external file
             try {
-                // Load the jar-file
-                String[] parts = filename.split("@file:");
-                if (parts.length != 2) {
-                       throw new PluginNotFoundException("Could not split at 
\"@file:\".");
-                }
-                
-                // Load the class inside file
-                URL[] serverURLs = new URL[]{new URL("file:" + parts[1])};
-                ClassLoader cl = new URLClassLoader(serverURLs);
-                cls = cl.loadClass(parts[0]);
+               String realURL = null;
+               String realClass = null;
+               
+               // Load the jar-file
+               String[] parts = filename.split("@");
+               if (parts.length != 2) {
+                       throw new PluginNotFoundException("Could not split at 
\"@\".");
+               }
+               realClass = parts[0];
+               realURL = parts[1];
+               
+               if (filename.endsWith(".url")) {
+                               // Load the txt-file
+                               BufferedReader in;
+                               URL url = new URL(parts[1]);
+                        URLConnection uc = url.openConnection();
+                       in = new BufferedReader(
+                                       new 
InputStreamReader(uc.getInputStream()));
+                       
+                       realURL = in.readLine().trim();
+               }
+               
+               // Load the class inside file
+               URL[] serverURLs = new URL[]{new URL(realURL)};
+               ClassLoader cl = new URLClassLoader(serverURLs);
+               cls = cl.loadClass(realClass);
             } catch (Exception e) {
-                throw new PluginNotFoundException("Initialization error:"
-                               + filename, e);
+               throw new PluginNotFoundException("Initialization error:"
+                               + filename, e);
             }
         } else {
-            // Load class
-            try {
-                cls = Class.forName(filename);
+               // Load class
+               try {
+                       cls = Class.forName(filename);
             } catch (ClassNotFoundException e) {
                throw new PluginNotFoundException(filename);
             }


Reply via email to