Skip to content

Enforce import style: auto-shorten FQCNs via OpenRewrite in CI#22935

Draft
gnodet wants to merge 7 commits intoapache:mainfrom
gnodet:enforce-fqcn-imports
Draft

Enforce import style: auto-shorten FQCNs via OpenRewrite in CI#22935
gnodet wants to merge 7 commits intoapache:mainfrom
gnodet:enforce-fqcn-imports

Conversation

@gnodet
Copy link
Copy Markdown
Contributor

@gnodet gnodet commented May 5, 2026

Summary

  • Add rewrite-maven-plugin with ShortenFullyQualifiedTypeReferences recipe to automatically replace unnecessary fully qualified class names with simple names + imports
  • Plugin is gated behind a -Prewrite Maven profile — only runs in CI, not during local builds
  • Uses runNoFork goal with runPerSubmodule=true to process each module immediately during the build
  • Generated code (src/generated/) is excluded from processing
  • Both PR and main build workflows now pass -Prewrite to regen.sh, and the existing "fail if uncommitted changes" step catches any unfixed FQCNs
  • Update CLAUDE.md with import style conventions for AI agents
  • Fix all 598 existing unnecessary FQCNs across 187 modules

How it works

  1. CI runs regen.sh with -Prewrite → OpenRewrite shortens unnecessary FQCNs and adds imports
  2. impsort sorts the new imports (already runs in the same build)
  3. formatter formats the code (already runs in the same build)
  4. Existing git status --porcelain step fails if any files were modified

Local developers can opt-in with mvn install -Prewrite to auto-fix FQCNs before pushing.

Test plan

  • Normal build (mvn install) does not run OpenRewrite
  • Build with -Prewrite runs OpenRewrite and shortens FQCNs per module
  • Generated files (src/generated/) are excluded
  • Modified files are detected by git status --porcelain
  • Full repo run fixes 598 files across 187 modules
  • CI green

…enRewrite

Add rewrite-maven-plugin with ShortenFullyQualifiedTypeReferences recipe
to automatically replace unnecessary FQCNs with simple class names and
add the corresponding import statements. Generated code (src/generated/)
is excluded from processing.

The plugin is gated behind a -Prewrite Maven profile so it only runs in
CI regen builds, not during local development. Both PR and main build
workflows now pass -Prewrite to regen.sh, and the existing
"fail if uncommitted changes" step catches any FQCN fixes that were not
committed by the PR author.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

ℹ️ CI did not run targeted module tests (root project files changed).


⚙️ View full build and test results

Copy link
Copy Markdown
Contributor

@apupier apupier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it not applied during normal build like for other formatting?

@gnodet gnodet marked this pull request as draft May 5, 2026 08:25
Copy link
Copy Markdown
Contributor

@oscerd oscerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Auto-fix generated by OpenRewrite ShortenFullyQualifiedTypeReferences
recipe across 598 files in 187 modules. Replaces inline fully qualified
class names with simple names and adds the corresponding import
statements where no import clash exists.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gnodet gnodet marked this pull request as ready for review May 5, 2026 10:44
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gnodet
Copy link
Copy Markdown
Contributor Author

gnodet commented May 5, 2026

Why is it not applied during normal build like for other formatting?

It takes a bit of time. The PR workflow is fine because it usually does not rebuild everything. But we can apply it globally if we want.

Comment on lines 34 to 35
import org.apache.camel.diagram.RouteDiagramLayoutEngine.TreeNode;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing import for jline Colors

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@davsclaus
Copy link
Copy Markdown
Contributor

LGTM

@gnodet gnodet marked this pull request as draft May 6, 2026 06:39
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants