Contributing a new feature or fix: Difference between revisions

From JogampWiki
Jump to navigation Jump to search
(Added copyright warning)
No edit summary
Line 78: Line 78:
* Type <tt>git checkout bug_xxx</tt>
* Type <tt>git checkout bug_xxx</tt>


= Change files, test, and commit =
= Change source files =


This is the code editing process. The following Git commands are useful:
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.


* <tt>git status</tt> (shows modified 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 maintainer's job easier, and makes it more likely your changes will be accepted.
* <tt>git commit -a -v</tt> (commits all modified files, lets you type commit message)
 
= 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 [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].
 
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:
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>
<tt>
Line 92: Line 101:


From within Eclipse, simply right-click the test's Java file in the Package Explorer and select "Debug As > JUnit Test".
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)


= Push branch back to Github =
= Push branch back to Github =


Once you're done coding and testing, you need to push your new branch back up to GitHub so others can see it. Here's the command:
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>
* <tt>git push origin bug_xxx</tt>

Revision as of 16:34, 11 January 2011

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 forked repository. When you're done, you submit a "pull request" on GitHub for the 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.

Please respect copyright law

When contributing to JOGL, 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 into JOGL. This could put its JOGL'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: 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.

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.

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 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.

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/nativewindow.all.jar:jar/newt.all.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)

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 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.
  • Press the "Send pull request" button.
  • More instructions are at http://help.github.com/pull-requests/

Wait for your pull request to be accepted

This may take a while, depending on how busy the 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!