| 1 | # Contributing guidelines |
| 2 | |
| 3 | ## Working on an issue |
| 4 | |
| 5 | Before starting to work on something, please comment in JIRA or ask on the mailing list |
| 6 | to make sure nobody else is working on it. |
| 7 | |
| 8 | If a fix applies both to 2.0 and 2.1, work on the 2.0 branch, your commit will eventually |
| 9 | get merged in 2.1. |
| 10 | |
| 11 | Before you send your pull request, make sure that: |
| 12 | |
| 13 | - you have a unit test that failed before the fix and succeeds after. |
| 14 | - the fix is mentioned in `driver-core/CHANGELOG.rst`. |
| 15 | - the commit message include the reference of the JIRA ticket for automatic linking |
| 16 | (example: `Fix NPE when a connection fails during pool construction (JAVA-503).`). |
| 17 | |
| 18 | As long as your pull request is not merged, it's OK to rebase your branch and push with |
| 19 | `--force`. |
| 20 | |
| 21 | If you want to contribute but don't have a specific issue in mind, the [lhf](https://datastax-oss.atlassian.net/secure/IssueNavigator.jspa?reset=true&mode=hide&jqlQuery=project%20%3D%20JAVA%20AND%20status%20in%20(Open%2C%20Reopened)%20AND%20labels%20%3D%20lhf) |
| 22 | label in JIRA is a good place to start: it marks "low hanging fruits" that don't require |
| 23 | in-depth knowledge of the codebase. |
| 24 | |
| 25 | ## Editor configuration |
| 26 | |
| 27 | ### General |
| 28 | |
| 29 | We consider automatic formatting as a help, not a crutch. Sometimes it makes sense to |
| 30 | break the rules to make the code more readable, for instance aligning columns (see the |
| 31 | constant declarations in `DataType.Name` for an example of this). |
| 32 | |
| 33 | **Please do not reformat whole files, only the lines that you have added or modified**. |
| 34 | |
| 35 | |
| 36 | ### Eclipse |
| 37 | |
| 38 | Formatter: |
| 39 | |
| 40 | - Preferences > Java > Code Style > Formatter. |
| 41 | - Click "Import". |
| 42 | - Select `src/main/config/ide/eclipse-formatter.xml`. |
| 43 | |
| 44 | Import order: |
| 45 | |
| 46 | - Preferences > Java > Code Style > Organize imports. |
| 47 | - Click "Import". |
| 48 | - Select `src/main/config/ide/eclipse.importorder`. |
| 49 | |
| 50 | Prevent trailing whitespaces: |
| 51 | |
| 52 | - Preferences > Java > Editor > Save Actions. |
| 53 | - Check "Perform the selected actions on save". |
| 54 | - Ensure "Format source code" and "Organize imports" are unchecked. |
| 55 | - Check "Additional actions". |
| 56 | - Click "Configure". |
| 57 | - In the "Code Organizing" tab, check "Remove trailing whitespace" and "All lines". |
| 58 | - Click "OK" (the text area should only have one action "Remove trailing white spaces"). |
| 59 | |
| 60 | |
| 61 | ### IntelliJ IDEA |
| 62 | |
| 63 | - File > Import Settings... |
| 64 | - Select `src/main/config/ide/intellij-code-style.jar`. |
| 65 | |
| 66 | This should add a new Code Style scheme called "java-driver". |
| 67 | |
| 68 | ## Running the tests |
| 69 | |
| 70 | We use TestNG. There are 3 test categories: |
| 71 | |
| 72 | - "unit": pure Java unit tests. |
| 73 | - "short" and "long": integration tests that launch Cassandra instances. |
| 74 | |
| 75 | The Maven build uses profiles named after the categories to choose which tests to run: |
| 76 | |
| 77 | ``` |
| 78 | mvn test -Pshort |
| 79 | ``` |
| 80 | |
| 81 | The default is "unit". Each profile runs the ones before it ("short" runs unit, etc.) |
| 82 | |
| 83 | Integration tests use [CCM](https://github.com/pcmanus/ccm) to bootstrap Cassandra instances. |
| 84 | Two Maven properties control its execution: |
| 85 | |
| 86 | - `cassandra.version`: the Cassandra version. This has a default value in the root POM, |
| 87 | you can override it on the command line (`-Dcassandra.version=...`). |
| 88 | - `ipprefix`: the prefix of the IP addresses that the Cassandra instances will bind to (see |
| 89 | below). This defaults to `127.0.1.`. |
| 90 | |
| 91 | |
| 92 | CCM launches multiple Cassandra instances on localhost by binding to different addresses. The |
| 93 | driver uses up to 6 different instances (127.0.1.1 to 127.0.1.6 with the default prefix). |
| 94 | You'll need to define loopback aliases for this to work, on Mac OS X your can do it with: |
| 95 | |
| 96 | ``` |
| 97 | sudo ifconfig lo0 alias 127.0.1.1 up |
| 98 | sudo ifconfig lo0 alias 127.0.1.2 up |
| 99 | ... |
| 100 | ``` |