Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Setting up Eclipse: Difference between revisions

From MoodleDocs
No edit summary
m (Changed protection level for "Setting up Eclipse" ([Edit=Allow only administrators] (indefinite)))
 
(123 intermediate revisions by 35 users not shown)
Line 1: Line 1:
[http://www.eclipse.org/ Eclipse] is an IDE originally designed for Java, but now with plugins for many languages, including PHP. It has lots of very powerful features, and it is the editor of choice for most of the OU Moodle developers, and a number of other people in the community.
{{Template:WillNotMigrate}}
[http://www.eclipse.org/ Eclipse] is an IDE originally designed for Java, but now with plugins for many languages including PHP. It has lots of very powerful features, and it is the editor that some Moodle developers like to use. Other (more) popular choices are vim and emacs.


However, it is not the easiest program in the world to get started with, so I'm going to take you through it step by step. These instructions assume Eclipse 3.2, the current version at the time of writing. It should not change much between releases.
However, Eclipse is not the easiest program in the world to get started with, so I'm going to take you through it step by step. These instructions assume Eclipse 3.2, the current version at the time of writing. It should not change much between releases.


;Warning
This article started off as a brain-dump by [[User:Tim Hunt|Tim Hunt]]. Since then, several other people have worked through it and made corrections and the information should be pretty accurate.
:This is just a brain-dump, and since I already have Eclipse installed on all my computers I have not been able to test all the the steps. I would be very grateful if some people could try these instructions and make the necessary corrections.[[User:Tim Hunt|Tim Hunt]] 21:32, 12 August 2006 (WST)
 
A new PHP plugin called PDT, which is better, but uses more memory. Follow the instructions [[#Installing_the_necessary_plugins,_for_Eclipse_Classic]] PART 1. The following instructions, from the section [[#Setting_the_preferences_for_Moodle_development]] mostly still apply after you have done the install, but some of the details are a bit different.


==Prerequisites==
==Prerequisites==


Eclipse is written in Java, so I would recommend getting the latest Java runtime environment from http://java.com/ for maximum speed and reliability.
Eclipse is written in Java, so I recommend getting the latest Java runtime environment from http://java.com/ for maximum speed and reliability.


Also, Eclipse is quite big, so I recomment lots of memory in your computer. I have used it on all of Windows, MacOS X and Linux with 1GB of memory, and that is plenty.
Eclipse is quite big, so I recommend lots of memory in your computer. I have used it on Windows, MacOS X and Linux, in each case with 1GB of memory, and that is plenty.


==Installing Eclipse==
==Installing Eclipse==


Go to http://www.eclipse.org/downloads/. Click on the link where it says '''Download now: Eclipse SDK 3.2''' It should have automatically detected which platform you are using. Choose a Mirror, and wait for the ~100MB download.
Go to http://www.eclipse.org/downloads/. Click on the link corresponding to your operating system where it says '''Eclipse Classic'''. Choose a Mirror, and wait for the ~100MB download.


You will notice that what you have got is a zip file (unless your system automatically decompresses it for you).
You will notice that what you have got is a zip file (unless your system automatically decompresses it for you).


On Windows, upzip it into '''C:\Program Files''' (all the files go into an '''Eclipse''' folder there). Then look in the Eclipse folder and drag Eclipse.exe to the Start menu/Desktop/Quicklaunch bar to make a shortcut for starting it.
On Windows, unzip it into '''C:\Program Files''' (all the files go into an '''Eclipse''' folder there). Then look in the Eclipse folder and drag Eclipse.exe to the Start menu/Desktop/Quicklaunch bar to make a shortcut for starting it.


On MacOS, unzip and copy the Eclipse folder into Applications. Go into the Eclipse folder and drag the Eclipse app to the Dock for ease of launching.
On MacOS, unzip and copy the Eclipse folder into Applications. Go into the Eclipse folder and drag the Eclipse app to the Dock for ease of launching.
Line 26: Line 28:
==The first time you run Eclipse==
==The first time you run Eclipse==


The first time you lauch Eclipse it does a bit of setup stuff, for instance, it create a '''workspace'''. This is where it stores the things you are working on. The default location is sensible on all platforms, so use that.
The first time you launch Eclipse it does a bit of setup stuff, for instance, it creates a '''workspace'''. This is where it stores the things you are working on. The default location is sensible on all platforms, so use that.
 
For some reason, every time you start Eclipse, it asks you which workspace you want to use. I have never seen the need to have more than one, so I recommend turning on the checkbox that says "Use this as the default and do not ask again".
 
Another thing that happens the first time you run Eclipse is that you arrive at a welcome screen. This has links to various bits of help, which you can read if you like, but you probably don't need to if you are following these instructions. So find the button on the welcome page that closes it and gets you to the main Eclipse screen.


For some reason, every time you start Eclipse, it asks you which workspace you want to use. I have never seen the need to have more than one, so I recommend turning on the checkbox that says "Don't ask me this again".
==Installing the necessary plugins, for Eclipse Classic==


Another thing that happens the first time you run Eclipse is that you arrive at a welcome screen. This has links to various bits of help, which you can read if you like, but you probaly don't need to if you are following these instructions. So find the button on the welcome page that closes it and gets you to the main Eclipse screen.
By default, Eclipse comes with the Java tools. For everything else you will need to install some plugins. Before we begin make sure Eclipse is up to date. '''Help > Check for Updates'''. For old versions of Eclipse, Eclipse 3.4 or before go to Part 2.


==Installing the necessary plugins==
====PART 1====
PHP Development Tools (PDT) is part of the Eclipse's standard plugins.
#Open up Eclipse and on the menu bar go to '''Help > Install New Software'''
#In the "Work with" box type in <nowiki>http://download.eclipse.org/releases/</nowiki>''<release name>''/
::for example http://download.eclipse.org/releases/juno/
#In the next box "type filter text" type in "'''php'''"
#Select the plugin "'''PHP Development Tools (PDT) SDK Feature'''"
#Make sure "Contact all update sites during install ..." is selected and click "'''Next'''"
# Follow the rest of the installation process.


By default, Eclipse comes with the Java tools. For everything else you will need to install some plugins.
====PART 2====
The following information of this section about plugins for PHP is for Eclipse 3.4 Ganymede or before.


If you are sitting behind a web proxy, from the '''Window''' menu choose '''Preferences ...'''. Choose '''Install/Update''' from the tree view on the left, and enter the proxy information in the boxes on the right. If you aren't behind a proxy, ignore this step.
If you are sitting behind a web proxy, from the '''Window''' menu choose '''Preferences ...'''. Choose '''Install/Update''' from the tree view on the left, and enter the proxy information in the boxes on the right. If you aren't behind a proxy, ignore this step. (On Eclipse 3.4.0 on OSX this is in '''Eclipse > Preferences > General > Network Connections''')


From the '''Help''' menu choose '''Software Updates -> Find and Install'''.
From the '''Help''' menu choose '''Check for Updates'''.


On the first screen of the wizard, make sure that "Search for new features to install" is selected, then click '''Next >'''.
On the first screen of the wizard, make sure that "Search for new features to install" is selected, then click '''Next >'''.
Line 44: Line 59:
The next screen is a list of upgrade sites to check. You need to add one to the list, so click the '''New Remote Site ...''' Button.
The next screen is a list of upgrade sites to check. You need to add one to the list, so click the '''New Remote Site ...''' Button.


In the pop-up dialog, give the remote site a name like '''PHPeclipse update site'''; set the URL to http://phpeclipse.sourceforge.net/update/releases/; then click '''OK'''.
In the pop-up dialog, give the remote site a name like '''PHPeclipse Update Site'''; set the URL to http://update.phpeclipse.net/update/nightly; then click '''OK'''. Click '''Finish'''. Under '''PHPEclipse Nightly Builds''', check '''PHPeclipse'''. Click '''Finish'''. Wait while it downloads (this may take a few minutes). Click '''Install'''. You will be prompted to restart Eclipse, click '''Restart'''.
 
''Note, there is now also another PHP editor for Eclipse. The update URL is http://download.eclipse.org/tools/pdt/updates/''


Back in the wizard, turn on just two things in the box "Sites to include in search":
''As of 05.02.2018, the update URL is:  http://download.eclipse.org/tools/pdt/updates/5.3''
* Your newly created ''''Phpeclipse update site'''; and
 
* the one called '''Callisto Discovery Site'''.
Restart the wizard (from the '''Help''' menu choose '''Software Updates -> Find and Install''').
 
On the first screen of the wizard, make sure that "Search for new features to install" is selected, then click '''Next >'''.
 
Select just two things in the box "Sites to include in search":
* Your newly created '''Phpeclipse Update Site'''; and
* the one called '''Europa Discovery Site''' (or possibly '''Callisto Discovery Site''').
Then click '''Finish'''.
Then click '''Finish'''.


It goes off sees what updates are avaiable at those sites. As it does so, it may occasionally pop up a dialog asking you to choose a mirror. Each time, select a sensible one.
It goes off and sees what updates are available at those sites. As it does so, it may occasionally pop up a dialog asking you to choose a mirror. Each time, select a sensible one.


Eventually, you get to a new wizard for selecting and installing the updates you want. The ones you want (you may have to search the tree structure) are, '''PHPeclipse''' and all the '''Web Standard Tools (WST)''' ones.
Eventually, you get to a new wizard for selecting and installing the updates you want (Select the features to install). The ones you want (you may have to expand and search the tree structure) are: all the '''PHPEclipse Nightly Builds''' (from your newly created PHPEclipse Update Site) and the '''Web Standard Tools (WST)''' (usually under Callisto or Europa Discovery Site --> Web and J2EE Development).  


Next, and very importantly, you must click the '''Select Required''' button. Then you can click the '''Next >''' button.
Next, and very importantly, you must click the '''Select Required''' button which should resolve dependencies and remove the warning message you are probably worrying about. Then you can click the '''Next >''' button.


Read and agree to all the license agreements. Then click '''Next >'''.  
Read and agree to all the license agreements. Then click '''Next >'''.  
Line 61: Line 84:
Click '''Finish''', and wait for the plugins to download.
Click '''Finish''', and wait for the plugins to download.


Once the downloads have finished, a warning will pop-up telling you that all the plugins you downloaded are not digitally signed. The Eclipse Foundation build digital signing of plugins into their archetecture as a security measure, and then did not sign any of their own plugins! Anyway, click the '''Install All''' button.
Once the downloads have finished, a warning will pop-up telling you that all the plugins you downloaded are not digitally signed. The Eclipse Foundation built digital signing of plugins into their architecture as a security measure, and then did not sign any of their own plugins! Anyway, click the '''Install All''' button.


Finally, a Window will pop up asking you to restart Eclipse. Do so.
Finally, a window will pop up asking you to restart Eclipse. Do so.


==Setting the preferences for Moodle development==
==Setting the preferences for Moodle development==


Now go to the '''Window''' menu, and choose '''Preferences ...'''.
Now go to the '''Window''' menu, and choose '''Preferences ...''' ('''Eclipse''' menu on Mac OS X).


The Eclipse preferences are emense, with a tree view on the left, which selects which screen to display on the right. Don't panic, we'll guide you through it.
The Eclipse preferences are immense, with a tree view on the left, which selects which screen to display on the right. Don't panic, we'll guide you through it.


===General settings===
===General settings===


If you have strong feelings about fonts, choose '''General -> Appearance -> Colors and Fonts''' from the tree on the left. Then on the right look under '''Basic''' and change '''Text Font'''. All the other editor font settings will inherit from this, so this is probably the only one you have to change.
If you have strong feelings about fonts (I would hate to edit code an anything except Andale Mono), choose '''General -> Appearance -> Colors and Fonts''' from the tree on the left. Then on the right look under '''Basic''' and change '''Text Font'''. All the other editor font settings will inherit from this, so this is probably the only one you have to change.


Under ''"General -> Content Types''', select PHP Source File, and add "*.html" to the box at the bottom.
Under '''General -> Content Types''', select PHP Source File, and add '''*.html''' to the box at the bottom.


Under '"General -> Editors -> File Associations''', add "*.php" to the top box. With "*.php" selected in the top box, make sure "PHP Editor" is set to default in the bottom box. With "*.html" selected in the top box, select "PHP Editor" in the bottom box and click the "Default" button to change it, because in Moodle, most HTML files actually contain PHP code.
Under '''General -> Editors -> File Associations''', if it is not already there, add '''*.php''' to the top box. With '''*.php''' selected in the top box, make sure '''PHP Editor''' is set to default in the bottom box (use the '''Default''' button - the default will appear at the top of the list).  


If you use a web proxy, enter the details under '"Internet -> Proxy Settings'''. (Yes, I know you have entered the somewhere else before. Now you have to enter them again here. I don't know why. You just do.)
With '''*.html''' selected in the top box, if it is not already there, add '''PHP Editor''' to the bottom box. Then select '''PHP Editor''' in the bottom box and click the '''Default''' button to change it, because in Moodle, most HTML files actually contain PHP code.
 
If you use a web proxy, enter the details under '''Network Connections'''. (Yes, I know you have entered them somewhere else before. Now you have to enter them again here. I don't know why. You just do.)


===PHP Settings===
===PHP Settings===


These are all hidden under the '''PHPeclipse Web Development''' bit of the tree.
Under '''General -> Editors -> Text Editors''', check '''Show line numbers''' to display line numbers in the left margin (optional). Click '''Apply'''. (When you are editing a PHP file, you could left-click in the left margin and tick the '''Show Line Numbers''' line in the contextual menu. However, this toggle only applies to plain text files, ''not'' to HTML or PHP files. The only place where you can toggle line numbers on/off for such files is in the PHP/Appearance menu.)


Under '''PHPeclipse Web Development -> Browser Preview Defaults''', turn off both checkboxes.
Under '''PHPeclipse -> Browser Preview Defaults''', turn off all checkboxes (if necessary). Click '''Apply'''.


Under '''PHPeclipse Web Development -> PHP''', on the '''Appearance''' tab, set "Displayed tab width" to 4.
Under '''PHPeclipse -> PHP''', on the '''Appearance''' tab, set '''Displayed tab width''' to 4 (if necessary). Click '''Apply'''.


Under '''PHPeclipse Web Development -> PHP''', on the '''Typing''' tab, turn off all the options except "Pasting for correct indentation", "Insert spaces for tab" and "Close PHPdocs and comments". It would be nice to turn on more of these options, but most of the rest don't work very well.
Under '''PHPeclipse -> PHP''', on the '''Typing''' tab, turn off all the options except '''Pasting for correct indentation''', '''Insert spaces for tab''' and '''Close PHPdocs and comments'''. Click '''Apply'''.


Under '''PHPeclipse Web Development -> PHP -> Formatter''', on the '''New Lines''' tab, turn on '''Clear all blank lines'''.
Under '''PHPeclipse -> PHP -> Editor''', turn on '''Remove trailing spaces on editor save'''. Click '''Apply'''.


Under '''PHPeclipse Web Development -> PHP -> Formatter''', on the '''Style''' tab, turn off '''Indentation is represented by a tab'''.
Under '''PHPeclipse -> PHP -> Formatter''', on the '''New Lines''' tab, turn on '''Clear all blank lines'''. Click '''Apply'''.


Under '''PHPeclipse Web Development -> PHP -> Templates''', I like to define a new template to help with debugging:
Under '''PHPeclipse -> PHP -> Formatter''', on the '''Style''' tab, turn off '''Indentation is represented by a tab'''. Click '''Apply'''.
 
Under '''PHPeclipse -> PHP -> Templates''', I like to define a new template to help with debugging:
;Name
;Name
:dump  
:dump  
Line 101: Line 128:
:Dump a PHP variable
:Dump a PHP variable
;Pattern
;Pattern
:<pre>echo '<pre>'; //DONOTCOMMIT
<pre>print_object(${word_selection}${cursor}); // DONOTCOMMIT</pre>
print_r(${cursor});
You can do other useful things with templates too. Here are two more I use:
echo '</pre>';</pre>
<pre>debugging("'${word_selection}${cursor}'"); // DONOTCOMMIT</pre>
You can do other useful things with templates too.
<pre>$$string['${word_selection}${cursor}'] = '.';</pre>
That is, a simple debug message with a stack trace, and a new language string.
 
There is a really stupid bug. Under '''PHPeclipse -> Project Defaults''', you would like to add "." to the '''Include Paths''', but you can't using the GUI. You will have to edit one of the Eclipse config files by hand. So
# Note down the path to your Eclipse profile. On Windows it will be something like '''C:/Documents and settings/XXXX/workspace''', and on Unixy systems something like '''~/workspace'''.
# Close Eclipse.
# Open the file '''net.sourceforge.phpeclipse.ui.prefs''' that is in the directory '''(your workspace)/.metadata/.plugins/org.eclipse.core.runtime/.settings''' in a text editor.
# Look for a line in the file that starts '''_php_include_paths=''' If it is not there, add it at the end.
# Change this line to say '''_php_include_paths=.'''
# Run Eclipse again.
 
===SSH2===
 
You probably want to generate or load a SSH private key, to make it more convenient to connect to places like github. Hopefully someone can write step-by-step instructions for what needs to be done.
 
===Git Settings===
 
These are almost all hidden under the '''Team''' bit of the tree.
 
Please can someone add step by step instructions here. You need to use git for Moodle development. The default settings may be fine.
 
===Web and XML settings===
 
For each XXX in CSS, HTML, Javascript, XML:
 
Under '''Web and XML -> XML Files -> Source''', choose '''Indent using spaces''' and '''indentation size''' 4.
 
==Checking out the Moodle code==
 
From the '''File''' menu, choose '''New -> Project ...'''.
 
In the wizard that pops up, choose '''Git -> Projects from Git''', then click '''Next >'''.
 
... Please can someone fill in the rest of the steps here. It should match [[Git for developers]].


There is a really stupid bug. Under '''PHPeclipse Web Development -> Project Defaults''', you would like to add "." to the '''Include Paths''', but you can't. There is a page on the web with instructions for working round this (basically, you have to edit one of the config files by hand), but I can't find it now.
If you also need another branch (2.8, 2.9, ...) repeat all the other steps with a few changes:
* Select the appropriate branch.
* Use a different project name (e.g. moodle28, moodle29, etc.).


===CVS Settings===
==Let your development web server know where your files are==


These are all hidden under the '''Team''' bit of the tree.
Either by editing you web server's config files, or using a symbolic link. Make sure your webserver can see your new working set of files at a sensible URL, so you can test the code you are working on.


Under '''Team -> CVS -> SSH2 Connection Method''', you can set up a public/private key pair. If you do this, you won't have to keep typing your Sourceforge password when doing CVS operations. See http://sourceforge.net/docs/F02/ for the instructions of what you have to do at the Sourceforge end to make this work. That should make it clear what you have to do in Eclipse.


The rest of the ones in this section are personal preferences, but I recomment them because the default settings are very irritating.
==Quick tour of some cool features, and remaining configuration changes==


Under '''Team''', set "Perspectives" to '''None'''.
I find the default workbench setup is pretty good. Here is a quick guide to some of the bits.


Under '''Team -> CVS -> Annotate''' set "Use Quick Diff annotate mode for local file annotations" to '''Yes''', and '''Open perspective after a 'Show Annotations' operation" to '''No'''.
===Navigator===


Under '''Team -> CVS -> Console", turn on "Show CVS console automatically when command is run".
To the left is the '''Navigator'''. This is a tree view of all your files. If you double-click on a file, it opens in the editor in the middle. Try opening '''course/lib.php''' now. You will notice that it comes up nicely syntax-highlighted.


Under '''Team -> CVS -> Label Decorations''', switch to the '''Icon Decorations''' tab and turn on all the settings, and then on the '''Text Decorations''' tab change both "File Decoration" and "Folder Decoration" to be just '''{name}'''.
===Error highlighting===


===Web and XML settings===
In the middle of the file, just type any old text, for example "I like Eclipse". Obviously, this is not valid PHP syntax, and Eclipse will notice this, and put a red underline under it. Also, by the scrollbar is a ruler with a red mark in it to show the error.
 
You will see some yellow marks lower down the ruler. There are warnings. Click on one, and you will be taken to where that warning is in the file. Hover your mouse over the warning, and you will get a tooltip explaining what the problem might be.
 
Save the edited file. (Don't worry that it is broken, we'll clean up the mess later.) Notice that a red error marker is added to the file in the navigator, so you can see that there is a problem. Also, error markers are added to the course folder, and the whole project, so you could see there was an error even if the navigator tree was collapsed.
 
You will probably find lots of warnings that the config.php file can't be found. In the navigator, find the file '''config-dist.php'''. Do '''Copy''' then '''Paste''' and choose to call the new file '''config.php'''. Edit this new config.php as normal. You should find that most of the include file warnings have gone now.
 
Notice also that there is another marker on each file icon. A little yellow cylinder on most files, but a white-on-brown star on the one you have edited. This is telling you the git status of each file. The brown stars are changes you have made but not checked in yet.
 
===Outline===
 
Over to the right is the Outline view. This shows a list of functions and classes defined in this file. By default, they are listed in the same order as in the file, but if you click on the '''az''' toolbar button, they are sorted into alphabetical order.
 
Click on the function name '''add_course_module''' in the Outline. You will see that the editor scrolls to the definition of that function.
 
===Code navigation===
 
In that function, hover the mouse pointer over the function name '''insert_record'''. After a while, the documentation for that function will appear in a big tooltip.
 
Hold down CTRL, move the mouse pointer over the function name '''insert_record''', then click. Eclipse should load '''dmllib.php''', and scroll you to where this function is defined. (You can also do this by clicking on the function name and pressing the F3 key.)
 
In the main Eclipse toolbar, there are forward and back arrows like in a web browser. Click back now to get back to '''course/lib.php'''.
 
===Open resource===
 
From the '''Navigate''' menu, choose '''Open Resource...'''. In the dialog that pops up, start typing a filename for instance type '''moodlel'''. In the box in the middle of the dialog, you will see it list all the files in the project whose names start that way. At the bottom is a box which lists the different folders that contain a file with that name. This can be a very quick way of opening files with fairly unique names like moodlelib.php, without having to click through the levels of the navigator tree. Of course, it is not so useful for an index.php file! Click OK now to open moodlelib.php. (It would actually work if you just did CTRL + Shift + R, moodlel, Enter.)
 
===Multi-file search===
 
Scroll down moodlelib a little bit, and double click on the name of the constant '''MOODLE_INTERNAL''' where it is defined, so that the text is selected. Then, from the '''Search''' menu, choose '''Search...'''. Notice that the '''Containing text''' box has already been filled in for you with the text you just selected. Of course you can just type text into this box without selecting it first. Notice that you can do regular expression searches, but leave that turned off for now. In the '''File name patterns''' box type '''*.css, *.html, *.inc, *.js, *.php, *.xml'''. (This is the most useful general setting for working on moodle. Eclipse will remember this setting, so you only have to enter it once.) Click '''Search'''.


Foreach XXX in CSS, HTML, Javascript, XML:
The search results will appear in a new view underneath the editor. That view has a toolbar with yellow up and down arrows. Click the down arrow a few times and it will take you to the first few matches in the code, opening the relevant files as necessary.


Under '''Web and XML -> XXX Files ->XXX Source''', choose '''Indent using spaces''' and '''indentation size''' 4.
== Related Links ==


==Checking out the Moodle code==
There is an excellent series of articles published by IBM on using Eclipse for Drupal developement here : [http://www-128.ibm.com/developerworks/ibm/osource/index.html Using open source software to design, develop, and deploy a collaborative Web site Tools and techniques for getting relatively complicated Web sites up and running quickly].


==Some cool Eclipse features you should know about==
[[Category:Developer tools|Eclipse]]

Latest revision as of 16:00, 5 May 2022


Warning: This page is no longer in use. The information contained on the page should NOT be seen as relevant or reliable.


Eclipse is an IDE originally designed for Java, but now with plugins for many languages including PHP. It has lots of very powerful features, and it is the editor that some Moodle developers like to use. Other (more) popular choices are vim and emacs.

However, Eclipse is not the easiest program in the world to get started with, so I'm going to take you through it step by step. These instructions assume Eclipse 3.2, the current version at the time of writing. It should not change much between releases.

This article started off as a brain-dump by Tim Hunt. Since then, several other people have worked through it and made corrections and the information should be pretty accurate.

A new PHP plugin called PDT, which is better, but uses more memory. Follow the instructions #Installing_the_necessary_plugins,_for_Eclipse_Classic PART 1. The following instructions, from the section #Setting_the_preferences_for_Moodle_development mostly still apply after you have done the install, but some of the details are a bit different.

Prerequisites

Eclipse is written in Java, so I recommend getting the latest Java runtime environment from http://java.com/ for maximum speed and reliability.

Eclipse is quite big, so I recommend lots of memory in your computer. I have used it on Windows, MacOS X and Linux, in each case with 1GB of memory, and that is plenty.

Installing Eclipse

Go to http://www.eclipse.org/downloads/. Click on the link corresponding to your operating system where it says Eclipse Classic. Choose a Mirror, and wait for the ~100MB download.

You will notice that what you have got is a zip file (unless your system automatically decompresses it for you).

On Windows, unzip it into C:\Program Files (all the files go into an Eclipse folder there). Then look in the Eclipse folder and drag Eclipse.exe to the Start menu/Desktop/Quicklaunch bar to make a shortcut for starting it.

On MacOS, unzip and copy the Eclipse folder into Applications. Go into the Eclipse folder and drag the Eclipse app to the Dock for ease of launching.

On Linux, unzip somewhere suitable, and make an easy way to launch it.

The first time you run Eclipse

The first time you launch Eclipse it does a bit of setup stuff, for instance, it creates a workspace. This is where it stores the things you are working on. The default location is sensible on all platforms, so use that.

For some reason, every time you start Eclipse, it asks you which workspace you want to use. I have never seen the need to have more than one, so I recommend turning on the checkbox that says "Use this as the default and do not ask again".

Another thing that happens the first time you run Eclipse is that you arrive at a welcome screen. This has links to various bits of help, which you can read if you like, but you probably don't need to if you are following these instructions. So find the button on the welcome page that closes it and gets you to the main Eclipse screen.

Installing the necessary plugins, for Eclipse Classic

By default, Eclipse comes with the Java tools. For everything else you will need to install some plugins. Before we begin make sure Eclipse is up to date. Help > Check for Updates. For old versions of Eclipse, Eclipse 3.4 or before go to Part 2.

PART 1

PHP Development Tools (PDT) is part of the Eclipse's standard plugins.

  1. Open up Eclipse and on the menu bar go to Help > Install New Software
  2. In the "Work with" box type in http://download.eclipse.org/releases/<release name>/
for example http://download.eclipse.org/releases/juno/
  1. In the next box "type filter text" type in "php"
  2. Select the plugin "PHP Development Tools (PDT) SDK Feature"
  3. Make sure "Contact all update sites during install ..." is selected and click "Next"
  4. Follow the rest of the installation process.

PART 2

The following information of this section about plugins for PHP is for Eclipse 3.4 Ganymede or before.

If you are sitting behind a web proxy, from the Window menu choose Preferences .... Choose Install/Update from the tree view on the left, and enter the proxy information in the boxes on the right. If you aren't behind a proxy, ignore this step. (On Eclipse 3.4.0 on OSX this is in Eclipse > Preferences > General > Network Connections)

From the Help menu choose Check for Updates.

On the first screen of the wizard, make sure that "Search for new features to install" is selected, then click Next >.

The next screen is a list of upgrade sites to check. You need to add one to the list, so click the New Remote Site ... Button.

In the pop-up dialog, give the remote site a name like PHPeclipse Update Site; set the URL to http://update.phpeclipse.net/update/nightly; then click OK. Click Finish. Under PHPEclipse Nightly Builds, check PHPeclipse. Click Finish. Wait while it downloads (this may take a few minutes). Click Install. You will be prompted to restart Eclipse, click Restart.

Note, there is now also another PHP editor for Eclipse. The update URL is http://download.eclipse.org/tools/pdt/updates/

As of 05.02.2018, the update URL is: http://download.eclipse.org/tools/pdt/updates/5.3

Restart the wizard (from the Help menu choose Software Updates -> Find and Install).

On the first screen of the wizard, make sure that "Search for new features to install" is selected, then click Next >.

Select just two things in the box "Sites to include in search":

  • Your newly created Phpeclipse Update Site; and
  • the one called Europa Discovery Site (or possibly Callisto Discovery Site).

Then click Finish.

It goes off and sees what updates are available at those sites. As it does so, it may occasionally pop up a dialog asking you to choose a mirror. Each time, select a sensible one.

Eventually, you get to a new wizard for selecting and installing the updates you want (Select the features to install). The ones you want (you may have to expand and search the tree structure) are: all the PHPEclipse Nightly Builds (from your newly created PHPEclipse Update Site) and the Web Standard Tools (WST) (usually under Callisto or Europa Discovery Site --> Web and J2EE Development).

Next, and very importantly, you must click the Select Required button which should resolve dependencies and remove the warning message you are probably worrying about. Then you can click the Next > button.

Read and agree to all the license agreements. Then click Next >.

Click Finish, and wait for the plugins to download.

Once the downloads have finished, a warning will pop-up telling you that all the plugins you downloaded are not digitally signed. The Eclipse Foundation built digital signing of plugins into their architecture as a security measure, and then did not sign any of their own plugins! Anyway, click the Install All button.

Finally, a window will pop up asking you to restart Eclipse. Do so.

Setting the preferences for Moodle development

Now go to the Window menu, and choose Preferences ... (Eclipse menu on Mac OS X).

The Eclipse preferences are immense, with a tree view on the left, which selects which screen to display on the right. Don't panic, we'll guide you through it.

General settings

If you have strong feelings about fonts (I would hate to edit code an anything except Andale Mono), choose General -> Appearance -> Colors and Fonts from the tree on the left. Then on the right look under Basic and change Text Font. All the other editor font settings will inherit from this, so this is probably the only one you have to change.

Under General -> Content Types, select PHP Source File, and add *.html to the box at the bottom.

Under General -> Editors -> File Associations, if it is not already there, add *.php to the top box. With *.php selected in the top box, make sure PHP Editor is set to default in the bottom box (use the Default button - the default will appear at the top of the list).

With *.html selected in the top box, if it is not already there, add PHP Editor to the bottom box. Then select PHP Editor in the bottom box and click the Default button to change it, because in Moodle, most HTML files actually contain PHP code.

If you use a web proxy, enter the details under Network Connections. (Yes, I know you have entered them somewhere else before. Now you have to enter them again here. I don't know why. You just do.)

PHP Settings

Under General -> Editors -> Text Editors, check Show line numbers to display line numbers in the left margin (optional). Click Apply. (When you are editing a PHP file, you could left-click in the left margin and tick the Show Line Numbers line in the contextual menu. However, this toggle only applies to plain text files, not to HTML or PHP files. The only place where you can toggle line numbers on/off for such files is in the PHP/Appearance menu.)

Under PHPeclipse -> Browser Preview Defaults, turn off all checkboxes (if necessary). Click Apply.

Under PHPeclipse -> PHP, on the Appearance tab, set Displayed tab width to 4 (if necessary). Click Apply.

Under PHPeclipse -> PHP, on the Typing tab, turn off all the options except Pasting for correct indentation, Insert spaces for tab and Close PHPdocs and comments. Click Apply.

Under PHPeclipse -> PHP -> Editor, turn on Remove trailing spaces on editor save. Click Apply.

Under PHPeclipse -> PHP -> Formatter, on the New Lines tab, turn on Clear all blank lines. Click Apply.

Under PHPeclipse -> PHP -> Formatter, on the Style tab, turn off Indentation is represented by a tab. Click Apply.

Under PHPeclipse -> PHP -> Templates, I like to define a new template to help with debugging:

Name
dump
Description
Dump a PHP variable
Pattern
print_object(${word_selection}${cursor}); // DONOTCOMMIT

You can do other useful things with templates too. Here are two more I use:

debugging("'${word_selection}${cursor}'"); // DONOTCOMMIT
$$string['${word_selection}${cursor}'] = '.';

That is, a simple debug message with a stack trace, and a new language string.

There is a really stupid bug. Under PHPeclipse -> Project Defaults, you would like to add "." to the Include Paths, but you can't using the GUI. You will have to edit one of the Eclipse config files by hand. So

  1. Note down the path to your Eclipse profile. On Windows it will be something like C:/Documents and settings/XXXX/workspace, and on Unixy systems something like ~/workspace.
  2. Close Eclipse.
  3. Open the file net.sourceforge.phpeclipse.ui.prefs that is in the directory (your workspace)/.metadata/.plugins/org.eclipse.core.runtime/.settings in a text editor.
  4. Look for a line in the file that starts _php_include_paths= If it is not there, add it at the end.
  5. Change this line to say _php_include_paths=.
  6. Run Eclipse again.

SSH2

You probably want to generate or load a SSH private key, to make it more convenient to connect to places like github. Hopefully someone can write step-by-step instructions for what needs to be done.

Git Settings

These are almost all hidden under the Team bit of the tree.

Please can someone add step by step instructions here. You need to use git for Moodle development. The default settings may be fine.

Web and XML settings

For each XXX in CSS, HTML, Javascript, XML:

Under Web and XML -> XML Files -> Source, choose Indent using spaces and indentation size 4.

Checking out the Moodle code

From the File menu, choose New -> Project ....

In the wizard that pops up, choose Git -> Projects from Git, then click Next >.

... Please can someone fill in the rest of the steps here. It should match Git for developers.

If you also need another branch (2.8, 2.9, ...) repeat all the other steps with a few changes:

  • Select the appropriate branch.
  • Use a different project name (e.g. moodle28, moodle29, etc.).

Let your development web server know where your files are

Either by editing you web server's config files, or using a symbolic link. Make sure your webserver can see your new working set of files at a sensible URL, so you can test the code you are working on.


Quick tour of some cool features, and remaining configuration changes

I find the default workbench setup is pretty good. Here is a quick guide to some of the bits.

Navigator

To the left is the Navigator. This is a tree view of all your files. If you double-click on a file, it opens in the editor in the middle. Try opening course/lib.php now. You will notice that it comes up nicely syntax-highlighted.

Error highlighting

In the middle of the file, just type any old text, for example "I like Eclipse". Obviously, this is not valid PHP syntax, and Eclipse will notice this, and put a red underline under it. Also, by the scrollbar is a ruler with a red mark in it to show the error.

You will see some yellow marks lower down the ruler. There are warnings. Click on one, and you will be taken to where that warning is in the file. Hover your mouse over the warning, and you will get a tooltip explaining what the problem might be.

Save the edited file. (Don't worry that it is broken, we'll clean up the mess later.) Notice that a red error marker is added to the file in the navigator, so you can see that there is a problem. Also, error markers are added to the course folder, and the whole project, so you could see there was an error even if the navigator tree was collapsed.

You will probably find lots of warnings that the config.php file can't be found. In the navigator, find the file config-dist.php. Do Copy then Paste and choose to call the new file config.php. Edit this new config.php as normal. You should find that most of the include file warnings have gone now.

Notice also that there is another marker on each file icon. A little yellow cylinder on most files, but a white-on-brown star on the one you have edited. This is telling you the git status of each file. The brown stars are changes you have made but not checked in yet.

Outline

Over to the right is the Outline view. This shows a list of functions and classes defined in this file. By default, they are listed in the same order as in the file, but if you click on the az toolbar button, they are sorted into alphabetical order.

Click on the function name add_course_module in the Outline. You will see that the editor scrolls to the definition of that function.

Code navigation

In that function, hover the mouse pointer over the function name insert_record. After a while, the documentation for that function will appear in a big tooltip.

Hold down CTRL, move the mouse pointer over the function name insert_record, then click. Eclipse should load dmllib.php, and scroll you to where this function is defined. (You can also do this by clicking on the function name and pressing the F3 key.)

In the main Eclipse toolbar, there are forward and back arrows like in a web browser. Click back now to get back to course/lib.php.

Open resource

From the Navigate menu, choose Open Resource.... In the dialog that pops up, start typing a filename for instance type moodlel. In the box in the middle of the dialog, you will see it list all the files in the project whose names start that way. At the bottom is a box which lists the different folders that contain a file with that name. This can be a very quick way of opening files with fairly unique names like moodlelib.php, without having to click through the levels of the navigator tree. Of course, it is not so useful for an index.php file! Click OK now to open moodlelib.php. (It would actually work if you just did CTRL + Shift + R, moodlel, Enter.)

Multi-file search

Scroll down moodlelib a little bit, and double click on the name of the constant MOODLE_INTERNAL where it is defined, so that the text is selected. Then, from the Search menu, choose Search.... Notice that the Containing text box has already been filled in for you with the text you just selected. Of course you can just type text into this box without selecting it first. Notice that you can do regular expression searches, but leave that turned off for now. In the File name patterns box type *.css, *.html, *.inc, *.js, *.php, *.xml. (This is the most useful general setting for working on moodle. Eclipse will remember this setting, so you only have to enter it once.) Click Search.

The search results will appear in a new view underneath the editor. That view has a toolbar with yellow up and down arrows. Click the down arrow a few times and it will take you to the first few matches in the code, opening the relevant files as necessary.

Related Links

There is an excellent series of articles published by IBM on using Eclipse for Drupal developement here : Using open source software to design, develop, and deploy a collaborative Web site Tools and techniques for getting relatively complicated Web sites up and running quickly.