Note:

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

Setting up Netbeans: Difference between revisions

From MoodleDocs
(→‎Coding faster: moved PHP Team Blog link to "See also" section)
(Update instructions to reflect Git usage)
(45 intermediate revisions by 13 users not shown)
Line 16: Line 16:
== Installation ==
== Installation ==


* I recommend downloading the latest [http://www.netbeans.org/downloads/indexB.html 6.7.1 version with PHP support ]. It's only a 26 MB download.
* Download the latest stable version from http://netbeans.org. Get the bundle that contains only PHP support.
* Install and run it.
* Install and run it.


== Set up for Moodle development ==
== Set up for Moodle development ==


* Checkout your Moodle project with a '''CVS client''' - see [[CVS for Administrators]] or [[CVS for developers|CVS for Developers]].
* Checkout your Moodle project with a '''CVS client''' - see [[:en:Git for Administrators]] or [[Git for developers|Git for Developers]].


* Open File > New Project > PHP > PHP Application > Next
* Make sure you have forked the moodle repository to your personal Git
: You're going to set the project now. ''Name'', ''Location'' and ''Folder'' are used by NetBeans and are not related to the source code. So you can choose whatever you like, except your source folder. ''Sources'' has to be your checked out Moodle branch/head folder. The rest is clear enough. Don't forget to choose UTF-8 for ''Default Encoding''.


: Example:
* Open Team > Git > Clone


Project Name:        Moodle 1.9 Stable
* URL: git://github.com/YOUR_GIT_USERNAME/moodle.git. You can save it anywhere on local, the file isn't tied to vcs. Click Next
Project Location:    C:\Users\jerome\Documents\NetBeansProjects
 
Project Folder:      C:\Users\jerome\Documents\NetBeansProjects\Moodle 1.9 Stable
* Choose a branch to check out. Click Next
Project Sources:    C:\Users\jerome\Projects\branch19_STABLE\moodle
Project URL:         http://localhost/moodle19/
Index File:          index.php
Create:              unchecked
Default Encoding:    UTF-8
Set as Main Project: unchecked


* Click on Finish.
* Click on Finish.
* Open Run > Set Project Configuration > Customize
* Run As should be set to local server, Project URL: http://localhost/moodle . Index File: index.php. Click Ok


* Start coding!
* Start coding!
(Clicking the run button will launch the sire in Internet Explorer)
== Git with NetBeans ==
=== NBGit | Git Support for NetBeans ===
"NBGit is a module for the NetBeans IDE that adds support for working with the Git version control system. It uses the JGit library created as part of EGit to interact with Git repositories. Because the module is Java code all the way, it should work better cross-platform modulo platform specific differences, such as file system behavior. It is based on the NetBeans Mercurial module."
(http://nbgit.org)
<p class="note orange">
Unfortunately, the key word in that quote is '''should'''. In reality, because JGit is a rewrite from scratch of the tried-and-tested git core C code, it is still buggy, incomplete and unreliable. Therefore, the NetBeans and Eclipse git plugins are still only beta quality, and pretty sucky. Well, they mostly work for browsing the contents of the repository, but there is a small chance that if you use them for update operations, they will corrupt your repository. Hence, I am still doing git from the command-line.--[[User:Tim Hunt|Tim Hunt]] 11:11, 19 January 2010 (UTC)
</p>
=== Wiki page needs updating ===
Git is now integrated into Netbeans 7
https://netbeans.org/kb/70/ide/git.html


== CVS with NetBeans ==
== CVS with NetBeans ==
{{obsolete}}
moodle no longer uses CVS and has switched to Git ([Git for administrators] [Git for developers])


NetBeans comes with '''integrated CVS support''' which might be the easiest way to check out Moodle.
NetBeans comes with '''integrated CVS support''' which might be the easiest way to check out Moodle.


* In NetBeans, select Window->Versioning->CVS->Checkout
=== Anonymous checkout ===
* Select Team->CVS->Checkout
 
* Enter into CVS Root: '':pserver:anonymous@us.cvs.moodle.org:/cvsroot/moodle''
# In NetBeans, select Window->Versioning->CVS->Checkout
# Select Team->CVS->Checkout
# Enter into CVS Root: '':pserver:anonymous@us.cvs.moodle.org:/cvsroot/moodle''
: (Non-US-residents might use one of the other [https://docs.moodle.org/en/CVS_for_Administrators#CVS_Servers Moodle CVS servers] nearer to them.)
: (Non-US-residents might use one of the other [https://docs.moodle.org/en/CVS_for_Administrators#CVS_Servers Moodle CVS servers] nearer to them.)
* Click ''Next''
# Click ''Next''
* Browse or enter into ''Module:'' moodle
# Browse or enter into ''Module:'' moodle
* Browse or enter into ''Branch:'' MOODLE_19_STABLE
# Browse or enter into ''Branch:'' MOODLE_19_STABLE
* Browse or enter into ''Local Folder:'' C:\xampp\htdocs
# Browse or enter into ''Local Folder:'' C:\xampp\htdocs
* Click ''Finish'' (and wait a few minutes for Moodle to be checked out)
# Click ''Finish'' (and wait a few minutes for Moodle to be checked out)
* When you get the dialog box "Do you want to create an IDE project from the checked-out sources?", Click "Create Project..."
# When you get the dialog box "Do you want to create an IDE project from the checked-out sources?", Click "Create Project..."
* Select PHP Application with Existing Sources, and click Next
# Select PHP Application with Existing Sources, and click Next
* Browse or enter into ''Sources Folder'' C:\xampp\htdocs\moodle
# Browse or enter into ''Sources Folder'' C:\xampp\htdocs\moodle
* Enter into ''Project Name:'' moodle
# Enter into ''Project Name:'' moodle
* Keep the other defaults and click next
# Keep the other defaults and click next
* ''Run As:'' should have selected ''Local Web Site (running on local web server)''
# ''Run As:'' should have selected ''Local Web Site (running on local web server)''
* Enter into Project URL http://localhost/moodle/
# Enter into Project URL http://localhost/moodle/
* Browse or enter into ''Index File:'' index.php
# Browse or enter into ''Index File:'' index.php
* Click ''Finish''
# Click ''Finish''
 
=== Checkout for developers with write access ===
 
As far as I can tell, there is no way to get NetBeans to work with CVS keys on Mac/Linux via the system SSH binary, so you will need to use the internal SSH and your password (which you can choose to save).
 
If you wish to use NetBeans CVS and have CVS write access, the procedure is as follows:
 
====Checkout of main Moodle codebase====


=== Few warnings ===
# Follow the above instructions except for point 3
Some of these warnings could also apply to other IDE:
# At part 3, substitute '':ext:yourusername'' for the part before the @ and remove the country code from after it, leaving it like this  ''''':ext:yourusername'''@cvs.moodle.org:/cvsroot/moodle''
* If you want to delete a file from your computer but not from CVS, delete it from Windows Explorer/Nautilus/Finder. Otherwise your next commit could delete the file from CVS. <br/>In case you have already deleted a wrong file from Netbeans:  with Windows Explorer/Nautilus/Finder, delete all the folder content of this deleted file (including the CVS folder) and update the folder.
# Follow the rest of the instructions as above
* If you rename files and that other people are working on them, Netbeans could end up to mess up your CVS folder (even though that is quite rare). Then Netbeans CVS will refuse to update your code displaying a no explicit error as '''Update Failed'''. In this case, delete the content of the damaged folder with Windows Explorer/Nautilus/Finder. Then update this folder.
 
* If you create a patch or a new php file with Netbeans on Microsoft Windows, please check that it's a Unix format file. You may want to use another software to create Unix format patch/php file.
If you wish to work with a plugin, you will need to check this out separately and add it to the Moodle code project you have just made. This because for some reason, the 'Do you want to create a project' option fails to show any of the files once you open it if you try to check out the plugin on its own (NetBeans 6.7.1 on a Mac).
 
====Checkout of contrib code====
 
# Follow the above steps up to point 3, and again substitute '':ext:yourusername'' and click 'next'. Note that you should not try to specify the full contrib repository path yet.
# Click 'Browse...' next to the 'Module' dialogue
# Find the plugin you wish to work with in CONTRIB
# Click 'OK'
# Proceed as before up to point 6, then press 'Close' when asked if you want to create a new project.
# Now navigate to the folder you earlier specified in the 'local folder' dialogue and you will find a folder marked 'contrib'.
# navigate to the plugin folder, copy that folder, and then navigate to your main Moodle project folder and paste it where it belongs.
 
Note that the last three points may cause you some grief when attempting to commit changes. CVS doesn't seem to like having subfolders with different origins. A workaround that operates well for me is to check out the contrib code manually into a folder using the command line as specified in the CVS for developers instructions, then import that code as a new project with existing sources. This allows easy commits and updates, whilst keeping it separate. You can then make a symlink from you main Moodle project to your contrib directory, restart NetBeans (the CVS info and symlink stuff is only refreshed on restart) and then right click the linked directory and choose 'Ignore', then do the same and choose 'Exclude from commit'. You can now use the code as if it were part of Moodle, still getting all the code completion stuff, and also do clean updates and commits from the secondary project. [[User:Matt Gibson|Matt Gibson]] 19:53, 6 June 2010 (UTC)
 
===Adding a branch to your plugin===
Your plugin will likely start with just a HEAD tag and at some point, you will want to branch it so that you can have versions for different Moodles. To add a MOODLE_20_STABLE branch, for example, do the following.
 
# Checkout as above, but use the MOODLE_20_STABLE branch instead of MOODLE_19_STABLE
# You will end up with an empty folder, which you copy into place as above.
# Find the folder in NetBeans, then right click and choose CVS->Merge changes from branch...
# Choose to merge from whatever branch has all the current code, using the help link if not sure what to do.
 
There is a small chance that the Merge link will not be there, in which case, you will have to copy the files into the directory by hand outside netbeans and then check them in. If you do this, make sure you don't copy over the 'CVS' folders that will have been made when you checked out the MOODLE_19_STABLE code.
 
=== A few warnings ===
 
Some of these warnings could also apply to other IDEs:
 
* If you want to delete a file from your computer but not from CVS, delete it from Windows Explorer/Nautilus/Finder. Otherwise your next commit could delete the file from CVS. <br/>In case you have already deleted a wrong file from NetBeans:  with Windows Explorer/Nautilus/Finder, delete all the folder content of this deleted file (including the CVS folder) and update the folder.
* If you rename files and that other people are working on them, NetBeans could end up to mess up your CVS folder (even though that is quite rare). Then NetBeans CVS will refuse to update your code displaying a no explicit error as '''Update Failed'''. In this case, delete the content of the damaged folder with Windows Explorer/Nautilus/Finder. Then update this folder.
* If you create a patch or a new PHP file with NetBeans on Microsoft Windows, please check that it's a Unix format file. You may want to use another software to create Unix format patch/php files.


== Optimization ==
== Optimization ==


1. You may want to run Netbeans with the Sun JDK. Netbeans seems to work a bit better with the Sun JDK. Download it from  [http://java.sun.com/javase/downloads/index.jsp]. You'll have to edit Netbeans config file. Open netbeans/etc/netbeans.conf. Then uncomment and edit:  
=== Sun JDK ===
1. You may want to run NetBeans with the Sun JDK. NetBeans seems to work a bit better with the [http://java.sun.com/javase/downloads/index.jsp Sun JDK]. You'll have to edit NetBeans config file. Open netbeans/etc/netbeans.conf. Then uncomment and edit:  


  netbeans_jdkhome="your_JDK_path"
  netbeans_jdkhome="your_JDK_path"


2. To change the Netbeans look and feel run netbeans in the command line with this parameter:
2. To change the NetBeans look and feel run netbeans in the command line with this parameter:
  "netbeans"  --laf javax.swing.plaf.metal.MetalLookAndFeel  
  "netbeans"  --laf javax.swing.plaf.metal.MetalLookAndFeel  


3. If Netbeans starts to slow down, give it more memory
3. If NetBeans starts to slow down, give it more memory
  "netbeans" -J-Xmx600m
  "netbeans" -J-Xmx600m
See FAQ for more [http://wiki.netbeans.org/FaqSettingHeapSize details on memory optimisation].
=== ScanOnDemand ===
To prevent NetBeans from scanning the whole code with every start up you can use the following plug-in: http://wiki.netbeans.org/ScanOnDemand


== Coding faster ==
== Coding faster ==
You may want to have a look at the [http://wiki.netbeans.org/KeymapProfileFor60 keyboard shortcuts].
 
=== Coding standards ===
 
* There is NB config file available with the [https://github.com/enovation/moodle-utils/tree/master/netbeans-config Moodle coding settings]
 
=== Keyboard shortcuts ===
(Note: Some shortcuts might not work for PHP development.)
* [http://netbeanside61.blogspot.com/2008/04/top-10-netbeans-ide-keyboard-shortcuts.html Top 10 NetBeans IDE Keyboard Shortcuts I use the most]
* [http://wiki.netbeans.org/KeymapProfileFor60 NetBeans IDE 6.x Keyboard Shortcuts Specification]
 
=== PHPUnit support ===
See [http://netbeans.org/kb/docs/php/phpunit.html Netbeans PHPUnit support].
 
===JIRA support===
You can install the optional JIRA module in order to be able to interact with the Moodle Tracker from within NetBeans. This has the advantage of avoiding constantly switching back and forth from the browser and works quite well. Go to ''Tools->plugins->available plugins'' and search for JIRA. Once installed, right click 'issue trackers' in the 'services' pane to make a new tracker instance, then enter your details.


== See also: ==
== See also: ==
* Moodle forum: [http://moodle.org/mod/forum/discuss.php?d=112972 NetBeans 6.5 for moodle/PHP/debugging is a better experience v.s Eclipse]
Moodle forums
* [http://moodle.org/mod/forum/discuss.php?d=112972 NetBeans 6.5 for moodle/PHP/debugging is a better experience v.s Eclipse]
 
Online resources
* [http://www.netbeans.org/kb/trails/php.html NetBeans PHP Learning Trail]
* [http://www.netbeans.org/kb/trails/php.html NetBeans PHP Learning Trail]
* [http://wiki.netbeans.org/PHP NetBeans PHP Wiki]
* [http://wiki.netbeans.org/PHP NetBeans PHP Wiki]
* Sun's [http://blogs.sun.com/netbeansphp/ NetBeans PHP Team Blog]
* Sun's [http://blogs.sun.com/netbeansphp/ NetBeans PHP Team Blog]


Book
* [http://www.packtpub.com/netbeans-platform-6-8-developers-guide/book NetBeans Platform 6.8 Developer's Guide] by Jürgen Petri (March 2010), focus on Java and Swing


[[Category:NetBeans]]
[[Category:Developer tools|NetBeans]]
[[Category:Developer tools|NetBeans]]

Revision as of 08:04, 5 May 2017

NetBeans has got a good PHP support. You find a host of information on the website (tutorials, developer blog, screen casts, etc.).

Features

  • CVS integration: see all changes, lines deletion, diff in real time, show annotations, diff history...
  • Ctrl+Click: Go to declaration
  • Export/Import Diff Patch
  • Easy navigation
  • List of functions
  • Code completion
  • Instant rename
  • HTML, CSS, JavaScript support
  • MySQL manager
  • Quick Search
  • Very few bugs

Installation

  • Download the latest stable version from http://netbeans.org. Get the bundle that contains only PHP support.
  • Install and run it.

Set up for Moodle development

  • Make sure you have forked the moodle repository to your personal Git
  • Open Team > Git > Clone
  • Choose a branch to check out. Click Next
  • Click on Finish.
  • Open Run > Set Project Configuration > Customize
  • Start coding!

(Clicking the run button will launch the sire in Internet Explorer)

Git with NetBeans

NBGit | Git Support for NetBeans

"NBGit is a module for the NetBeans IDE that adds support for working with the Git version control system. It uses the JGit library created as part of EGit to interact with Git repositories. Because the module is Java code all the way, it should work better cross-platform modulo platform specific differences, such as file system behavior. It is based on the NetBeans Mercurial module." (http://nbgit.org)

Unfortunately, the key word in that quote is should. In reality, because JGit is a rewrite from scratch of the tried-and-tested git core C code, it is still buggy, incomplete and unreliable. Therefore, the NetBeans and Eclipse git plugins are still only beta quality, and pretty sucky. Well, they mostly work for browsing the contents of the repository, but there is a small chance that if you use them for update operations, they will corrupt your repository. Hence, I am still doing git from the command-line.--Tim Hunt 11:11, 19 January 2010 (UTC)

Wiki page needs updating

Git is now integrated into Netbeans 7 https://netbeans.org/kb/70/ide/git.html


CVS with NetBeans

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

moodle no longer uses CVS and has switched to Git ([Git for administrators] [Git for developers])

NetBeans comes with integrated CVS support which might be the easiest way to check out Moodle.

Anonymous checkout

  1. In NetBeans, select Window->Versioning->CVS->Checkout
  2. Select Team->CVS->Checkout
  3. Enter into CVS Root: :pserver:anonymous@us.cvs.moodle.org:/cvsroot/moodle
(Non-US-residents might use one of the other Moodle CVS servers nearer to them.)
  1. Click Next
  2. Browse or enter into Module: moodle
  3. Browse or enter into Branch: MOODLE_19_STABLE
  4. Browse or enter into Local Folder: C:\xampp\htdocs
  5. Click Finish (and wait a few minutes for Moodle to be checked out)
  6. When you get the dialog box "Do you want to create an IDE project from the checked-out sources?", Click "Create Project..."
  7. Select PHP Application with Existing Sources, and click Next
  8. Browse or enter into Sources Folder C:\xampp\htdocs\moodle
  9. Enter into Project Name: moodle
  10. Keep the other defaults and click next
  11. Run As: should have selected Local Web Site (running on local web server)
  12. Enter into Project URL http://localhost/moodle/
  13. Browse or enter into Index File: index.php
  14. Click Finish

Checkout for developers with write access

As far as I can tell, there is no way to get NetBeans to work with CVS keys on Mac/Linux via the system SSH binary, so you will need to use the internal SSH and your password (which you can choose to save).

If you wish to use NetBeans CVS and have CVS write access, the procedure is as follows:

Checkout of main Moodle codebase

  1. Follow the above instructions except for point 3
  2. At part 3, substitute :ext:yourusername for the part before the @ and remove the country code from after it, leaving it like this :ext:yourusername@cvs.moodle.org:/cvsroot/moodle
  3. Follow the rest of the instructions as above

If you wish to work with a plugin, you will need to check this out separately and add it to the Moodle code project you have just made. This because for some reason, the 'Do you want to create a project' option fails to show any of the files once you open it if you try to check out the plugin on its own (NetBeans 6.7.1 on a Mac).

Checkout of contrib code

  1. Follow the above steps up to point 3, and again substitute :ext:yourusername and click 'next'. Note that you should not try to specify the full contrib repository path yet.
  2. Click 'Browse...' next to the 'Module' dialogue
  3. Find the plugin you wish to work with in CONTRIB
  4. Click 'OK'
  5. Proceed as before up to point 6, then press 'Close' when asked if you want to create a new project.
  6. Now navigate to the folder you earlier specified in the 'local folder' dialogue and you will find a folder marked 'contrib'.
  7. navigate to the plugin folder, copy that folder, and then navigate to your main Moodle project folder and paste it where it belongs.

Note that the last three points may cause you some grief when attempting to commit changes. CVS doesn't seem to like having subfolders with different origins. A workaround that operates well for me is to check out the contrib code manually into a folder using the command line as specified in the CVS for developers instructions, then import that code as a new project with existing sources. This allows easy commits and updates, whilst keeping it separate. You can then make a symlink from you main Moodle project to your contrib directory, restart NetBeans (the CVS info and symlink stuff is only refreshed on restart) and then right click the linked directory and choose 'Ignore', then do the same and choose 'Exclude from commit'. You can now use the code as if it were part of Moodle, still getting all the code completion stuff, and also do clean updates and commits from the secondary project. Matt Gibson 19:53, 6 June 2010 (UTC)

Adding a branch to your plugin

Your plugin will likely start with just a HEAD tag and at some point, you will want to branch it so that you can have versions for different Moodles. To add a MOODLE_20_STABLE branch, for example, do the following.

  1. Checkout as above, but use the MOODLE_20_STABLE branch instead of MOODLE_19_STABLE
  2. You will end up with an empty folder, which you copy into place as above.
  3. Find the folder in NetBeans, then right click and choose CVS->Merge changes from branch...
  4. Choose to merge from whatever branch has all the current code, using the help link if not sure what to do.

There is a small chance that the Merge link will not be there, in which case, you will have to copy the files into the directory by hand outside netbeans and then check them in. If you do this, make sure you don't copy over the 'CVS' folders that will have been made when you checked out the MOODLE_19_STABLE code.

A few warnings

Some of these warnings could also apply to other IDEs:

  • If you want to delete a file from your computer but not from CVS, delete it from Windows Explorer/Nautilus/Finder. Otherwise your next commit could delete the file from CVS.
    In case you have already deleted a wrong file from NetBeans: with Windows Explorer/Nautilus/Finder, delete all the folder content of this deleted file (including the CVS folder) and update the folder.
  • If you rename files and that other people are working on them, NetBeans could end up to mess up your CVS folder (even though that is quite rare). Then NetBeans CVS will refuse to update your code displaying a no explicit error as Update Failed. In this case, delete the content of the damaged folder with Windows Explorer/Nautilus/Finder. Then update this folder.
  • If you create a patch or a new PHP file with NetBeans on Microsoft Windows, please check that it's a Unix format file. You may want to use another software to create Unix format patch/php files.

Optimization

Sun JDK

1. You may want to run NetBeans with the Sun JDK. NetBeans seems to work a bit better with the Sun JDK. You'll have to edit NetBeans config file. Open netbeans/etc/netbeans.conf. Then uncomment and edit:

netbeans_jdkhome="your_JDK_path"

2. To change the NetBeans look and feel run netbeans in the command line with this parameter:

"netbeans"  --laf javax.swing.plaf.metal.MetalLookAndFeel 

3. If NetBeans starts to slow down, give it more memory

"netbeans" -J-Xmx600m

See FAQ for more details on memory optimisation.

ScanOnDemand

To prevent NetBeans from scanning the whole code with every start up you can use the following plug-in: http://wiki.netbeans.org/ScanOnDemand

Coding faster

Coding standards

Keyboard shortcuts

(Note: Some shortcuts might not work for PHP development.)

PHPUnit support

See Netbeans PHPUnit support.

JIRA support

You can install the optional JIRA module in order to be able to interact with the Moodle Tracker from within NetBeans. This has the advantage of avoiding constantly switching back and forth from the browser and works quite well. Go to Tools->plugins->available plugins and search for JIRA. Once installed, right click 'issue trackers' in the 'services' pane to make a new tracker instance, then enter your details.

See also:

Moodle forums

Online resources

Book