Contributing a new feature or fix: Difference between revisions

From JogampWiki
Jump to navigation Jump to search
No edit summary
(→‎Create a new unit test: removed nativewindow.all.jar newt.all.jar and rename jogl.all.jar jogl.test.jar -> jogl-all.jar jogl-test.jar)
 
(14 intermediate revisions by one other user not shown)
Line 1: Line 1:
= Overview =
= Overview =


Contributing a new feature or bug fix is a bit more involved than just building JOGL. The main difference is that instead of pulling the code from the canonical repository on GitHub, you need to fork it, then work on your own repository. When you're done, you submit a "pull request" on GitHub for the lead developer to review your changes.
Contributing a new feature or bug fix to a JogAmp project is a bit more involved than just building it. The main difference is that instead of pulling the code from the canonical repository on GitHub, you need to fork it, then work on your own forked repository. When you're done, you submit a "pull request" on GitHub for the [[Maintainer and Contacts#Maintainer|module maintainer]] to review your changes.


You should already have built JOGL at least once before this, so you're sure Git and all the other tools are set up and working correctly.
I'll use JOGL as an example below, but this information applies to other JogAmp projects too.  You can find them in our [[Jogamp SCM Repositories|code repositories]].
 
You should already have built the JogAmp project you want to contribute to [[Building JOGL on the command line|on the command line]] or [[Building JOGL in Eclipse|in Eclipse]] at least once before this, so you're sure Git and all the other tools are set up and working correctly.
 
= Please respect copyright law =
 
When contributing to a JogAmp project, please be sure not to include any code or data that you can't legally donate to the Jogamp community. So for example, you shouldn't cut and paste code from some other commercial or open-source project. This could put its JogAmp's own open-source status in jeopardy, and would require painstaking effort to remove.


= Create a free GitHub account =
= Create a free GitHub account =


Go to http://github.com/ and create a free GitHub account. We use GitHub's infrastructure to share code between developers and manage pull requests.
Go to http://github.com/ and create a free GitHub account. We use GitHub's infrastructure to share code between developers and to manage pull requests.


= Generate new (or use existing) SSH keys =
= Generate new (or use existing) SSH keys =
Line 14: Line 20:


* To generate keys, see http://help.github.com/msysgit-key-setup/.
* To generate keys, see http://help.github.com/msysgit-key-setup/.
* If you already have RSA keys in an .ssh directory, you can just enter one of them into GitHub.
* If you already have RSA keys in an <tt>.ssh</tt> directory, you can just enter one of them into GitHub.
* To test, type "ssh git@github.com" and enter your passphrase at the prompt. It should say "You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed."
* To test, type <tt>ssh git@github.com</tt> and enter your passphrase at the prompt. It should say "You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed."


= Set your username and email in Git global settings =
= Set your username and email in Git global settings =
Line 21: Line 27:
This is needed so your changes to the code will be attributed to you correctly.
This is needed so your changes to the code will be attributed to you correctly.


* Open a shell
* Open a shell.
* Type this: git config --global user.name "Your Name"
* Type <tt>git config --global user.name "Your Name"</tt>
* Type this: git config --global user.email "someone@wherever.com"
* Type <tt>git config --global user.email "someone@wherever.com"</tt>




You can check the current values of these settings by typing "git config --global user.name" and "git config --global user.email".
You can check the current values of these settings by typing <tt>git config --global user.name</tt> and <tt>git config --global user.email</tt>.


= Fork the gluegen and jogl projects on GitHub =
= Fork the gluegen and jogl projects on GitHub =
Line 32: Line 38:
This creates your initial copies of the code repositories, and gives you a place to push your change branches to.
This creates your initial copies of the code repositories, and gives you a place to push your change branches to.


* See http://help.github.com/forking/ for instructions
* See http://help.github.com/forking/ for instructions.
* Log into GitHub
* Log into GitHub.
* Go to https://github.com/sgothel/gluegen, press the "Fork" button
* Go to https://github.com/sgothel/gluegen, then press the "Fork" button.
* Go to https://github.com/sgothel/jogl, press the "Fork" button
* Go to https://github.com/sgothel/jogl, then press the "Fork" button.


= Clone gluegen and jogl locally from your forks =
 
Now when you go to http://github.com/, you'll see gluegen and jogl under "Your Repositories" on the right.
 
= Clone gluegen and jogl from your forks =


This creates your local working copy of the code.
This creates your local working copy of the code.


