lukasz-antoniak commented on code in PR #2041: URL: https://github.com/apache/cassandra-java-driver/pull/2041#discussion_r2435389929
########## CONTRIBUTING.md: ########## @@ -17,518 +17,192 @@ specific language governing permissions and limitations under the License. --> -# Contributing guidelines +# Contributing Guidelines -## Code formatting +Thank you for your interest in contributing to the Apache Cassandra Java Driver! Please review the following guidelines to help you get started. -### Java +## Table of Contents -We follow the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html). See -https://github.com/google/google-java-format for IDE plugins. The rules are not configurable. +- [Bugs, Features, and Questions](#bugs-features-and-questions) +- [Development Environment Setup](#development-environment-setup) +- [To Submit a Pull Request](#to-submit-a-pull-request) +- [Coding Guide](#coding-guide) -The build will fail if the code is not formatted. To format all files from the command line, run: - -``` -mvn fmt:format -``` +## Bugs, Features, and Questions -Some aspects are not covered by the formatter: braces must be used with `if`, `else`, `for`, `do` -and `while` statements, even when the body is empty or contains only a single statement. +- To report bugs or request features, please file a ticket on our [JIRA](https://issues.apache.org/jira/projects/CASSJAVA). +- For questions, use our [user mailing list](https://groups.google.com/a/lists.datastax.com/g/java-driver-user). -### XML +## Development Environment Setup -The build will fail if XML files are not formatted correctly. Run the following command before you -commit: +### Build and IDE Configuration -```java -mvn xml-format:xml-format -``` +- Ensure Maven is installed and you are using Java 8. +- Build the project with: + ``` + mvn clean package -DskipTests + ``` +- If using an IDE like IntelliJ and encountering issues with guava-shaded classes: + - Run: + ``` + mvn clean install -DskipTests + ``` + - If IntelliJ uses a different Maven version, use the Maven window in IntelliJ: under `Lifecycle`, click `clean` and then `install`. -The formatter does not enforce a maximum line length, but please try to keep it below 100 characters -to keep files readable across all mediums (IDE, terminal, Github...). +### Running the Tests -### Other text files (markdown, etc) +#### Unit Tests -Similarly, enforce a right margin of 100 characters in those files. Editors and IDEs generally have -a way to configure this (for IDEA, install the "Wrap to column" plugin). +- Ensure you are using Java 8. +- Run: + ``` + mvn clean install -DskipTests + mvn test + ``` -## Coding style -- production code +#### Integration Tests + +1. Install Cassandra Cluster Manager (CCM) following its [README](https://github.com/apache/cassandra-ccm). +2. On macOS, enable loopback aliases: + ```shell + for i in {2..255}; do sudo ifconfig lo0 alias 127.0.0.$i up; done + ``` + Note: This may slow down networking. To remove the aliases after testing: + ```shell + for i in {2..255}; do sudo ifconfig lo0 -alias 127.0.0.$i up; done + ``` +3. Run integration tests: + ``` + mvn clean verify + ``` + To target a specific Cassandra version: + ``` + mvn verify -Dccm.version=3.11.0 + ``` + +### Code Formatting and License Headers + +- We follow the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html). See [google-java-format](https://github.com/google/google-java-format) for IDE plugins. +- To format code: + ``` + # Java files + mvn fmt:format + # XML files + mvn xml-format:xml-format + # License headers + mvn license:format + ``` -Do not use static imports. They make things harder to understand when you look at the code -someplace where you don't have IDE support, like Github's code view. +### Pre-commit Hook (Highly Recommended) -Avoid abbreviations in class and variable names. A good rule of thumb is that you should only use -them if you would also do so verbally, for example "id" and "config" are probably reasonable. -Single-letter variables are permissible if the variable scope is only a few lines, or for commonly -understood cases (like `i` for a loop index). +- Make `pre-commit.sh` executable: + ``` + chmod +x pre-commit.sh + ``` +- Set up the pre-commit hook: + ``` + ln -s ../../pre-commit.sh .git/hooks/pre-commit + ``` +- This script will format files and run unit tests before each commit. -Keep source files short. Short files are easy to understand and test. The average should probably -be around 200-300 lines. +## To Submit a Pull Request +- Pull request titles must follow the format: `{JIRA-ticket-number}: {JIRA-ticket-title}` + Example: `CASSJAVA-40: Driver testing against Java 21` +- Before merging, squash your commits into a single commit with a message formatted as: + ``` + {JIRA-ticket-number}: {JIRA-ticket-title} + patch by {your-name}; reviewed by {approver-1} and {approver-2} for {JIRA-ticket-number} + ``` + +## Coding Guide ### Javadoc -All types in "API" packages must be documented. For "internal" packages, documentation is optional, -but in no way discouraged: it's generally a good idea to have a class-level comment that explains -where the component fits in the architecture, and anything else that you feel is important. +- **API packages:** must be documented. +- **Internal packages:** optional but encouraged—add a short class-level comment explaining the component’s role. Review Comment: `encouraged - add ` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

