Python creates a custom eclipse IDE for you

Source: Internet
Author: User
Eclipse is a powerful framework that enables multiple extensions through the built-in plug-in mechanism. However, in order to add a little bit of extra functionality, it is inevitable that everyone will have to face the task of writing and deploying new plugins, which is obviously a bit of a headache. Now with the help of ease, we are able to do this in a better way-and the whole process doesn't need to involve any generation of Java code. Ease allows us to easily implement automated workbench functions using scripting languages like Python or JavaScript.


In this article, we'll work together to understand how to set up the eclipse environment with Python and ease, while considering a variety of possible ways to leverage Python to harden your IDE's solution.

Set up and run "Hello World"

The examples covered in today's article are based on the Python Java implementation scenario, Jython. You can install ease directly into the existing Eclipse IDE. In this example, however, we use Eclipse Mars and install the Ease ontology, its modules, and the Jython engine.

Within the Eclipse Installation dialog box (Help>install New software ... ), install ease:http://download.eclipse.org/ease/update/nightly

Next, tick the following components:

EASE core feature (EASE kernel function)
EASE Core UI feature (EASE kernel UI features)
EASE python Developer Resources (EASE Python developer Resource)
EASE Modules (incubation) (EASE module, incubation)
In this way, we are able to use ease and its various modules. Here we primarily need to use the resource module, which allows us to access the Eclipse workspace, project, and file API.


After successful installation of the above entries, the next step is to install the ease Jython engine: https://dl.bintray.com/pontesegger/ease-jython/. Once the plug-ins have been installed, test the ease below. Create a new project and add a file named hello.py with the following command:

print "Hello World"

Select the file, right-click and choose "Run as-EASE script". At this point you will see the console display "HELLP World".

Now you can start writing a Python script that can access the workspace and the project. Starting from here, we are adjusting the IDE based on the following goals.

Improve code Quality

Ensuring good code quality is a very difficult task, especially if the codebase is large or involves multiple developers. Some of these challenges can be easily solved by introducing scripts, such as batch formatting of certain types of files, or removing end-of-line lines of UNIX in source control systems such as git to simplify file content comparisons. It is also worth emphasizing that we can use the script to generate Eclipse markup, which allows for functional improvements in the way code is highlighted. The following script example can be used to add a task-tagging mechanism to all the "printstacktrace" methods to implement the Java file internal instrumentation. Click this link to view the source code: markers.py

First copy the files in the workspace, then right-click on the corresponding file and select "Run as-EASE script".

If you already have some Java files that contain printstacktraces, you can look in the task view at the edge of the editor to see the newly created markup.


Automated processing of tedious tasks

When you are working on multiple projects at the same time, you may want to automate some tedious and repetitive tasks. You might want to add a copyright title at the beginning of each source file, or update the source file when you adopt the new frame. For example, when we first switch to Tycho and MAVEN, we need to add a Pom.xml file for each project. This can be done with just a few lines of Python code. However, since Tycho currently supports no POM build, we need to remove these unnecessary pom files. Similarly, a few lines of Python script can be implemented. For example, here we use the following script to add a readme.md file to each open project in the workspace--if they belong to a Java or Python project, of course. Click on the link below to view the source code: add_readme.py.

To run the script, copy the file to the workspace, then right-click on the file and select "Run as-EASE script".

As a result, each open project will have a readme.md file, while the Java and Python projects have additional description lines.

New function Prototype design

You can also use Python scripts to quickly fix most of the features you need, or as a prototype to help team members or users understand how to use this new feature. For example, the Eclipse IDE does not currently support automatic saving of files that are being processed. While this feature will definitely appear in a future release, you can still do it yourself so that the current file is automatically saved every 30 seconds or when the editor is closed. The following is the code snippet in the Main method. Click on the link below to view the full source code: autosave.py

Before running this script, you will also need to check the "Allow Scripts to run code in UI thread" (allowing the script to run within the UI thread) option in the dialog box in Window > Preferences > Scripting. As a result, you will be able to add the file to your work, right-click on it and select "Run as-EASE script". Each time the editor makes a save operation, a saved message is printed in the console view. To turn off AutoSave, you can simply stop the script by tapping the "Terminate" red button in the console view.


Quickly extend the user interface with buttons, menus, and other items

One of the best features of ease is that it allows you to use your own scripts and quickly hook them into UI elements within the IDE-either as new buttons or as new menu entries. No need to write Java code or use a new plugin, just add a few lines of content to the script header-that's it.

The following example is a simple set of scripts that is responsible for creating three new projects for us:

The comment line that points to ease is responsible for adding a new button to the Project Manager toolbar. Here is another set of scripts that is responsible for adding another button to the same toolbar to remove the three items completely. Click on the link below to view its source code: createprojects.py and deleteprojects.py.

# name:D elete Fruit Projects # toolbar:project Explorer # description:get rid of the fruit projects LoadModule ("/syst Em/resources ") for name in [" Banana "," pineapple "," Mango "]: Project = getproject (name) project.delete (0, None)

To make these buttons appear correctly, we also need to add two script files to the new project--Here we call the new project "Scriptsproject". The next step is to open windows > Preference > Scripting > Script Locations. Click the "Add Workspace" button and select Scriptsproject. This project is now the default location for the script file to be stored. You should be able to see these buttons directly within the project manager without having to restart the IDE. With these new buttons, we are able to quickly create and delete these three corresponding items.


Integration with third-party tools

You may need to use tool options outside of the eclipse ecosystem at any time (and you must admit that, although eclipse itself is very powerful, it still has a compelling area). For such scenarios, it is very convenient for you to add the package request and the tool call to the script. The following example allows you to integrate Explorer.exe and add it to the content menu so that we can open the file browser at any time using the existing selection. Click on the link below to view its source code: explorer.py

In order for the menu to be displayed correctly, we need to add the script to a new project-we still call it "Scriptsproject". Next go to Windows > Preference > Scripting > Script Locations. Click the "Add Workspace" button and select Scriptsproject. Now, you should be able to right-click a file and see that the new menu entry appears in the pop-up menu. Click to open the file browser. (It's important to note that this feature is already in eclipse, but here we just use it as an example to explain how other third-party tools are integrated.) )

This Eclipse advanced scripting environment gives you the full potential of python, helping us to flexibly use the Eclipse IDE. The project is now in its infancy, so more exciting features and features can be expected in the future.

The above-mentioned is about Python to create a tailor-made eclipse IDE for your knowledge, we hope to help!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.