Archived
Add coding standards and quality enforcement tooling
- docs/coding-standards.md: Comprehensive Java coding standards - CLAUDE.md: AI assistant instructions for the project - .editorconfig: Editor configuration for consistent formatting - pom.xml: Updated with quality plugins (Checkstyle, SpotBugs, PMD, JaCoCo) - config/checkstyle/: Checkstyle configuration (Google Java Style based) - config/spotbugs/: SpotBugs exclusions - config/pmd/: PMD ruleset - .githooks/pre-commit: Pre-commit hook for local quality checks - .github/workflows/lint.yml: CI workflow for automated quality checks - docs/development.md: Updated for Java/Maven toolchain Quality enforcement: - Checkstyle runs on validate phase - SpotBugs and PMD run on verify phase - JaCoCo enforces 80% line coverage, 70% branch coverage - Pre-commit hook runs all checks before allowing commits - CI runs all checks on push and PR Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cf750b6eb5
commit
3c09ea978d
12 files changed
+2239
-90
No files matched your search
@@ -0,0 +1,41 @@
|
|||||||
|
# EditorConfig for Barn
|
||||||
|
# https://editorconfig.org
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.{kt,kts}]
|
||||||
|
indent_size = 4
|
||||||
|
max_line_length = 120
|
||||||
|
|
||||||
|
# ktlint specific settings
|
||||||
|
ktlint_code_style = ktlint_official
|
||||||
|
ktlint_standard_no-wildcard-imports = enabled
|
||||||
|
ktlint_standard_trailing-comma-on-call-site = enabled
|
||||||
|
ktlint_standard_trailing-comma-on-declaration-site = enabled
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
max_line_length = off
|
||||||
|
|
||||||
|
[*.{yml,yaml}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.{json,xml}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
||||||
|
|
||||||
|
[*.sh]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.gradle.kts]
|
||||||
|
indent_size = 4
|
||||||
Executable
+117
@@ -0,0 +1,117 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Pre-commit hook for Barn
|
||||||
|
#
|
||||||
|
# This hook runs code quality checks before allowing a commit.
|
||||||
|
# To install: git config core.hooksPath .githooks
|
||||||
|
#
|
||||||
|
# To bypass (use sparingly): git commit --no-verify
|
||||||
|
#
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "Running pre-commit checks..."
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Track if any check fails
|
||||||
|
FAILED=0
|
||||||
|
|
||||||
|
# Get list of staged Java files
|
||||||
|
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.java$' || true)
|
||||||
|
|
||||||
|
if [ -z "$STAGED_FILES" ]; then
|
||||||
|
echo -e "${GREEN}No Java files staged, skipping checks.${NC}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Checking staged Java files..."
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# CHECKSTYLE
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
echo -e "\n${YELLOW}Running Checkstyle...${NC}"
|
||||||
|
if mvn checkstyle:check -q 2>/dev/null; then
|
||||||
|
echo -e "${GREEN}✓ Checkstyle passed${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}✗ Checkstyle failed${NC}"
|
||||||
|
echo " Run 'mvn checkstyle:check' for details"
|
||||||
|
FAILED=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# COMPILE CHECK
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
echo -e "\n${YELLOW}Compiling...${NC}"
|
||||||
|
if mvn compile -q -DskipTests 2>/dev/null; then
|
||||||
|
echo -e "${GREEN}✓ Compilation passed${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}✗ Compilation failed${NC}"
|
||||||
|
echo " Run 'mvn compile' for details"
|
||||||
|
FAILED=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# SPOTBUGS (only if compile passed)
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
if [ $FAILED -eq 0 ]; then
|
||||||
|
echo -e "\n${YELLOW}Running SpotBugs...${NC}"
|
||||||
|
if mvn spotbugs:check -q 2>/dev/null; then
|
||||||
|
echo -e "${GREEN}✓ SpotBugs passed${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}✗ SpotBugs found issues${NC}"
|
||||||
|
echo " Run 'mvn spotbugs:check' for details"
|
||||||
|
echo " Run 'mvn spotbugs:gui' to view in GUI"
|
||||||
|
FAILED=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# PMD (only if compile passed)
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
if [ $FAILED -eq 0 ]; then
|
||||||
|
echo -e "\n${YELLOW}Running PMD...${NC}"
|
||||||
|
if mvn pmd:check -q 2>/dev/null; then
|
||||||
|
echo -e "${GREEN}✓ PMD passed${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}✗ PMD found issues${NC}"
|
||||||
|
echo " Run 'mvn pmd:check' for details"
|
||||||
|
FAILED=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# UNIT TESTS (optional, can be slow)
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
# Uncomment to run tests on every commit
|
||||||
|
# echo -e "\n${YELLOW}Running tests...${NC}"
|
||||||
|
# if mvn test -q 2>/dev/null; then
|
||||||
|
# echo -e "${GREEN}✓ Tests passed${NC}"
|
||||||
|
# else
|
||||||
|
# echo -e "${RED}✗ Tests failed${NC}"
|
||||||
|
# echo " Run 'mvn test' for details"
|
||||||
|
# FAILED=1
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# RESULT
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
if [ $FAILED -eq 1 ]; then
|
||||||
|
echo -e "${RED}Pre-commit checks failed!${NC}"
|
||||||
|
echo "Fix the issues above or use 'git commit --no-verify' to bypass (not recommended)"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo -e "${GREEN}All pre-commit checks passed!${NC}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
name: Lint
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
checkstyle:
|
||||||
|
name: Checkstyle
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up JDK 21
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
java-version: '21'
|
||||||
|
distribution: 'temurin'
|
||||||
|
cache: maven
|
||||||
|
|
||||||
|
- name: Run Checkstyle
|
||||||
|
run: mvn checkstyle:check
|
||||||
|
|
||||||
|
spotbugs:
|
||||||
|
name: SpotBugs
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up JDK 21
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
java-version: '21'
|
||||||
|
distribution: 'temurin'
|
||||||
|
cache: maven
|
||||||
|
|
||||||
|
- name: Run SpotBugs
|
||||||
|
run: mvn compile spotbugs:check
|
||||||
|
|
||||||
|
- name: Upload SpotBugs Report
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
if: failure()
|
||||||
|
with:
|
||||||
|
name: spotbugs-report
|
||||||
|
path: target/spotbugsXml.xml
|
||||||
|
|
||||||
|
pmd:
|
||||||
|
name: PMD
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up JDK 21
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
java-version: '21'
|
||||||
|
distribution: 'temurin'
|
||||||
|
cache: maven
|
||||||
|
|
||||||
|
- name: Run PMD
|
||||||
|
run: mvn compile pmd:check
|
||||||
|
|
||||||
|
- name: Upload PMD Report
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
if: failure()
|
||||||
|
with:
|
||||||
|
name: pmd-report
|
||||||
|
path: target/pmd.xml
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up JDK 21
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
java-version: '21'
|
||||||
|
distribution: 'temurin'
|
||||||
|
cache: maven
|
||||||
|
|
||||||
|
- name: Run Tests with Coverage
|
||||||
|
run: mvn test jacoco:report
|
||||||
|
|
||||||
|
- name: Upload Coverage Report
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: coverage-report
|
||||||
|
path: target/site/jacoco/
|
||||||
|
|
||||||
|
- name: Check Coverage Thresholds
|
||||||
|
run: mvn jacoco:check
|
||||||
|
|
||||||
|
verify:
|
||||||
|
name: Full Verification
|
||||||
|
needs: [checkstyle, spotbugs, pmd, test]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up JDK 21
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
java-version: '21'
|
||||||
|
distribution: 'temurin'
|
||||||
|
cache: maven
|
||||||
|
|
||||||
|
- name: Run Full Verify
|
||||||
|
run: mvn verify
|
||||||
|
|
||||||
|
- name: Upload Build Artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: build-artifacts
|
||||||
|
path: target/*.jar
|
||||||
@@ -0,0 +1,175 @@
|
|||||||
|
# Claude AI Instructions for Barn
|
||||||
|
|
||||||
|
> **First Step**: Always read `README.md` and relevant files in `docs/` before making changes.
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
|
||||||
|
Barn is a cross-platform job daemon for managing long-running media processing tasks (FFmpeg, WebDAV transfers). It runs as an OS service on Windows, macOS, and Linux.
|
||||||
|
|
||||||
|
**Key documentation to read first:**
|
||||||
|
|
||||||
|
1. `README.md` - Project overview and CLI commands
|
||||||
|
2. `docs/jobs.md` - Filesystem-based job state layout
|
||||||
|
3. `docs/config.md` - Configuration options
|
||||||
|
4. `docs/coding-standards.md` - **CRITICAL**: Code style and conventions
|
||||||
|
|
||||||
|
## Technology Stack
|
||||||
|
|
||||||
|
- **Language**: Java 21+
|
||||||
|
- **Build**: Maven
|
||||||
|
- **Native Image**: GraalVM Native Image
|
||||||
|
- **Code Style**: Checkstyle (Google Java Style)
|
||||||
|
- **Static Analysis**: SpotBugs, PMD
|
||||||
|
- **Testing**: JUnit 5, Mockito, AssertJ
|
||||||
|
|
||||||
|
## Code Standards (Mandatory)
|
||||||
|
|
||||||
|
Before writing any code, read `docs/coding-standards.md`. Key points:
|
||||||
|
|
||||||
|
### Formatting
|
||||||
|
- 4 spaces indentation (no tabs)
|
||||||
|
- 120 character line limit
|
||||||
|
- K&R brace style (opening brace on same line)
|
||||||
|
- Static imports first, then regular imports, alphabetically
|
||||||
|
|
||||||
|
### Naming
|
||||||
|
- Packages: `lowercase`
|
||||||
|
- Classes/Interfaces: `PascalCase`
|
||||||
|
- Methods/Variables: `camelCase`
|
||||||
|
- Constants: `SCREAMING_SNAKE_CASE`
|
||||||
|
|
||||||
|
### Java Idioms
|
||||||
|
- Use `final` for fields that don't change
|
||||||
|
- Use `Optional<T>` for return types that may be absent
|
||||||
|
- Use `Objects.requireNonNull()` for constructor parameters
|
||||||
|
- Use records for value objects
|
||||||
|
- Use sealed interfaces for state machines
|
||||||
|
- Use switch expressions (not statements)
|
||||||
|
- Use `var` for local variables with obvious types
|
||||||
|
|
||||||
|
### Error Handling
|
||||||
|
```java
|
||||||
|
// Good: Use Optional for methods that may not find a result
|
||||||
|
public Optional<Job> findJob(String id) {
|
||||||
|
return Optional.ofNullable(jobs.get(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Good: Validate preconditions
|
||||||
|
public void processJob(Job job) {
|
||||||
|
Objects.requireNonNull(job, "job must not be null");
|
||||||
|
if (job.getState() != JobState.QUEUED) {
|
||||||
|
throw new IllegalStateException("Job must be in QUEUED state");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Testing
|
||||||
|
- Use descriptive names: `methodName_condition_expectedResult()`
|
||||||
|
- Follow AAA pattern: Arrange, Act, Assert
|
||||||
|
- Minimum 80% line coverage
|
||||||
|
|
||||||
|
## Architecture Principles
|
||||||
|
|
||||||
|
### Filesystem as Database
|
||||||
|
- Job state is stored in `/tmp/barn/jobs/<job-id>/`
|
||||||
|
- Use atomic file operations
|
||||||
|
- Human-readable plain text files
|
||||||
|
- No external database dependencies
|
||||||
|
|
||||||
|
### Cross-Platform
|
||||||
|
- Use `System.getProperty("java.io.tmpdir")` for temp paths
|
||||||
|
- Avoid platform-specific commands
|
||||||
|
- Test on all three platforms (Windows, macOS, Linux)
|
||||||
|
|
||||||
|
### GraalVM Native Image
|
||||||
|
- Avoid reflection where possible
|
||||||
|
- Register any reflection in `reflect-config.json`
|
||||||
|
- Test native image builds
|
||||||
|
|
||||||
|
## File Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
barn/
|
||||||
|
src/
|
||||||
|
main/java/com/samsonmedia/barn/
|
||||||
|
Main.java # Entry point
|
||||||
|
cli/ # CLI commands (picocli)
|
||||||
|
config/ # Configuration parsing
|
||||||
|
jobs/ # Job management
|
||||||
|
service/ # Daemon/service logic
|
||||||
|
state/ # Filesystem state management
|
||||||
|
test/java/
|
||||||
|
unit/ # Unit tests
|
||||||
|
integration/ # Integration tests
|
||||||
|
e2e/ # End-to-end tests
|
||||||
|
docs/ # Documentation
|
||||||
|
config/
|
||||||
|
checkstyle/ # Checkstyle configuration
|
||||||
|
spotbugs/ # SpotBugs exclusions
|
||||||
|
pmd/ # PMD ruleset
|
||||||
|
.githooks/ # Git hooks
|
||||||
|
.github/workflows/ # CI/CD
|
||||||
|
pom.xml # Maven build
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Tasks
|
||||||
|
|
||||||
|
### Before Committing
|
||||||
|
```bash
|
||||||
|
mvn checkstyle:check # Check code style
|
||||||
|
mvn spotbugs:check # Bug detection
|
||||||
|
mvn pmd:check # Static analysis
|
||||||
|
mvn test # Run tests
|
||||||
|
mvn verify # Run all checks
|
||||||
|
```
|
||||||
|
|
||||||
|
### Commit Message Format
|
||||||
|
Follow Conventional Commits:
|
||||||
|
```
|
||||||
|
feat(jobs): add retry mechanism for failed jobs
|
||||||
|
fix(cli): handle spaces in file paths
|
||||||
|
docs(readme): update installation instructions
|
||||||
|
```
|
||||||
|
|
||||||
|
### Adding a New CLI Command
|
||||||
|
1. Create command class in `src/main/java/.../cli/`
|
||||||
|
2. Annotate with picocli `@Command`
|
||||||
|
3. Add to main command group
|
||||||
|
4. Add tests in `src/test/java/.../e2e/`
|
||||||
|
5. Update `README.md` and `docs/`
|
||||||
|
|
||||||
|
### Adding a Job State File
|
||||||
|
1. Update `docs/jobs.md` with the new file
|
||||||
|
2. Add read/write methods in `StateManager`
|
||||||
|
3. Add tests for persistence
|
||||||
|
4. Consider crash recovery implications
|
||||||
|
|
||||||
|
## Security Considerations
|
||||||
|
|
||||||
|
- Never log passwords, tokens, or credentials
|
||||||
|
- Validate job IDs to prevent path traversal
|
||||||
|
- Sanitize command inputs (no shell injection)
|
||||||
|
- Use atomic writes for state files
|
||||||
|
|
||||||
|
## What NOT to Do
|
||||||
|
|
||||||
|
- Don't return `null` - use `Optional<T>` instead
|
||||||
|
- Don't use raw types - always specify generics
|
||||||
|
- Don't use wildcard imports
|
||||||
|
- Don't skip tests for "simple" changes
|
||||||
|
- Don't use reflection without registering for native image
|
||||||
|
- Don't use platform-specific code without abstractions
|
||||||
|
- Don't commit without running `mvn verify`
|
||||||
|
- Don't catch `Exception` - catch specific exceptions
|
||||||
|
- Don't use `System.out.println` - use SLF4J logging
|
||||||
|
|
||||||
|
## Questions to Ask
|
||||||
|
|
||||||
|
Before implementing a feature, consider:
|
||||||
|
|
||||||
|
1. Does this work on Windows, macOS, AND Linux?
|
||||||
|
2. Will this survive a crash/restart?
|
||||||
|
3. Can the state be manually inspected in the filesystem?
|
||||||
|
4. Is this covered by tests?
|
||||||
|
5. Does this follow the existing patterns in the codebase?
|
||||||
|
6. Have I run `mvn verify` before committing?
|
||||||
@@ -130,6 +130,7 @@ Developers can use the --offline command line option to test how the service beh
|
|||||||
- [Barn Temporary Directory Layout](docs/jobs.md) describes how barn tracks jobs and storage
|
- [Barn Temporary Directory Layout](docs/jobs.md) describes how barn tracks jobs and storage
|
||||||
- [Barn Configuration](docs/config.md) describes configuration options, retry behavior, and cleanup policies
|
- [Barn Configuration](docs/config.md) describes configuration options, retry behavior, and cleanup policies
|
||||||
- [Development Guide](docs/development.md) covers local development setup and building from source
|
- [Development Guide](docs/development.md) covers local development setup and building from source
|
||||||
|
- [Coding Standards](docs/coding-standards.md) defines code style, conventions, and quality enforcement
|
||||||
- [Releasing](docs/releasing.md) describes version management and the release process
|
- [Releasing](docs/releasing.md) describes version management and the release process
|
||||||
- [CI/CD](docs/ci-cd.md) documents the GitHub Actions workflows for building and releasing
|
- [CI/CD](docs/ci-cd.md) documents the GitHub Actions workflows for building and releasing
|
||||||
- [Distribution](docs/distribution.md) covers package manager setup (WinGet, apt, AUR, Homebrew)
|
- [Distribution](docs/distribution.md) covers package manager setup (WinGet, apt, AUR, Homebrew)
|
||||||
|
|||||||
@@ -0,0 +1,264 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE module PUBLIC
|
||||||
|
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
|
||||||
|
"https://checkstyle.org/dtds/configuration_1_3.dtd">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Checkstyle configuration for Barn.
|
||||||
|
Based on Google Java Style Guide with modifications for Java 21+.
|
||||||
|
-->
|
||||||
|
<module name="Checker">
|
||||||
|
<property name="charset" value="UTF-8"/>
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
<property name="fileExtensions" value="java"/>
|
||||||
|
|
||||||
|
<!-- Suppressions -->
|
||||||
|
<module name="SuppressionFilter">
|
||||||
|
<property name="file" value="${config_loc}/suppressions.xml"/>
|
||||||
|
<property name="optional" value="true"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- File Length -->
|
||||||
|
<module name="FileLength">
|
||||||
|
<property name="max" value="500"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- Line Length -->
|
||||||
|
<module name="LineLength">
|
||||||
|
<property name="max" value="120"/>
|
||||||
|
<property name="ignorePattern" value="^package.*|^import.*|a]+ href|href|http://|https://|ftp://"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- No Tab Characters -->
|
||||||
|
<module name="FileTabCharacter">
|
||||||
|
<property name="eachLine" value="true"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- Trailing Whitespace -->
|
||||||
|
<module name="RegexpSingleline">
|
||||||
|
<property name="format" value="\s+$"/>
|
||||||
|
<property name="message" value="Line has trailing spaces."/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- Newline at End of File -->
|
||||||
|
<module name="NewlineAtEndOfFile"/>
|
||||||
|
|
||||||
|
<module name="TreeWalker">
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
<!-- NAMING CONVENTIONS -->
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
|
||||||
|
<module name="PackageName">
|
||||||
|
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="TypeName">
|
||||||
|
<property name="format" value="^[A-Z][a-zA-Z0-9]*$"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="MethodName">
|
||||||
|
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="MemberName">
|
||||||
|
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="ParameterName">
|
||||||
|
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="LocalVariableName">
|
||||||
|
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="ConstantName">
|
||||||
|
<property name="format" value="^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="StaticVariableName">
|
||||||
|
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
<!-- IMPORTS -->
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
|
||||||
|
<module name="AvoidStarImport"/>
|
||||||
|
|
||||||
|
<module name="IllegalImport"/>
|
||||||
|
|
||||||
|
<module name="RedundantImport"/>
|
||||||
|
|
||||||
|
<module name="UnusedImports"/>
|
||||||
|
|
||||||
|
<module name="ImportOrder">
|
||||||
|
<property name="groups" value="/^java\./,javax,org,com"/>
|
||||||
|
<property name="ordered" value="true"/>
|
||||||
|
<property name="separated" value="true"/>
|
||||||
|
<property name="option" value="top"/>
|
||||||
|
<property name="sortStaticImportsAlphabetically" value="true"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
<!-- WHITESPACE -->
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
|
||||||
|
<module name="GenericWhitespace"/>
|
||||||
|
|
||||||
|
<module name="MethodParamPad"/>
|
||||||
|
|
||||||
|
<module name="NoWhitespaceAfter">
|
||||||
|
<property name="tokens" value="AT,INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,ARRAY_DECLARATOR,INDEX_OP"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="NoWhitespaceBefore"/>
|
||||||
|
|
||||||
|
<module name="ParenPad"/>
|
||||||
|
|
||||||
|
<module name="TypecastParenPad"/>
|
||||||
|
|
||||||
|
<module name="WhitespaceAfter"/>
|
||||||
|
|
||||||
|
<module name="WhitespaceAround">
|
||||||
|
<property name="allowEmptyConstructors" value="true"/>
|
||||||
|
<property name="allowEmptyMethods" value="true"/>
|
||||||
|
<property name="allowEmptyTypes" value="true"/>
|
||||||
|
<property name="allowEmptyLoops" value="true"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="EmptyLineSeparator">
|
||||||
|
<property name="allowNoEmptyLineBetweenFields" value="true"/>
|
||||||
|
<property name="allowMultipleEmptyLines" value="false"/>
|
||||||
|
<property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="Indentation">
|
||||||
|
<property name="basicOffset" value="4"/>
|
||||||
|
<property name="caseIndent" value="4"/>
|
||||||
|
<property name="arrayInitIndent" value="4"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
<!-- BRACES -->
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
|
||||||
|
<module name="LeftCurly"/>
|
||||||
|
|
||||||
|
<module name="RightCurly"/>
|
||||||
|
|
||||||
|
<module name="NeedBraces"/>
|
||||||
|
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
<!-- CODING -->
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
|
||||||
|
<module name="EmptyStatement"/>
|
||||||
|
|
||||||
|
<module name="EqualsHashCode"/>
|
||||||
|
|
||||||
|
<module name="HiddenField">
|
||||||
|
<property name="ignoreConstructorParameter" value="true"/>
|
||||||
|
<property name="ignoreSetter" value="true"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="IllegalInstantiation"/>
|
||||||
|
|
||||||
|
<module name="InnerAssignment"/>
|
||||||
|
|
||||||
|
<module name="MissingSwitchDefault"/>
|
||||||
|
|
||||||
|
<module name="MultipleVariableDeclarations"/>
|
||||||
|
|
||||||
|
<module name="SimplifyBooleanExpression"/>
|
||||||
|
|
||||||
|
<module name="SimplifyBooleanReturn"/>
|
||||||
|
|
||||||
|
<module name="StringLiteralEquality"/>
|
||||||
|
|
||||||
|
<module name="OneStatementPerLine"/>
|
||||||
|
|
||||||
|
<module name="OverloadMethodsDeclarationOrder"/>
|
||||||
|
|
||||||
|
<module name="VariableDeclarationUsageDistance"/>
|
||||||
|
|
||||||
|
<module name="DefaultComesLast"/>
|
||||||
|
|
||||||
|
<module name="FallThrough"/>
|
||||||
|
|
||||||
|
<module name="UnnecessaryParentheses"/>
|
||||||
|
|
||||||
|
<module name="UnnecessarySemicolonAfterTypeMemberDeclaration"/>
|
||||||
|
|
||||||
|
<module name="UnnecessarySemicolonInEnumeration"/>
|
||||||
|
|
||||||
|
<module name="UnnecessarySemicolonInTryWithResources"/>
|
||||||
|
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
<!-- DESIGN -->
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
|
||||||
|
<module name="FinalClass"/>
|
||||||
|
|
||||||
|
<module name="HideUtilityClassConstructor"/>
|
||||||
|
|
||||||
|
<module name="InterfaceIsType"/>
|
||||||
|
|
||||||
|
<module name="OneTopLevelClass"/>
|
||||||
|
|
||||||
|
<module name="VisibilityModifier">
|
||||||
|
<property name="allowPublicFinalFields" value="true"/>
|
||||||
|
<property name="protectedAllowed" value="true"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
<!-- JAVADOC -->
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
|
||||||
|
<module name="InvalidJavadocPosition"/>
|
||||||
|
|
||||||
|
<module name="JavadocMethod">
|
||||||
|
<property name="accessModifiers" value="public"/>
|
||||||
|
<property name="allowMissingParamTags" value="true"/>
|
||||||
|
<property name="allowMissingReturnTag" value="true"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="JavadocType">
|
||||||
|
<property name="scope" value="public"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="JavadocStyle">
|
||||||
|
<property name="checkFirstSentence" value="false"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="MissingJavadocMethod">
|
||||||
|
<property name="scope" value="public"/>
|
||||||
|
<property name="minLineCount" value="2"/>
|
||||||
|
<property name="allowedAnnotations" value="Override, Test, BeforeEach, AfterEach, BeforeAll, AfterAll"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="MissingJavadocType">
|
||||||
|
<property name="scope" value="public"/>
|
||||||
|
<property name="skipAnnotations" value="Generated"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
<!-- MISCELLANEOUS -->
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
|
||||||
|
<module name="ArrayTypeStyle"/>
|
||||||
|
|
||||||
|
<module name="CommentsIndentation"/>
|
||||||
|
|
||||||
|
<module name="UpperEll"/>
|
||||||
|
|
||||||
|
<module name="ModifierOrder"/>
|
||||||
|
|
||||||
|
<module name="RedundantModifier"/>
|
||||||
|
|
||||||
|
<!-- Suppress warnings with @SuppressWarnings annotation -->
|
||||||
|
<module name="SuppressWarningsHolder"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="SuppressWarningsFilter"/>
|
||||||
|
</module>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE suppressions PUBLIC
|
||||||
|
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
|
||||||
|
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
|
||||||
|
|
||||||
|
<suppressions>
|
||||||
|
<!-- Suppress Javadoc requirements for test classes -->
|
||||||
|
<suppress checks="MissingJavadocType" files=".*Test\.java$"/>
|
||||||
|
<suppress checks="MissingJavadocMethod" files=".*Test\.java$"/>
|
||||||
|
<suppress checks="JavadocMethod" files=".*Test\.java$"/>
|
||||||
|
<suppress checks="JavadocType" files=".*Test\.java$"/>
|
||||||
|
|
||||||
|
<!-- Suppress magic number checks in tests -->
|
||||||
|
<suppress checks="MagicNumber" files=".*Test\.java$"/>
|
||||||
|
|
||||||
|
<!-- Allow longer lines in test files -->
|
||||||
|
<suppress checks="LineLength" files=".*Test\.java$"/>
|
||||||
|
|
||||||
|
<!-- Suppress for generated code -->
|
||||||
|
<suppress checks=".*" files=".*[\\/]generated[\\/].*"/>
|
||||||
|
</suppressions>
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<ruleset name="Barn PMD Ruleset"
|
||||||
|
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||||
|
|
||||||
|
<description>
|
||||||
|
PMD ruleset for Barn project.
|
||||||
|
Based on PMD best practices with adjustments for modern Java.
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
<!-- BEST PRACTICES -->
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
|
||||||
|
<rule ref="category/java/bestpractices.xml">
|
||||||
|
<!-- Allow JUnit 5 assertions -->
|
||||||
|
<exclude name="JUnitTestContainsTooManyAsserts"/>
|
||||||
|
<exclude name="JUnitAssertionsShouldIncludeMessage"/>
|
||||||
|
<!-- We use Mockito, not JUnit 4 -->
|
||||||
|
<exclude name="JUnit4TestShouldUseTestAnnotation"/>
|
||||||
|
<exclude name="JUnit4TestShouldUseBeforeAnnotation"/>
|
||||||
|
<exclude name="JUnit4TestShouldUseAfterAnnotation"/>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod">
|
||||||
|
<properties>
|
||||||
|
<property name="ignoredAnnotations" value="jakarta.annotation.PostConstruct|javax.annotation.PostConstruct"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
<!-- CODE STYLE -->
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
|
||||||
|
<rule ref="category/java/codestyle.xml">
|
||||||
|
<!-- We prefer explicit imports -->
|
||||||
|
<exclude name="OnlyOneReturn"/>
|
||||||
|
<!-- Allow short variable names like 'id', 'in', 'out' -->
|
||||||
|
<exclude name="ShortVariable"/>
|
||||||
|
<!-- Allow longer method names for clarity -->
|
||||||
|
<exclude name="LongVariable"/>
|
||||||
|
<!-- Allow static imports for test utilities -->
|
||||||
|
<exclude name="TooManyStaticImports"/>
|
||||||
|
<!-- We have our own formatting rules -->
|
||||||
|
<exclude name="AtLeastOneConstructor"/>
|
||||||
|
<!-- Allow default package for CLI commands -->
|
||||||
|
<exclude name="CommentDefaultAccessModifier"/>
|
||||||
|
<!-- Java 21+ has useful implicit classes -->
|
||||||
|
<exclude name="UnnecessaryFullyQualifiedName"/>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="category/java/codestyle.xml/ClassNamingConventions">
|
||||||
|
<properties>
|
||||||
|
<property name="utilityClassPattern" value="[A-Z][a-zA-Z0-9]+(Utils?|Helper|Constants)"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="category/java/codestyle.xml/MethodNamingConventions">
|
||||||
|
<properties>
|
||||||
|
<property name="methodPattern" value="[a-z][a-zA-Z0-9]*"/>
|
||||||
|
<property name="nativePattern" value="[a-z][a-zA-Z0-9]*"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
<!-- DESIGN -->
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
|
||||||
|
<rule ref="category/java/design.xml">
|
||||||
|
<!-- Modern Java allows reasonable complexity -->
|
||||||
|
<exclude name="LawOfDemeter"/>
|
||||||
|
<!-- Allow data classes with many fields -->
|
||||||
|
<exclude name="TooManyFields"/>
|
||||||
|
<!-- Exclude for builders and configs -->
|
||||||
|
<exclude name="ExcessivePublicCount"/>
|
||||||
|
<!-- Allow reasonable method size -->
|
||||||
|
<exclude name="ExcessiveMethodLength"/>
|
||||||
|
<!-- Allow reasonable class size -->
|
||||||
|
<exclude name="ExcessiveClassLength"/>
|
||||||
|
<!-- Too strict for modern patterns -->
|
||||||
|
<exclude name="AvoidCatchingGenericException"/>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="category/java/design.xml/CyclomaticComplexity">
|
||||||
|
<properties>
|
||||||
|
<property name="classReportLevel" value="80"/>
|
||||||
|
<property name="methodReportLevel" value="15"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="category/java/design.xml/NPathComplexity">
|
||||||
|
<properties>
|
||||||
|
<property name="reportLevel" value="200"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="category/java/design.xml/TooManyMethods">
|
||||||
|
<properties>
|
||||||
|
<property name="maxmethods" value="25"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
<!-- DOCUMENTATION -->
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
|
||||||
|
<rule ref="category/java/documentation.xml">
|
||||||
|
<exclude name="CommentRequired"/>
|
||||||
|
<exclude name="CommentSize"/>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
<!-- ERROR PRONE -->
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
|
||||||
|
<rule ref="category/java/errorprone.xml">
|
||||||
|
<!-- Allow null assignments in cleanup -->
|
||||||
|
<exclude name="NullAssignment"/>
|
||||||
|
<!-- Allow close in finally for legacy code -->
|
||||||
|
<exclude name="CloseResource"/>
|
||||||
|
<!-- We validate beans differently -->
|
||||||
|
<exclude name="BeanMembersShouldSerialize"/>
|
||||||
|
<!-- Too strict -->
|
||||||
|
<exclude name="DataflowAnomalyAnalysis"/>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="category/java/errorprone.xml/AvoidLiteralsInIfCondition">
|
||||||
|
<properties>
|
||||||
|
<property name="ignoreMagicNumbers" value="-1,0,1,2"/>
|
||||||
|
<property name="ignoreExpressions" value="true"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
<!-- MULTITHREADING -->
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
|
||||||
|
<rule ref="category/java/multithreading.xml">
|
||||||
|
<!-- We use modern concurrency utilities -->
|
||||||
|
<exclude name="UseConcurrentHashMap"/>
|
||||||
|
<exclude name="DoNotUseThreads"/>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
<!-- PERFORMANCE -->
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
|
||||||
|
<rule ref="category/java/performance.xml">
|
||||||
|
<!-- Modern JVM handles this well -->
|
||||||
|
<exclude name="AvoidInstantiatingObjectsInLoops"/>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
<!-- SECURITY -->
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
|
||||||
|
<rule ref="category/java/security.xml"/>
|
||||||
|
|
||||||
|
</ruleset>
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<FindBugsFilter
|
||||||
|
xmlns="https://github.com/spotbugs/filter/3.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
|
||||||
|
|
||||||
|
<!-- Exclude test classes from certain checks -->
|
||||||
|
<Match>
|
||||||
|
<Source name="~.*Test\.java"/>
|
||||||
|
<Or>
|
||||||
|
<Bug pattern="DM_DEFAULT_ENCODING"/>
|
||||||
|
<Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
|
||||||
|
</Or>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Exclude generated code -->
|
||||||
|
<Match>
|
||||||
|
<Source name="~.*[\\/]generated[\\/].*"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Allow System.exit in Main class -->
|
||||||
|
<Match>
|
||||||
|
<Class name="com.samsonmedia.barn.Main"/>
|
||||||
|
<Bug pattern="DM_EXIT"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Allow command execution in specific classes -->
|
||||||
|
<Match>
|
||||||
|
<Or>
|
||||||
|
<Class name="~.*ProcessExecutor.*"/>
|
||||||
|
<Class name="~.*CommandRunner.*"/>
|
||||||
|
</Or>
|
||||||
|
<Bug pattern="COMMAND_INJECTION"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Exclude false positives for try-with-resources -->
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Allow serialization without serialVersionUID for internal classes -->
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="SE_NO_SERIALVERSIONID"/>
|
||||||
|
<Not>
|
||||||
|
<Class name="~.*Exception"/>
|
||||||
|
</Not>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
</FindBugsFilter>
|
||||||
@@ -0,0 +1,579 @@
|
|||||||
|
# Coding Standards
|
||||||
|
|
||||||
|
This document defines the coding standards and conventions for the Barn project.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
Barn is written in **Java 21+** and follows industry best practices for code quality, maintainability, and consistency. We use automated tools to enforce these standards.
|
||||||
|
|
||||||
|
### Enforcement Tools
|
||||||
|
|
||||||
|
| Tool | Purpose | Configuration |
|
||||||
|
|------|---------|---------------|
|
||||||
|
| [Checkstyle](https://checkstyle.org/) | Code formatting & style | `config/checkstyle/checkstyle.xml` |
|
||||||
|
| [SpotBugs](https://spotbugs.github.io/) | Bug detection | `config/spotbugs/exclude.xml` |
|
||||||
|
| [PMD](https://pmd.github.io/) | Static analysis | `config/pmd/ruleset.xml` |
|
||||||
|
| [JaCoCo](https://www.jacoco.org/) | Code coverage | Maven plugin |
|
||||||
|
| Pre-commit hooks | Local enforcement | `.githooks/pre-commit` |
|
||||||
|
| GitHub Actions | CI enforcement | `.github/workflows/lint.yml` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Code Style
|
||||||
|
|
||||||
|
We follow the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html) with the following specifics:
|
||||||
|
|
||||||
|
### Formatting
|
||||||
|
|
||||||
|
- **Indentation**: 4 spaces (no tabs)
|
||||||
|
- **Max line length**: 120 characters
|
||||||
|
- **Braces**: K&R style (opening brace on same line)
|
||||||
|
- **Blank lines**: Single blank line between methods, two before class members
|
||||||
|
- **Import ordering**: Static imports first, then regular imports, alphabetically
|
||||||
|
|
||||||
|
### Naming Conventions
|
||||||
|
|
||||||
|
| Element | Convention | Example |
|
||||||
|
|---------|------------|---------|
|
||||||
|
| Packages | lowercase, no underscores | `com.samsonmedia.barn.jobs` |
|
||||||
|
| Classes | PascalCase | `JobManager`, `ConfigParser` |
|
||||||
|
| Interfaces | PascalCase | `StateManager`, `Executable` |
|
||||||
|
| Methods | camelCase | `createJob()`, `parseConfig()` |
|
||||||
|
| Variables | camelCase | `jobId`, `maxRetries` |
|
||||||
|
| Constants | SCREAMING_SNAKE_CASE | `MAX_RETRIES`, `DEFAULT_TIMEOUT` |
|
||||||
|
| Type parameters | Single uppercase letter | `T`, `K`, `V` |
|
||||||
|
|
||||||
|
### File Organization
|
||||||
|
|
||||||
|
```java
|
||||||
|
// 1. Package statement
|
||||||
|
package com.samsonmedia.barn.jobs;
|
||||||
|
|
||||||
|
// 2. Imports (static first, then regular, alphabetically)
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
|
import com.samsonmedia.barn.config.Config;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages job lifecycle and state.
|
||||||
|
*
|
||||||
|
* <p>Jobs are persisted to the filesystem and can survive service restarts.
|
||||||
|
* See docs/jobs.md for the filesystem layout.
|
||||||
|
*/
|
||||||
|
public class JobManager {
|
||||||
|
|
||||||
|
// 3. Constants
|
||||||
|
private static final String JOB_ID_PREFIX = "job-";
|
||||||
|
|
||||||
|
// 4. Static fields
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(JobManager.class);
|
||||||
|
|
||||||
|
// 5. Instance fields
|
||||||
|
private final Config config;
|
||||||
|
private final StateManager stateManager;
|
||||||
|
private final Map<String, Job> jobs;
|
||||||
|
|
||||||
|
// 6. Constructors
|
||||||
|
public JobManager(Config config, StateManager stateManager) {
|
||||||
|
this.config = requireNonNull(config, "config");
|
||||||
|
this.stateManager = requireNonNull(stateManager, "stateManager");
|
||||||
|
this.jobs = new ConcurrentHashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. Public methods
|
||||||
|
public Job createJob(Command command) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8. Private methods
|
||||||
|
private String generateJobId() {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
// 9. Nested classes
|
||||||
|
private static class JobIdGenerator {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Java Best Practices
|
||||||
|
|
||||||
|
### Null Safety
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Good: Use Optional for return types that may be absent
|
||||||
|
public Optional<Job> findJob(String id) {
|
||||||
|
return Optional.ofNullable(jobs.get(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Good: Use requireNonNull for constructor parameters
|
||||||
|
public JobManager(Config config) {
|
||||||
|
this.config = Objects.requireNonNull(config, "config must not be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Good: Use @Nullable/@NonNull annotations
|
||||||
|
public void setTag(@Nullable String tag) {
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Avoid: Returning null from methods
|
||||||
|
public Job findJob(String id) {
|
||||||
|
return jobs.get(id); // Bad - returns null if not found
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Immutability
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Good: Use final fields
|
||||||
|
private final String id;
|
||||||
|
private final JobState state;
|
||||||
|
|
||||||
|
// Good: Use unmodifiable collections
|
||||||
|
public List<Job> getJobs() {
|
||||||
|
return Collections.unmodifiableList(jobs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Good: Use records for value objects (Java 16+)
|
||||||
|
public record Job(
|
||||||
|
String id,
|
||||||
|
JobState state,
|
||||||
|
Instant createdAt
|
||||||
|
) {}
|
||||||
|
|
||||||
|
// Good: Use builder pattern for complex objects
|
||||||
|
Job job = Job.builder()
|
||||||
|
.id(generateId())
|
||||||
|
.state(JobState.QUEUED)
|
||||||
|
.createdAt(Instant.now())
|
||||||
|
.build();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Modern Java Features (21+)
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Good: Use var for local variables with obvious types
|
||||||
|
var jobs = new ArrayList<Job>();
|
||||||
|
var config = loadConfig();
|
||||||
|
|
||||||
|
// Good: Use switch expressions
|
||||||
|
String status = switch (state) {
|
||||||
|
case QUEUED -> "Waiting to run";
|
||||||
|
case RUNNING -> "Currently executing";
|
||||||
|
case FAILED -> "Failed: " + errorMessage;
|
||||||
|
case SUCCEEDED -> "Completed successfully";
|
||||||
|
case CANCELED -> "Canceled by user";
|
||||||
|
};
|
||||||
|
|
||||||
|
// Good: Use pattern matching
|
||||||
|
if (obj instanceof Job job) {
|
||||||
|
processJob(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Good: Use text blocks for multi-line strings
|
||||||
|
String json = """
|
||||||
|
{
|
||||||
|
"jobId": "%s",
|
||||||
|
"state": "%s"
|
||||||
|
}
|
||||||
|
""".formatted(jobId, state);
|
||||||
|
|
||||||
|
// Good: Use sealed classes for state machines
|
||||||
|
public sealed interface JobState
|
||||||
|
permits Queued, Running, Failed, Succeeded, Canceled {
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Resource Management
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Good: Use try-with-resources
|
||||||
|
try (var reader = Files.newBufferedReader(path)) {
|
||||||
|
return reader.lines().toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Good: Use try-with-resources for multiple resources
|
||||||
|
try (var in = Files.newInputStream(source);
|
||||||
|
var out = Files.newOutputStream(target)) {
|
||||||
|
in.transferTo(out);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Error Handling
|
||||||
|
|
||||||
|
### Use Exceptions Appropriately
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Good: Use checked exceptions for recoverable errors
|
||||||
|
public Config loadConfig(Path path) throws ConfigurationException {
|
||||||
|
try {
|
||||||
|
return parseConfig(Files.readString(path));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ConfigurationException("Failed to load config: " + path, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Good: Use unchecked exceptions for programming errors
|
||||||
|
public void processJob(Job job) {
|
||||||
|
if (job == null) {
|
||||||
|
throw new IllegalArgumentException("job must not be null");
|
||||||
|
}
|
||||||
|
if (job.getState() != JobState.QUEUED) {
|
||||||
|
throw new IllegalStateException("Job must be in QUEUED state");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Good: Create domain-specific exceptions
|
||||||
|
public class JobNotFoundException extends RuntimeException {
|
||||||
|
public JobNotFoundException(String jobId) {
|
||||||
|
super("Job not found: " + jobId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Logging
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Use SLF4J
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(JobManager.class);
|
||||||
|
|
||||||
|
// Good: Use appropriate log levels
|
||||||
|
LOG.debug("Processing job: {}", jobId); // Development details
|
||||||
|
LOG.info("Job completed: {}", jobId); // Normal operations
|
||||||
|
LOG.warn("Retry attempt {} for job: {}", attempt, jobId); // Potential issues
|
||||||
|
LOG.error("Job failed", exception); // Errors
|
||||||
|
|
||||||
|
// Good: Use parameterized logging (not string concatenation)
|
||||||
|
LOG.info("Job {} state changed from {} to {}", jobId, oldState, newState);
|
||||||
|
|
||||||
|
// Bad: String concatenation (evaluates even if level disabled)
|
||||||
|
LOG.debug("Job " + jobId + " processing"); // Avoid
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Testing Standards
|
||||||
|
|
||||||
|
### Test Naming
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Use descriptive method names with underscores
|
||||||
|
@Test
|
||||||
|
void createJob_shouldGenerateUniqueId() { }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createJob_whenServiceNotRunning_shouldThrowException() { }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void processJob_withMaxRetriesExceeded_shouldMarkAsFailed() { }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test Structure (AAA Pattern)
|
||||||
|
|
||||||
|
```java
|
||||||
|
@Test
|
||||||
|
void completeJob_shouldTransitionToSucceeded() {
|
||||||
|
// Arrange
|
||||||
|
var job = createTestJob(JobState.RUNNING);
|
||||||
|
var manager = new JobManager(testConfig);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
manager.completeJob(job.getId(), 0);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var updated = manager.getJob(job.getId());
|
||||||
|
assertThat(updated).isPresent();
|
||||||
|
assertThat(updated.get().getState()).isEqualTo(JobState.SUCCEEDED);
|
||||||
|
assertThat(updated.get().getFinishedAt()).isNotNull();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test Coverage Requirements
|
||||||
|
|
||||||
|
| Type | Minimum Coverage |
|
||||||
|
|------|-----------------|
|
||||||
|
| Line coverage | 80% |
|
||||||
|
| Branch coverage | 70% |
|
||||||
|
| Critical paths | 100% |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
### Javadoc Comments
|
||||||
|
|
||||||
|
```java
|
||||||
|
/**
|
||||||
|
* Manages job lifecycle including creation, execution, and cleanup.
|
||||||
|
*
|
||||||
|
* <p>Jobs are persisted to the filesystem and can survive service restarts.
|
||||||
|
* See <a href="docs/jobs.md">jobs.md</a> for the filesystem layout.
|
||||||
|
*
|
||||||
|
* <p>This class is thread-safe.
|
||||||
|
*
|
||||||
|
* @see Job
|
||||||
|
* @see StateManager
|
||||||
|
*/
|
||||||
|
public class JobManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new job for the given command.
|
||||||
|
*
|
||||||
|
* <p>The job is assigned a unique ID and placed in the {@link JobState#QUEUED}
|
||||||
|
* state. It will be picked up by the scheduler based on available capacity.
|
||||||
|
*
|
||||||
|
* @param command the command to execute, must not be null
|
||||||
|
* @param tag optional tag for filtering jobs, may be null
|
||||||
|
* @return the created job, never null
|
||||||
|
* @throws IllegalStateException if the service is not running
|
||||||
|
* @throws NullPointerException if command is null
|
||||||
|
*/
|
||||||
|
public Job createJob(Command command, @Nullable String tag) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### When to Document
|
||||||
|
|
||||||
|
- **Always**: Public API, interfaces, complex algorithms
|
||||||
|
- **Sometimes**: Private methods with complex logic
|
||||||
|
- **Never**: Self-explanatory code, obvious getters/setters
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Good: Document non-obvious behavior
|
||||||
|
/**
|
||||||
|
* Calculates retry delay using exponential backoff.
|
||||||
|
* The delay doubles with each attempt, capped at {@code maxDelay}.
|
||||||
|
*
|
||||||
|
* @param attempt the current attempt number (0-based)
|
||||||
|
* @return the delay before the next retry
|
||||||
|
*/
|
||||||
|
Duration calculateRetryDelay(int attempt);
|
||||||
|
|
||||||
|
// Bad: Unnecessary documentation
|
||||||
|
/** Returns the job ID. */
|
||||||
|
String getJobId(); // Obvious - no doc needed
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Git Conventions
|
||||||
|
|
||||||
|
### Commit Messages
|
||||||
|
|
||||||
|
Follow [Conventional Commits](https://www.conventionalcommits.org/):
|
||||||
|
|
||||||
|
```
|
||||||
|
<type>(<scope>): <description>
|
||||||
|
|
||||||
|
[optional body]
|
||||||
|
|
||||||
|
[optional footer]
|
||||||
|
```
|
||||||
|
|
||||||
|
Types:
|
||||||
|
- `feat`: New feature
|
||||||
|
- `fix`: Bug fix
|
||||||
|
- `docs`: Documentation only
|
||||||
|
- `style`: Code style (formatting, no logic change)
|
||||||
|
- `refactor`: Code change that neither fixes a bug nor adds a feature
|
||||||
|
- `perf`: Performance improvement
|
||||||
|
- `test`: Adding or fixing tests
|
||||||
|
- `chore`: Build process, dependencies, tooling
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
```
|
||||||
|
feat(jobs): add retry mechanism for failed jobs
|
||||||
|
|
||||||
|
fix(cli): handle spaces in file paths correctly
|
||||||
|
|
||||||
|
docs(readme): update installation instructions
|
||||||
|
|
||||||
|
refactor(config): extract parsing logic to separate class
|
||||||
|
|
||||||
|
test(jobs): add integration tests for job lifecycle
|
||||||
|
```
|
||||||
|
|
||||||
|
### Branch Naming
|
||||||
|
|
||||||
|
```
|
||||||
|
<type>/<description>
|
||||||
|
|
||||||
|
feature/add-retry-mechanism
|
||||||
|
fix/handle-spaces-in-paths
|
||||||
|
docs/update-installation
|
||||||
|
refactor/extract-config-parser
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Running Quality Checks
|
||||||
|
|
||||||
|
### Local Development
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Format code (via IDE or Checkstyle)
|
||||||
|
mvn checkstyle:check
|
||||||
|
|
||||||
|
# Run static analysis
|
||||||
|
mvn spotbugs:check
|
||||||
|
mvn pmd:check
|
||||||
|
|
||||||
|
# Run all checks
|
||||||
|
mvn verify
|
||||||
|
|
||||||
|
# Run tests with coverage
|
||||||
|
mvn test jacoco:report
|
||||||
|
```
|
||||||
|
|
||||||
|
### Pre-commit Hook
|
||||||
|
|
||||||
|
The pre-commit hook runs automatically on `git commit`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install hooks (run once after cloning)
|
||||||
|
git config core.hooksPath .githooks
|
||||||
|
|
||||||
|
# Or manually
|
||||||
|
cp .githooks/pre-commit .git/hooks/
|
||||||
|
chmod +x .git/hooks/pre-commit
|
||||||
|
```
|
||||||
|
|
||||||
|
### CI Checks
|
||||||
|
|
||||||
|
All pull requests must pass:
|
||||||
|
- Checkstyle formatting check
|
||||||
|
- SpotBugs analysis
|
||||||
|
- PMD analysis
|
||||||
|
- Unit tests
|
||||||
|
- Integration tests
|
||||||
|
- Code coverage thresholds (80%)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## IDE Setup
|
||||||
|
|
||||||
|
### IntelliJ IDEA
|
||||||
|
|
||||||
|
1. Import the project as a Maven project
|
||||||
|
2. Install plugins: CheckStyle-IDEA, SpotBugs
|
||||||
|
3. Import code style:
|
||||||
|
- Settings → Editor → Code Style → Java
|
||||||
|
- Import from `config/checkstyle/checkstyle.xml`
|
||||||
|
4. Enable EditorConfig: Settings → Editor → Code Style → Enable EditorConfig
|
||||||
|
|
||||||
|
### VS Code
|
||||||
|
|
||||||
|
1. Install extensions: Java Extension Pack, Checkstyle for Java
|
||||||
|
2. EditorConfig is automatically respected
|
||||||
|
3. Configure Checkstyle extension to use project config
|
||||||
|
|
||||||
|
### Eclipse
|
||||||
|
|
||||||
|
1. Import as Maven project
|
||||||
|
2. Install Checkstyle plugin
|
||||||
|
3. Configure to use `config/checkstyle/checkstyle.xml`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Dependency Guidelines
|
||||||
|
|
||||||
|
### Adding Dependencies
|
||||||
|
|
||||||
|
1. Check if functionality exists in JDK first
|
||||||
|
2. Prefer well-maintained, widely-used libraries
|
||||||
|
3. Consider native image compatibility (GraalVM)
|
||||||
|
4. Document why the dependency is needed in commit message
|
||||||
|
|
||||||
|
### Banned Patterns
|
||||||
|
|
||||||
|
- No reflection-heavy libraries without GraalVM config
|
||||||
|
- No dependencies with known security vulnerabilities
|
||||||
|
- No transitive dependency conflicts
|
||||||
|
|
||||||
|
### Approved Libraries
|
||||||
|
|
||||||
|
| Category | Library | Notes |
|
||||||
|
|----------|---------|-------|
|
||||||
|
| CLI parsing | picocli | Native image compatible |
|
||||||
|
| JSON | Jackson or Gson | Configure for native image |
|
||||||
|
| Logging | SLF4J + Logback | Standard logging |
|
||||||
|
| Testing | JUnit 5 | Standard testing |
|
||||||
|
| Assertions | AssertJ | Fluent assertions |
|
||||||
|
| Mocking | Mockito | Standard mocking |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Security
|
||||||
|
|
||||||
|
### Sensitive Data
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Never log sensitive data
|
||||||
|
LOG.info("Authenticating user: {}", username); // Good
|
||||||
|
LOG.info("Password: {}", password); // Bad!
|
||||||
|
|
||||||
|
// Mask sensitive values
|
||||||
|
public static String maskToken(String token) {
|
||||||
|
if (token.length() <= 8) return "****";
|
||||||
|
return token.substring(0, 4) + "****" + token.substring(token.length() - 4);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Input Validation
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Validate all external input
|
||||||
|
public void executeCommand(String command) {
|
||||||
|
Objects.requireNonNull(command, "command");
|
||||||
|
if (command.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("Command cannot be blank");
|
||||||
|
}
|
||||||
|
if (command.contains(";") || command.contains("&&")) {
|
||||||
|
throw new SecurityException("Command injection detected");
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### File Operations
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Use secure file operations
|
||||||
|
public void writeState(String jobId, String state) throws IOException {
|
||||||
|
// Validate job ID to prevent path traversal
|
||||||
|
if (!jobId.matches("[a-zA-Z0-9-]+")) {
|
||||||
|
throw new IllegalArgumentException("Invalid job ID: " + jobId);
|
||||||
|
}
|
||||||
|
|
||||||
|
Path path = baseDir.resolve("jobs").resolve(jobId).resolve("state");
|
||||||
|
// Use atomic write
|
||||||
|
Files.writeString(path, state, StandardCharsets.UTF_8,
|
||||||
|
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
1. **Format**: Use Checkstyle, follow Google Java Style
|
||||||
|
2. **Analyze**: Use SpotBugs and PMD, fix all warnings
|
||||||
|
3. **Test**: 80% coverage, meaningful tests
|
||||||
|
4. **Document**: Javadoc for public API
|
||||||
|
5. **Commit**: Conventional commits, descriptive messages
|
||||||
|
6. **Review**: All PRs require review and passing CI
|
||||||
|
|
||||||
|
When in doubt, prioritize **readability** and **maintainability** over cleverness.
|
||||||
+290
-86
@@ -9,11 +9,51 @@ This document covers local development setup and building Barn from source.
|
|||||||
| Requirement | Version | Notes |
|
| Requirement | Version | Notes |
|
||||||
|-------------|---------|-------|
|
|-------------|---------|-------|
|
||||||
| JDK | 21+ | Required for building |
|
| JDK | 21+ | Required for building |
|
||||||
| GraalVM CE | 21+ | Required for native image builds |
|
| Maven | 3.9+ | Build tool |
|
||||||
| Gradle | 8.x | Wrapper included in project |
|
| GraalVM CE | 21+ | Required for native image builds (optional) |
|
||||||
| Git | Any recent | For version control |
|
| Git | Any recent | For version control |
|
||||||
|
|
||||||
### Installing GraalVM
|
### Installing JDK 21
|
||||||
|
|
||||||
|
**macOS (Homebrew):**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
brew install openjdk@21
|
||||||
|
```
|
||||||
|
|
||||||
|
**Linux (SDKMAN):**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s "https://get.sdkman.io" | bash
|
||||||
|
sdk install java 21-tem
|
||||||
|
```
|
||||||
|
|
||||||
|
**Windows:**
|
||||||
|
|
||||||
|
Download from [Adoptium](https://adoptium.net/) and add to PATH.
|
||||||
|
|
||||||
|
### Installing Maven
|
||||||
|
|
||||||
|
**macOS (Homebrew):**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
brew install maven
|
||||||
|
```
|
||||||
|
|
||||||
|
**Linux:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt install maven # Debian/Ubuntu
|
||||||
|
sudo dnf install maven # Fedora
|
||||||
|
```
|
||||||
|
|
||||||
|
**Windows:**
|
||||||
|
|
||||||
|
Download from [Apache Maven](https://maven.apache.org/download.cgi) and add to PATH.
|
||||||
|
|
||||||
|
### Installing GraalVM (Optional)
|
||||||
|
|
||||||
|
GraalVM is required for building native images.
|
||||||
|
|
||||||
**macOS (Homebrew):**
|
**macOS (Homebrew):**
|
||||||
|
|
||||||
@@ -42,14 +82,18 @@ Download from [GraalVM Downloads](https://www.graalvm.org/downloads/) and add to
|
|||||||
barn/
|
barn/
|
||||||
src/
|
src/
|
||||||
main/
|
main/
|
||||||
kotlin/ # Application source code
|
java/ # Application source code
|
||||||
resources/ # Configuration and resource files
|
resources/ # Configuration and resource files
|
||||||
test/
|
test/
|
||||||
kotlin/ # Unit and integration tests
|
java/ # Unit and integration tests
|
||||||
build.gradle.kts # Build configuration
|
config/
|
||||||
gradle.properties # Version and build properties
|
checkstyle/ # Checkstyle configuration
|
||||||
settings.gradle.kts # Project settings
|
spotbugs/ # SpotBugs exclusions
|
||||||
docs/ # Documentation
|
pmd/ # PMD ruleset
|
||||||
|
docs/ # Documentation
|
||||||
|
.githooks/ # Git hooks
|
||||||
|
.github/workflows/ # CI/CD workflows
|
||||||
|
pom.xml # Maven build configuration
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -59,42 +103,131 @@ barn/
|
|||||||
### Build the JAR
|
### Build the JAR
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./gradlew build
|
mvn package
|
||||||
```
|
```
|
||||||
|
|
||||||
This compiles the source, runs tests, and produces a JAR in `build/libs/`.
|
This compiles the source, runs tests, and produces a JAR in `target/`.
|
||||||
|
|
||||||
### Run Tests
|
### Skip Tests
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Run all tests
|
mvn package -DskipTests
|
||||||
./gradlew test
|
|
||||||
|
|
||||||
# Run specific test class
|
|
||||||
./gradlew test --tests "com.samsonmedia.barn.JobManagerTest"
|
|
||||||
|
|
||||||
# Run with verbose output
|
|
||||||
./gradlew test --info
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Build Native Image
|
### Build with All Quality Checks
|
||||||
|
|
||||||
Building a native executable requires GraalVM with Native Image support:
|
```bash
|
||||||
|
mvn verify
|
||||||
|
```
|
||||||
|
|
||||||
|
### Build without Quality Checks (Fast)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn package -Pfast
|
||||||
|
```
|
||||||
|
|
||||||
|
### Clean Build
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn clean package
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Running Tests
|
||||||
|
|
||||||
|
### Run All Tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn test
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run Specific Test Class
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn test -Dtest=JobManagerTest
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run Specific Test Method
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn test -Dtest=JobManagerTest#createJob_shouldGenerateUniqueId
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run with Verbose Output
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn test -X
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run Integration Tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn verify
|
||||||
|
```
|
||||||
|
|
||||||
|
### Generate Coverage Report
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn test jacoco:report
|
||||||
|
# Open target/site/jacoco/index.html
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Code Quality
|
||||||
|
|
||||||
|
### Run Checkstyle
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn checkstyle:check
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run SpotBugs
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn compile spotbugs:check
|
||||||
|
|
||||||
|
# View in GUI
|
||||||
|
mvn compile spotbugs:gui
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run PMD
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn compile pmd:check
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run All Quality Checks
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn verify
|
||||||
|
```
|
||||||
|
|
||||||
|
### Skip Quality Checks
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn package -Pfast
|
||||||
|
# Or individually:
|
||||||
|
mvn package -Dcheckstyle.skip=true
|
||||||
|
mvn package -Dspotbugs.skip=true
|
||||||
|
mvn package -Dpmd.skip=true
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Native Image Build
|
||||||
|
|
||||||
|
Building a native executable requires GraalVM:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Ensure GraalVM is active
|
# Ensure GraalVM is active
|
||||||
java -version # Should show GraalVM
|
java -version # Should show GraalVM
|
||||||
|
|
||||||
# Build native image
|
# Build native image
|
||||||
./gradlew nativeCompile
|
mvn package -Pnative
|
||||||
```
|
|
||||||
|
|
||||||
The native binary is output to `build/native/nativeCompile/barn`.
|
# The binary is output to target/barn
|
||||||
|
|
||||||
### Clean Build
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./gradlew clean build
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -104,13 +237,13 @@ The native binary is output to `build/native/nativeCompile/barn`.
|
|||||||
### From JAR
|
### From JAR
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
java -jar build/libs/barn.jar --help
|
java -jar target/barn-0.1.0-SNAPSHOT.jar --help
|
||||||
```
|
```
|
||||||
|
|
||||||
### From Native Binary
|
### From Native Binary
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./build/native/nativeCompile/barn --help
|
./target/barn --help
|
||||||
```
|
```
|
||||||
|
|
||||||
### Development Mode
|
### Development Mode
|
||||||
@@ -118,7 +251,7 @@ java -jar build/libs/barn.jar --help
|
|||||||
Use the `--offline` flag to test commands without running the service:
|
Use the `--offline` flag to test commands without running the service:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./gradlew run --args="run --offline echo hello"
|
java -jar target/barn-0.1.0-SNAPSHOT.jar run --offline echo hello
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -130,25 +263,63 @@ Use the `--offline` flag to test commands without running the service:
|
|||||||
1. Open IntelliJ IDEA
|
1. Open IntelliJ IDEA
|
||||||
2. Select **File > Open**
|
2. Select **File > Open**
|
||||||
3. Navigate to the `barn` directory and open it
|
3. Navigate to the `barn` directory and open it
|
||||||
4. IntelliJ will detect the Gradle project and import it
|
4. IntelliJ will detect the Maven project and import it
|
||||||
5. Wait for Gradle sync to complete
|
5. Wait for indexing to complete
|
||||||
|
|
||||||
**Recommended plugins:**
|
**Install Plugins:**
|
||||||
|
|
||||||
- Kotlin
|
- CheckStyle-IDEA
|
||||||
- Gradle
|
- SpotBugs
|
||||||
|
|
||||||
**Run configurations:**
|
**Import Code Style:**
|
||||||
|
|
||||||
- Create a Kotlin Application configuration
|
1. Settings → Editor → Code Style → Java
|
||||||
- Main class: `com.samsonmedia.barn.MainKt`
|
2. Click gear icon → Import Scheme → CheckStyle Configuration
|
||||||
|
3. Select `config/checkstyle/checkstyle.xml`
|
||||||
|
|
||||||
|
**Run Configuration:**
|
||||||
|
|
||||||
|
- Create Application configuration
|
||||||
|
- Main class: `com.samsonmedia.barn.Main`
|
||||||
- Program arguments: `--help` (or any command)
|
- Program arguments: `--help` (or any command)
|
||||||
|
|
||||||
### VS Code
|
### VS Code
|
||||||
|
|
||||||
1. Install the Kotlin and Gradle extensions
|
1. Install extensions: Java Extension Pack, Checkstyle for Java
|
||||||
2. Open the `barn` folder
|
2. Open the `barn` folder
|
||||||
3. The Gradle extension will detect the project
|
3. The Java extension will detect the Maven project
|
||||||
|
|
||||||
|
**Configure Checkstyle:**
|
||||||
|
|
||||||
|
Settings → Checkstyle: Configuration → set to `config/checkstyle/checkstyle.xml`
|
||||||
|
|
||||||
|
### Eclipse
|
||||||
|
|
||||||
|
1. Import as Maven project
|
||||||
|
2. Install Checkstyle plugin from Marketplace
|
||||||
|
3. Configure to use `config/checkstyle/checkstyle.xml`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Git Hooks
|
||||||
|
|
||||||
|
Install the pre-commit hook to run checks before each commit:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git config core.hooksPath .githooks
|
||||||
|
```
|
||||||
|
|
||||||
|
The hook runs:
|
||||||
|
- Checkstyle
|
||||||
|
- Compilation check
|
||||||
|
- SpotBugs
|
||||||
|
- PMD
|
||||||
|
|
||||||
|
To bypass (use sparingly):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git commit --no-verify
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -156,55 +327,35 @@ Use the `--offline` flag to test commands without running the service:
|
|||||||
|
|
||||||
### Format Code
|
### Format Code
|
||||||
|
|
||||||
|
IntelliJ IDEA: **Code → Reformat Code** (Ctrl+Alt+L / Cmd+Alt+L)
|
||||||
|
|
||||||
|
VS Code: Right-click → Format Document
|
||||||
|
|
||||||
|
### Update Dependencies
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./gradlew ktlintFormat
|
mvn versions:display-dependency-updates
|
||||||
|
mvn versions:display-plugin-updates
|
||||||
```
|
```
|
||||||
|
|
||||||
### Check Code Style
|
### Generate Project Reports
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./gradlew ktlintCheck
|
mvn site
|
||||||
```
|
# Open target/site/index.html
|
||||||
|
|
||||||
### Generate Documentation
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./gradlew dokkaHtml
|
|
||||||
```
|
|
||||||
|
|
||||||
Output is in `build/dokka/html/`.
|
|
||||||
|
|
||||||
### Dependency Updates
|
|
||||||
|
|
||||||
Check for outdated dependencies:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./gradlew dependencyUpdates
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
### GraalVM Not Found
|
### Compilation Fails with Lint Errors
|
||||||
|
|
||||||
Ensure `GRAALVM_HOME` is set and GraalVM is on your PATH:
|
The project uses `-Werror` to treat warnings as errors. Fix all warnings:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
export GRAALVM_HOME=/path/to/graalvm
|
# See detailed warnings
|
||||||
export PATH=$GRAALVM_HOME/bin:$PATH
|
mvn compile -X
|
||||||
```
|
|
||||||
|
|
||||||
### Native Image Build Fails
|
|
||||||
|
|
||||||
Common causes:
|
|
||||||
|
|
||||||
1. **Reflection configuration missing**: Add classes to `reflect-config.json`
|
|
||||||
2. **Resource not included**: Add to `resource-config.json`
|
|
||||||
3. **Insufficient memory**: Increase heap with `-J-Xmx8g`
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./gradlew nativeCompile -Pnative.heap=8g
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Tests Fail on Windows
|
### Tests Fail on Windows
|
||||||
@@ -215,35 +366,88 @@ Ensure line endings are consistent:
|
|||||||
git config core.autocrlf input
|
git config core.autocrlf input
|
||||||
```
|
```
|
||||||
|
|
||||||
### Gradle Wrapper Issues
|
### Checkstyle Violations
|
||||||
|
|
||||||
Regenerate the wrapper:
|
View details:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
gradle wrapper --gradle-version 8.5
|
mvn checkstyle:checkstyle
|
||||||
|
# Open target/site/checkstyle.html
|
||||||
|
```
|
||||||
|
|
||||||
|
### SpotBugs Issues
|
||||||
|
|
||||||
|
View in GUI:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn compile spotbugs:gui
|
||||||
```
|
```
|
||||||
|
|
||||||
### Out of Memory During Build
|
### Out of Memory During Build
|
||||||
|
|
||||||
Increase Gradle daemon memory in `gradle.properties`:
|
Increase Maven heap:
|
||||||
|
|
||||||
```properties
|
```bash
|
||||||
org.gradle.jvmargs=-Xmx4g
|
export MAVEN_OPTS="-Xmx2g"
|
||||||
|
mvn package
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Native Image Build Fails
|
||||||
|
|
||||||
|
Common causes:
|
||||||
|
|
||||||
|
1. **Reflection configuration missing**: Add to `src/main/resources/META-INF/native-image/reflect-config.json`
|
||||||
|
2. **Resource not included**: Add to `resource-config.json`
|
||||||
|
3. **Insufficient memory**: Increase heap with `-J-Xmx8g`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Environment Variables
|
## Environment Variables
|
||||||
|
|
||||||
| Variable | Description |
|
| Variable | Description |
|
||||||
|----------|-------------|
|
|----------|-------------|
|
||||||
|
| `JAVA_HOME` | Path to JDK installation |
|
||||||
| `GRAALVM_HOME` | Path to GraalVM installation |
|
| `GRAALVM_HOME` | Path to GraalVM installation |
|
||||||
| `JAVA_HOME` | Path to JDK (can point to GraalVM) |
|
| `MAVEN_OPTS` | JVM options for Maven |
|
||||||
| `BARN_LOG_LEVEL` | Override log level during development |
|
| `BARN_LOG_LEVEL` | Override log level during development |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Useful Maven Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Clean everything
|
||||||
|
mvn clean
|
||||||
|
|
||||||
|
# Compile only
|
||||||
|
mvn compile
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
mvn test
|
||||||
|
|
||||||
|
# Package JAR
|
||||||
|
mvn package
|
||||||
|
|
||||||
|
# Install to local repo
|
||||||
|
mvn install
|
||||||
|
|
||||||
|
# Full verification
|
||||||
|
mvn verify
|
||||||
|
|
||||||
|
# Generate site/reports
|
||||||
|
mvn site
|
||||||
|
|
||||||
|
# Dependency tree
|
||||||
|
mvn dependency:tree
|
||||||
|
|
||||||
|
# Effective POM
|
||||||
|
mvn help:effective-pom
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Next Steps
|
## Next Steps
|
||||||
|
|
||||||
|
- [Coding Standards](coding-standards.md) - Code style and conventions
|
||||||
- [Releasing](releasing.md) - How to create releases
|
- [Releasing](releasing.md) - How to create releases
|
||||||
- [CI/CD](ci-cd.md) - Automated build and release workflows
|
- [CI/CD](ci-cd.md) - Automated build and release workflows
|
||||||
@@ -4,14 +4,434 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>org.media.samson</groupId>
|
<groupId>com.samsonmedia</groupId>
|
||||||
<artifactId>barn</artifactId>
|
<artifactId>barn</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>Barn</name>
|
||||||
|
<description>Cross-platform job daemon for media processing</description>
|
||||||
|
<url>https://github.com/samson-media/barn</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>25</maven.compiler.source>
|
<!-- Java Version -->
|
||||||
<maven.compiler.target>25</maven.compiler.target>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
|
||||||
|
<!-- Dependency Versions -->
|
||||||
|
<picocli.version>4.7.6</picocli.version>
|
||||||
|
<jackson.version>2.18.2</jackson.version>
|
||||||
|
<slf4j.version>2.0.16</slf4j.version>
|
||||||
|
<logback.version>1.5.15</logback.version>
|
||||||
|
|
||||||
|
<!-- Test Dependency Versions -->
|
||||||
|
<junit.version>5.11.4</junit.version>
|
||||||
|
<mockito.version>5.14.2</mockito.version>
|
||||||
|
<assertj.version>3.27.0</assertj.version>
|
||||||
|
|
||||||
|
<!-- Plugin Versions -->
|
||||||
|
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
|
||||||
|
<maven-surefire-plugin.version>3.5.2</maven-surefire-plugin.version>
|
||||||
|
<maven-failsafe-plugin.version>3.5.2</maven-failsafe-plugin.version>
|
||||||
|
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
|
||||||
|
<maven-shade-plugin.version>3.6.0</maven-shade-plugin.version>
|
||||||
|
<checkstyle-plugin.version>3.6.0</checkstyle-plugin.version>
|
||||||
|
<checkstyle.version>10.21.1</checkstyle.version>
|
||||||
|
<spotbugs-plugin.version>4.8.6.6</spotbugs-plugin.version>
|
||||||
|
<pmd-plugin.version>3.26.0</pmd-plugin.version>
|
||||||
|
<jacoco-plugin.version>0.8.12</jacoco-plugin.version>
|
||||||
|
<native-maven-plugin.version>0.10.4</native-maven-plugin.version>
|
||||||
|
|
||||||
|
<!-- Code Quality Thresholds -->
|
||||||
|
<jacoco.line.coverage>0.80</jacoco.line.coverage>
|
||||||
|
<jacoco.branch.coverage>0.70</jacoco.branch.coverage>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- CLI -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>info.picocli</groupId>
|
||||||
|
<artifactId>picocli</artifactId>
|
||||||
|
<version>${picocli.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JSON -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Logging -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>${logback.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Annotations -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.spotbugs</groupId>
|
||||||
|
<artifactId>spotbugs-annotations</artifactId>
|
||||||
|
<version>4.8.6</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Testing -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>${mockito.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-junit-jupiter</artifactId>
|
||||||
|
<version>${mockito.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>${assertj.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<!-- Compiler -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${maven.compiler.source}</source>
|
||||||
|
<target>${maven.compiler.target}</target>
|
||||||
|
<compilerArgs>
|
||||||
|
<arg>-Xlint:all</arg>
|
||||||
|
<arg>-Werror</arg>
|
||||||
|
</compilerArgs>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>info.picocli</groupId>
|
||||||
|
<artifactId>picocli-codegen</artifactId>
|
||||||
|
<version>${picocli.version}</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!-- Unit Tests -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>${maven-surefire-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<includes>
|
||||||
|
<include>**/*Test.java</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*IT.java</exclude>
|
||||||
|
<exclude>**/*E2ETest.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!-- Integration Tests -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-failsafe-plugin</artifactId>
|
||||||
|
<version>${maven-failsafe-plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>integration-test</goal>
|
||||||
|
<goal>verify</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<includes>
|
||||||
|
<include>**/*IT.java</include>
|
||||||
|
<include>**/*E2ETest.java</include>
|
||||||
|
</includes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!-- JAR -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>${maven-jar-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>com.samsonmedia.barn.Main</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!-- Fat JAR -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>${maven-shade-plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<transformers>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<mainClass>com.samsonmedia.barn.Main</mainClass>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
<!-- CODE QUALITY PLUGINS -->
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
|
||||||
|
<!-- Checkstyle - Code Style -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
|
<version>${checkstyle-plugin.version}</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.puppycrawl.tools</groupId>
|
||||||
|
<artifactId>checkstyle</artifactId>
|
||||||
|
<version>${checkstyle.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<configuration>
|
||||||
|
<configLocation>config/checkstyle/checkstyle.xml</configLocation>
|
||||||
|
<suppressionsLocation>config/checkstyle/suppressions.xml</suppressionsLocation>
|
||||||
|
<consoleOutput>true</consoleOutput>
|
||||||
|
<failsOnError>true</failsOnError>
|
||||||
|
<violationSeverity>warning</violationSeverity>
|
||||||
|
<includeTestSourceDirectory>true</includeTestSourceDirectory>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>validate</id>
|
||||||
|
<phase>validate</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!-- SpotBugs - Bug Detection -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.github.spotbugs</groupId>
|
||||||
|
<artifactId>spotbugs-maven-plugin</artifactId>
|
||||||
|
<version>${spotbugs-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<effort>Max</effort>
|
||||||
|
<threshold>Low</threshold>
|
||||||
|
<failOnError>true</failOnError>
|
||||||
|
<excludeFilterFile>config/spotbugs/exclude.xml</excludeFilterFile>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.h3xstream.findsecbugs</groupId>
|
||||||
|
<artifactId>findsecbugs-plugin</artifactId>
|
||||||
|
<version>1.13.0</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>spotbugs-check</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!-- PMD - Static Analysis -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-pmd-plugin</artifactId>
|
||||||
|
<version>${pmd-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<rulesets>
|
||||||
|
<ruleset>config/pmd/ruleset.xml</ruleset>
|
||||||
|
</rulesets>
|
||||||
|
<failOnViolation>true</failOnViolation>
|
||||||
|
<printFailingErrors>true</printFailingErrors>
|
||||||
|
<includeTests>true</includeTests>
|
||||||
|
<targetJdk>${maven.compiler.target}</targetJdk>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>pmd-check</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!-- JaCoCo - Code Coverage -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
<version>${jacoco-plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>prepare-agent</id>
|
||||||
|
<goals>
|
||||||
|
<goal>prepare-agent</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>report</id>
|
||||||
|
<phase>test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>report</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>check</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<rules>
|
||||||
|
<rule>
|
||||||
|
<element>BUNDLE</element>
|
||||||
|
<limits>
|
||||||
|
<limit>
|
||||||
|
<counter>LINE</counter>
|
||||||
|
<value>COVEREDRATIO</value>
|
||||||
|
<minimum>${jacoco.line.coverage}</minimum>
|
||||||
|
</limit>
|
||||||
|
<limit>
|
||||||
|
<counter>BRANCH</counter>
|
||||||
|
<value>COVEREDRATIO</value>
|
||||||
|
<minimum>${jacoco.branch.coverage}</minimum>
|
||||||
|
</limit>
|
||||||
|
</limits>
|
||||||
|
</rule>
|
||||||
|
</rules>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
<!-- PROFILES -->
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<!-- Native Image Build -->
|
||||||
|
<profile>
|
||||||
|
<id>native</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.graalvm.buildtools</groupId>
|
||||||
|
<artifactId>native-maven-plugin</artifactId>
|
||||||
|
<version>${native-maven-plugin.version}</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>build-native</id>
|
||||||
|
<goals>
|
||||||
|
<goal>compile-no-fork</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>package</phase>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<imageName>barn</imageName>
|
||||||
|
<mainClass>com.samsonmedia.barn.Main</mainClass>
|
||||||
|
<buildArgs>
|
||||||
|
<buildArg>--no-fallback</buildArg>
|
||||||
|
<buildArg>-H:+ReportExceptionStackTraces</buildArg>
|
||||||
|
<buildArg>--enable-url-protocols=https</buildArg>
|
||||||
|
</buildArgs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
|
||||||
|
<!-- Skip quality checks for fast builds -->
|
||||||
|
<profile>
|
||||||
|
<id>fast</id>
|
||||||
|
<properties>
|
||||||
|
<checkstyle.skip>true</checkstyle.skip>
|
||||||
|
<spotbugs.skip>true</spotbugs.skip>
|
||||||
|
<pmd.skip>true</pmd.skip>
|
||||||
|
<jacoco.skip>true</jacoco.skip>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
<!-- REPORTING -->
|
||||||
|
<!-- ================================================================== -->
|
||||||
|
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
|
<version>${checkstyle-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<configLocation>config/checkstyle/checkstyle.xml</configLocation>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.github.spotbugs</groupId>
|
||||||
|
<artifactId>spotbugs-maven-plugin</artifactId>
|
||||||
|
<version>${spotbugs-plugin.version}</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-pmd-plugin</artifactId>
|
||||||
|
<version>${pmd-plugin.version}</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
<version>${jacoco-plugin.version}</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</reporting>
|
||||||
</project>
|
</project>
|
||||||
Reference in new issue
Block a user