Commit 33c65b66 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added support for downloading pluggins. JM-715

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3987 b35dd754-fafc-0310-a699-88a17e54d16e
parent 331c42cd
......@@ -16,27 +16,13 @@ import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.jivesoftware.admin.AdminConsole;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.Version;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.database.DbConnectionManager;
import java.io.File;
import java.io.FileFilter;
import java.io.FileOutputStream;
import java.io.InputStream;
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.io.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
......@@ -119,6 +105,48 @@ public class PluginManager {
childPluginMap.clear();
}
/**
* Installs or updates an existing plugin.
*
* @param in the input stream that contains the new plugin definition.
* @param pluginFilename the filename of the plugin to create or update.
* @return true if the plugin was successfully installed or updated.
*/
public boolean installPlugin(InputStream in, String pluginFilename) {
try {
byte[] b = new byte[1024];
int len;
// Absolute path to the plugin file
String absolutePath = pluginDirectory + File.separator + pluginFilename;
// Save input stream contents to a temp file
OutputStream out = new FileOutputStream(absolutePath + ".part");
while ((len = in.read(b)) != -1) {
//write byte to file
out.write(b, 0, len);
}
out.close();
// Delete old .jar (if it exists)
new File(absolutePath).delete();
// Rename temp file to .jar
new File(absolutePath + ".part").renameTo(new File(absolutePath));
}
catch (IOException e) {
Log.error("Error installing new version of plugin: " + pluginFilename, e);
return false;
}
return true;
}
/**
* Returns true if the specified filename, that belongs to a plugin, exists.
*
* @param pluginFilename the filename of the plugin to create or update.
* @return true if the specified filename, that belongs to a plugin, exists.
*/
public boolean isPluginDownloaded(String pluginFilename) {
return new File(pluginDirectory + File.separator + pluginFilename).exists();
}
/**
* Returns a Collection of all installed plugins.
*
......
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