Using Eclipse for editing Moodle code

Using Eclipse for editing Moodle code

by Tim Hunt -
Number of replies: 33
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I've just added a page to Moodle Docs:

http://docs.moodle.org/en/Setting_up_Eclipse_for_Moodle_development

So now none of you have an excuse for using an inferior editor.
Average of ratings: -
In reply to Tim Hunt

Re: Using Eclipse for editing Moodle code

by Michael Champanis -
Some things I have discovered:

Adding "." to include path:

Edit 'net.sourceforge.phpeclipse.ui.prefs' found in this directory:
/home/username/workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings

and change/add '_php_include_paths', e.g.

  _php_include_paths=.


Removing multitude of include-file warnings:

Right-click your moodle project in Navigator
 -> Choose Properties
   -> PHP Parser section
     -> Style Tab
       .. Change all to 'Ignore', except 'Don't use keyword as identifier'

In reply to Michael Champanis

Re: Using Eclipse for editing Moodle code

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Thanks for finding the instructions for setting the include path for me.

The main way to get rid of the include files warnings is to copy config-dist.php to config.php and then edit it. Then of course, the warnings go away.


Generally it is a good thing that Eclipse generates warnings, and the best way to fix them is to fix the code. One of the most common warnings I see is where people have ignored security issues point 2 from http://docs.moodle.org/en/Coding#Security_issues_.28and_handling_form_and_URL_data.29. So I don't recommend turning the warnings off.


And I was not trying to start an editor holy war. (Although that was niaive - any posting to a forum about editors will start one). I just think that Eclipse is a good choice for some people, but it is hard to get started with, so I wrote the document to help. Everyone is, of course, welcome to use whatever editor they like.
In reply to Tim Hunt

Re: Using Eclipse for editing Moodle code

by Michael Champanis -
I copied my config.php into the new moodle project dir, but the include warnings didn't go away - after fiddling for a bit I ended up turning include warnings off wink

Although yes, I shouldn't have recommended turning them all off, the uninitialised var option is a good one to leave on.
In reply to Tim Hunt

Re: Using Eclipse for editing Moodle code

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
deprecated <xmp> works for me much better with print_r() for debugging purposes wink It is also much easier to find forgotten debug code because there is no xmp tag in cvs.
In reply to Tim Hunt

Re: Using Eclipse for editing Moodle code

by Martín Langhoff -
> So now none of you have an excuse for using an inferior editor.

big grin

Might be worthwhile to mention in the wiki that not all Moodle developers use Eclipse. Actually, AFAICT most are using vim or emacs. You wouldn't want to mislead anyone into thinking that Eclipse is the one true editor of the moodle world.

Heh. I actually like my editor-with-OS-aspirations! Does that make me weird?

(Actually, IMHO most editors truly suck, and we would be a great case study of Stockholm syndrome)
In reply to Martín Langhoff

Re: Using Eclipse for editing Moodle code

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
It would be good to know what developers find helpful in the editors they use. In the Dallas PHP User's Group (dallasphp.org), we had a presentation on editors and Eclipse got a good rating on features but it seemed difficult to setup. As I continue my own migration more and more towards Linux I would like to know what editors are being used and the advantages/disadvantages of each. Features that I liked from PHP Designer where syntax highlighting and the fact that it showed a list of the functions in a file as well as an attempt to show required and included files.
In reply to Anthony Borrow

Re: Using Eclipse for editing Moodle code

by Penny Leach -
I use emacs. Disadvantages first because there's less:

* it doesn't always come installed, often I ssh into a server and find there's no emacs and I'm forced to switch my brain to vi.

* steep learning curve (apparently - I didn't find it too hard), but you'll get that with most editors. I found vi much harder to get my head around than emacs.

Advantages:

* syntax highlighting

* infinitely customisable (eg: set moodle based projects to use 4 space indenting, set various other projects to use tabs as required by coding specs)

* really good diff mode (I use this a lot because I seem to spend a lot of time doing really tricky merges where I have to resolve a lot of conflicts by hand)

* ... & it has a psychiatrist!
In reply to Penny Leach

Re: Using Eclipse for editing Moodle code

by Martín Langhoff -
> * ... & it has a psychiatrist!

And the catalyst team needs it wink
In reply to Martín Langhoff

Re: Using Eclipse for editing Moodle code

by Jun Yamog -
I think I better change my current PHP editor (emacs) to Eclipse. 

"You wouldn't want to mislead anyone into thinking that all catalyst team needs a psychiatrist to the moodle world."
In reply to Penny Leach

Re: Using Eclipse for editing Moodle code

by Tony Hursh -
Ah, yes. M-x psychoanalyze-pinhead is good for hours (well, minutes) of fun.

I've always been an emacs guy (figuring that if an editor isn't Turing-complete, what good is it?), but lately I've been grown quite fond of Textmate. It's not free, and is only for OS X, but it's very nice nonetheless.

