Very nice. I assume we retry 5 times just as with the old code?

Long term, Freenet-based plugins will need a revocation URL etc, of course.

It's great that somebody is dealing with this. I doubt very much I'd have time 
to, but it's an important feature for 0.8.

I assume that we always download on startup with the new code? Is there any 
caching of the previous downloaded version (for URL-based plugins)?

On Monday 28 July 2008 13:58, saces at freenetproject.org wrote:
> Author: saces
> Date: 2008-07-28 12:58:02 +0000 (Mon, 28 Jul 2008)
> New Revision: 21444
> 
> Added:
>    trunk/freenet/src/freenet/pluginmanager/PluginDownLoader.java
>    trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFile.java
>    trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFreenet.java
>    trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderOfficial.java
>    trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderURL.java
> Log:
> new plugin downloader for pluginmanager
> 
> Added: trunk/freenet/src/freenet/pluginmanager/PluginDownLoader.java
> ===================================================================
> --- trunk/freenet/src/freenet/pluginmanager/PluginDownLoader.java             
>                 
(rev 0)
> +++ trunk/freenet/src/freenet/pluginmanager/PluginDownLoader.java     
> 2008-07-28 
12:58:02 UTC (rev 21444)
> @@ -0,0 +1,33 @@
> +/* 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.pluginmanager;
> +
> +import java.io.IOException;
> +import java.io.InputStream;
> +
> +/**
> + * load a plugin from wherever 
> + * @author saces
> + *
> + */
> +public abstract class PluginDownLoader<T> {
> +     
> +     private T source;
> +
> +     public String setSource(String source) throws PluginNotFoundException {
> +             this.source = checkSource(source);
> +             return getPluginName(source);
> +     }
> +
> +     public T getSource() {
> +             return source;
> +     }
> +     
> +     abstract InputStream getInputStream() throws IOException, 
PluginNotFoundException;
> +     
> +     abstract T checkSource(String source) throws PluginNotFoundException;
> +     
> +     abstract String getPluginName(String source) throws 
PluginNotFoundException;
> +
> +}
> 
> 
> Property changes on: 
trunk/freenet/src/freenet/pluginmanager/PluginDownLoader.java
> ___________________________________________________________________
> Name: svn:mime-type
>    + text/plain
> 
> Added: trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFile.java
> ===================================================================
> --- trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFile.java         
>                 
(rev 0)
> +++ trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFile.java 
2008-07-28 12:58:02 UTC (rev 21444)
> @@ -0,0 +1,27 @@
> +/* 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.pluginmanager;
> +
> +import java.io.File;
> +import java.io.FileInputStream;
> +import java.io.IOException;
> +import java.io.InputStream;
> +
> +public class PluginDownLoaderFile extends PluginDownLoader<File> {
> +
> +     public File checkSource(String source) {
> +             return new File(source);
> +     }
> +
> +     @Override
> +     InputStream getInputStream() throws IOException {
> +             return new FileInputStream(getSource());
> +     }
> +
> +     @Override
> +     String getPluginName(String source) throws PluginNotFoundException {
> +             return source.substring(source.lastIndexOf('/') + 1);
> +     }
> +
> +}
> 
> 
> Property changes on: 
trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFile.java
> ___________________________________________________________________
> Name: svn:mime-type
>    + text/plain
> 
> Added: trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFreenet.java
> ===================================================================
> --- trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFreenet.java      
>                         
(rev 0)
> +++ trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFreenet.java      
2008-07-28 12:58:02 UTC (rev 21444)
> @@ -0,0 +1,49 @@
> +/* 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.pluginmanager;
> +
> +import java.io.IOException;
> +import java.io.InputStream;
> +import java.net.MalformedURLException;
> +
> +import freenet.client.FetchException;
> +import freenet.client.FetchResult;
> +import freenet.client.HighLevelSimpleClient;
> +import freenet.keys.FreenetURI;
> +import freenet.support.Logger;
> +
> +public class PluginDownLoaderFreenet extends PluginDownLoader<FreenetURI> {
> +     
> +     final HighLevelSimpleClient hlsc;
> +     
> +     PluginDownLoaderFreenet(HighLevelSimpleClient hlsc) {
> +             this.hlsc = hlsc;
> +     }
> +
> +     public FreenetURI checkSource(String source) throws 
PluginNotFoundException {
> +             try {
> +                     return new FreenetURI(source);
> +             } catch (MalformedURLException e) {
> +                     Logger.error(this, "not a valid freenet key: " + 
> source, e);
> +                     throw new PluginNotFoundException("not a valid freenet 
> key: " + source, 
e);
> +             }
> +     }
> +
> +     @Override
> +     InputStream getInputStream() throws IOException, 
> PluginNotFoundException {
> +             try {
> +                     FetchResult fres = hlsc.fetch(getSource());
> +                     return fres.asBucket().getInputStream();
> +             } catch (FetchException e) {
> +                     Logger.error(this, "error while fetching plugin: " + 
> getSource(), e);
> +                     throw new PluginNotFoundException("error while fetching 
> plugin: " + 
getSource(), e);
> +             }
> +     }
> +
> +     @Override
> +     String getPluginName(String source) throws PluginNotFoundException {
> +             return source.substring(source.lastIndexOf('/') + 1);
> +     }
> +
> +}
> 
> 
> Property changes on: 
trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderFreenet.java
> ___________________________________________________________________
> Name: svn:mime-type
>    + text/plain
> 
> Added: trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderOfficial.java
> ===================================================================
> --- trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderOfficial.java     
>                         
(rev 0)
> +++ trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderOfficial.java     
2008-07-28 12:58:02 UTC (rev 21444)
> @@ -0,0 +1,19 @@
> +/* 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.pluginmanager;
> +
> +import java.net.URL;
> +
> +public class PluginDownLoaderOfficial extends PluginDownLoaderURL {
> +
> +     public URL checkSource(String source) throws PluginNotFoundException {
> +             return 
super.checkSource("http://downloads.freenetproject.org/alpha/plugins/"; + 
source + ".jar.url");
> +     }
> +
> +     @Override
> +     String getPluginName(String source) throws PluginNotFoundException {
> +             return source;
> +     }
> +
> +}
> 
> 
> Property changes on: 
trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderOfficial.java
> ___________________________________________________________________
> Name: svn:mime-type
>    + text/plain
> 
> Added: trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderURL.java
> ===================================================================
> --- trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderURL.java          
>                 
(rev 0)
> +++ trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderURL.java  
2008-07-28 12:58:02 UTC (rev 21444)
> @@ -0,0 +1,43 @@
> +/* 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.pluginmanager;
> +
> +import java.io.IOException;
> +import java.io.InputStream;
> +import java.net.MalformedURLException;
> +import java.net.URL;
> +import java.net.URLConnection;
> +
> +import freenet.support.Logger;
> +
> +public class PluginDownLoaderURL extends PluginDownLoader<URL> {
> +
> +     public URL checkSource(String source) throws PluginNotFoundException {
> +             try {
> +                     return new URL(source);
> +             } catch (MalformedURLException e) {
> +                     Logger.error(this, "could not build plugin url for " + 
> source, e);
> +                     throw new PluginNotFoundException("could not build 
> plugin url for " + 
source, e);
> +             }
> +     }
> +
> +     @Override
> +     InputStream getInputStream() throws IOException {
> +             URLConnection urlConnection = getSource().openConnection();
> +             urlConnection.setUseCaches(false);
> +             urlConnection.setAllowUserInteraction(false);
> +             urlConnection.connect();
> +             return urlConnection.getInputStream();
> +     }
> +
> +     @Override
> +     String getPluginName(String source) throws PluginNotFoundException {
> +             String name = source.substring(source.lastIndexOf('/') + 1);
> +             if (name.endsWith(".url")) {
> +                     name = name.substring(0, name.length() - 4);
> +             }
> +             return name;
> +     }
> +
> +}
> 
> 
> Property changes on: 
trunk/freenet/src/freenet/pluginmanager/PluginDownLoaderURL.java
> ___________________________________________________________________
> Name: svn:mime-type
>    + text/plain
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20080801/97932281/attachment.pgp>

Reply via email to