Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update get classpath by artifact name to support bazel #4750

Merged
merged 3 commits into from
Dec 6, 2024

Conversation

amishra-u
Copy link
Contributor

@amishra-u amishra-u commented Dec 5, 2024

What's changed?

Added support to retrieve the classpath by artifact name for Bazel projects.

What's your motivation?

In Bazel projects, creating an instance of JavaParser with artifact names as classpath can fail when artifact names include a "-". This issue arises because Bazel replaces "-" with "_" when generating JAR files.

Example usage

JavaParser.fromJavaVersion().classpath("aws-java-sdk-s3").build()

Above code fails with IllegalStateException Unable to construct JavaParser.

To address this, updated JarPattern to include the normalized artifact name, ensuring it can correctly locate the JAR file names generated using bazel convention.

Note: A minor refactor to make code testable for the part which was updated.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@timtebeek timtebeek self-requested a review December 5, 2024 21:50
@timtebeek timtebeek added the enhancement New feature or request label Dec 5, 2024
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks for the changes here @amishra-u ; good to improve compatibility indeed.

@timtebeek timtebeek merged commit e571da7 into openrewrite:main Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants