diff --git a/AGENTS.md b/AGENTS.md index 9aa2409f4e8..0432e873177 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -51,13 +51,13 @@ docs/ Developer documentation (see below) ./gradlew :dd-java-agent:shadowJar # Build agent jar only (dd-java-agent/build/libs/) ./gradlew :path:to:module:test # Run tests for a specific module ./gradlew :path:to:module:test -PtestJvm=11 # Test on a specific JVM version -./gradlew spotlessApply # Auto-format code (google-java-format) +./gradlew spotlessApply # Auto-format code (Prince of Space) ./gradlew spotlessCheck # Verify formatting ``` ## Code conventions -- **Formatting**: google-java-format enforced via Spotless. Run `./gradlew spotlessApply` before committing. +- **Formatting**: Prince of Space enforced via Spotless. Run `./gradlew spotlessApply` before committing. - **Static imports**: Prefer static imports over class-qualified calls for call-style helpers, in both test (Assertions.assertEquals, Mockito.mock) and production code (Collections.emptyList). Wildcard imports disallowed — see CONTRIBUTING.md. - **Documentation**: Use concise Javadoc comments (`/** ... */`) for class, method, and field documentation. - **Instrumentation layout**: `dd-java-agent/instrumentation/{framework}/{framework}-{minVersion}/` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c023a09af5e..64fa15427eb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,6 +34,9 @@ We have automatic code formatting enabled in Gradle configuration using [Spotles Our main goal is to avoid extensive reformatting caused by different IDEs with different opinions about how things should be formatted by establishing a single _point of truth_. +Java sources use [Prince of Space](https://github.com/agustafson/prince-of-space) with two-space indentation and a +100-character line width. + To reformat all the files that need reformatting: ```bash @@ -55,13 +58,15 @@ For IntelliJ IDEA, we suggest the following settings and plugin. * `Use single class import`: checked * `Class count to use import with '*'`: `9999` (some number sufficiently large that is unlikely to matter) * `Names count to use static import with '*'`: `9999` - * Use the following import layout to ensure consistency with google-java-format: + * Use the following import layout: ![import layout](https://user-images.githubusercontent.com/734411/43430811-28442636-94ae-11e8-86f1-f270ddcba023.png) * top right Settings icon -> `Settings...` ->`Editor` > `Code Style` > `Groovy` > `Imports` * `Class count to use import with '*'`: `9999` (some number sufficiently large that is unlikely to matter) * `Names count to use static import with '*'`: `9999` * To run test in a specific JDK use the `testJvm` property, e.g. `-PtestJvm=11` -* Install the [Google Java Format](https://plugins.jetbrains.com/plugin/8527-google-java-format) plugin +* Install the [Prince of Space](https://github.com/agustafson/prince-of-space/releases) IntelliJ plugin from its release ZIP + * Under `Settings` > `Tools` > `Prince of Space`, use a two-space indent, a 100-character line length, balanced wrapping, + no trailing commas, no closing parenthesis on a new line, and the project language level ### Static imports diff --git a/build.gradle.kts b/build.gradle.kts index 0bb5a4caee6..dc91f9fb9ae 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -41,7 +41,11 @@ with(extensions["spotlessPredeclare"] as SpotlessExtension) { removeUnusedImports() forbidWildcardImports() - googleJavaFormat(libs.versions.google.java.format.get()) + princeOfSpace(libs.versions.prince.of.space.get()) + .indentSize(2) + .lineLength(100) + .javaLanguageLevel(25) + trimTrailingWhitespace() tableTestFormatter(libs.versions.tabletest.formatter.get()) } groovyGradle { diff --git a/buildSrc/call-site-instrumentation-plugin/build.gradle.kts b/buildSrc/call-site-instrumentation-plugin/build.gradle.kts index 542a4d1ca99..46a7339b82b 100644 --- a/buildSrc/call-site-instrumentation-plugin/build.gradle.kts +++ b/buildSrc/call-site-instrumentation-plugin/build.gradle.kts @@ -22,7 +22,11 @@ spotless { targetExclude("src/test/resources/**") removeUnusedImports() forbidWildcardImports() - googleJavaFormat(libs.versions.google.java.format.get()) + princeOfSpace(libs.versions.prince.of.space.get()) + .indentSize(2) + .lineLength(100) + .javaLanguageLevel(25) + trimTrailingWhitespace() } } diff --git a/buildSrc/modifiable-config-agent/build.gradle.kts b/buildSrc/modifiable-config-agent/build.gradle.kts index 838800eff6b..b634979cb19 100644 --- a/buildSrc/modifiable-config-agent/build.gradle.kts +++ b/buildSrc/modifiable-config-agent/build.gradle.kts @@ -18,7 +18,11 @@ spotless { targetExclude("src/test/resources/**") removeUnusedImports() forbidWildcardImports() - googleJavaFormat(libs.versions.google.java.format.get()) + princeOfSpace(libs.versions.prince.of.space.get()) + .indentSize(2) + .lineLength(100) + .javaLanguageLevel(25) + trimTrailingWhitespace() } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e79e1561762..d7655b9c2df 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,7 +10,7 @@ shadow = "9.4.2" spotbugs_annotations = "4.10.3" # Source code formatters -google-java-format = "1.36.1" +prince-of-space = "2.2.0" greclipse = "4.27" # Pinned. See: https://github.com/diffplug/spotless/issues/3013 ktlint = "1.8.0" scalafmt = "3.11.5" diff --git a/gradle/spotless.gradle b/gradle/spotless.gradle index cb7aaa4d3f8..6c26ca6b86c 100644 --- a/gradle/spotless.gradle +++ b/gradle/spotless.gradle @@ -46,10 +46,22 @@ spotless { // set explicit target to workaround https://github.com/diffplug/spotless/issues/1163 target 'src/**/*.java' // ignore embedded test projects and everything in build dir, e.g. generated sources - targetExclude('src/test/resources/**', buildDirectory) + // Prince of Space 2.2.0 does not preserve this toggle fence and conflicts with TableTest formatting. + targetExclude( + 'src/test/resources/**', + '**/CiVisibilityCountMetric.java', + '**/ClientIpAddressResolver.java', + '**/RumInjectorConfigTest.java', + '**/TagInterceptorTest.java', + '**/TraceStructureWriterTest.java', + buildDirectory) removeUnusedImports() forbidWildcardImports() - googleJavaFormat(libs.versions.google.java.format.get()) + princeOfSpace(libs.versions.prince.of.space.get()) + .indentSize(2) + .lineLength(100) + .javaLanguageLevel(25) + trimTrailingWhitespace() tableTestFormatter(libs.versions.tabletest.formatter.get()) } } diff --git a/test-published-dependencies/build.gradle.kts b/test-published-dependencies/build.gradle.kts index 20b93d82241..c72dbaaa13a 100644 --- a/test-published-dependencies/build.gradle.kts +++ b/test-published-dependencies/build.gradle.kts @@ -37,7 +37,11 @@ allprojects { target("src/**/*.java") removeUnusedImports() forbidWildcardImports() - googleJavaFormat(libs.versions.google.java.format.get()) + princeOfSpace(libs.versions.prince.of.space.get()) + .indentSize(2) + .lineLength(100) + .javaLanguageLevel(25) + trimTrailingWhitespace() } } }