In reply to Penny Leach

Re: Using Eclipse for editing Moodle code

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers
Eclipse isn't for everyone, but I happen to have been hooked.

It does all of the items above, and
- syntax checking with error and warning flagging in the editor,'
- link to function documentation by hovering over a function,
- integrated CVS,
- a great diff tool,
- object class navigator and function navigator.

mike
In reply to Anthony Borrow

Re: Using Eclipse for editing Moodle code

by Michael Champanis -
I like vim for smallish tasks - editing a couple files, testing stuff etc. It's fast, has good syntax highlighting, good regex, you know, the usual.

I've used ActiveState Komodo to develop moodle, but found it slow and buggy. It's search functions would randomly crash the whole IDE without warning (like *click* *window disappears*). So that got fairly annoying, plus it was really pretty sluggish on my machine, browsing the project file system was definitely not snappy.

I'm using Eclipse now, after taking a break for a while. It's fast, has good code navigation, highlighting and auto-tips.

I think important features of a good editor are:
  • Fast and powerful search in files/folders (preferably regex enabled)
  • Fast and accessible code navigation (from file to file, methods, include files etc.)
  • Decent highlighting that also shows you bracket-matching (pet peeve)
In reply to Anthony Borrow

Re: Using Eclipse for editing Moodle code

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I haven't read a single editor feature mentioned here that I can't do in a terminal with vim, ctags and possibly grep, sort and a few other unix tools. And they are pre-installed on every server!

Vim vim vim vim vim vim - yay! kiss
In reply to Tim Hunt

Re: Using Eclipse for editing Moodle code

by Samuli Karevaara -
From the docs: "Eclipse is quite big, so I recommend lots of memory in your computer."

Plus the fact that it's written in java makes it too sluggish on my four year old laptop with 256 megs of RAM. Of the "heavy" IDEs I like NetBeans the best.

All editors seem to have problems when auto-indenting mixed php+html+css+javascript though tongueout

Vim takes a lot of configuring to get it right with PHP... I'm still looking for better UI for code folding, the 7138 lines (yes...) of moodlelib.php would like that smile
In reply to Tim Hunt

Re: Using Eclipse for editing Moodle code

by John Isner -
Tim,
On my second attempt, I got Eclipse installed and configured on Ubuntu. Your instructions were excellent! However you lost me at the end of article under "Let your development web server know where your files are."

Your instructions assume that the user is starting from scratch: They check out files from cvs from within Eclipse, then tell the Web server where the files are. But what if a user (me!) previously checked out Moodle source following the instructions in http://docs.moodle.org/en/CVS_for_Administrators? Now the Web server knows where the files are and the problem becomes one of "Letting Eclipse know where your files are."

Maybe it can't be done this way. Must the sources always be checked out into a working directory owned by Eclipse?

FYI I'm using anonymous CVS so no changes will ever be checked in.
In reply to John Isner

Re: Using Eclipse for editing Moodle code

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The secret is to use a symbolic link. I assume your set-up is something like this.

in /var/www/moodle is the copy of the Moodle files that Apache uses, which you checked out using command-line CVS, and have possibly modified since.

In ~john/workspace/moodle are the files you checked out from CVS using Eclipse, plus some extra files (like .project) that Eclipse uses to store its information.

You have at least three choices:

1. Use the files in Eclipse to create a new Moodle install that you use for development work. That is, do
cd /var/www
ls -s ~john/workspace/moodle moodle_dev
make a config.php with a different db prefix, then go to http://localhost/moodle_dev/ to install the new version. Do the development there, then when you have finished any change, copy the changes into /var/www/moodle.

