Author: nextgens
Date: 2008-08-14 21:22:53 +0000 (Thu, 14 Aug 2008)
New Revision: 21874
Modified:
trunk/freenet/src/freenet/pluginmanager/PluginManager.java
Log:
indent
Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginManager.java 2008-08-14
21:22:13 UTC (rev 21873)
+++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java 2008-08-14
21:22:53 UTC (rev 21874)
@@ -55,12 +55,10 @@
* TODO: Synchronize
*
*/
-
private final HashMap toadletList;
/* All currently starting plugins. */
private final Set<PluginProgress> startingPlugins = new
HashSet<PluginProgress>();
-
private final Vector<PluginInfoWrapper> pluginWrappers;
final Node node;
private final NodeClientCore core;
@@ -70,23 +68,25 @@
private final HighLevelSimpleClient client;
public PluginManager(Node node) {
-
+
logMINOR = Logger.shouldLog(Logger.MINOR, this);
logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
// config
-
+
toadletList = new HashMap();
pluginWrappers = new Vector();
this.node = node;
this.core = node.clientCore;
-
- if(logMINOR) Logger.minor(this, "Starting Plugin Manager");
-
- if(logDEBUG) Logger.debug(this, "Initialize Plugin Manager
config");
-
+
+ if(logMINOR)
+ Logger.minor(this, "Starting Plugin Manager");
+
+ if(logDEBUG)
+ Logger.debug(this, "Initialize Plugin Manager config");
+
client =
core.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS, true);
-
+
pmconfig = new SubConfig("pluginmanager", node.config);
// pmconfig.register("configfile", "fplugins.ini", 9, true, true,
"PluginConfig.configFile", "PluginConfig.configFileLong",
// new StringCallback() {
@@ -117,45 +117,45 @@
// Start plugins in the config
pmconfig.register("loadplugin", null, 9, true, false,
"PluginManager.loadedOnStartup", "PluginManager.loadedOnStartupLong",
- new StringArrCallback() {
- public String[] get() {
- return getConfigLoadString();
- }
+ new StringArrCallback() {
- public void set(String[] val) throws
InvalidConfigValueException {
- //if(storeDir.equals(new File(val))) return;
- // FIXME
- throw new
InvalidConfigValueException(L10n.getString("PluginManager.cannotSetOnceLoaded"));
- }
+ public String[] get() {
+ return getConfigLoadString();
+ }
- public boolean isReadOnly() {
- return true;
- }
- });
+ public void set(String[] val) throws
InvalidConfigValueException {
+ //if(storeDir.equals(new File(val)))
return;
+ // FIXME
+ throw new
InvalidConfigValueException(L10n.getString("PluginManager.cannotSetOnceLoaded"));
+ }
+ public boolean isReadOnly() {
+ return true;
+ }
+ });
+
String fns[] = pmconfig.getStringArr("loadplugin");
- if (fns != null) {
- for (String name : fns)
+ if(fns != null)
+ for(String name : fns)
startPluginAuto(name, false);
- }
pmconfig.finishedInitialization();
}
private String[] getConfigLoadString() {
- try{
+ try {
Iterator it = getPlugins().iterator();
Vector v = new Vector();
- while (it.hasNext()) {
+ while(it.hasNext()) {
PluginInfoWrapper pluginInfoWrapper =
(PluginInfoWrapper) it.next();
v.add(pluginInfoWrapper.getFilename());
}
return (String[]) v.toArray(new String[v.size()]);
- }catch (NullPointerException e){
- Logger.error(this, "error while loading plugins:
disabling them:"+e);
+ } catch(NullPointerException e) {
+ Logger.error(this, "error while loading plugins:
disabling them:" + e);
return new String[0];
}
}
@@ -165,32 +165,30 @@
*
* @return All currently starting plugins
*/
- public Set/* <PluginProgess> */getStartingPlugins() {
- synchronized (startingPlugins) {
+ public Set/* <PluginProgess> */ getStartingPlugins() {
+ synchronized(startingPlugins) {
return new HashSet/* <PluginProgress>
*/(startingPlugins);
}
}
-
-
// try to guess around...
public void startPluginAuto(final String pluginname, boolean store) {
-
- if (isOfficialPlugin(pluginname)) {
+
+ if(isOfficialPlugin(pluginname)) {
startPluginOfficial(pluginname, store);
return;
}
-
+
try {
FreenetURI uri = new FreenetURI(pluginname);
startPluginFreenet(pluginname, store);
return;
- } catch (MalformedURLException e) {
+ } catch(MalformedURLException e) {
// not a freenet key
}
-
+
File[] roots = File.listRoots();
- for (File f: roots) {
- if (pluginname.startsWith(f.getName())) {
+ for(File f : roots) {
+ if(pluginname.startsWith(f.getName())) {
startPluginFile(pluginname, store);
return;
}
@@ -198,28 +196,28 @@
startPluginURL(pluginname, store);
}
-
+
public void startPluginOfficial(final String pluginname, boolean store)
{
realStartPlugin(new PluginDownLoaderOfficial(), pluginname,
store);
}
-
+
public void startPluginFile(final String filename, boolean store) {
realStartPlugin(new PluginDownLoaderFile(), filename, store);
}
-
+
public void startPluginURL(final String filename, boolean store) {
realStartPlugin(new PluginDownLoaderURL(), filename, store);
}
-
+
public void startPluginFreenet(final String filename, boolean store) {
realStartPlugin(new PluginDownLoaderFreenet(client), filename,
true);
}
-
+
private void realStartPlugin(final PluginDownLoader pdl, final String
filename, final boolean store) {
- if (filename.trim().length() == 0)
+ if(filename.trim().length() == 0)
return;
final PluginProgress pluginProgress = new
PluginProgress(filename);
- synchronized (startingPlugins) {
+ synchronized(startingPlugins) {
startingPlugins.add(pluginProgress);
}
node.executor.execute(new Runnable() {
@@ -231,15 +229,15 @@
plug = loadPlugin(pdl, filename);
pluginProgress.setProgress(PluginProgress.STARTING);
PluginInfoWrapper pi =
PluginHandler.startPlugin(PluginManager.this, filename, plug, new
PluginRespirator(node, PluginManager.this));
- synchronized (pluginWrappers) {
+ synchronized(pluginWrappers) {
pluginWrappers.add(pi);
}
Logger.normal(this, "Plugin loaded: " +
filename);
- } catch (PluginNotFoundException e) {
+ } catch(PluginNotFoundException e) {
Logger.normal(this, "Loading plugin
failed (" + filename + ')', e);
String message = e.getMessage();
- core.alerts.register(new
SimpleUserAlert(true, l10n("pluginLoadingFailedTitle"),
l10n("pluginLoadingFailedWithMessage", new String[] { "name", "message" }, new
String[] { filename, message }), l10n("pluginLoadingFailedShort", "name",
filename), UserAlert.ERROR, PluginManager.class));
- } catch (UnsupportedClassVersionError e) {
+ core.alerts.register(new
SimpleUserAlert(true, l10n("pluginLoadingFailedTitle"),
l10n("pluginLoadingFailedWithMessage", new String[]{"name", "message"}, new
String[]{filename, message}), l10n("pluginLoadingFailedShort", "name",
filename), UserAlert.ERROR, PluginManager.class));
+ } catch(UnsupportedClassVersionError e) {
Logger.error(this, "Could not load
plugin " + filename + " : " + e, e);
System.err.println("Could not load
plugin " + filename + " : " + e);
e.printStackTrace();
@@ -247,13 +245,13 @@
Logger.error(this, "Plugin " + filename
+ " appears to require a later JVM");
core.alerts.register(new
SimpleUserAlert(true, l10n("pluginReqNewerJVMTitle", "name", filename),
l10n("pluginReqNewerJVM", "name", filename), l10n("pluginLoadingFailedShort",
"name", filename), UserAlert.ERROR, PluginManager.class));
} finally {
- synchronized (startingPlugins) {
+ synchronized(startingPlugins) {
startingPlugins.remove(pluginProgress);
}
}
/* try not to destroy the config. */
- synchronized (this) {
- if (store)
+ synchronized(this) {
+ if(store)
core.storeConfig();
}
}
@@ -263,18 +261,15 @@
void register(FredPlugin plug, PluginInfoWrapper pi) {
// handles FProxy? If so, register
- if (pi.isPproxyPlugin())
+ if(pi.isPproxyPlugin())
registerToadlet(plug);
- if(pi.isIPDetectorPlugin()) {
+ if(pi.isIPDetectorPlugin())
node.ipDetector.registerIPDetectorPlugin((FredPluginIPDetector) plug);
- }
- if(pi.isPortForwardPlugin()) {
+ if(pi.isPortForwardPlugin())
node.ipDetector.registerPortForwardPlugin((FredPluginPortForward) plug);
- }
- if(pi.isBandwidthIndicator()) {
+ if(pi.isBandwidthIndicator())
node.ipDetector.registerBandwidthIndicatorPlugin((FredPluginBandwidthIndicator)
plug);
- }
}
/**
@@ -290,7 +285,7 @@
}
private String l10n(String key, String pattern, String value) {
- return L10n.getString("PluginManager."+key, pattern, value);
+ return L10n.getString("PluginManager." + key, pattern, value);
}
/**
@@ -309,20 +304,21 @@
return L10n.getString("PluginManager." + key, patterns, values);
}
- private void registerToadlet(FredPlugin pl){
+ private void registerToadlet(FredPlugin pl) {
//toadletList.put(e.getStackTrace()[1].getClass().toString(),
pl);
- synchronized (toadletList) {
+ synchronized(toadletList) {
toadletList.put(pl.getClass().getName(), pl);
}
- Logger.normal(this, "Added HTTP handler for
/plugins/"+pl.getClass().getName()+ '/');
+ Logger.normal(this, "Added HTTP handler for /plugins/" +
pl.getClass().getName() + '/');
}
/**
* Remove a plugin from the plugin list.
*/
public void removePlugin(PluginInfoWrapper pi) {
- synchronized (pluginWrappers) {
- if(!pluginWrappers.remove(pi)) return;
+ synchronized(pluginWrappers) {
+ if(!pluginWrappers.remove(pi))
+ return;
}
core.storeConfig();
}
@@ -336,78 +332,76 @@
public void removeCachedCopy(String pluginSpecification) {
int lastSlash = pluginSpecification.lastIndexOf('/');
File pluginFile;
- if (lastSlash == -1) {
+ if(lastSlash == -1)
/* Windows, maybe? */
lastSlash = pluginSpecification.lastIndexOf('\\');
- }
File pluginDirectory = new File(node.getNodeDir(), "plugins");
- if (lastSlash == -1) {
+ if(lastSlash == -1)
/* it's an official plugin! */
pluginFile = new File(pluginDirectory,
pluginSpecification + ".jar");
- } else {
+ else
pluginFile = new File(pluginDirectory,
pluginSpecification.substring(lastSlash + 1));
- }
- if(logDEBUG) Logger.minor(this, "Delete plugin - plugname: " +
pluginSpecification + "filename: " + pluginFile.getAbsolutePath() , new
Exception("debug"));
- if (pluginFile.exists()) {
+ if(logDEBUG)
+ Logger.minor(this, "Delete plugin - plugname: " +
pluginSpecification + "filename: " + pluginFile.getAbsolutePath(), new
Exception("debug"));
+ if(pluginFile.exists())
pluginFile.delete();
- }
}
public void unregisterPluginToadlet(PluginInfoWrapper pi) {
- synchronized (toadletList) {
+ synchronized(toadletList) {
try {
toadletList.remove(pi.getPluginClassName());
- Logger.normal(this, "Removed HTTP handler for
/plugins/"+
- pi.getPluginClassName()+ '/',
new Exception("debug"));
- } catch (Throwable ex) {
+ Logger.normal(this, "Removed HTTP handler for
/plugins/" +
+ pi.getPluginClassName() + '/', new
Exception("debug"));
+ } catch(Throwable ex) {
Logger.error(this, "removing Plugin", ex);
}
}
}
public void addToadletSymlinks(PluginInfoWrapper pi) {
- synchronized (toadletList) {
+ synchronized(toadletList) {
try {
String targets[] =
pi.getPluginToadletSymlinks();
- if (targets == null)
+ if(targets == null)
return;
- for (int i = 0 ; i < targets.length ; i++) {
+ for(int i = 0; i < targets.length; i++) {
toadletList.remove(targets[i]);
Logger.normal(this, "Removed HTTP
symlink: " + targets[i] +
- " =>
/plugins/"+pi.getPluginClassName()+ '/');
+ " => /plugins/" +
pi.getPluginClassName() + '/');
}
- } catch (Throwable ex) {
+ } catch(Throwable ex) {
Logger.error(this, "removing Toadlet-link", ex);
}
}
}
public void removeToadletSymlinks(PluginInfoWrapper pi) {
- synchronized (toadletList) {
+ synchronized(toadletList) {
String rm = null;
try {
String targets[] =
pi.getPluginToadletSymlinks();
- if (targets == null)
+ if(targets == null)
return;
- for (int i = 0 ; i < targets.length ; i++) {
+ for(int i = 0; i < targets.length; i++) {
rm = targets[i];
toadletList.remove(targets[i]);
pi.removePluginToadletSymlink(targets[i]);
Logger.normal(this, "Removed HTTP
symlink: " + targets[i] +
- " =>
/plugins/"+pi.getPluginClassName()+ '/');
+ " => /plugins/" +
pi.getPluginClassName() + '/');
}
- } catch (Throwable ex) {
+ } catch(Throwable ex) {
Logger.error(this, "removing Toadlet-link: " +
rm, ex);
}
}
}
public String dumpPlugins() {
- StringBuffer out= new StringBuffer();
- synchronized (pluginWrappers) {
- for(int i=0;i<pluginWrappers.size();i++) {
+ StringBuffer out = new StringBuffer();
+ synchronized(pluginWrappers) {
+ for(int i = 0; i < pluginWrappers.size(); i++) {
PluginInfoWrapper pi = pluginWrappers.get(i);
out.append(pi.toString());
out.append('\n');
@@ -418,57 +412,57 @@
public Set getPlugins() {
HashSet out = new HashSet();
- synchronized (pluginWrappers) {
- for(int i=0;i<pluginWrappers.size();i++) {
+ synchronized(pluginWrappers) {
+ for(int i = 0; i < pluginWrappers.size(); i++) {
PluginInfoWrapper pi = pluginWrappers.get(i);
out.add(pi);
}
}
return out;
}
-
+
/**
* look for PluginInfo for a FCPPlugin with given classname
* @param plugname
* @return the PluginInfo or null if not found
*/
public PluginInfoWrapper getFCPPluginInfo(String plugname) {
- synchronized (pluginWrappers) {
- for(int i=0;i<pluginWrappers.size();i++) {
+ synchronized(pluginWrappers) {
+ for(int i = 0; i < pluginWrappers.size(); i++) {
PluginInfoWrapper pi = pluginWrappers.get(i);
- if (pi.getPluginClassName().equals(plugname))
+ if(pi.getPluginClassName().equals(plugname))
return pi;
}
}
return null;
}
-
+
/**
* look for a FCPPlugin with given classname
* @param plugname
* @return the plugin or null if not found
*/
public FredPluginFCP getFCPPlugin(String plugname) {
- synchronized (pluginWrappers) {
- for(int i=0;i<pluginWrappers.size();i++) {
+ synchronized(pluginWrappers) {
+ for(int i = 0; i < pluginWrappers.size(); i++) {
PluginInfoWrapper pi = pluginWrappers.get(i);
- if (pi.isFCPPlugin() &&
pi.getPluginClassName().equals(plugname))
+ if(pi.isFCPPlugin() &&
pi.getPluginClassName().equals(plugname))
return (FredPluginFCP) pi.plug;
}
}
return null;
}
-
+
/**
* look for a Plugin with given classname
* @param plugname
* @return the true if not found
*/
public boolean isPluginLoaded(String plugname) {
- synchronized (pluginWrappers) {
- for(int i=0;i<pluginWrappers.size();i++) {
+ synchronized(pluginWrappers) {
+ for(int i = 0; i < pluginWrappers.size(); i++) {
PluginInfoWrapper pi = pluginWrappers.get(i);
- if (pi.getPluginClassName().equals(plugname))
+ if(pi.getPluginClassName().equals(plugname))
return true;
}
}
@@ -477,30 +471,30 @@
public String handleHTTPGet(String plugin, HTTPRequest request) throws
PluginHTTPException {
FredPlugin handler = null;
- synchronized (toadletList) {
- handler = (FredPlugin)toadletList.get(plugin);
+ synchronized(toadletList) {
+ handler = (FredPlugin) toadletList.get(plugin);
}
/*if (handler == null)
- return null;
+ return null;
*/
- if (handler instanceof FredPluginHTTP)
- return ((FredPluginHTTP)handler).handleHTTPGet(request);
+ if(handler instanceof FredPluginHTTP)
+ return ((FredPluginHTTP)
handler).handleHTTPGet(request);
throw new NotFoundPluginHTTPException("Plugin not found!",
"/plugins");
}
public String handleHTTPPost(String plugin, HTTPRequest request) throws
PluginHTTPException {
FredPlugin handler = null;
- synchronized (toadletList) {
- handler = (FredPlugin)toadletList.get(plugin);
+ synchronized(toadletList) {
+ handler = (FredPlugin) toadletList.get(plugin);
}
/*if (handler == null)
- return null;
+ return null;
*/
- if (handler instanceof FredPluginHTTP)
- return
((FredPluginHTTP)handler).handleHTTPPost(request);
+ if(handler instanceof FredPluginHTTP)
+ return ((FredPluginHTTP)
handler).handleHTTPPost(request);
throw new NotFoundPluginHTTPException("Plugin not found!",
"/plugins");
}
@@ -508,36 +502,33 @@
public void killPlugin(String name, int maxWaitTime) {
PluginInfoWrapper pi = null;
boolean found = false;
- synchronized (pluginWrappers) {
- for(int i=0;i<pluginWrappers.size() && !found;i++) {
+ synchronized(pluginWrappers) {
+ for(int i = 0; i < pluginWrappers.size() && !found;
i++) {
pi = pluginWrappers.get(i);
- if (pi.getThreadName().equals(name)) {
+ if(pi.getThreadName().equals(name)) {
found = true;
break;
}
}
}
- if (found) {
+ if(found)
pi.stopPlugin(this, maxWaitTime);
- }
}
public void killPlugin(FredPlugin plugin, int maxWaitTime) {
PluginInfoWrapper pi = null;
boolean found = false;
- synchronized (pluginWrappers) {
- for(int i=0;i<pluginWrappers.size() && !found;i++) {
+ synchronized(pluginWrappers) {
+ for(int i = 0; i < pluginWrappers.size() && !found;
i++) {
pi = pluginWrappers.get(i);
- if (pi.plug == plugin) {
+ if(pi.plug == plugin)
found = true;
- }
}
}
- if (found) {
+ if(found)
pi.stopPlugin(this, maxWaitTime);
- }
}
-
+
/**
* Returns a list of the names of all available official plugins. Right
now
* this list is hardcoded but in future we could retrieve this list
from emu
@@ -546,7 +537,7 @@
* @return A list of all available plugin names
*/
public List<String> findAvailablePlugins() {
- List<String> availablePlugins = new ArrayList<String> ();
+ List<String> availablePlugins = new ArrayList<String>();
availablePlugins.add("Echo");
availablePlugins.add("Freemail");
availablePlugins.add("HelloWorld");
@@ -562,12 +553,14 @@
availablePlugins.add("XMLSpider");
return availablePlugins;
}
-
+
public boolean isOfficialPlugin(String name) {
- if ((name == null) || (name.trim().length() == 0)) return false;
+ if((name == null) || (name.trim().length() == 0))
+ return false;
List<String> availablePlugins = findAvailablePlugins();
- for(String n:availablePlugins) {
- if (n.equals(name)) return true;
+ for(String n : availablePlugins) {
+ if(n.equals(name))
+ return true;
}
return false;
}
@@ -588,12 +581,12 @@
* If anything goes wrong.
*/
private FredPlugin loadPlugin(PluginDownLoader pdl, String name) throws
PluginNotFoundException {
-
+
pdl.setSource(name);
-
+
/* check for plugin directory. */
File pluginDirectory = new File(node.getNodeDir(), "plugins");
- if ((pluginDirectory.exists() &&
!pluginDirectory.isDirectory()) || (!pluginDirectory.exists() &&
!pluginDirectory.mkdirs())) {
+ if((pluginDirectory.exists() && !pluginDirectory.isDirectory())
|| (!pluginDirectory.exists() && !pluginDirectory.mkdirs())) {
Logger.error(this, "could not create plugin directory");
throw new PluginNotFoundException("could not create
plugin directory");
}
@@ -603,12 +596,11 @@
File pluginFile = new File(pluginDirectory, filename);
/* check if file needs to be downloaded. */
- if (logMINOR) {
+ if(logMINOR)
Logger.minor(this, "plugin file " +
pluginFile.getAbsolutePath() + " exists: " + pluginFile.exists());
- }
int RETRIES = 5;
- for(int i=0;i<RETRIES;i++) {
- if (!pluginFile.exists() || pluginFile.length() == 0) {
+ for(int i = 0; i < RETRIES; i++) {
+ if(!pluginFile.exists() || pluginFile.length() == 0)
try {
File tempPluginFile = null;
OutputStream pluginOutputStream = null;
@@ -616,13 +608,13 @@
try {
tempPluginFile =
File.createTempFile("plugin-", ".jar", pluginDirectory);
tempPluginFile.deleteOnExit();
-
-
+
+
pluginOutputStream = new
FileOutputStream(tempPluginFile);
pluginInputStream =
pdl.getInputStream();
byte[] buffer = new byte[1024];
int read;
- while ((read =
pluginInputStream.read(buffer)) != -1) {
+ while((read =
pluginInputStream.read(buffer)) != -1) {
pluginOutputStream.write(buffer, 0, read);
}
pluginOutputStream.close();
@@ -632,33 +624,32 @@
Logger.error(this,
"could not rename temp file to plugin file");
throw new
PluginNotFoundException("could not rename temp file to plugin file");
}
-
+
String digest =
pdl.getSHA1sum();
- if (digest != null) {
+ if(digest != null) {
String testsum =
getFileSHA1(pluginFile);
- if
(!(digest.equalsIgnoreCase(testsum))) {
-
Logger.error(this, "Checksum verification failed, should be " +digest+ " but
was " + testsum);
- throw new
PluginNotFoundException("Checksum verification failed, should be " +digest+ "
but was " + testsum);
+
if(!(digest.equalsIgnoreCase(testsum))) {
+
Logger.error(this, "Checksum verification failed, should be " + digest + " but
was " + testsum);
+ throw new
PluginNotFoundException("Checksum verification failed, should be " + digest + "
but was " + testsum);
}
}
-
- } catch (IOException ioe1) {
+
+ } catch(IOException ioe1) {
Logger.error(this, "could not
load plugin", ioe1);
- if (tempPluginFile != null) {
+ if(tempPluginFile != null)
tempPluginFile.delete();
- }
throw new
PluginNotFoundException("could not load plugin: " + ioe1.getMessage(), ioe1);
} finally {
Closer.close(pluginOutputStream);
Closer.close(pluginInputStream);
}
- } catch (PluginNotFoundException e) {
- if(i < RETRIES-1) {
- Logger.normal(this, "Failed to
load plugin: "+e, e);
+ } catch(PluginNotFoundException e) {
+ if(i < RETRIES - 1) {
+ Logger.normal(this, "Failed to
load plugin: " + e, e);
continue;
- } else throw e;
+ } else
+ throw e;
}
- }
}
/* now get the manifest file. */
@@ -667,32 +658,32 @@
try {
pluginJarFile = new JarFile(pluginFile);
Manifest manifest = pluginJarFile.getManifest();
- if (manifest == null) {
+ if(manifest == null) {
Logger.error(this, "could not load manifest
from plugin file");
pluginFile.delete();
throw new PluginNotFoundException("could not
load manifest from plugin file");
}
Attributes mainAttributes =
manifest.getMainAttributes();
- if (mainAttributes == null) {
+ if(mainAttributes == null) {
Logger.error(this, "manifest does not contain
attributes");
pluginFile.delete();
throw new PluginNotFoundException("manifest
does not contain attributes");
}
pluginMainClassName =
mainAttributes.getValue("Plugin-Main-Class");
- if (pluginMainClassName == null) {
+ if(pluginMainClassName == null) {
Logger.error(this, "manifest does not contain a
Plugin-Main-Class attribute");
pluginFile.delete();
throw new PluginNotFoundException("manifest
does not contain a Plugin-Main-Class attribute");
}
- } catch (JarException je1) {
+ } catch(JarException je1) {
Logger.error(this, "could not process jar file", je1);
pluginFile.delete();
throw new PluginNotFoundException("could not process
jar file", je1);
- } catch (ZipException ze1) {
+ } catch(ZipException ze1) {
Logger.error(this, "could not process jar file", ze1);
pluginFile.delete();
throw new PluginNotFoundException("could not process
jar file", ze1);
- } catch (IOException ioe1) {
+ } catch(IOException ioe1) {
Logger.error(this, "error processing jar file", ioe1);
pluginFile.delete();
throw new PluginNotFoundException("error procesesing
jar file", ioe1);
@@ -704,36 +695,36 @@
JarClassLoader jarClassLoader = new
JarClassLoader(pluginFile);
Class pluginMainClass =
jarClassLoader.loadClass(pluginMainClassName);
Object object = pluginMainClass.newInstance();
- if (!(object instanceof FredPlugin)) {
+ if(!(object instanceof FredPlugin)) {
Logger.error(this, "plugin main class is not a
plugin");
pluginFile.delete();
throw new PluginNotFoundException("plugin main
class is not a plugin");
}
return (FredPlugin) object;
- } catch (IOException ioe1) {
+ } catch(IOException ioe1) {
Logger.error(this, "could not load plugin", ioe1);
pluginFile.delete();
throw new PluginNotFoundException("could not load
plugin", ioe1);
- } catch (ClassNotFoundException cnfe1) {
+ } catch(ClassNotFoundException cnfe1) {
Logger.error(this, "could not find plugin class",
cnfe1);
pluginFile.delete();
throw new PluginNotFoundException("could not find
plugin class", cnfe1);
- } catch (InstantiationException ie1) {
+ } catch(InstantiationException ie1) {
Logger.error(this, "could not instantiate plugin", ie1);
pluginFile.delete();
throw new PluginNotFoundException("could not
instantiate plugin", ie1);
- } catch (IllegalAccessException iae1) {
+ } catch(IllegalAccessException iae1) {
Logger.error(this, "could not access plugin main
class", iae1);
pluginFile.delete();
throw new PluginNotFoundException("could not access
plugin main class", iae1);
- } catch (NoClassDefFoundError ncdfe1) {
+ } catch(NoClassDefFoundError ncdfe1) {
Logger.error(this, "could not find class def, may a
missing lib?", ncdfe1);
pluginFile.delete();
throw new PluginNotFoundException("could not find class
def, may a missing lib?", ncdfe1);
- } catch (Throwable t) {
+ } catch(Throwable t) {
Logger.error(this, "unexcpected error while plugin
loading", t);
pluginFile.delete();
- throw new PluginNotFoundException("unexcpected error
while plugin loading "+t, t);
+ throw new PluginNotFoundException("unexcpected error
while plugin loading " + t, t);
}
}
@@ -742,7 +733,7 @@
MessageDigest hash = null;
FileInputStream fis = null;
BufferedInputStream bis = null;
-
+
try {
hash = MessageDigest.getInstance("SHA-1");
// We compute the hash
@@ -753,9 +744,9 @@
byte[] buffer = new byte[BUFFERSIZE];
while((len = bis.read(buffer)) > -1) {
hash.update(buffer, 0, len);
- }
- } catch (Exception e) {
- throw new PluginNotFoundException("Error while
computing sha1 hash of the downloaded plugin: "+e, e);
+ }
+ } catch(Exception e) {
+ throw new PluginNotFoundException("Error while
computing sha1 hash of the downloaded plugin: " + e, e);
} finally {
Closer.close(bis);
Closer.close(fis);
@@ -777,16 +768,12 @@
/** State for downloading. */
public static final PluginProgress DOWNLOADING = new
PluginProgress();
-
/** State for starting. */
public static final PluginProgress STARTING = new
PluginProgress();
-
/** The starting time. */
private long startingTime = System.currentTimeMillis();
-
/** The current state. */
private PluginProgress pluginProgress;
-
/** The name by which the plugin is loaded. */
private String name;
@@ -857,14 +844,11 @@
*/
@Override
public String toString() {
- if (this == DOWNLOADING) {
+ if(this == DOWNLOADING)
return "downloading";
- } else if (this == STARTING) {
+ else if(this == STARTING)
return "starting";
- }
return "PluginProgress[name=" + name + ",startingTime="
+ startingTime + ",progress=" + pluginProgress + "]";
}
-
}
-
}