|
| 1 | +# Coding Conventions |
| 2 | + |
| 3 | +<!-- This file documents project-specific coding standards for exhort-java-api. --> |
| 4 | + |
| 5 | +## Language and Framework |
| 6 | + |
| 7 | +- **Primary Language**: Java 17 |
| 8 | +- **Build Tool**: Maven 3.8+ |
| 9 | +- **Module System**: Java 9+ modules (`module-info.java`) |
| 10 | +- **Key Libraries**: Jackson 2.20.0 (JSON), CycloneDX 11.0.1 (SBOM), Jakarta Mail/Annotation APIs |
| 11 | +- **Async Model**: `CompletableFuture` throughout the API |
| 12 | + |
| 13 | +## Code Style |
| 14 | + |
| 15 | +- **Formatter**: Spotless Maven Plugin with Google Java Format (GOOGLE style, `reflowLongStrings` enabled) |
| 16 | +- **Indentation**: 2 spaces for Java, XML, YAML; 2 spaces for JSON |
| 17 | +- **Line length**: 100 characters (120 for XML/FXML) |
| 18 | +- **Line endings**: LF |
| 19 | +- **Charset**: UTF-8 |
| 20 | +- **License header**: Apache 2.0, automatically injected by Spotless |
| 21 | +- **EditorConfig**: `.editorconfig` enforces formatting rules |
| 22 | +- **Code coverage**: 81% unit test threshold (JaCoCo), 50 mutation threshold (PIT) |
| 23 | + |
| 24 | +## Naming Conventions |
| 25 | + |
| 26 | +- **Packages**: `io.github.guacsec.trustifyda.*` |
| 27 | +- **Classes**: PascalCase |
| 28 | + - Providers: `*Provider` (e.g., `JavaMavenProvider`, `PythonPipProvider`) |
| 29 | + - Factories: `*Factory` (e.g., `JavaScriptProviderFactory`, `SbomFactory`) |
| 30 | + - Abstract bases: `Base*Provider` (e.g., `BaseJavaProvider`) |
| 31 | + - Utility classes: `final` with private constructor |
| 32 | +- **Interfaces**: Simple names without `I` prefix (`Api`, `Provider`, `Sbom`) |
| 33 | + - Inner static classes for related types: `Api.MediaType`, `Provider.Content` |
| 34 | +- **Methods**: camelCase (`provideStack()`, `provideComponent()`, `getCustomPathOrElse()`) |
| 35 | +- **Constants**: UPPER_SNAKE_CASE (`TRUSTIFY_DA_BACKEND_URL`, `CYCLONEDX_MEDIA_TYPE`) |
| 36 | +- **Enums**: PascalCase class, UPPER_CASE values (`MAVEN`, `NPM`, `GRADLE`) |
| 37 | +- **Test classes**: Snake_case pattern (`Operations_Test`, `Java_Maven_Provider_Test`) |
| 38 | + |
| 39 | +## File Organization |
| 40 | + |
| 41 | +``` |
| 42 | +src/main/java/io/github/guacsec/trustifyda/ |
| 43 | +├── Api.java # Main interface |
| 44 | +├── Provider.java # Abstract provider contract |
| 45 | +├── cli/ # CLI implementation |
| 46 | +├── exception/ # Custom exceptions |
| 47 | +├── image/ # Image analysis |
| 48 | +├── impl/ # ExhortApi implementation, RequestManager |
| 49 | +├── logging/ # LoggersFactory |
| 50 | +├── providers/ # 18+ ecosystem provider implementations |
| 51 | +├── sbom/ # SBOM handling (Sbom, SbomFactory, CycloneDXSbom) |
| 52 | +├── tools/ # Utilities (Ecosystem, Operations) |
| 53 | +├── utils/ # Environment, IgnorePatternDetector |
| 54 | +└── vcs/ # Version control utilities |
| 55 | +``` |
| 56 | + |
| 57 | +- Test resources: `src/test/resources/tst_manifests/` |
| 58 | +- Integration tests: `src/it/` (Maven Invoker Plugin) |
| 59 | + |
| 60 | +## Error Handling |
| 61 | + |
| 62 | +- Runtime exceptions preferred over checked (e.g., `PackageNotInstalledException extends RuntimeException`) |
| 63 | +- `CompletableFuture` for async operations with completion exception handling |
| 64 | +- `IOException` allowed for file operations (checked exception) |
| 65 | +- Environment validation at initialization time |
| 66 | +- Logging via `LoggersFactory.getLogger()` (Java Logging API) |
| 67 | + |
| 68 | +## Testing Conventions |
| 69 | + |
| 70 | +- **Frameworks**: JUnit Jupiter 5, Mockito 5.17.0, AssertJ 3.27.3 |
| 71 | +- **Extensions**: JUnit Pioneer (`@SetSystemProperty`, `@ClearSystemProperty`) |
| 72 | +- **Assertions**: AssertJ fluent API (`assertThat()`, `assertThatRuntimeException()`) |
| 73 | +- **Mocking**: Mockito (`@Mock`, `@InjectMocks`, `mockStatic()`, BDDMockito) |
| 74 | +- **Test structure**: `@Nested` classes, `@ParameterizedTest @MethodSource` |
| 75 | +- **Test naming**: Snake_case classes, descriptive methods (`when_running_process_for_existing_command_should_not_throw_exception`) |
| 76 | +- **Test runner**: junit-platform-maven-plugin |
| 77 | + |
| 78 | +## Commit Messages |
| 79 | + |
| 80 | +- Follow Conventional Commits: `type(scope): description` |
| 81 | +- DCO sign-off required |
| 82 | +- Pull request titles must follow Conventional Commits format |
| 83 | + |
| 84 | +## Test Fixtures |
| 85 | + |
| 86 | +- **Dependabot suppression**: Test fixture directories contain intentionally pinned (sometimes vulnerable) dependencies. When adding a new test fixture directory with a manifest file, review `.github/dependabot.yml` to ensure the new path is covered. Non-maven ecosystems are suppressed via root-level `ignore: [{dependency-name: "*"}]` entries. Maven fixtures use per-directory entries with `/**` globs since maven is the production ecosystem; add the parent directory if a new maven fixture tree is introduced. |
| 87 | + |
| 88 | +## Test Fixtures |
| 89 | + |
| 90 | +- **Dependabot suppression**: Test fixture directories contain intentionally pinned (sometimes vulnerable) dependencies. When adding a new test fixture directory with a manifest file, review `.github/dependabot.yml` to ensure the new path is covered. Non-maven ecosystems are suppressed via root-level `ignore: [{dependency-name: "*"}]` entries. Maven fixtures use explicit per-directory entries since maven is the production ecosystem; add the directory path if a new maven fixture is introduced. |
| 91 | + |
| 92 | +## Dependencies |
| 93 | + |
| 94 | +- All versions in `<properties>` section: `{artifact-name}.version` pattern |
| 95 | +- Compile scope: Jackson, Jakarta, CycloneDX, TOML parsers |
| 96 | +- Test scope: JUnit, Mockito, AssertJ, JUnit Pioneer |
| 97 | +- Maven Shade Plugin for CLI JAR with all dependencies |
| 98 | +- Distribution to Maven Central (flatten plugin, OSSRH mode) |
| 99 | +- GitHub Maven repository for `trustify-da-api-model` |
| 100 | +- Enforcer plugin: dependency convergence, no circular dependencies |
0 commit comments