I. Overview
My friends who have been paying attention to my blog will see that recently I have been paying attention to the compilation of eclipse source code, but apart from simple compilation settings and tedious and patient source code stripping, there seems to be nothing interesting. Now, after a series of warm-up exercises, I will join you in the eclipse kernel to see how it works?
1. Eclipse source code version: 3.1.1; Size: 63.2 MB
Eclipse-sourceBuild-srcIncluded-3.1.1.zip
: Http://download.eclipse.org/eclipse/downloads
2. Source insight v3.5, a source code reading Tool
It is actually a code editing software, because there is a powerful code analysis tool that can easily track the relevance of the code, so it is often used as a tool to read the code.
: Http://sourceinsight.com/down35.html
To facilitate code analysis, we only extract the code of the following plug-ins:
Org. Eclipse. Platform org. Eclipse. platform_3.1.1.jar
Org. Eclipse. Core. commands org. Eclipse. Core. commands_3.1.0.jar
Org. Eclipse. Core. Expressions org. Eclipse. Core. expressions_3.1.0.jar
Org. Eclipse. Core. runtime org. Eclipse. Core. runtime_3.1.1.jar
Org. Eclipse. Help org. Eclipse. help_3.1.0.jar
Org. Eclipse. jface org. Eclipse. jface_3.1.1.jar
Org. Eclipse. osgi org. Eclipse. osgi_3.1.1.jar
Org. Eclipse. SWT. win32.win32. x86 org. Eclipse. SWT. win32.win32. x86_3.1.1.jar
Org. Eclipse. SWT org. Eclipse. swt_3.1.0.jar
Org. Eclipse. UI. workbench org. Eclipse. UI. workbench_3.1.1.jar
Org. Eclipse. UI org. Eclipse. ui_3.1.1.jar
Org. Eclipse. Update. configurator org. Eclipse. Update. configurator_3.1.0.jar
Decompress the code to an empty directory and import it to the project of source insight.
Ii. Eclipse Startup Process
First, we start from the eclipse startup process.
1、eclipse.exe
It is the Startup File of eclipse and the executable file related to the platform. Its function is relatively simple. It mainly loads the startup. jar file. The code is located in the/Features/org. Eclipse. Platform. launchers/library directory of eclipse source code and corresponds to multiple platforms. For the Win32 platform, you can directly run the build. BAT file under the Win32 Directory to compile it (you need to install the C compiler ).
2. startup. Jar
This is the real Startup File of eclipse. You can run the Java-jar startup. Jar command in the command line to start eclipse. Its entry is org. Eclipse. Core. launcher. Main. Its source code is in Main. Java under the subdirectory of the org. Eclipse. Platform/src directory. We track back from the main function and find basicrun, which is the main part of startup.
Protected void basicrun (string [] ARGs) throws exception {
......
Setupvmproperties (); // sets VM attributes
Processconfiguration (); // read the configuration/config. ini configuration file.
......
// Need to ensure that getinstalllocation is called at least once to initialize the value.
// Do this after processing the configuration to allow the configuration to set
// The Install location.
Getinstalllocation ();
// Locate boot plugin (may return-dev mode variations)
URL [] bootpath = getbootpath (bootlocation );
Setsecuritypolicy (bootpath); // sets the execution permission
// Splash handling is done here, because the default case needs to know
// The location of the boot plugin we are going to use
Handlesplash (bootpath );
Invokeframework (passthruargs, bootpath); // start the eclipse Kernel
}
The previous part of this function is to set some attributes. The most important thing is the final invokeframework function, which is the core to start eclipse. Next, let's take a look at the specific content of the invokeframework function.
Private void invokeframework (string [] passthruargs, URL [] bootpath) throws classnotfoundexception, nosuchmethodexception, illegalaccessexception, error, exception, invocationtargetexception {
......
Urlclassloader loader = new startupclassloader (bootpath, parent );
Class clazz = loader. loadclass (starter); // load string starter = "org. Eclipse. Core. runtime. adaptor. eclipsestarter ";
Method method = clazz. getdeclaredmethod ("run", new class [] {string []. Class, runnable. Class}); // obtain the run Method
......
Method. Invoke (clazz, new object [] {passthruargs, endsplashhandler}); // call the run Method
......
}
First, create the loader, which is a urlclassloader type. Load the class "org. Eclipse. Core. runtime. adaptor. eclipsestarter", obtain its run method, and then call this method.
3. osgi startup
The source code of the "org. Eclipse. Core. runtime. adaptor. eclipsestarter" class is located at/plugins/org. Eclipse. osgi/eclipseadaptor/src/org/Eclipse/CORE/runtime/adaptor. It can be seen that it is already in the osgi package, and it is the osgi startup class.
Public static void startup (string [] ARGs, runnable endsplashhandler) throws exception {
......
Adaptor = createadaptor (); // create an adapter
......
Osgi = new osgi (Adaptor); // creates an osgi object. This is what we are looking.
......
Osgi. Launch (); // starts osgi
......
Context = osgi. getbundlecontext (); // obtain the execution context of the loaded bundle.
......
Bundle [] startbundles = loadbasicbundles (); // load bundle
Setstartlevel (getstartlevel (); // you can specify the startup level.
......
}