2. Get rid of the old files under apache, and use the Eclipse ones for both. That is, use CVS to tell you if you have edited any files under /var/www/moodle, if so, copy just those files into your Eclipse workspace.
Then
cd /var/www
rm -rf moodle
ls -s ~john/workspace/moodle moodle

3. Get rid of the Eclipse files, and use the apache ones for both. That is, work out which files Eclipse needs to store its information. Copy those files from ~john/workspace/moodle to /var/www/moodle. Then do
cd ~john/workspace
rm -rf moodle
ls -s /var/www/moodle moodle


I would probably go for 2 (that is what I do on my Mac laptop for development). However, since this involves deleting a lot of stuff, please do take a backup first and be very careful. Also, my unix skills are a bit rusty, so check those command lines before running them, don't just copy and paste.

Also, I have ignored file permissions above. You may need to sudo some of those commands, and when you have finished, you may need to change the access permissions on the Moodle files.
In reply to Tim Hunt

Re: Using Eclipse for editing Moodle code

by John Isner -
Hi Tim,
Thank you for the explanation. In paragraph 3 you said

In ~john/workspace/moodle are the files you checked out from CVS using Eclipse, plus some extra files (like .project) that Eclipse uses to store its information.

No, I never checked out files from CVS using Eclipse. The only checkout is in /var/www, done from the command line prior to installing Eclipse. The Eclipse workspace ~john/workspace/moodle is empty (except for a single file called .project). But scenarios 1 and 2 are valuable information (in 2, there is a typo: "ls -s" should be "ln -s")

That leaves scenario 3, which I can use. You say

work out which files Eclipse needs to store its information

I stopped shortly after I reached the section "Checking out the Moodle code" in your wiki article. I did not give Eclipse a repository location. So my 'moodle' workspace has only one file so far:

~john/workspace/moodle/.project

It contains a few lines of not-very-interesting XML. I will configure the repository first to see what other files, if any, are created, then copy those files to /var/www/moodle.

If I run into trouble (e.g., with permissions), I'll create a new Moodle install (choice 1), which seems to be the standard way of using Eclipse.
In reply to John Isner

Re: Using Eclipse for editing Moodle code

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
It might be worth checking out a copy of Moodle into Eclipse, to see what metadata files it creates. You can always delete that copy again.
In reply to Tim Hunt

Re: Using Eclipse for editing Moodle code

by John Isner -
Great idea. Thanks for all your help.
In reply to John Isner

Re: Using Eclipse for editing Moodle code

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
John - I found it best to do my CVS updating in Eclipse. I simply created a virtual directory in apache to point to my Eclipse workspace. When I need to test something I simply create the config.php page and we are off to the races. Actually, I've even automated with a little bash script the process of creating the moodledata folder, shutting down my database, making a copy of my production database, and restarting the database so that I have a uniform way of doing things in the config.php. It has really simplified testing stuff. Now that I've crossed over to Eclipse it is hard to imagine going back as it allows me to do and handle pretty much anything (except ironically something as simple as printing a file with line numbers - I confess to sometimes thinking better on paper). Peace - Anthony
In reply to Tim Hunt

Re: Using Eclipse for editing Moodle code

by John Isner -
Today I resumed my seemingly never-ending Eclipse set-up project. I followed the advice above and checked out moodle into my Eclipse workspace using anonymous CVS.

When I click a php or html file in the Navigator, I get the following error:

Error opening the editor.
Reason: net.sourceforge.phpeclipse.phpeditor.PHPUnitEditor

I get the same error for *.html files. I am able to edit *.txt files.

I reviewed my file associations (Window -> Preferences -> General -> Content types) to make sure they are set up correctly, and they are:

*.php -> PHP Editor (default)
*.html -> PHP Editor (default)

I checked the jar files under my Eclipse install directory, and there is a
/home/jisner/Desktop/ECLIPSE/eclipse/plugins/net.sourceforge.phpeclipse_1.1.8/phpeclipse.jar

I did jar -tf on the jar file and found (among hundreds of classes)

net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.class

So my question is why the PHPUnitEditor class is not being found.

I should mention two possibly relevant differences between your instructions and what I encountered while installing and configuring Eclipse Classic (on Ubuntu):
  • In the Installing the necessary plugins step, there was no Callisto discovery site (only Europa). This seems very odd!!
  • In the very last step under Setting the preferences for Moodle development I was unable to find Web and XML settings under Window -> Preferences.
