import java.io.BufferedWriter;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.net.URLStreamHandlerFactory;
import java.security.AllPermission;
import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.Policy;
import java.security.ProtectionDomain;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class Main
{
protected boolean debug = false;
protected String bootLocation = null;
protected URL installLocation = null;
protected URL configurationLocation = null;
protected String parentConfigurationLocation = null;
protected String framework = "org.eclipse.osgi";
protected String devClassPath = null;
protected boolean inDevelopmentMode = false;
private String exitData = null;
private String name = null;
private String launcher = null;
private String vm = null;
private String[] vmargs = null;
private String[] commands = null;
private String[] extensionPaths = null;
private String showSplash = null;
private String endSplash = null;
private boolean initialize = false;
private Process showProcess = null;
private boolean splashDown = false;
private final Thread endSplashHandler = new Thread() {
public void run() {
Main.this.takeDownSplash();
}
};
private static final String FRAMEWORK = "-framework";
private static final String INSTALL = "-install";
private static final String INITIALIZE = "-initialize";
private static final String VM = "-vm";
private static final String VMARGS = "-vmargs";
private static final String DEBUG = "-debug";
private static final String DEV = "-dev";
private static final String CONFIGURATION = "-configuration";
private static final String EXITDATA = "-exitdata";
private static final String NOSPLASH = "-nosplash";
private static final String SHOWSPLASH = "-showsplash";
private static final String NAME = "-name";
private static final String LAUNCHER = "-launcher";
private static final String NL = "-nl";
private static final String ENDSPLASH = "-endsplash";
private static final String SPLASH_IMAGE = "splash.bmp";
private static final String CLEAN = "-clean";
private static final String NOEXIT = "-noExit";
private static final String OSGI = "org.eclipse.osgi";
private static final String STARTER = "org.eclipse.core.runtime.adaptor.EclipseStarter";
private static final String PLATFORM_URL = "platform:/base/";
private static final String ECLIPSE_PROPERTIES = "eclipse.properties";
private static final String FILE_SCHEME = "file:";
protected static final String REFERENCE_SCHEME = "reference:";
protected static final String JAR_SCHEME = "jar:";
private static final String DEFAULT_JRE_REQUIRED = "1.4.1";
private static final String CONFIG_DIR = "configuration/";
private static final String CONFIG_FILE = "config.ini";
private static final String CONFIG_FILE_TEMP_SUFFIX = ".tmp";
private static final String CONFIG_FILE_BAK_SUFFIX = ".bak";
private static final String ECLIPSE = "eclipse";
private static final String PRODUCT_SITE_MARKER = ".eclipseproduct";
private static final String PRODUCT_SITE_ID = "id";
private static final String PRODUCT_SITE_VERSION = "version";
private static final String PROP_USER_HOME = "user.home";
private static final String PROP_USER_DIR = "user.dir";
private static final String PROP_INSTALL_AREA = "osgi.install.area";
private static final String PROP_CONFIG_AREA = "osgi.configuration.area";
private static final String PROP_CONFIG_AREA_DEFAULT = "osgi.configuration.area.default";
private static final String PROP_BASE_CONFIG_AREA = "osgi.baseConfiguration.area";
private static final String PROP_SHARED_CONFIG_AREA = "osgi.sharedConfiguration.area";
private static final String PROP_CONFIG_CASCADED = "osgi.configuration.cascaded";
protected static final String PROP_FRAMEWORK = "osgi.framework";
private static final String PROP_SPLASHPATH = "osgi.splashPath";
private static final String PROP_SPLASHLOCATION = "osgi.splashLocation";
private static final String PROP_CLASSPATH = "osgi.frameworkClassPath";
private static final String PROP_EXTENSIONS = "osgi.framework.extensions";
private static final String PROP_FRAMEWORK_SYSPATH = "osgi.syspath";
private static final String PROP_FRAMEWORK_SHAPE = "osgi.framework.shape";
private static final String PROP_LOGFILE = "osgi.logfile";
private static final String PROP_REQUIRED_JAVA_VERSION = "osgi.requiredJavaVersion";
private static final String PROP_PARENT_CLASSLOADER = "osgi.parentClassloader";
private static final String PROP_EOF = "eof";
private static final String PROP_NL = "osgi.nl";
private static final String PROP_NOSHUTDOWN = "osgi.noShutdown";
private static final String PROP_DEBUG = "osgi.debug";
private static final String PROP_EXITCODE = "eclipse.exitcode";
private static final String PROP_EXITDATA = "eclipse.exitdata";
private static final String PROP_VM = "eclipse.vm";
private static final String PROP_VMARGS = "eclipse.vmargs";
private static final String PROP_COMMANDS = "eclipse.commands";
private static final String PROP_ECLIPSESECURITY = "eclipse.security";
private static final String NONE = "@none";
private static final String NO_DEFAULT = "@noDefault";
private static final String USER_HOME = "@user.home";
private static final String USER_DIR = "@user.dir";
private static final String PARENT_CLASSLOADER_APP = "app";
private static final String PARENT_CLASSLOADER_EXT = "ext";
private static final String PARENT_CLASSLOADER_BOOT = "boot";
protected static final String SESSION = "!SESSION";
protected static final String ENTRY = "!ENTRY";
protected static final String MESSAGE = "!MESSAGE";
protected static final String STACK = "!STACK";
protected static final int ERROR = 4;
protected static final String PLUGIN_ID = "org.eclipse.core.launcher";
protected File logFile = null;
protected BufferedWriter log = null;
protected boolean newSession = true;
protected void basicRun(String[] args)
throws Exception
{
System.getProperties().setProperty("eclipse.startTime", Long.toString(System.currentTimeMillis()));
this.commands = args;
String[] passThruArgs = processCommandLine(args);
if (!this.debug)
{
this.debug = (System.getProperty("osgi.debug") != null);
}setupVMProperties();
processConfiguration();
if (!checkVersion(System.getProperty("java.version"), System.getProperty("osgi.requiredJavaVersion", "1.4.1"))) {
return;
}
getInstallLocation();
URL[] bootPath = getBootPath(this.bootLocation);
setSecurityPolicy(bootPath);
handleSplash(bootPath);
invokeFramework(passThruArgs, bootPath);
}
protected void setSecurityPolicy(URL[] bootPath) {
String eclipseSecurity = System.getProperty("eclipse.security");
if (eclipseSecurity != null) {
SecurityManager sm = System.getSecurityManager();
boolean setSM = false;
if (sm == null) {
if (eclipseSecurity.length() < 1)
eclipseSecurity = "java.lang.SecurityManager";
try
{
Class clazz = Class.forName(eclipseSecurity);
sm = (SecurityManager)clazz.newInstance();
setSM = true;
}
catch (Throwable t) {
System.setProperty("java.security.manager", eclipseSecurity);
}
}
ProtectionDomain domain = Main.class.getProtectionDomain();
CodeSource source = null;
if (domain != null)
source = Main.class.getProtectionDomain().getCodeSource();
if ((domain == null) || (source == null)) {
log("Can not automatically set the security manager. Please use a policy file.");
return;
}
URL[] rootURLs = new URL[bootPath.length + 1];
rootURLs[0] = source.getLocation();
System.arraycopy(bootPath, 0, rootURLs, 1, bootPath.length);
Policy eclispePolicy = new EclipsePolicy(Policy.getPolicy(), rootURLs);
Policy.setPolicy(eclispePolicy);
if (setSM)
System.setSecurityManager(sm);
}
}
private void invokeFramework(String[] passThruArgs, URL[] bootPath) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, Error, Exception, InvocationTargetException {
String type = System.getProperty("osgi.parentClassloader", "boot");
ClassLoader parent = null;
if ("app".equalsIgnoreCase(type)) {
parent = ClassLoader.getSystemClassLoader();
} else if ("ext".equalsIgnoreCase(type)) {
ClassLoader appCL = ClassLoader.getSystemClassLoader();
if (appCL != null)
parent = appCL.getParent();
}
URLClassLoader loader = new StartupClassLoader(bootPath, parent);
Class clazz = loader.loadClass("org.eclipse.core.runtime.adaptor.EclipseStarter");
Method method = clazz.getDeclaredMethod("run", new Class[] { [Ljava.lang.String.class, Runnable.class });
try {
method.invoke(clazz, new Object[] { passThruArgs, this.endSplashHandler });
} catch (InvocationTargetException e) {
if ((e.getTargetException() instanceof Error))
throw ((Error)e.getTargetException());
if ((e.getTargetException() instanceof Exception)) {
throw ((Exception)e.getTargetException());
}
throw e;
}
}
private boolean checkVersion(String availableVersion, String requiredVersion)
{
if ((requiredVersion == null) || (availableVersion == null))
return true;
try {
Identifier required = new Identifier(requiredVersion);
Identifier available = new Identifier(availableVersion);
boolean compatible = available.isGreaterEqualTo(required);
if (!compatible)
{
System.getProperties().put("eclipse.exitcode", "14");
System.getProperties().put("eclipse.exitdata", "Required Java version: " + requiredVersion + ". Available: " + availableVersion + '.');
}
return compatible;
}
catch (SecurityException e)
{
return true;
}
catch (NumberFormatException e) {
}
return true;
}
protected String decode(String urlString)
{
byte[] decodedBytes;
int decodedLength;
try
{
Class clazz = URLDecoder.class;
Method method = clazz.getDeclaredMethod("decode", new Class[] { String.class, String.class });
if (urlString.indexOf('+') >= 0) {
int len = urlString.length();
StringBuffer buf = new StringBuffer(len);
for (int i = 0; i < len; i++) {
char c = urlString.charAt(i);
if (c == '+')
buf.append("%2B");
else
buf.append(c);
}
urlString = buf.toString();
}
Object result = method.invoke(null, new Object[] { urlString, "UTF-8" });
if (result != null) {
return (String)result;
}
}
catch (Exception replaced)
{
boolean replaced = false;
byte[] encodedBytes = urlString.getBytes();
int encodedLength = encodedBytes.length;
decodedBytes = new byte[encodedLength];
decodedLength = 0;
for (int i = 0; i < encodedLength; i++) {
byte b = encodedBytes[i];
if (b == 37) {
i++; byte enc1 = encodedBytes[i];
i++; byte enc2 = encodedBytes[i];
b = (byte)((hexToByte(enc1) << 4) + hexToByte(enc2));
replaced = true;
}
decodedBytes[(decodedLength++)] = b;
}
if (!replaced)
return urlString;
try {
return new String(decodedBytes, 0, decodedLength, "UTF-8"); } catch (UnsupportedEncodingException e) {
}
}
return new String(decodedBytes, 0, decodedLength);
}
protected String[] getArrayFromList(String prop)
{
if ((prop == null) || (prop.trim().equals("")))
return new String[0];
Vector list = new Vector();
StringTokenizer tokens = new StringTokenizer(prop, ",");
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken().trim();
if (!token.equals(""))
list.addElement(token);
}
return list.isEmpty() ? new String[0] : (String[])list.toArray(new String[list.size()]);
}
private URL[] getDevPath(URL base)
throws IOException
{
ArrayList result = new ArrayList(5);
if (this.inDevelopmentMode) {
addDevEntries(base, result);
}
addBaseJars(base, result);
return (URL[])result.toArray(new URL[result.size()]);
}
URL constructURL(URL url, String name)
{
String externalForm = url.toExternalForm();
if (externalForm.endsWith(".jar"))
try {
return new URL("jar:" + url + "!/" + name);
}
catch (MalformedURLException localMalformedURLException1)
{
}
try
{
return new URL(url, name);
} catch (MalformedURLException e) {
}
return null;
}
private void readFrameworkExtensions(URL base, ArrayList result) throws IOException {
String[] extensions = getArrayFromList(System.getProperties().getProperty("osgi.framework.extensions"));
String parent = new File(base.getFile()).getParent().toString();
ArrayList extensionResults = new ArrayList(extensions.length);
for (int i = 0; i < extensions.length; i++)
{
String path = searchFor(extensions[i], parent);
if (path == null) {
log("Could not find extension: " + extensions[i]);
}
else {
if (this.debug) {
System.out.println("Loading extension: " + extensions[i]);
}
URL extensionURL = null;
if (this.installLocation.getProtocol().equals("file")) {
extensionResults.add(path);
extensionURL = new File(path).toURL();
} else {
extensionURL = new URL(this.installLocation.getProtocol(), this.installLocation.getHost(), this.installLocation.getPort(), path);
}
Properties extensionProperties = null;
try {
extensionProperties = loadProperties(constructURL(extensionURL, "eclipse.properties"));
} catch (IOException e) {
if (this.debug)
System.out.println("\teclipse.properties not found");
}
String extensionClassPath = null;
if (extensionProperties != null)
extensionClassPath = extensionProperties.getProperty("osgi.frameworkClassPath");
else
extensionProperties = new Properties();
String[] entries = (extensionClassPath == null) || (extensionClassPath.length() == 0) ? new String[] { "" } : getArrayFromList(extensionClassPath);
String qualifiedPath;
String qualifiedPath;
if (System.getProperty("osgi.frameworkClassPath") == null)
qualifiedPath = ".";
else
qualifiedPath = "";
for (int j = 0; j < entries.length; j++)
qualifiedPath = qualifiedPath + ", file:" + path + entries[j];
extensionProperties.put("osgi.frameworkClassPath", qualifiedPath);
mergeProperties(System.getProperties(), extensionProperties);
if (this.inDevelopmentMode)
addDevEntries(extensionURL, result);
}
}
this.extensionPaths = ((String[])extensionResults.toArray(new String[extensionResults.size()]));
}
private void addBaseJars(URL base, ArrayList result) throws IOException {
String baseJarList = System.getProperty("osgi.frameworkClassPath");
if (baseJarList == null) {
readFrameworkExtensions(base, result);
baseJarList = System.getProperties().getProperty("osgi.frameworkClassPath");
}
File fwkFile = new File(base.getFile());
boolean fwkIsDirectory = fwkFile.isDirectory();
if (fwkIsDirectory)
System.getProperties().setProperty("osgi.framework.shape", "folder");
else {
System.getProperties().setProperty("osgi.framework.shape", "jar");
}
String fwkPath = new File(base.getFile()).getParentFile().getAbsolutePath();
if (Character.isUpperCase(fwkPath.charAt(0))) {
char[] chars = fwkPath.toCharArray();
chars[0] = Character.toLowerCase(chars[0]);
fwkPath = new String(chars);
}
System.getProperties().setProperty("osgi.syspath", fwkPath);
String[] baseJars = getArrayFromList(baseJarList);
if (baseJars.length == 0) {
if ((!this.inDevelopmentMode) && (new File(base.getFile()).isDirectory()))
throw new IOException("Unable to initialize osgi.frameworkClassPath");
addEntry(base, result);
return;
}
for (int i = 0; i < baseJars.length; i++) {
String string = baseJars[i];
try
{
if (string.equals(".")) {
addEntry(base, result);
}
URL url = null;
if (string.startsWith("file:"))
url = new File(string.substring(5)).toURL();
else
url = new URL(string);
addEntry(url, result);
} catch (MalformedURLException e) {
addEntry(new URL(base, string), result);
}
}
}
protected void addEntry(URL url, List result) {
if (new File(url.getFile()).exists())
result.add(url);
}
private void addDevEntries(URL base, List result) throws MalformedURLException {
String[] locations = getArrayFromList(this.devClassPath);
for (int i = 0; i < locations.length; i++) {
String location = locations[i];
File path = new File(location);
URL url;
URL url;
if (path.isAbsolute()) {
url = path.toURL();
}
else {
char lastChar = location.charAt(location.length() - 1);
URL url;
if ((location.endsWith(".jar")) || (lastChar == '/') || (lastChar == '\\'))
url = new URL(base, location);
else
url = new URL(base, location + "/");
}
addEntry(url, result);
}
}
protected URL[] getBootPath(String base)
throws IOException
{
URL url = null;
if (base != null) {
url = buildURL(base, true);
}
else {
url = getInstallLocation();
String path = new File(url.getFile(), "plugins").toString();
path = searchFor(this.framework, path);
if (path == null)
throw new RuntimeException("Could not find framework");
if (url.getProtocol().equals("file"))
url = new File(path).toURL();
else
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
}
if (System.getProperty("osgi.framework") == null)
System.getProperties().put("osgi.framework", url.toExternalForm());
if (this.debug) {
System.out.println("Framework located:\n " + url.toExternalForm());
}
URL[] result = getDevPath(url);
if (this.debug) {
System.out.println("Framework classpath:");
for (int i = 0; i < result.length; i++)
System.out.println(" " + result[i].toExternalForm());
}
return result;
}
protected String searchFor(String target, String start)
{
FileFilter filter = new FileFilter(target) {
public boolean accept(File candidate) {
return (candidate.getName().equals(this.val$target)) || (candidate.getName().startsWith(this.val$target + "_"));
}
};
File[] candidates = new File(start).listFiles(filter);
if (candidates == null)
return null;
String[] arrays = new String[candidates.length];
for (int i = 0; i < arrays.length; i++) {
arrays[i] = candidates[i].getName();
}
int result = findMax(arrays);
if (result == -1)
return null;
return candidates[result].getAbsolutePath().replace(File.separatorChar, '/') + (candidates[result].isDirectory() ? "/" : "");
}
protected int findMax(String[] candidates) {
int result = -1;
Object maxVersion = null;
for (int i = 0; i < candidates.length; i++) {
String name = candidates[i];
String version = "";
int index = name.indexOf('_');
if (index != -1)
version = name.substring(index + 1);
Object currentVersion = getVersionElements(version);
if (maxVersion == null) {
result = i;
maxVersion = currentVersion;
}
else if (compareVersion((Object[])maxVersion, (Object[])currentVersion) < 0) {
result = i;
maxVersion = currentVersion;
}
}
return result;
}
private int compareVersion(Object[] left, Object[] right)
{
int result = ((Integer)left[0]).compareTo((Integer)right[0]);
if (result != 0) {
return result;
}
result = ((Integer)left[1]).compareTo((Integer)right[1]);
if (result != 0) {
return result;
}
result = ((Integer)left[2]).compareTo((Integer)right[2]);
if (result != 0) {
return result;
}
return ((String)left[3]).compareTo((String)right[3]);
}
private Object[] getVersionElements(String version)
{
if (version.endsWith(".jar"))
version = version.substring(0, version.length() - 4);
Object[] result = { new Integer(0), new Integer(0), new Integer(0), "" };
StringTokenizer t = new StringTokenizer(version, ".");
int i = 0;
while ((t.hasMoreTokens()) && (i < 4)) {
String token = t.nextToken();
if (i < 3) {
try
{
result[(i++)] = new Integer(token);
}
catch (Exception e) {
break;
}
}
else {
result[(i++)] = token;
}
}
return result;
}
private static URL buildURL(String spec, boolean trailingSlash) {
if (spec == null)
return null;
boolean isFile = spec.startsWith("file:");
try {
if (isFile) {
File toAdjust = new File(spec.substring(5));
if (toAdjust.isDirectory()) {
return adjustTrailingSlash(toAdjust.toURL(), trailingSlash);
}
return toAdjust.toURL();
}
return new URL(spec);
}
catch (MalformedURLException e)
{
if (isFile)
return null;
try {
File toAdjust = new File(spec);
if (toAdjust.isDirectory()) {
return adjustTrailingSlash(toAdjust.toURL(), trailingSlash);
}
return toAdjust.toURL(); } catch (MalformedURLException e1) {
}
}
return null;
}
private static URL adjustTrailingSlash(URL url, boolean trailingSlash)
throws MalformedURLException
{
String file = url.getFile();
if (trailingSlash == file.endsWith("/"))
return url;
file = trailingSlash ? file + "/" : file.substring(0, file.length() - 1);
return new URL(url.getProtocol(), url.getHost(), file);
}
private URL buildLocation(String property, URL defaultLocation, String userDefaultAppendage) {
URL result = null;
String location = System.getProperty(property);
System.getProperties().remove(property);
try
{
if (location == null) {
result = defaultLocation; } else {
if (location.equalsIgnoreCase("@none"))
return null;
if (location.equalsIgnoreCase("@noDefault")) {
result = buildURL(location, true);
} else {
if (location.startsWith("@user.home")) {
String base = substituteVar(location, "@user.home", "user.home");
location = new File(base, userDefaultAppendage).getAbsolutePath();
} else if (location.startsWith("@user.dir")) {
String base = substituteVar(location, "@user.dir", "user.dir");
location = new File(base, userDefaultAppendage).getAbsolutePath();
}
result = buildURL(location, true);
}
}
} finally {
if (result != null)
System.getProperties().put(property, result.toExternalForm());
}
if (result != null) {
System.getProperties().put(property, result.toExternalForm());
}
return result;
}
private String substituteVar(String source, String var, String prop) {
String value = System.getProperty(prop, "");
return value + source.substring(var.length());
}
private String computeDefaultConfigurationLocation()
{
URL install = getInstallLocation();
if (install.getProtocol().equals("file")) {
File installDir = new File(install.getFile());
if (canWrite(installDir)) {
return installDir.getAbsolutePath() + File.separator + "configuration/";
}
}
return computeDefaultUserAreaLocation("configuration/");
}
private static boolean canWrite(File installDir) {
if (!installDir.canWrite()) {
return false;
}
if (!installDir.isDirectory()) {
return false;
}
File fileTest = null;
try {
fileTest = File.createTempFile("writtableArea", null, installDir);
}
catch (IOException localIOException) {
return false;
} finally {
if (fileTest != null)
fileTest.delete();
}
return true;
}
private String computeDefaultUserAreaLocation(String pathAppendage)
{
URL installURL = getInstallLocation();
if (installURL == null)
return null;
File installDir = new File(installURL.getFile());
String appName = ".eclipse";
File eclipseProduct = new File(installDir, ".eclipseproduct");
if (eclipseProduct.exists()) {
Properties props = new Properties();
try {
props.load(new FileInputStream(eclipseProduct));
String appId = props.getProperty("id");
if ((appId == null) || (appId.trim().length() == 0))
appId = "eclipse";
String appVersion = props.getProperty("version");
if ((appVersion == null) || (appVersion.trim().length() == 0))
appVersion = "";
appName = appName + File.separator + appId + "_" + appVersion;
}
catch (IOException localIOException)
{
}
}
String userHome = System.getProperty("user.home");
return new File(userHome, appName + "/" + pathAppendage).getAbsolutePath();
}
public static void main(String argString)
{
Vector list = new Vector(5);
for (StringTokenizer tokens = new StringTokenizer(argString, " "); tokens.hasMoreElements(); )
list.addElement(tokens.nextElement());
main((String[])list.toArray(new String[list.size()]));
}
public static void main(String[] args)
{
int result = 0;
try {
result = new Main().run(args);
}
catch (Throwable t)
{
t.printStackTrace();
} finally {
if (!Boolean.getBoolean("osgi.noShutdown"))
{
System.exit(result);
}
}
}
public int run(String[] args)
{
int result = 0;
try {
basicRun(args);
String exitCode = System.getProperty("eclipse.exitcode");
try {
result = exitCode == null ? 0 : Integer.parseInt(exitCode);
} catch (NumberFormatException e) {
result = 17;
}
}
catch (Throwable e)
{
if (!"13".equals(System.getProperty("eclipse.exitcode"))) {
log("Exception launching the Eclipse Platform:");
log(e);
String message = "An error has occurred";
if (this.logFile == null)
message = message + " and could not be logged: \n" + e.getMessage();
else
message = message + ". See the log file\n" + this.logFile.getAbsolutePath();
System.getProperties().put("eclipse.exitdata", message);
}
result = 13;
}
finally {
takeDownSplash();
}
System.getProperties().put("eclipse.exitcode", Integer.toString(result));
setExitData();
return result;
}
private void setExitData() {
String data = System.getProperty("eclipse.exitdata");
if ((this.exitData == null) || (data == null)) {
return;
}
runCommand(true, new String[] { "-exitdata", this.exitData, data });
}
protected String[] processCommandLine(String[] args)
{
if (args.length == 0)
return args;
int[] configArgs = new int[args.length];
configArgs[0] = -1;
int configArgIndex = 0;
for (int i = 0; i < args.length; i++) {
boolean found = false;
if (args[i].equalsIgnoreCase("-debug")) {
this.debug = true;
}
else
{
if (args[i].equalsIgnoreCase("-nosplash")) {
this.splashDown = true;
found = true;
}
if (args[i].equalsIgnoreCase("-noExit")) {
System.getProperties().put("osgi.noShutdown", "true");
found = true;
}
if (args[i].equalsIgnoreCase("-initialize")) {
this.initialize = true;
}
else if ((args[i].equalsIgnoreCase("-dev")) && ((i + 1 == args.length) || ((i + 1 < args.length) && (args[(i + 1)].startsWith("-"))))) {
this.inDevelopmentMode = true;
}
else if (found) {
configArgs[(configArgIndex++)] = i;
}
else if (args[i].equalsIgnoreCase("-vmargs"))
{
args[i] = null;
i++;
this.vmargs = new String[args.length - i];
for (int j = 0; i < args.length; i++) {
this.vmargs[(j++)] = args[i];
args[i] = null;
}
}
else
{
if ((i == args.length - 1) || (args[(i + 1)].startsWith("-")))
continue;
i++; String arg = args[i];
if (args[(i - 1)].equalsIgnoreCase("-dev")) {
this.inDevelopmentMode = true;
this.devClassPath = processDevArg(arg);
}
else
{
if (args[(i - 1)].equalsIgnoreCase("-framework")) {
this.framework = arg;
found = true;
}
if (args[(i - 1)].equalsIgnoreCase("-install")) {
System.getProperties().put("osgi.install.area", arg);
found = true;
}
if (args[(i - 1)].equalsIgnoreCase("-configuration")) {
System.getProperties().put("osgi.configuration.area", arg);
found = true;
}
if (args[(i - 1)].equalsIgnoreCase("-exitdata")) {
this.exitData = arg;
found = true;
}
if (args[(i - 1)].equalsIgnoreCase("-showsplash")) {
this.showSplash = arg;
found = true;
}
if (args[(i - 1)].equalsIgnoreCase("-name")) {
this.name = arg;
found = true;
}
if (args[(i - 1)].equalsIgnoreCase("-launcher")) {
this.launcher = arg;
found = true;
}
if (args[(i - 1)].equalsIgnoreCase("-endsplash")) {
this.endSplash = arg;
found = true;
}
if (args[(i - 1)].equalsIgnoreCase("-vm")) {
this.vm = arg;
found = true;
}
if (args[(i - 1)].equalsIgnoreCase("-nl")) {
System.getProperties().put("osgi.nl", arg);
found = true;
}
if (found) {
configArgs[(configArgIndex++)] = (i - 1);
configArgs[(configArgIndex++)] = i;
}
}
}
}
}
String[] passThruArgs = new String[args.length - configArgIndex - (this.vmargs == null ? 0 : this.vmargs.length + 1)];
configArgIndex = 0;
int j = 0;
for (int i = 0; i < args.length; i++) {
if (i == configArgs[configArgIndex])
configArgIndex++;
else if (args[i] != null)
passThruArgs[(j++)] = args[i];
}
return passThruArgs;
}
private String processDevArg(String arg) {
if (arg == null)
return null;
try {
URL location = new URL(arg);
Properties props = load(location, null);
String result = props.getProperty("org.eclipse.osgi");
return result == null ? props.getProperty("*") : result;
}
catch (MalformedURLException e) {
return arg;
} catch (IOException e) {
}
return null;
}
private URL getConfigurationLocation()
{
if (this.configurationLocation != null)
return this.configurationLocation;
this.configurationLocation = buildLocation("osgi.configuration.area", null, "");
if (this.configurationLocation == null) {
this.configurationLocation = buildLocation("osgi.configuration.area.default", null, "");
if (this.configurationLocation == null)
this.configurationLocation = buildURL(computeDefaultConfigurationLocation(), true);
}
if (this.configurationLocation != null)
System.getProperties().put("osgi.configuration.area", this.configurationLocation.toExternalForm());
if (this.debug)
System.out.println("Configuration location:\n " + this.configurationLocation);
return this.configurationLocation;
}
private void processConfiguration()
{
URL baseConfigurationLocation = null;
Properties baseConfiguration = null;
if (System.getProperty("osgi.configuration.area") == null) {
String baseLocation = System.getProperty("osgi.baseConfiguration.area");
if (baseLocation != null)
{
baseConfigurationLocation = buildURL(baseLocation, true);
}if (baseConfigurationLocation == null)
{
try
{
baseConfigurationLocation = new URL(getInstallLocation(), "configuration/");
} catch (MalformedURLException localMalformedURLException) {
}
}
baseConfiguration = loadConfiguration(baseConfigurationLocation);
if (baseConfiguration != null)
{
String location = baseConfiguration.getProperty("osgi.configuration.area");
if (location != null) {
System.getProperties().put("osgi.configuration.area", location);
}
location = baseConfiguration.getProperty("osgi.install.area");
if ((location != null) && (System.getProperty("osgi.install.area") == null)) {
System.getProperties().put("osgi.install.area", location);
}
}
}
Properties configuration = baseConfiguration;
if ((configuration == null) || (!getConfigurationLocation().equals(baseConfigurationLocation)))
configuration = loadConfiguration(getConfigurationLocation());
mergeProperties(System.getProperties(), configuration);
if ("false".equalsIgnoreCase(System.getProperty("osgi.configuration.cascaded")))
{
System.getProperties().remove("osgi.sharedConfiguration.area");
} else {
ensureAbsolute("osgi.sharedConfiguration.area");
URL sharedConfigURL = buildLocation("osgi.sharedConfiguration.area", null, "");
if (sharedConfigURL == null)
try
{
sharedConfigURL = new URL(getInstallLocation(), "configuration/");
}
catch (MalformedURLException localMalformedURLException1)
{
}
if (sharedConfigURL != null) {
if (sharedConfigURL.equals(getConfigurationLocation()))
{
System.getProperties().remove("osgi.sharedConfiguration.area");
}
else
{
configuration = baseConfiguration;
if (!sharedConfigURL.equals(baseConfigurationLocation))
configuration = loadConfiguration(sharedConfigURL);
mergeProperties(System.getProperties(), configuration);
System.getProperties().put("osgi.sharedConfiguration.area", sharedConfigURL.toExternalForm());
if (this.debug) {
System.out.println("Shared configuration location:\n " + sharedConfigURL.toExternalForm());
}
}
}
}
String urlString = System.getProperty("osgi.framework", null);
if (urlString != null) {
URL url = buildURL(urlString, true);
System.getProperties().put("osgi.framework", url.toExternalForm());
this.bootLocation = resolve(urlString);
}
}
private void ensureAbsolute(String locationProperty)
{
String propertyValue = System.getProperty(locationProperty);
if (propertyValue == null)
{
return;
}URL locationURL = null;
try {
locationURL = new URL(propertyValue);
}
catch (MalformedURLException e) {
return;
}
String locationPath = locationURL.getPath();
if (locationPath.startsWith("/"))
{
return;
}URL installURL = getInstallLocation();
if (!locationURL.getProtocol().equals(installURL.getProtocol()))
{
return;
}try {
URL absoluteURL = new URL(installURL, locationPath);
System.getProperties().put(locationProperty, absoluteURL.toExternalForm());
}
catch (MalformedURLException localMalformedURLException1)
{
}
}
private URL getInstallLocation()
{
if (this.installLocation != null) {
return this.installLocation;
}
String installArea = System.getProperty("osgi.install.area");
if (installArea != null) {
this.installLocation = buildURL(installArea, true);
if (this.installLocation == null)
throw new IllegalStateException("Install location is invalid: " + installArea);
System.getProperties().put("osgi.install.area", this.installLocation.toExternalForm());
if (this.debug)
System.out.println("Install location:\n " + this.installLocation);
return this.installLocation;
}
ProtectionDomain domain = Main.class.getProtectionDomain();
CodeSource source = null;
URL result = null;
if (domain != null)
source = domain.getCodeSource();
if ((source == null) || (domain == null)) {
if (this.debug)
System.out.println("CodeSource location is null. Defaulting the install location to file:startup.jar");
try {
result = new URL("file:startup.jar");
}
catch (MalformedURLException localMalformedURLException) {
}
}
if (source != null) {
result = source.getLocation();
}
String path = decode(result.getFile());
File file = new File(path);
path = file.toString().replace('\\', '/');
if ((File.separatorChar == '\\') &&
(Character.isUpperCase(path.charAt(0)))) {
char[] chars = path.toCharArray();
chars[0] = Character.toLowerCase(chars[0]);
path = new String(chars);
}
if (path.toLowerCase().endsWith(".jar"))
path = path.substring(0, path.lastIndexOf("/") + 1);
try
{
try
{
path = new File(path).toURL().getFile();
}
catch (MalformedURLException localMalformedURLException1) {
}
this.installLocation = new URL(result.getProtocol(), result.getHost(), result.getPort(), path);
System.getProperties().put("osgi.install.area", this.installLocation.toExternalForm());
}
catch (MalformedURLException localMalformedURLException2) {
}
if (this.debug)
System.out.println("Install location:\n " + this.installLocation);
return this.installLocation;
}
private Properties loadConfiguration(URL url)
{
Properties result = null;
try {
url = new URL(url, "config.ini");
} catch (MalformedURLException e) {
return null;
}
try {
if (this.debug)
System.out.print("Configuration file:\n " + url.toString());
result = loadProperties(url);
if (this.debug)
System.out.println(" loaded");
} catch (IOException e) {
if (this.debug)
System.out.println(" not found or not read");
}
return result;
}
private Properties loadProperties(URL url) throws IOException
{
if (url == null)
return null;
Properties result = null;
IOException originalException = null;
try {
result = load(url, null);
} catch (IOException e1) {
originalException = e1;
try {
result = load(url, ".tmp");
} catch (IOException e2) {
try {
result = load(url, ".bak");
} catch (IOException e3) {
throw originalException;
}
}
}
return result;
}
private Properties load(URL url, String suffix)
throws IOException
{
if ((suffix != null) && (!suffix.equals(""))) {
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + suffix);
}
Properties props = new Properties();
InputStream is = null;
try {
is = url.openStream();
props.load(is);
} finally {
if (is != null)
try {
is.close();
}
catch (IOException localIOException) {
}
}
return props;
}
private void handleSplash(URL[] defaultPath)
{
if ((this.initialize) || (this.splashDown)) {
this.showSplash = null;
this.endSplash = null;
return;
}
if ((this.showSplash != null) || (this.endSplash != null))
{
try
{
Runtime.getRuntime().addShutdownHook(this.endSplashHandler);
}
catch (Exception localException)
{
}
}
if (this.endSplash != null) {
this.showSplash = null;
return;
}
if (this.showSplash == null) {
return;
}
String location = getSplashLocation(defaultPath);
if (this.debug)
System.out.println("Splash location:\n " + location);
if (location == null) {
return;
}
this.showProcess = runCommand(false, new String[] { "-showsplash", this.showSplash, location });
}
private Process runCommand(boolean block, String[] extraArgs) {
int NBR_DEFAULT_ARGS = 3;
String[] args = new String[3 + extraArgs.length];
args[0] = this.launcher;
args[1] = "-name";
args[2] = this.name;
for (int i = 0; i < extraArgs.length; i++) {
args[(i + 3)] = extraArgs[i];
}
if (this.debug) {
System.out.print("runCommand:\n ");
for (int i = 0; i < args.length; i++) {
System.out.print('<' + args[i] + '>');
}
System.out.println();
}
Process result = null;
try {
result = Runtime.getRuntime().exec(args);
if (block)
result.waitFor();
} catch (Exception e) {
log(("Exception running command: " + extraArgs != null) && (extraArgs.length > 0) ? extraArgs[0] : null);
log(e);
}
return result;
}
protected void takeDownSplash()
{
if (this.splashDown) {
return;
}
if (this.endSplash != null) {
try {
Runtime.getRuntime().exec(this.endSplash);
}
catch (Exception localException)
{
}
}
if (this.showProcess != null) {
this.showProcess.destroy();
this.showProcess = null;
}
this.splashDown = true;
try
{
Runtime.getRuntime().removeShutdownHook(this.endSplashHandler);
}
catch (IllegalStateException localIllegalStateException)
{
}
}
private String getSplashLocation(URL[] bootPath)
{
String result = System.getProperty("osgi.splashLocation");
if (result != null)
return result;
String splashPath = System.getProperty("osgi.splashPath");
if (splashPath != null) {
String[] entries = getArrayFromList(splashPath);
ArrayList path = new ArrayList(entries.length);
for (int i = 0; i < entries.length; i++) {
String entry = resolve(entries[i]);
if ((entry == null) || (entry.startsWith("file:"))) {
File entryFile = new File(entry.substring(5).replace('/', File.separatorChar));
entry = searchFor(entryFile.getName(), entryFile.getParent());
if (entry != null)
path.add(entry);
} else {
log("Invalid splash path entry: " + entries[i]);
}
}
result = searchForSplash((String[])path.toArray(new String[path.size()]));
if (result != null) {
System.getProperties().put("osgi.splashLocation", result);
return result;
}
}
String temp = bootPath[0].getFile();
temp = temp.replace('/', File.separatorChar);
int ix = temp.lastIndexOf("plugins" + File.separator);
if (ix != -1) {
int pix = temp.indexOf(File.separator, ix + 8);
if (pix != -1) {
temp = temp.substring(0, pix);
result = searchForSplash(new String[] { temp });
if (result != null)
System.getProperties().put("osgi.splashLocation", result);
}
}
return result;
}
private String searchForSplash(String[] searchPath)
{
if (searchPath == null) {
return null;
}
String locale = (String)System.getProperties().get("osgi.nl");
if (locale == null)
locale = Locale.getDefault().toString();
String[] nlVariants = buildNLVariants(locale);
for (int i = 0; i < nlVariants.length; i++) {
for (int j = 0; j < searchPath.length; j++)
{
if (isJAR(searchPath[j])) {
String result = extractSplashFromJAR(searchPath[j], nlVariants[i]);
if (result != null)
return result;
}
else {
String path = searchPath[j];
if (!path.endsWith(File.separator))
path = path + File.separator;
path = path + nlVariants[i];
File result = new File(path);
if (result.exists()) {
return result.getAbsolutePath();
}
}
}
}
return null;
}
private static void transferStreams(InputStream source, OutputStream destination)
{
byte[] buffer = new byte[8096];
try
{
int bytesRead = -1;
try {
bytesRead = source.read(buffer);
}
catch (IOException localIOException1)
{
}
while (true)
while (true)
{
return;
int bytesRead;
if (bytesRead == -1) break label136;
try {
destination.write(buffer, 0, bytesRead);
} catch (IOException e) {
}
}
}
finally {
try {
source.close();
}
catch (IOException localIOException6)
{
try
{
destination.close(); } catch (IOException localIOException7) {
} } finally { try { destination.close();
}
catch (IOException localIOException8)
{
}
}
}
try
{
label136: source.close();
}
catch (IOException localIOException10)
{
try
{
destination.close(); } catch (IOException localIOException11) {
} } finally { try { destination.close();
}
catch (IOException localIOException12)
{
}
}
}
private String extractSplashFromJAR(String jarPath, String splashPath)
{
String configLocation = System.getProperty("osgi.configuration.area");
if (configLocation == null) {
log("Configuration area not set yet. Unable to extract splash from JAR'd plug-in: " + jarPath);
return null;
}
URL configURL = buildURL(configLocation, false);
if (configURL == null) {
return null;
}
File splash = new File(configURL.getPath(), "org.eclipse.osgi");
splash = new File(splash, splashPath);
if (splash.exists())
{
boolean clean = false;
for (int i = 0; i < this.commands.length; i++) {
if ("-clean".equalsIgnoreCase(this.commands[i])) {
clean = true;
splash.delete();
break;
}
}
if (!clean)
return splash.getAbsolutePath();
}
try
{
file = new ZipFile(jarPath);
}
catch (IOException e)
{
ZipFile file;
log("Exception looking for splash in JAR file: " + jarPath);
log(e);
return null;
}
ZipFile file;
ZipEntry entry = file.getEntry(splashPath.replace(File.separatorChar, '/'));
if (entry == null)
return null;
InputStream input = null;
try {
input = file.getInputStream(entry);
} catch (IOException e) {
log("Exception opening splash: " + entry.getName() + " in JAR file: " + jarPath);
log(e);
return null;
}
splash.getParentFile().mkdirs();
try
{
output = new BufferedOutputStream(new FileOutputStream(splash));
}
catch (FileNotFoundException e)
{
try
{
OutputStream output;
input.close();
}
catch (IOException localIOException1) {
}
return null;
}
OutputStream output;
transferStreams(input, output);
return splash.exists() ? splash.getAbsolutePath() : null;
}
private boolean isJAR(String path)
{
if (path.endsWith(File.separator))
return false;
int index = path.lastIndexOf('.');
if (index == -1)
return false;
index++;
if (index >= path.length())
return false;
return "JAR".equalsIgnoreCase(path.substring(index));
}
private static String[] buildNLVariants(String locale)
{
String nl = locale;
ArrayList result = new ArrayList(4);
while (true)
{
result.add("nl" + File.separatorChar + nl.replace('_', File.separatorChar) + File.separatorChar + "splash.bmp");
int lastSeparator = nl.lastIndexOf('_');
if (lastSeparator == -1)
break;
nl = nl.substring(0, lastSeparator);
}
int lastSeparator;
result.add("splash.bmp");
return (String[])result.toArray(new String[result.size()]);
}
private String resolve(String urlString)
{
if (urlString.startsWith("reference:")) {
urlString = urlString.substring(10);
System.getProperties().put("osgi.framework", urlString);
}
if (urlString.startsWith("platform:/base/")) {
String path = urlString.substring("platform:/base/".length());
return getInstallLocation() + path;
}
return urlString;
}
protected synchronized void log(Object obj)
{
if (obj == null)
return;
try {
openLogFile();
try {
if (this.newSession) {
this.log.write("!SESSION");
this.log.write(32);
String timestamp = new Date().toString();
this.log.write(timestamp);
this.log.write(32);
for (int i = "!SESSION".length() + timestamp.length(); i < 78; i++)
this.log.write(45);
this.log.newLine();
this.newSession = false;
}
write(obj);
} finally {
if (this.logFile == null) {
if (this.log != null)
this.log.flush();
}
else closeLogFile();
}
}
catch (Exception e) {
System.err.println("An exception occurred while writing to the platform log:");
e.printStackTrace(System.err);
System.err.println("Logging to the console instead.");
try
{
this.log = logForStream(System.err);
write(obj);
this.log.flush();
} catch (Exception e2) {
System.err.println("An exception occurred while logging to the console:");
e2.printStackTrace(System.err);
}
} finally {
this.log = null;
}
}
private void write(Object obj)
throws IOException
{
if (obj == null)
return;
if ((obj instanceof Throwable)) {
this.log.write("!STACK");
this.log.newLine();
((Throwable)obj).printStackTrace(new PrintWriter(this.log));
} else {
this.log.write("!ENTRY");
this.log.write(32);
this.log.write("org.eclipse.core.launcher");
this.log.write(32);
this.log.write(String.valueOf(4));
this.log.write(32);
this.log.write(String.valueOf(0));
this.log.write(32);
try {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS");
this.log.write(formatter.format(new Date()));
}
catch (Exception e) {
this.log.write(Long.toString(System.currentTimeMillis()));
}
this.log.newLine();
this.log.write("!MESSAGE");
this.log.write(32);
this.log.write(String.valueOf(obj));
}
this.log.newLine();
}
private void computeLogFileLocation() {
String logFileProp = System.getProperty("osgi.logfile");
if (logFileProp != null) {
if ((this.logFile == null) || (!logFileProp.equals(this.logFile.getAbsolutePath()))) {
this.logFile = new File(logFileProp);
this.logFile.getParentFile().mkdirs();
}
return;
}
URL base = buildURL(System.getProperty("osgi.configuration.area"), false);
if (base == null)
return;
this.logFile = new File(base.getPath(), Long.toString(System.currentTimeMillis()) + ".log");
this.logFile.getParentFile().mkdirs();
System.setProperty("osgi.logfile", this.logFile.getAbsolutePath());
}
private int hexToByte(byte b)
{
switch (b) {
case 48:
return 0;
case 49:
return 1;
case 50:
return 2;
case 51:
return 3;
case 52:
return 4;
case 53:
return 5;
case 54:
return 6;
case 55:
return 7;
case 56:
return 8;
case 57:
return 9;
case 65:
case 97:
return 10;
case 66:
case 98:
return 11;
case 67:
case 99:
return 12;
case 68:
case 100:
return 13;
case 69:
case 101:
return 14;
case 70:
case 102:
return 15;
case 58:
case 59:
case 60:
case 61:
case 62:
case 63:
case 64:
case 71:
case 72:
case 73:
case 74:
case 75:
case 76:
case 77:
case 78:
case 79:
case 80:
case 81:
case 82:
case 83:
case 84:
case 85:
case 86:
case 87:
case 88:
case 89:
case 90:
case 91:
case 92:
case 93:
case 94:
case 95:
case 96: } throw new IllegalArgumentException("Switch error decoding URL");
}
private void openLogFile() throws IOException
{
computeLogFileLocation();
try {
this.log = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(this.logFile.getAbsolutePath(), true), "UTF-8"));
} catch (IOException e) {
this.logFile = null;
throw e;
}
}
private BufferedWriter logForStream(OutputStream output) {
try {
return new BufferedWriter(new OutputStreamWriter(output, "UTF-8")); } catch (UnsupportedEncodingException e) {
}
return new BufferedWriter(new OutputStreamWriter(output));
}
private void closeLogFile() throws IOException
{
try {
if (this.log != null) {
this.log.flush();
this.log.close();
}
} finally {
this.log = null;
}
}
private void mergeProperties(Properties destination, Properties source) {
if ((destination == null) || (source == null))
return;
for (Enumeration e = source.keys(); e.hasMoreElements(); ) {
String key = (String)e.nextElement();
if (key.equals("osgi.frameworkClassPath")) {
String destinationClasspath = destination.getProperty("osgi.frameworkClassPath");
String sourceClasspath = source.getProperty("osgi.frameworkClassPath");
if (destinationClasspath == null)
destinationClasspath = sourceClasspath;
else
destinationClasspath = destinationClasspath + sourceClasspath;
destination.put("osgi.frameworkClassPath", destinationClasspath);
}
else if (!key.equals("eof")) {
String value = source.getProperty(key);
if (destination.getProperty(key) == null)
destination.put(key, value);
}
}
}
private void setupVMProperties() {
if (this.vm != null)
System.getProperties().put("eclipse.vm", this.vm);
setMultiValueProperty("eclipse.vmargs", this.vmargs);
setMultiValueProperty("eclipse.commands", this.commands);
}
private void setMultiValueProperty(String property, String[] value) {
if (value != null) {
StringBuffer result = new StringBuffer(300);
for (int i = 0; i < value.length; i++) {
if (value[i] != null) {
result.append(value[i]);
result.append('\n');
}
}
System.getProperties().put(property, result.toString());
}
}
private class EclipsePolicy extends Policy
{
private Policy policy;
private URL[] urls;
private PermissionCollection allPermissions;
private Permission allPermission = new AllPermission();
EclipsePolicy(Policy policy, URL[] urls) {
this.policy = policy;
this.urls = urls;
this.allPermissions = new PermissionCollection() {
private static final long serialVersionUID = 3258131349494708277L;
public void add(Permission permission) {
}
public boolean implies(Permission permission) {
return true;
}
public Enumeration elements() {
return new Enumeration() {
int cur = 0;
public boolean hasMoreElements() {
return this.cur < 1;
}
public Object nextElement() {
if (this.cur == 0) {
this.cur = 1;
return Main.EclipsePolicy.this.allPermission;
}
throw new NoSuchElementException();
} } ;
} } ;
}
public PermissionCollection getPermissions(CodeSource codesource) {
if (contains(codesource.getLocation()))
return this.allPermissions;
return this.policy == null ? this.allPermissions : this.policy.getPermissions(codesource);
}
public PermissionCollection getPermissions(ProtectionDomain domain) {
if (contains(domain.getCodeSource().getLocation()))
return this.allPermissions;
return this.policy == null ? this.allPermissions : this.policy.getPermissions(domain);
}
public boolean implies(ProtectionDomain domain, Permission permission) {
if (contains(domain.getCodeSource().getLocation()))
return true;
return this.policy == null ? true : this.policy.implies(domain, permission);
}
public void refresh() {
if (this.policy != null)
this.policy.refresh();
}
private boolean contains(URL url)
{
for (int i = 0; i < this.urls.length; i++)
{
if (this.urls[i] == url)
return true;
}
return false;
}
}
static class Identifier
{
private static final String DELIM = ". _-";
private int major;
private int minor;
private int service;
Identifier(int major, int minor, int service)
{
this.major = major;
this.minor = minor;
this.service = service;
}
Identifier(String versionString)
{
StringTokenizer tokenizer = new StringTokenizer(versionString, ". _-");
if (tokenizer.hasMoreTokens()) {
this.major = Integer.parseInt(tokenizer.nextToken());
}
if (tokenizer.hasMoreTokens()) {
this.minor = Integer.parseInt(tokenizer.nextToken());
}
try
{
if (tokenizer.hasMoreTokens())
this.service = Integer.parseInt(tokenizer.nextToken());
}
catch (NumberFormatException localNumberFormatException)
{
}
}
boolean isGreaterEqualTo(Identifier minimum)
{
if (this.major < minimum.major)
return false;
if (this.major > minimum.major) {
return true;
}
if (this.minor < minimum.minor)
return false;
if (this.minor > minimum.minor) {
return true;
}
return this.service >= minimum.service;
}
}
private class StartupClassLoader extends URLClassLoader
{
public StartupClassLoader(URL[] urls)
{
super();
}
public StartupClassLoader(URL[] urls, ClassLoader parent) {
super(parent);
}
public StartupClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
super(parent, factory);
}
protected String findLibrary(String name) {
if (Main.this.extensionPaths == null)
return super.findLibrary(name);
String libName = System.mapLibraryName(name);
for (int i = 0; i < Main.this.extensionPaths.length; i++) {
File libFile = new File(Main.this.extensionPaths[i], libName);
if (libFile.isFile())
return libFile.getAbsolutePath();
}
return super.findLibrary(name);
}
}
}