Skip to content

Add recipe to migrate commons-lang usage to JDK APIs#1594

Merged
jonesbusy merged 2 commits intojenkins-infra:mainfrom
s4chinjha:feature/commons-lang-to-jdk
Feb 26, 2026
Merged

Add recipe to migrate commons-lang usage to JDK APIs#1594
jonesbusy merged 2 commits intojenkins-infra:mainfrom
s4chinjha:feature/commons-lang-to-jdk

Conversation

@s4chinjha
Copy link
Contributor

Fixes #1542

This PR adds a new recipe to help migrate commons-lang usage to standard JDK APIs using OpenRewrite.

What I did

  • Added a new recipe MigrateCommonsLangToJdkApi in recipes.yml
  • Reused existing OpenRewrite recipes instead of writing custom logic
  • Added the required dependency (rewrite-apache) for these recipes
  • Added a test to verify the transformation works
  • Updated validate_metadata.py to include the new migration ID

The recipe replaces common StringUtils usages with equivalent JDK methods like Objects.toString and null-safe checks.


Testing

  • Added a test case in DeclarativeRecipesTest
  • Verified transformations like:
    • StringUtils.defaultString → Objects.toString
    • StringUtils.isEmpty → JDK checks
  • Ran the specific test:
    mvn -pl plugin-modernizer-core -Dtest=DeclarativeRecipesTest#migrateCommonsLangToJdkApi test
  • Ran full build:
    mvn clean install

All tests passed successfully.


Checklist

  • Working from a feature branch
  • Clear PR title and description
  • Linked the issue
  • Added test for the change

@s4chinjha s4chinjha requested a review from jonesbusy as a code owner February 24, 2026 16:55
@jonesbusy
Copy link
Collaborator

Can you add minimal PR title and body template? It's more user friendly. You can get inspired from commons land 2 to 3 recipe.

Are all the OpenRewrite Recipes for Commons Lang to JDK added?

No need test for them, they can be added to the list. It's just to confirm the recipe is available on the declarative recipe collection.

PR looks already in good shape!

@s4chinjha s4chinjha force-pushed the feature/commons-lang-to-jdk branch from b75f4eb to 8da79f6 Compare February 24, 2026 20:58
@s4chinjha
Copy link
Contributor Author

Thanks for the review!

I’ve made the changes:

  • Added PR title and body like other recipes
  • Marked them with skip-verification so tests don’t fail
  • Kept the main recipe only for commons-lang to JDK changes

I used existing OpenRewrite recipes instead of writing custom code.

Let me know if anything else needs to be fixed 🙂

@jonesbusy
Copy link
Collaborator

Last change is incorrect, we don't generate extra files. Please use JTE like other recipes and provide test for TemplateUtils.

Ideally I would like to see a dry-run change for for a plugin that need to be transformed

@jonesbusy
Copy link
Collaborator

jonesbusy commented Feb 25, 2026

Some examples

jenkinsci/naginator-plugin#196
jenkinsci/postbuildscript-plugin#281
jenkinsci/view-job-filters-plugin#116
jenkinsci/groovy-plugin#106
jenkinsci/aws-credentials-plugin#325

Also the skip-verification is needed on the new recipe. We want to ensure that the plugin compile before pushing a PR

@jonesbusy jonesbusy added the enhancement For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted label Feb 25, 2026
@s4chinjha s4chinjha force-pushed the feature/commons-lang-to-jdk branch 2 times, most recently from a5ce701 to 8da79f6 Compare February 25, 2026 14:16
@s4chinjha
Copy link
Contributor Author

Thanks for the feedback. I’m working on the changes as suggested and will update the PR soon.

@jonesbusy
Copy link
Collaborator

Sure thanks. I think we can safely include all those recipes: https://docs.openrewrite.org/recipes/apache/commons/lang

@s4chinjha s4chinjha closed this Feb 26, 2026
@s4chinjha s4chinjha force-pushed the feature/commons-lang-to-jdk branch from dca9b1d to e00c3e4 Compare February 26, 2026 01:50
@jonesbusy
Copy link
Collaborator

Why closing the PR?

@s4chinjha
Copy link
Contributor Author

s4chinjha commented Feb 26, 2026

Hi @jonesbusy,

Sorry for closing the PR by mistake. I’m still working on the changes currently validating the recipe with dry-run on real plugins and updating tests as suggested.

I’ll reopen it once everything is ready.

Thanks!

@s4chinjha s4chinjha reopened this Feb 26, 2026
@s4chinjha s4chinjha requested a review from jonesbusy February 26, 2026 08:21
@s4chinjha
Copy link
Contributor Author

I’m currently looking into the reasons why the checks are failing. I’ll fix the issues and push an update shortly.

@jonesbusy
Copy link
Collaborator

Sure. Only replaceLibrariesByApiPluginWithBom is expected to fail.

I will disable it on main branch

@jonesbusy
Copy link
Collaborator

#1601

@s4chinjha s4chinjha force-pushed the feature/commons-lang-to-jdk branch from b93dff2 to 5946d07 Compare February 26, 2026 12:07
@s4chinjha
Copy link
Contributor Author

I’ve addressed the feedback, fixed the issues, and updated the recipe configuration. The branch has also been rebased on the latest main. Please take another look @jonesbusy

@jonesbusy
Copy link
Collaborator

Thanks! LGTM

@jonesbusy jonesbusy changed the title Add OpenRewrite recipe to migrate commons-lang usage to JDK APIs Add recipe to migrate commons-lang usage to JDK APIs Feb 26, 2026
@jonesbusy jonesbusy merged commit 95236f3 into jenkins-infra:main Feb 26, 2026
17 checks passed
@s4chinjha s4chinjha deleted the feature/commons-lang-to-jdk branch February 26, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrating commons-lang API to JDK API

2 participants