* Open a new shell and cd to where you want your repositories
* Open a new shell and cd to where you want your repositories.
* Type these commands (they'll require your SSH passphrase)
* Type these commands (they'll require your SSH passphrase).
** To get gluegen: git clone git@github.com:YourGitHubName/gluegen.git gluegen  
** To get gluegen: <tt>git clone git@github.com:YourGitHubUsername/gluegen.git gluegen</tt>
** To get jogl: git clone git@github.com:YourGitHubName/jogl.git jogl  
** To get jogl: <tt>git clone git@github.com:YourGitHubUsername/jogl.git jogl</tt>


= Build the projects =
= Build the projects =
Line 50: Line 59:
This works just like the build process discussed in [[Building JOGL on the command line|"Building JOGL on the command line"]].
This works just like the build process discussed in [[Building JOGL on the command line|"Building JOGL on the command line"]].


* cd to gluegen/make, type "ant clean", then type "ant"
* cd to <tt>gluegen/make</tt>, type <tt>ant clean</tt>, then type <tt>ant</tt>.
* cd to jogl/make, type "ant clean", then type "ant"
* cd to <tt>jogl/make</tt>, type <tt>ant clean</tt>, then type <tt>ant</tt>.
 
= Create an enhancement request or bug report =
 
Log into https://jogamp.org/bugzilla/ and create an enhancement request or bug report.
 
This gives you a Bugzilla ticket number, which is good to name your code branches with. A new feature can be entered into Bugzilla as ticket with severity set to "enhancement" instead of "critical", "major", et cetera.
 
NOTE: Your Bugzilla login is the full email address you used to create an account on the JogAmp forum, with the same password.
 
= Create a branch for your feature or fix =


= Create a bug report at https://jogamp.org/bugzilla/ =
This keeps your changes together in a form that's easy to push back to the server. Putting your changes in a branch also lets you quickly switch between it and any other branches you may be working on at the same time.


This gives you a bug number, which is good to name your code branches with.
* cd to <tt>jogl</tt>
* Type <tt>git branch bug_xxx</tt>
* Type <tt>git checkout bug_xxx</tt>


NOTE: There's currently a bug the Bugzilla "Log In" link. You can click it and type your login and password, but it doesn't log you in.
= Change source files =


So instead of clicking the "Log In" link, click the "New" link, and log in on the page that says "I need a legitimate login and password to continue". You'll need to type your full email address, then your password.
This is the code editing process. Use your favorite text editor or IDE to make your contribution. Make sure to put the same Jogamp community copyright notice at the top as in all the other source code files.


= Create branch for fix =
If you're editing existing code files, please be considerate. Don't make needless whitespace changes, and try to use the same style as the existing code. This makes the [[Maintainer and Contacts#Maintainer|module maintainer's]]  job easier, and makes it more likely your changes will be accepted.


* cd jogl
= Create a new unit test =
* git branch bug_xxx
* git checkout bug_xxx


= Change files, test, and commit =
Whether fixing a bug or contributing a new feature, you should always create a new unit test to ensure that your contribution works properly. This unit test will also become part of the test suite that's run on every new contribution, to make sure that future changes don't undo your bug fix or break your feature.


* git status (shows modified files)  
You can see an example of a unit test at [https://github.com/sgothel/jogl/blob/master/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java jogl/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java].
* git commit -a -v (commits all modified files, lets you type commit message)  
 
The filename of a unit test for a bug should also contain the Bugzilla ticket number, for example "TestGrayTextureFromFileAWTBug417.java".
 
Test file names need to start with "Test", and should have "AWT" or "NEWT" somewhere in the name so the Ant build will see them.
 
You can run individual JUnit tests either from the command line or from within Eclipse. From the Linux command line, if you're in the <tt>jogl/build</tt> directory, you can run a single unit test like this:
 
<tt>
java -Djava.awt.headless=false -Djava.library.path="lib" -cp "../../gluegen/make/lib/junit.jar:$ANT_HOME/lib/ant.jar:$ANT_HOME/lib/ant-junit.jar:jar/gluegen-rt.jar:jar/jogl-all.jar:jar/jogl-test.jar" com.jogamp.opengl.test.junit.jogl.texture.TestGrayTextureFromFileAWTBug417
</tt>
 
From within Eclipse, simply right-click the test's Java file in the Package Explorer and select "Debug As > JUnit Test".
 
= Run test suite and commit =
 
Before you commit your changes, your modified branch should pass all the unit tests in the suite, both your new tests and the current ones.
 
To run all the tests in the suite, cd to <tt>jogl/make</tt> and type <tt>ant junit.run</tt>. Make sure that any new unit tests you added are run as part of this suite.
 
The following Git commands are useful when you're ready to commit your changes:
 
* <tt>git status</tt> (shows modified files)  
* <tt>git commit -a -v</tt> (commits all modified files, lets you type commit message)  
 
Each commit should contain only one bug fix or new feature. Avoid combining lots of different changes into one giant commit, because that makes it difficult for the [[Maintainer and Contacts#Maintainer|module maintainer]] to review your changes and accept them quickly. The ideal commit changes the bare minimum number of lines needed to fix a bug or add a feature.


= Push branch back to Github =
= Push branch back to Github =
* git push origin bug_xxx  
 
Once you're done coding, testing, and committing, you need to push your new branch back up to GitHub so others can see it. Here's the command:
 
* <tt>git push origin bug_xxx</tt>


= Send pull request on Github =
= Send pull request on Github =


* Instructions on http://help.github.com/pull-requests/
With your branch available on GitHub, you can finally submit a pull request to the [[Maintainer and Contacts#Maintainer|module maintainer]].
* Go to your project on Github  
 
* Switch branch to bug_xxx  
* Go to your project on Github.
* Press "Pull Request" button  
* Hover your mouse over the "Switch Branches" button, and select "bug_xxx" from the list.
* Type comment, check diffs  
* Press "Pull Request" button.
* Press "Send pull request"  
* Type a comment, and check the diffs.
** Make sure not to submit a pull request that includes extra whitespace changes; these make it hard to identify the real code changes.
** Make sure you're not committing any files that have extraneous changes in them that aren't part of your fix or enhancement.
* Press the "Send pull request" button.
* More instructions are at http://help.github.com/pull-requests/
 
= Invite feedback on your new feature or fix =
 
You can let others know about your changes on the [http://jogamp.org/forum.html Jogamp forum]. This is useful to let people know about upcoming changes, and to keep them from duplicating your effort without knowing.
 
If you include the URL of your pull request, people can comment on it on GitHub too.


= Wait for your pull request to be accepted =
= Wait for your pull request to be accepted =


This may take a while, depending on how busy the lead developer is. Also, the lead may ask you to change some aspects of your commits if they don't fit in with other code or don't work during regression testing.
This may take a while, depending on how busy the [[Maintainer and Contacts#Maintainer|module maintainer]] is. Also, the maintainer may ask you to change some aspects of your commits if they don't fit in with other code or don't work during regression testing.


When your pull request is accepted, update the bug status to "Resolved" on Bugzilla!
When your pull request is accepted, update the bug status to "Resolved" on Bugzilla!

Latest revision as of 22:33, 2 March 2013

Overview

Contributing a new feature or bug fix to a JogAmp project is a bit more involved than just building it. The main difference is that instead of pulling the code from the canonical repository on GitHub, you need to fork it, then work on your own forked repository. When you're done, you submit a "pull request" on GitHub for the module maintainer to review your changes.

I'll use JOGL as an example below, but this information applies to other JogAmp projects too. You can find them in our code repositories.

You should already have built the JogAmp project you want to contribute to on the command line or in Eclipse at least once before this, so you're sure Git and all the other tools are set up and working correctly.

Please respect copyright law

When contributing to a JogAmp project, please be sure not to include any code or data that you can't legally donate to the Jogamp community. So for example, you shouldn't cut and paste code from some other commercial or open-source project. This could put its JogAmp's own open-source status in jeopardy, and would require painstaking effort to remove.

Create a free GitHub account

Go to http://github.com/ and create a free GitHub account. We use GitHub's infrastructure to share code between developers and to manage pull requests.

Generate new (or use existing) SSH keys

You'll use these keys to access your GitHub code repositories.

  • To generate keys, see http://help.github.com/msysgit-key-setup/.
  • If you already have RSA keys in an .ssh directory, you can just enter one of them into GitHub.
  • To test, type ssh git@github.com and enter your passphrase at the prompt. It should say "You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed."

Set your username and email in Git global settings

This is needed so your changes to the code will be attributed to you correctly.

  • Open a shell.
  • Type git config --global user.name "Your Name"
  • Type git config --global user.email "someone@wherever.com"


You can check the current values of these settings by typing git config --global user.name and git config --global user.email.

Fork the gluegen and jogl projects on GitHub

This creates your initial copies of the code repositories, and gives you a place to push your change branches to.


Now when you go to http://github.com/, you'll see gluegen and jogl under "Your Repositories" on the right.

Clone gluegen and jogl from your forks

This creates your local working copy of the code.

  • Open a new shell and cd to where you want your repositories.
  • Type these commands (they'll require your SSH passphrase).
    • To get gluegen: git clone git@github.com:YourGitHubUsername/gluegen.git gluegen
    • To get jogl: git clone git@github.com:YourGitHubUsername/jogl.git jogl

Build the projects

This works just like the build process discussed in "Building JOGL on the command line".

  • cd to gluegen/make, type ant clean, then type ant.
  • cd to jogl/make, type ant clean, then type ant.

Create an enhancement request or bug report

Log into https://jogamp.org/bugzilla/ and create an enhancement request or bug report.

This gives you a Bugzilla ticket number, which is good to name your code branches with. A new feature can be entered into Bugzilla as ticket with severity set to "enhancement" instead of "critical", "major", et cetera.

NOTE: Your Bugzilla login is the full email address you used to create an account on the JogAmp forum, with the same password.

Create a branch for your feature or fix

This keeps your changes together in a form that's easy to push back to the server. Putting your changes in a branch also lets you quickly switch between it and any other branches you may be working on at the same time.

  • cd to jogl
  • Type git branch bug_xxx
  • Type git checkout bug_xxx

Change source files

This is the code editing process. Use your favorite text editor or IDE to make your contribution. Make sure to put the same Jogamp community copyright notice at the top as in all the other source code files.

If you're editing existing code files, please be considerate. Don't make needless whitespace changes, and try to use the same style as the existing code. This makes the module maintainer's job easier, and makes it more likely your changes will be accepted.

Create a new unit test

Whether fixing a bug or contributing a new feature, you should always create a new unit test to ensure that your contribution works properly. This unit test will also become part of the test suite that's run on every new contribution, to make sure that future changes don't undo your bug fix or break your feature.

You can see an example of a unit test at jogl/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java.

The filename of a unit test for a bug should also contain the Bugzilla ticket number, for example "TestGrayTextureFromFileAWTBug417.java".

Test file names need to start with "Test", and should have "AWT" or "NEWT" somewhere in the name so the Ant build will see them.

You can run individual JUnit tests either from the command line or from within Eclipse. From the Linux command line, if you're in the jogl/build directory, you can run a single unit test like this:

java -Djava.awt.headless=false -Djava.library.path="lib" -cp "../../gluegen/make/lib/junit.jar:$ANT_HOME/lib/ant.jar:$ANT_HOME/lib/ant-junit.jar:jar/gluegen-rt.jar:jar/jogl-all.jar:jar/jogl-test.jar" com.jogamp.opengl.test.junit.jogl.texture.TestGrayTextureFromFileAWTBug417

From within Eclipse, simply right-click the test's Java file in the Package Explorer and select "Debug As > JUnit Test".

Run test suite and commit

Before you commit your changes, your modified branch should pass all the unit tests in the suite, both your new tests and the current ones.

To run all the tests in the suite, cd to jogl/make and type ant junit.run. Make sure that any new unit tests you added are run as part of this suite.

The following Git commands are useful when you're ready to commit your changes:

  • git status (shows modified files)
  • git commit -a -v (commits all modified files, lets you type commit message)

Each commit should contain only one bug fix or new feature. Avoid combining lots of different changes into one giant commit, because that makes it difficult for the module maintainer to review your changes and accept them quickly. The ideal commit changes the bare minimum number of lines needed to fix a bug or add a feature.

Push branch back to Github

Once you're done coding, testing, and committing, you need to push your new branch back up to GitHub so others can see it. Here's the command:

  • git push origin bug_xxx

Send pull request on Github

With your branch available on GitHub, you can finally submit a pull request to the module maintainer.

  • Go to your project on Github.
  • Hover your mouse over the "Switch Branches" button, and select "bug_xxx" from the list.
  • Press "Pull Request" button.
  • Type a comment, and check the diffs.
    • Make sure not to submit a pull request that includes extra whitespace changes; these make it hard to identify the real code changes.
    • Make sure you're not committing any files that have extraneous changes in them that aren't part of your fix or enhancement.
  • Press the "Send pull request" button.
  • More instructions are at http://help.github.com/pull-requests/

Invite feedback on your new feature or fix

You can let others know about your changes on the Jogamp forum. This is useful to let people know about upcoming changes, and to keep them from duplicating your effort without knowing.

If you include the URL of your pull request, people can comment on it on GitHub too.

Wait for your pull request to be accepted

This may take a while, depending on how busy the module maintainer is. Also, the maintainer may ask you to change some aspects of your commits if they don't fit in with other code or don't work during regression testing.

When your pull request is accepted, update the bug status to "Resolved" on Bugzilla!