|
| 1 | +# Contributing to OpenMapView |
| 2 | + |
| 3 | +[Back to README](../README.md) |
| 4 | + |
| 5 | +This guide outlines the development workflow and requirements for contributing to OpenMapView. |
| 6 | + |
| 7 | +## Code Quality Requirements |
| 8 | + |
| 9 | +All contributions must meet the following requirements before being merged: |
| 10 | + |
| 11 | +### 1. Code Formatting |
| 12 | + |
| 13 | +All Kotlin code must follow the project's formatting rules enforced by Spotless with ktlint 1.3.1. |
| 14 | + |
| 15 | +**Before committing**, run: |
| 16 | + |
| 17 | +```bash |
| 18 | +./gradlew spotlessApply |
| 19 | +``` |
| 20 | + |
| 21 | +This automatically formats all code according to the project's style rules: |
| 22 | +- 4 spaces indentation |
| 23 | +- No trailing whitespace |
| 24 | +- Files end with newline |
| 25 | +- Consistent ktlint formatting |
| 26 | + |
| 27 | +**To check formatting** without applying changes: |
| 28 | + |
| 29 | +```bash |
| 30 | +./gradlew spotlessCheck |
| 31 | +``` |
| 32 | + |
| 33 | +The CI pipeline will fail if code is not properly formatted. |
| 34 | + |
| 35 | +### 2. Copyright Headers |
| 36 | + |
| 37 | +All `.kt` and `.kts` files must include the MIT license header at the top: |
| 38 | + |
| 39 | +```kotlin |
| 40 | +/* |
| 41 | + * Copyright (c) 2025 Alexander Farber |
| 42 | + * SPDX-License-Identifier: MIT |
| 43 | + * |
| 44 | + * This file is part of the OpenMapView project (https://github.com/afarber/OpenMapView) |
| 45 | + */ |
| 46 | +``` |
| 47 | + |
| 48 | +Running `./gradlew spotlessApply` automatically adds this header to any files missing it. |
| 49 | + |
| 50 | +**Why copyright headers matter:** Including copyright headers on all source files helps avoid potential legal issues and keeps this library clean to use for both personal and commercial applications. The MIT license identifier makes licensing terms explicit and unambiguous. |
| 51 | + |
| 52 | +The CI pipeline includes a copyright check that will fail if any Kotlin files are missing the required header. |
| 53 | + |
| 54 | +## Automated Git Hooks (Recommended) |
| 55 | + |
| 56 | +Git hooks can automatically check formatting and copyright headers before commits, preventing CI failures. |
| 57 | + |
| 58 | +### Setup Pre-commit Hook |
| 59 | + |
| 60 | +From the repository root, run: |
| 61 | + |
| 62 | +```bash |
| 63 | +./scripts/setup-git-hooks.sh |
| 64 | +``` |
| 65 | + |
| 66 | +This installs a pre-commit hook that automatically: |
| 67 | +1. Checks code formatting with `./scripts/check-format.sh` |
| 68 | +2. Checks copyright headers with `./scripts/check-copyright.sh` |
| 69 | +3. Blocks the commit if any issues are found |
| 70 | +4. Provides instructions to run `./gradlew spotlessApply` to fix issues |
| 71 | + |
| 72 | +### What Happens on Commit |
| 73 | + |
| 74 | +When committing changes, the hook runs: |
| 75 | + |
| 76 | +``` |
| 77 | +Running pre-commit checks... |
| 78 | +
|
| 79 | +1. Checking code formatting... |
| 80 | + Code formatting: OK |
| 81 | +2. Checking copyright headers... |
| 82 | + Copyright headers: OK |
| 83 | +
|
| 84 | +All pre-commit checks passed! |
| 85 | +``` |
| 86 | + |
| 87 | +If issues are found, the commit is blocked and instructions are displayed. |
| 88 | + |
| 89 | +**Note:** Git hooks are local and not tracked in the repository. Each developer must run the setup script after cloning. |
| 90 | + |
| 91 | +## Testing Requirements |
| 92 | + |
| 93 | +### Unit Tests |
| 94 | + |
| 95 | +All new features and bug fixes should include unit tests. |
| 96 | + |
| 97 | +Run unit tests: |
| 98 | + |
| 99 | +```bash |
| 100 | +./gradlew :openmapview:test |
| 101 | +``` |
| 102 | + |
| 103 | +### Instrumentation Tests |
| 104 | + |
| 105 | +For features requiring real Android framework APIs or rendering, add instrumentation tests. |
| 106 | + |
| 107 | +Run instrumentation tests (requires emulator or device): |
| 108 | + |
| 109 | +```bash |
| 110 | +./gradlew :openmapview:connectedAndroidTest |
| 111 | +``` |
| 112 | + |
| 113 | +## Pull Request Process |
| 114 | + |
| 115 | +1. Fork the repository |
| 116 | +2. Create a feature branch from `main` |
| 117 | +3. Make changes following the code quality requirements |
| 118 | +4. Run `./gradlew spotlessApply` before committing |
| 119 | +5. Ensure all tests pass locally |
| 120 | +6. Push changes and create a pull request |
| 121 | +7. CI must pass (formatting, tests, builds) |
| 122 | +8. Address any review feedback |
| 123 | + |
| 124 | +## CI Pipeline |
| 125 | + |
| 126 | +The CI pipeline runs automatically on all pull requests and includes: |
| 127 | + |
| 128 | +1. **Format Check** - Verifies Spotless formatting |
| 129 | +2. **Copyright Check** - Verifies MIT license headers |
| 130 | +3. **Unit Tests** - Runs all JVM unit tests |
| 131 | +4. **Build Library** - Builds the OpenMapView AAR |
| 132 | +5. **Build Examples** - Builds all example applications |
| 133 | + |
| 134 | +All checks must pass before merging. |
| 135 | + |
| 136 | +## Build Commands |
| 137 | + |
| 138 | +```bash |
| 139 | +# Format code |
| 140 | +./gradlew spotlessApply |
| 141 | + |
| 142 | +# Check formatting |
| 143 | +./gradlew spotlessCheck |
| 144 | + |
| 145 | +# Run unit tests |
| 146 | +./gradlew :openmapview:test |
| 147 | + |
| 148 | +# Build library |
| 149 | +./gradlew :openmapview:assembleRelease |
| 150 | + |
| 151 | +# Build all examples |
| 152 | +./gradlew assembleDebug |
| 153 | + |
| 154 | +# Run instrumentation tests |
| 155 | +./gradlew :openmapview:connectedAndroidTest |
| 156 | +``` |
| 157 | + |
| 158 | +## Questions or Issues? |
| 159 | + |
| 160 | +For questions about contributing, open an issue on GitHub: https://github.com/afarber/OpenMapView/issues |
| 161 | + |
0 commit comments