In reply to John Isner

Re: Using Eclipse for editing Moodle code

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
John - Callisto and Europa seem to be going back and forth. The original instructions were Europa and then when I did it there was no Europa option and only Callisto so I changed it in the documentation. Now it looks like (pardon the pun) that Europa has eclipsed Callisto once again so I have changed the docs page so that the primary reference is to Europa (at least according to: http://www.builderau.com.au/news/soa/Europa-eclipses-Callisto-in-Friday-s-overhaul/0,339028227,339279238,00.htm) this is the case.

Have you seen and applied:

Error loading php files after Ubuntu 7.04 Install

A java issue with Ubuntu 7.04 may cause an error when you attempt to load php pages. Refer to: http://www.plog4u.org/index.php/Using_PHPEclipse_:_Installation_:_Installing_PHPEclipse for details about how to fix this in Ubuntu 7.04.

I had this problem too of not being able to open files. I will say that once I got it working it is hard to imagine going back to not having Eclipse. I have found it very helpful. I've standardized my moodle files and I have symbolic links created for /moodle/code /moodle/data and /moodle/sql which take me to the respective places. I even created a script that will take my production data and create a new database, create the new data folder, etc. so that I can easily setup a new install. It has kept me from having to think about where things are.

I'll attach the script in case you might find it helpful. Peace - Anthony
In reply to Anthony Borrow

Re: Using Eclipse for editing Moodle code

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
What is going on here is that the Eclipse project uses moons as the code name for its releases. So, Europa was the 3.2 release, and Callisto was the 3.3 release - or is it the other way round. Anyway, if you have Eclipse 3.2, then you need to use one of these to find plugins, and if you have the other then you need the other one.
In reply to Tim Hunt

Re: Using Eclipse for editing Moodle code

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Tim - Thanks for shining a little light on the subject. I was in the dark on the use of moons. Peace - Anthony
In reply to Anthony Borrow

Re: Using Eclipse for editing Moodle code

by John Isner -
After posting, I decided to start over. I removed everything and made a new printout of Development:Setting_up_eclipse (which had changed!). This time I found the standard Web Tools on the Europa site and was able to complete all the steps. However I once again got 'Error opening editor' when I attempted to open a php file. Grrr.

Have you seen and applied:

Error loading php files after Ubuntu 7.04 Install

I never thought to look beyond the point in the document where I got stuck. But FYI I'm not running Ubuntu 7.04. I'm running Ubuntu 6.06.

Out of curiosity, I clicked on the link you gave
http://www.plog4u.org/index.php/Using_PHPEclipse_:_Installation_:_Installing_PHPEclipse.

The error loading php files is mentioned under "distro specific instructions." Well I did not install a "distro" (i.e., I did not us Synaptic). I did a manual installation of the Eclipse Classic package following the instructions in your document, which are identical to the instructions for Automated installation on the above page.

Also out of curiousity, I tried the "fix" given for the Ubunto 7.04 distro
  1. Close eclipse and at the bash prompt:
  2. sudo apt-get install sun-java6-jre
  3. sudo nano -w /etc/eclipse/java_home
  4. Insert /usr/lib/jvm/java-6-sun on the line above /usr/lib/jvm/java-gcj
  5. Close and save the file
There is no sun-java6-jre. The latest I can see from Synaptic is sun-java5-jre, which is the version I have installed.

I just blew Eclipse away again. I'll try to install it again under the next full moon.

In reply to John Isner

Re: Using Eclipse for editing Moodle code

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Well, you could consider upgrading you Ubuntu install - if you are feeling brave. The one time I did a major upgrade of Ubuntu, it just worked flawlessly. I was very impressed. But still, it is the sort of thing where you should talk a backup first.

Anyway 6.06, that dates from about the Moodle 1.6 time. Moodle has improved a lot since then, I expect Ubuntu has too.
In reply to John Isner

Re: Using Eclipse for editing Moodle code

by Samuli Karevaara -
I've had similar experiences. I've tried to start using Eclipse a couple of times, but some odd detail always tripped me over and led the Eclipse to crash and burn. Many of the problems were PHPEclipse related. The project seems to have been a bit slow, but only today I discovered another PHP & Eclipse -project: PHP Development Tools framework for the Eclipse platform (PDT). As the project is hosted at eclipse.org and they just released 1.0 this week, another try of Eclipse for me could be ahead...

Has anyone here tried PDT yet ?
In reply to Samuli Karevaara

Re: Using Eclipse for editing Moodle code

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes, in due course, I am sure this new PHP project will be a better option. I just have not got around to trying it yet. It would be interesting to know how good it is.
In reply to Samuli Karevaara

Re: Using Eclipse for editing Moodle code

by John Isner -
I'll wait for your report on PDT. Meanwhile, I'll dust off vim and ctags smile
In reply to Samuli Karevaara

Re: Using Eclipse for editing Moodle code

by Myles Carrick -
Hey Samuli,

Yeah I'd be interested to hear about it now that the project is at 1.0.
I regularly use the Aptana / RadRails Eclipse plugins (http://aptana.com) for Rails development... it's great - and available for all 3 desktop platforms I use each day (Ubuntu, OSX and Windows).
To be honest, although I have PHPEclipse configured, if in Ubuntu doing PHP stuff I often just use vim - but the feature list of PDT looks impressive (http://www.eclipse.org/pdt/documents/PDT_1.0_Release_Review.pdf)
FWIW I don't use the CVS tools even when doing PHP work in Eclipse - I now just run a terminal with git managing my source... (thanks to easy merging with Catalyst's git repo)... and it doesn't matter then which editor I'm using.

Re. John's earlier question, sun-java6-jre isn't available from the regular synaptic sources for 6.06... but easily available if you enable the dapper-backports sources (eg. http://packages.ubuntu.com/dapper-backports/libs/sun-java6-jre). Install that using apt-get and you'll be laughing.

MC
Average of ratings: Useful (1)
In reply to Myles Carrick

Re: Using Eclipse for editing Moodle code

by John Isner -
Myles,
I installed sun-java6-jre from the backports sources and tried again -- blowing everything away and starting from the beginning. I get exactly the same result. Java can't run the PHPEditor. Exit laughing.

Incidentally, here's a list of discrepancies I encountered following the instructions. FYI I downloaded Eclipse Classic (Linux version).

The first time you run Eclipse

There was no welcome screen. Instead, I got an error message which read

Intro Error. Could not find a valid configuration for Intro Part: intro element extension: org.eclipse.ui-intro in Bundle: org.eclipse.ui.intro-universal. Check Error log for details.

Installing the necessary plugins

When i restarted, I got an error message which read

Could not save workbench layout.
Reason: Problems occurred saving workbench.
Details >>
Unable to save perspecive: workspace-java. could not save View:Welcome

FYI my workbench is in ~/workbench.

As Eclipse restarts, I get another Intro Error.

Web and XML settings

There was no such entry in my Windows -> Preferences tree

Checking out the Moodle code

From the File menu, choose New -> Project .., then click Next >

There is no Next >

There was no prompt to Create a new respository location

Click Refresh Tags, then choose the branch you want. For now leave it set to HEAD.

Using anonymous CVS with host uk.cvs.moodle.org, I was surprised to see the only branch tags available were 1.6 and 1.7.

------

After the checkout completed, I attempted to edit one of the php files in the top level directory and got the same error as before

Error opening the editor. Reason: net.sourceforge.phpeclipse.phpeditor.PHPEditor


In reply to Samuli Karevaara

Svar: Re: Using Eclipse for editing Moodle code

by Mattias Wirf -
Hello there! Oh Yes smile I got it working on Ubuntu Gutsy Gibbon Beta 7.10 (installed while on Feisty Fawn 7.04), Suns java 6, Eclipse Europa, PDT (prior to version 1).
I didn't have any trouble, but I had to install a lot of other plugins that was required by PDT.

It's brilliant, and with new java Eclipse runs great.

In reply to Mattias Wirf

Re: Svar: Re: Using Eclipse for editing Moodle code

by Myles Carrick -
Yes... I suspect that this is going to need to be the way forward. I wanted to do a bit of experimenting on my OSX laptop and the list of dependencies drove me nuts - and got frustrated with the stuffing around (am travelling in Poland prior to a trip to the UK Moot and decided to configure it the night before leaving, hehe)... so just downloaded and installed the pre-packaged installer ;)