📄 pluginmanager.java
字号:
toRemove.add(w);
}
}
}
}
}
}
for (Iterator i = toRemove.iterator(); i.hasNext();) {
PluginDefinition w = (PluginDefinition) i.next();
plugins.remove(w);
}
}
public PluginDefinition getPluginDefinition(String name) {
return (PluginDefinition) pluginDefinitionMap.get(name);
}
public void start() {
for (Iterator i = pluginDefinitions.iterator(); i.hasNext();) {
PluginDefinition w = (PluginDefinition) i.next();
Plugin plugin = (Plugin) pluginMap.get(w.getDescriptor().getId());
if (plugin == null) {
log.error("No plugin instance named " + w.getDescriptor().getId());
} else {
try {
plugin.startPlugin();
w.getStatus().status = STATUS_STARTED;
} catch (PluginException pe) {
w.getStatus().exception = pe;
w.getStatus().status = STATUS_ERRORED;
log.error("Failed to start plugin " + w.getDescriptor().getId() + ".", pe);
try {
if (plugin.canStopPlugin()) {
plugin.stopPlugin();
}
} catch (Throwable t2) {
log.error("Failed to stop plugin " + plugin.getClass(), t2);
}
}
}
}
/*
* Now get the started plugins and test it against the last known
* started plugins. If this changes the clear out the JSP cache
*/
StringBuffer startedPlugins = new StringBuffer();
for (Iterator i = plugins(); i.hasNext();) {
Plugin p = (Plugin) i.next();
PluginDefinition def = getPluginDefinition(p);
if (def.getStatus().getStatus() == PluginManager.STATUS_STARTED) {
if (startedPlugins.length() > 0) {
startedPlugins.append(',');
}
startedPlugins.append(def.getDescriptor().getId());
}
}
String lastStartedPlugins = PREF.get("lastStartedPlugins", "");
if (!lastStartedPlugins.equals(startedPlugins.toString())) {
if (log.isInfoEnabled())
log.info("Plugin state has changed, clearing JSP cache.");
File tmpDir = new File(ContextHolder.getContext().getTempDirectory(), "org");
if (tmpDir.exists()) {
Util.delTree(tmpDir);
}
PREF.put("lastStartedPlugins", startedPlugins.toString());
}
}
public boolean isStopping() {
return stopping;
}
public void stop() {
stopping = true;
try {
for (Iterator i = pluginDefinitions.iterator(); i.hasNext();) {
PluginDefinition w = (PluginDefinition) i.next();
Plugin plugin = (Plugin) pluginMap.get(w.getDescriptor().getId());
if (plugin == null) {
log.error("No plugin instance named " + w.getDescriptor().getId());
} else {
try {
if (plugin.canStopPlugin()) {
plugin.stopPlugin();
w.getStatus().status = STATUS_STOPPED;
}
} catch (Throwable te) {
w.getStatus().exception = te;
log.error("Failed to stop plugin " + w.getDescriptor().getId() + ".", te);
}
}
}
} finally {
stopping = false;
}
}
public boolean canStop() {
for (Iterator i = pluginDefinitions.iterator(); i.hasNext();) {
PluginDefinition w = (PluginDefinition) i.next();
Plugin plugin = (Plugin) pluginMap.get(w.getDescriptor().getId());
if (plugin == null) {
log.error("No plugin instance named " + w.getDescriptor().getId());
}
if (!plugin.canStopPlugin())
return false;
}
return true;
}
public Iterator plugins() {
return plugins.iterator();
}
public int getPluginCount() {
return plugins.size();
}
public Plugin getPluginAt(int r) {
return ((Plugin) plugins.get(r));
}
public Plugin getPlugin(String name) {
return (Plugin) pluginMap.get(name);
}
public ClassLoader getPluginClassLoader() {
return classLoader;
}
public Plugin[] getPluginsOfClass(Class pluginClass) {
Vector v = new Vector();
for (Iterator i = plugins.iterator(); i.hasNext();) {
Plugin w = (Plugin) i.next();
if (pluginClass.isAssignableFrom(w.getClass()))
v.addElement(w);
}
Plugin[] p = new Plugin[v.size()];
v.copyInto(p);
return p;
}
public Class loadClass(String plugin, String className) throws ClassNotFoundException {
Plugin p = getPlugin(plugin);
if (p == null) {
throw new ClassNotFoundException("The plugin " + plugin + " could not be located.");
}
return p.getClass().getClassLoader().loadClass(className);
}
public void removePlugin(Plugin plugin) {
for (Iterator i = pluginMap.entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
if (entry.getValue() == plugin) {
PluginDefinition def = getPluginDefinition(entry.getKey().toString());
plugins.remove(plugin);
pluginMap.remove(entry.getKey().toString());
pluginDefinitions.remove(def);
pluginDefinitionMap.remove(entry.getKey().toString());
break;
}
}
}
public PluginDefinition getPluginDefinition(Plugin plugin) {
for (Iterator i = pluginMap.entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
if (entry.getValue() == plugin) {
PluginDefinition def = getPluginDefinition(entry.getKey().toString());
return def;
}
}
return null;
}
/**
*
*/
public void removeAllPluginDefinitions() {
pluginDefinitions.clear();
pluginDefinitionMap.clear();
}
/**
* @return
*/
public Iterator pluginDefinitions() {
return pluginDefinitions.iterator();
}
/**
* Check if the {@link Plugin#installPlugin()} method should be run
* on each known plugin.
*/
public void install() {
Preferences p = ContextHolder.getContext().getPreferences().node("installed");
for (Iterator i = pluginDefinitions.iterator(); i.hasNext();) {
PluginDefinition w = (PluginDefinition) i.next();
Plugin plugin = (Plugin) pluginMap.get(w.getDescriptor().getId());
if (plugin == null) {
log.error("No plugin instance named " + w.getDescriptor().getId());
} else {
try {
if(!p.getBoolean(w.getDescriptor().getId(), false)) {
log.info("Installing plugin " + w.getDescriptor().getId() + ".");
plugin.installPlugin();
p.putBoolean(w.getDescriptor().getId(), true);
}
} catch (PluginException pe) {
log.error("Failed to install plugin " + w.getDescriptor().getId() + ".", pe);
}
}
}
}
/**
* Uninstall the pluging with the specified ID
*
* @param id
* @throws PluginException if no such plugin exists or error occurs during uninstallation
*/
public void uninstall(String id) throws PluginException {
Preferences p = ContextHolder.getContext().getPreferences().node("installed");
Plugin plugin = (Plugin) pluginMap.get(id);
if (plugin == null) {
throw new PluginException("No plugin instance named " + id);
} else {
try {
plugin.uninstallPlugin();
}
finally {
p.remove(id);
}
}
}
/**
* Reset the 'installed' flag so that the plugin is installed again the
* next time the plugin manager (the server) starts again.
*
* @param id id
*/
public void installOnNextStart(String id) {
Preferences p = PREF.node("installed");
p.remove(id);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -