diff --git a/.githooks/pre-commit b/.githooks/pre-commit deleted file mode 100755 index eb77167ce8..0000000000 --- a/.githooks/pre-commit +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -# -# Pre-commit hook that runs Spotless check on the Java SDK when Java source -# files are staged. Only triggers if changes exist under java/sdk/src/. -# -# To install this hook, run from the repository root: -# git config core.hooksPath .githooks -# - -# Only run Spotless if staged changes include Java source files under java/sdk/src/ -if ! git diff --cached --name-only | grep -q '^java/sdk/src/'; then - exit 0 -fi - -echo "Running Spotless check on java/ ..." - -# Run spotless check from the java directory -(cd java && mvn spotless:check -q) - -if [ $? -ne 0 ]; then - echo "" - echo "❌ Spotless check failed!" - echo " Run 'cd java && mvn spotless:apply' to fix formatting issues." - echo "" - exit 1 -fi - -echo "✓ Spotless check passed" -exit 0 diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 476f4e5689..cf9b6155d5 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -28,9 +28,9 @@ - Go: `cd go && go test ./...` - .NET: `cd dotnet && dotnet test test/GitHub.Copilot.SDK.Test.csproj` - **.NET testing note:** Never add `InternalsVisibleTo` to any project file when writing tests. Tests must only access public APIs. - - Java: `cd java && mvn clean verify` (full build + tests), `mvn spotless:apply` (format code before commit) + - Java: `cd java && mvn clean verify` (full build + tests), `mvn -pl sdk spotless:apply` (format code) - Java single test: `cd java && mvn test -Dtest=CopilotClientTest` | single method: `mvn test -Dtest=ToolsTest#testToolInvocation` - - Java format check only: `mvn spotless:check` | Build without tests: `mvn clean package -DskipTests` + - Java formatting and Javadoc checks: `mvn -pl sdk spotless:check checkstyle:check` | Build without tests: `mvn clean package -DskipTests` - **Java testing note:** Always use `mvn verify` without `-q` and without piping through `grep`. Never add `InternalsVisibleTo` equivalent — tests must only access public APIs. - Use configured LSPs for supported operations like finding references instead of pattern matching, renaming symbols, etc. @@ -57,7 +57,7 @@ - Some scripts (typegen, formatting) call external tools: `gofmt`, `dotnet format`, `tsx` (available via npm), `quicktype`/`quicktype-core` (used by the Node typegen script), and `prettier` (provided as an npm devDependency). Most of these are available through the repo's package scripts or devDependencies—run `just install` (and `cd nodejs && npm ci`) to install them. Ensure the required tools are available in CI / developer machines. - Tests may assume `node >= 18`, `python >= 3.9`, platform differences handled (Windows uses `shell=True` for npx in harness). - Java requires JDK 17+ and Maven 3.9+. Java E2E tests also require Node.js (for the replay proxy). -- Java pre-commit hook runs `mvn spotless:check`. Enable with `git config core.hooksPath .githooks` (auto-enabled in Copilot coding agent environment via `copilot-setup-steps.yml`). +- Java formatting and Javadoc checks use `just format-java` and `just lint-java` from the repository root, and are included in `just format` and `just lint`. CI enforces Spotless and Checkstyle; `mvn verify` alone does not run Spotless. ## Where to add new code or tests 🧭 diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index d25689b3b9..d6265a3331 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -80,10 +80,6 @@ jobs: with: version: v0.82.10 - # Enable repository pre-commit hooks (Spotless checks for Java source changes) - - name: Enable pre-commit hooks - run: git config core.hooksPath .githooks - # Install JavaScript dependencies - name: Install Node.js dependencies working-directory: ./nodejs diff --git a/java/README.md b/java/README.md index 38c5a19de6..9b8b243247 100644 --- a/java/README.md +++ b/java/README.md @@ -577,9 +577,6 @@ Requires JDK 25 or later and a supported [Node.js version](../nodejs/README.md#p git clone https://github.com/github/copilot-sdk.git cd copilot-sdk/java -# Enable git hooks for code formatting -git config core.hooksPath .githooks - # Build and test with JDK 25 mvn test-compile jar:jar mvn verify -Dskip.test.harness=true @@ -589,6 +586,22 @@ mvn verify -Dskip.test.harness=true mvn jacoco:prepare-agent@wire-up-coverage-instrumentation antrun:run@print-test-jdk-banner surefire:test failsafe:integration-test failsafe:verify jacoco:report@build-coverage-report-from-tests -Denforcer.skip=true ``` +#### Formatting and linting + +From the repository root, run `just format-java` to apply formatting and `just lint-java` to check formatting and Javadoc. These recipes are also included in `just format` and `just lint`. + +Without `just`, run the equivalent Maven commands from `java/`: + +```bash +# Apply formatting +mvn -pl sdk spotless:apply + +# Check formatting and Javadoc +mvn -pl sdk spotless:check checkstyle:check +``` + +CI enforces both checks. Spotless runs explicitly in CI; `mvn verify` alone does not check formatting. + #### Development Setup for native embedding Run native-runtime Maven commands from the `java` directory. Native packaging requires Node.js in addition to JDK 25 and Maven because `copilot-native/scripts/fetch-native.mjs` retrieves the pinned runtime package from the corresponding GitHub release. diff --git a/justfile b/justfile index 69666bc00a..1707f0966f 100644 --- a/justfile +++ b/justfile @@ -3,10 +3,10 @@ default: @just --list # Format all code across all languages -format: format-go format-python format-nodejs format-dotnet format-rust +format: format-go format-python format-nodejs format-dotnet format-java format-rust # Lint all code across all languages -lint: lint-go lint-python lint-nodejs lint-dotnet lint-rust +lint: lint-go lint-python lint-nodejs lint-dotnet lint-java lint-rust # Run tests for all languages test: test-go test-python test-nodejs test-dotnet test-rust test-harness test-corrections @@ -31,6 +31,11 @@ format-dotnet: @echo "=== Formatting .NET code ===" @cd dotnet && dotnet format src/GitHub.Copilot.SDK.csproj +# Format Java code +format-java: + @echo "=== Formatting Java code ===" + @cd java && mvn -pl sdk spotless:apply + # Lint Go code lint-go: @echo "=== Linting Go code ===" @@ -51,6 +56,11 @@ lint-dotnet: @echo "=== Linting .NET code ===" @cd dotnet && dotnet format src/GitHub.Copilot.SDK.csproj --verify-no-changes +# Lint Java code +lint-java: + @echo "=== Linting Java code ===" + @cd java && mvn -pl sdk spotless:check checkstyle:check + # Test Go code test-go: @echo "=== Testing Go code ==="