📄 pluginlauncherimpl.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: PluginLauncherImpl.java
package org.gudy.azureus2.pluginsimpl.local.launch;
import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.AzureusCoreFactory;
import com.aelitis.azureus.launcher.Launcher;
import java.io.*;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.util.Constants;
import org.gudy.azureus2.core3.util.SystemProperties;
import org.gudy.azureus2.plugins.LaunchablePlugin;
import org.gudy.azureus2.plugins.Plugin;
import org.gudy.azureus2.plugins.logging.LoggerChannelListener;
import org.gudy.azureus2.pluginsimpl.PluginUtils;
// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.launch:
// PluginSingleInstanceHandler
public class PluginLauncherImpl
{
private static Map preloaded_plugins = new HashMap();
public PluginLauncherImpl()
{
}
private static void main(String args[])
{
launch(args);
}
public static void launch(String args[])
{
LoggerChannelListener listener;
LaunchablePlugin launchables[];
if (Launcher.checkAndLaunch(org/gudy/azureus2/pluginsimpl/local/launch/PluginLauncherImpl, args))
return;
COConfigurationManager.preInitialise();
listener = new LoggerChannelListener() {
public void messageLogged(int type, String content)
{
log(content, false);
}
public void messageLogged(String str, Throwable error)
{
log(str, true);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
error.printStackTrace(pw);
pw.flush();
log(sw.toString(), true);
}
protected synchronized void log(String str, boolean stdout)
{
label0:
{
File log_file = PluginLauncherImpl.getApplicationFile("launch.log");
PrintWriter pw = null;
try
{
pw = new PrintWriter(new FileWriter(log_file, true));
if (str.endsWith("\n"))
{
if (stdout)
System.err.print((new StringBuilder()).append("PluginLauncher: ").append(str).toString());
pw.print(str);
} else
{
if (stdout)
System.err.println((new StringBuilder()).append("PluginLauncher: ").append(str).toString());
pw.println(str);
}
}
catch (Throwable e)
{
if (pw != null)
pw.close();
break label0;
}
finally
{
if (pw != null)
pw.close();
throw exception1;
}
if (pw != null)
pw.close();
break label0;
}
}
};
launchables = findLaunchablePlugins(listener);
if (launchables.length == 0)
{
listener.messageLogged(3, "No launchable plugins found");
return;
}
if (launchables.length > 1)
listener.messageLogged(3, "Multiple launchable plugins found, running first");
SystemProperties.setApplicationEntryPoint("org.gudy.azureus2.plugins.PluginLauncher");
launchables[0].setDefaults(args);
if (PluginSingleInstanceHandler.process(listener, args))
return;
boolean restart;
boolean process_succeeded;
Thread core_thread = new Thread("PluginLauncher", listener) {
final LoggerChannelListener val$listener;
public void run()
{
try
{
Thread.sleep(500L);
AzureusCore azureus_core = AzureusCoreFactory.create();
azureus_core.start();
}
catch (Throwable e)
{
listener.messageLogged("PluginLauncher: launch fails", e);
}
}
{
listener = loggerchannellistener;
super(x0);
}
};
core_thread.setDaemon(true);
core_thread.start();
restart = false;
process_succeeded = false;
restart = launchables[0].process();
process_succeeded = true;
try
{
if (restart)
AzureusCoreFactory.getSingleton().restart();
else
AzureusCoreFactory.getSingleton().stop();
}
catch (Throwable e)
{
if (process_succeeded)
throw e;
}
break MISSING_BLOCK_LABEL_214;
Exception exception;
exception;
try
{
if (restart)
AzureusCoreFactory.getSingleton().restart();
else
AzureusCoreFactory.getSingleton().stop();
}
catch (Throwable e)
{
if (process_succeeded)
throw e;
}
throw exception;
Throwable e;
e;
listener.messageLogged("PluginLauncher: launch fails", e);
}
private static LaunchablePlugin[] findLaunchablePlugins(LoggerChannelListener listener)
{
List res;
File plugins[];
int i;
res = new ArrayList();
File app_dir = getApplicationFile("plugins");
if (!app_dir.exists() && app_dir.isDirectory())
{
listener.messageLogged(3, (new StringBuilder()).append("Application dir '").append(app_dir).append("' not found").toString());
return new LaunchablePlugin[0];
}
plugins = app_dir.listFiles();
if (plugins == null || plugins.length == 0)
{
listener.messageLogged(3, (new StringBuilder()).append("Application dir '").append(app_dir).append("' empty").toString());
return new LaunchablePlugin[0];
}
i = 0;
_L3:
if (i >= plugins.length) goto _L2; else goto _L1
_L1:
File plugin_dir;
plugin_dir = plugins[i];
if (!plugin_dir.isDirectory())
continue; /* Loop/switch isn't completed */
ClassLoader classLoader;
ClassLoader root_cl;
File contents[];
classLoader = org/gudy/azureus2/pluginsimpl/local/launch/PluginLauncherImpl.getClassLoader();
root_cl = classLoader;
contents = plugin_dir.listFiles();
if (contents == null || contents.length == 0)
continue; /* Loop/switch isn't completed */
Properties props;
File properties_file;
FileInputStream fis;
String plugin_version[] = {
null
};
String plugin_id[] = {
null
};
contents = getHighestJarVersions(contents, plugin_version, plugin_id, true);
for (int j = 0; j < contents.length; j++)
classLoader = addFileToClassPath(root_cl, classLoader, contents[j]);
props = new Properties();
properties_file = new File(plugin_dir, "plugin.properties");
if (!properties_file.exists())
break MISSING_BLOCK_LABEL_319;
fis = null;
fis = new FileInputStream(properties_file);
props.load(fis);
if (fis != null)
fis.close();
break MISSING_BLOCK_LABEL_358;
Exception exception;
exception;
if (fis != null)
fis.close();
throw exception;
if (classLoader instanceof URLClassLoader)
{
URLClassLoader current = (URLClassLoader)classLoader;
URL url = current.findResource("plugin.properties");
if (url != null)
props.load(url.openStream());
}
String plugin_class = (String)props.get("plugin.class");
if (plugin_class == null || plugin_class.indexOf(';') != -1)
continue; /* Loop/switch isn't completed */
try
{
Class c = classLoader.loadClass(plugin_class);
Plugin plugin = (Plugin)c.newInstance();
if (plugin instanceof LaunchablePlugin)
{
preloaded_plugins.put(plugin_class, plugin);
res.add(plugin);
}
}
catch (Throwable e)
{
listener.messageLogged((new StringBuilder()).append("Load of plugin in '").append(plugin_dir).append("' fails").toString(), e);
}
i++;
goto _L3
_L2:
LaunchablePlugin x[] = new LaunchablePlugin[res.size()];
res.toArray(x);
return x;
}
public static Plugin getPreloadedPlugin(String cla)
{
return (Plugin)preloaded_plugins.get(cla);
}
private static File getApplicationFile(String filename)
{
String path = SystemProperties.getApplicationPath();
if (Constants.isOSX)
path = (new StringBuilder()).append(path).append("/").append(SystemProperties.getApplicationName()).append(".app/Contents/").toString();
return new File(path, filename);
}
public static File[] getHighestJarVersions(File files[], String version_out[], String id_out[], boolean discard_non_versioned_when_versioned_found)
{
List res = new ArrayList();
Map version_map = new HashMap();
for (int i = 0; i < files.length; i++)
{
File f = files[i];
String name = f.getName().toLowerCase();
if (!name.endsWith(".jar"))
continue;
int cvs_pos = name.lastIndexOf("_cvs");
int sep_pos;
if (cvs_pos <= 0)
sep_pos = name.lastIndexOf("_");
else
sep_pos = name.lastIndexOf("_", cvs_pos - 1);
if (sep_pos == -1 || sep_pos == name.length() - 1 || !Character.isDigit(name.charAt(sep_pos + 1)))
{
res.add(f);
continue;
}
String prefix = name.substring(0, sep_pos);
String version = name.substring(sep_pos + 1, cvs_pos > 0 ? cvs_pos : name.length() - 4);
String prev_version = (String)version_map.get(prefix);
if (prev_version == null)
{
version_map.put(prefix, version);
continue;
}
if (PluginUtils.comparePluginVersions(prev_version, version) < 0)
version_map.put(prefix, version);
}
if (version_map.size() > 0 && discard_non_versioned_when_versioned_found)
res.clear();
if (version_map.containsKey("azrating"))
version_map.remove("rating");
Iterator it = version_map.keySet().iterator();
label0:
do
{
if (it.hasNext())
{
String prefix = (String)it.next();
String version = (String)version_map.get(prefix);
String target = (new StringBuilder()).append(prefix).append("_").append(version).toString();
version_out[0] = version;
id_out[0] = prefix;
int i = 0;
do
{
if (i >= files.length)
continue label0;
File f = files[i];
String lc_name = f.getName().toLowerCase();
if (lc_name.equals((new StringBuilder()).append(target).append(".jar").toString()) || lc_name.equals((new StringBuilder()).append(target).append("_cvs.jar").toString()))
{
res.add(f);
continue label0;
}
i++;
} while (true);
}
File res_array[] = new File[res.size()];
res.toArray(res_array);
return res_array;
} while (true);
}
public static ClassLoader addFileToClassPath(ClassLoader root, ClassLoader classLoader, File f)
{
if (f.exists() && !f.isDirectory() && f.getName().endsWith(".jar"))
try
{
if (classLoader instanceof URLClassLoader)
{
URL old[] = ((URLClassLoader)classLoader).getURLs();
URL new_urls[] = new URL[old.length + 1];
System.arraycopy(old, 0, new_urls, 1, old.length);
new_urls[0] = f.toURL();
classLoader = new URLClassLoader(new_urls, classLoader != root ? classLoader.getParent() : classLoader);
} else
{
classLoader = new URLClassLoader(new URL[] {
f.toURL()
}, classLoader);
}
}
catch (Exception e)
{
e.printStackTrace();
}
return classLoader;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -