mchades commented on issue #9834:
URL: https://github.com/apache/gravitino/issues/9834#issuecomment-3827492077

   ## Implementation Notes
   
   After investigating this issue, here are the key findings and recommended 
solution:
   
   ### Problem Analysis
   
   1. **Google Java Format doesn't enforce line length**: Spotless uses Google 
Java Format which handles code formatting (indentation, whitespace) but does 
**not** automatically split long string literals or enforce line length limits.
   
   2. **Custom step needed**: We need to add a custom Spotless step to check 
line length:
   
   ```kotlin
   custom("Enforce line length limit (100 chars)") { fileContent ->
     val maxLineLength = 100
     val lines = fileContent.split("\n")
     val violations = mutableListOf<String>()
     lines.forEachIndexed { index, line ->
       val trimmedLine = line.trimEnd('\r')
       if (trimmedLine.length > maxLineLength) {
         violations.add("Line \${index + 1}: \${trimmedLine.length} chars (max 
\$maxLineLength)")
       }
     }
     if (violations.isNotEmpty()) {
       throw AssertionError(
         "Lines exceed \$maxLineLength characters:\n  
\${violations.joinToString("\n  ")}"
       )
     }
     fileContent
   }
   ```
   
   3. **Gradual adoption challenge**: There are **784 Java files** with lines 
exceeding 100 characters. Using `ratchetFrom('origin/main')` allows gradual 
adoption by only checking changed files.
   
   4. **CI shallow clone issue**: GitHub Actions uses shallow clone, so 
`origin/main` reference doesn't exist, causing `ratchetFrom` to fail with `No 
such reference 'origin/main'`.
   
   ### Recommended Solution
   
   Modify the CI workflow to fetch the main branch before running Spotless:
   
   ```yaml
   - uses: actions/checkout@v4
   - name: Fetch main branch for Spotless ratchet
     run: git fetch origin main --depth=1
   - name: Build
     run: ./gradlew build
   ```
   
   Alternatively, use `fetch-depth: 0` in the checkout action to get full git 
history (but this increases CI time).
   
   ### Files to Modify
   
   1. `build.gradle.kts`: Add the custom line length check step and 
`ratchetFrom('origin/main')`
   2. `.github/workflows/build.yml` (and other relevant workflows): Add `git 
fetch origin main --depth=1` step


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to