启动篇 (eclipse 3.30代码分析)

xiaoxiao2026-08-28  1

启动类

通过查看eclipse.exe文件,可以判断是 org.eclipse.equinox.launcher.Main 在plugin org.eclipse.equinox.launcher_1.0.1.R33x_v20080118.jar里面 org.eclipse.equinox.launcher.Main作者推荐只能从命令行启动,需要api调用,请使用EclipseStarter  启动类的输入参数是在 : eclipse.ini文件里面

重要属性 

osgi.install.area: eclipse 安装地方,如果你没有指定,默认是下列代码得到 ProtectionDomain domain = Main.class.getProtectionDomain(); CodeSource source = null; URL result = null; if (domain != null) source = domain.getCodeSource(); if (source == null || domain == null) { if (debug) System.out.println("CodeSource location is null. Defaulting the install location to file:startup.jar"); //$NON-NLS-1$ try { result = new URL("file:startup.jar"); //$NON-NLS-1$ } catch (MalformedURLException e2) { //Ignore } } if (source != null) result = source.getLocation(); String path = decode(result.getFile()); // normalize to not have leading / so we can check the form File file = new File(path); path = file.toString().replace('\\', '/'); // TODO need a better test for windows // If on Windows then canonicalize the drive letter to be lowercase. // remember that there may be UNC paths if (File.separatorChar == '\\') if (Character.isUpperCase(path.charAt(0))) { char[] chars = path.toCharArray(); chars[0] = Character.toLowerCase(chars[0]); path = new String(chars); } if (path.toLowerCase().endsWith(".jar")) //$NON-NLS-1$ path = path.substring(0, path.lastIndexOf("/") + 1); //$NON-NLS-1$ if (path.toLowerCase().endsWith("/plugins/")) //$NON-NLS-1$ path = path.substring(0, path.length() - "/plugins/".length()); //$NON-NLS-1$ try { try { // create a file URL (via File) to normalize the form (e.g., put // the leading / on if necessary) path = new File(path).toURL().getFile(); } catch (MalformedURLException e1) { // will never happen. The path is straight from a URL. } installLocation = new URL(result.getProtocol(), result.getHost(), result.getPort(), path); System.getProperties().put(PROP_INSTALL_AREA, installLocation.toExternalForm()); } catch (MalformedURLException e) { // TODO Very unlikely case. log here. }  得出来的结果就是plugins的父目录 osgi.configuration.area: 默认情况是在 ${osgi.install.area}/configuration, 当然你也可以配置,它会从这个目录下面去读config.ini文件

API 启动类

相关资源:Eclipse源代码分析部分
转载请注明原文地址: https://www.6miu.com/read-5051996.html

最新回复(0)