Skip to content

Handle nested JAR files in getClassNamesFromPackage and reduce cognit…#2620

Merged
k8s-ci-robot merged 7 commits intokubernetes-client:masterfrom
scovl:fix-issue1659
Apr 14, 2023
Merged

Handle nested JAR files in getClassNamesFromPackage and reduce cognit…#2620
k8s-ci-robot merged 7 commits intokubernetes-client:masterfrom
scovl:fix-issue1659

Conversation

@scovl
Copy link
Copy Markdown
Contributor

@scovl scovl commented Apr 7, 2023

This commit updates the getClassNamesFromPackage method to properly handle nested JAR files within fat JARs. It checks for a second exclamation mark in the URL to identify nested JARs and uses a JarInputStream to read the entries and load the appropriate classes. This change ensures correct class loading when the application is packaged as a fat JAR with nested dependencies and breaks down the original getClassNamesFromPackage method into smaller, more manageable functions, following SonarLint rule java:S3776. The changes improve code readability and maintainability by reducing cognitive complexity.

This is a bug fix reported in #1659

This pull request includes a series of changes to address the issues and suggestions pointed out by the SonarLint analysis (only critical and major smells). Each change has been committed with an appropriate commit. These changes include improvements such as code simplification, use of Optional instead of null, more informative Javadoc tags, among others.

The refactoring of the findApiResourceByGroupVersionKind method involved creating a new HashMap to store API resources by their kind and group. This new map allows for faster lookup of resources during the method's execution, improving the overall performance. The previous implementation required iterating through all resources until a match was found, resulting in a slower search. The new implementation leverages the HashMap data structure, which provides faster access to resources by key. This refactoring improves the code's maintainability, readability, and efficiency.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 7, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: lobocode / name: Vitor Lobo (e02477c)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Apr 7, 2023
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @lobocode!

It looks like this is your first PR to kubernetes-client/java 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/java has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 7, 2023
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 7, 2023
Comment thread util/src/main/java/io/kubernetes/client/util/ModelMapper.java Outdated
@brendandburns
Copy link
Copy Markdown
Contributor

there's a bunch of style/whitespace changes in this PR, can you run mvn spotless:apply and mvn spotless:check and then I can give it a more detailed review.

@scovl
Copy link
Copy Markdown
Contributor Author

scovl commented Apr 9, 2023

there's a bunch of style/whitespace changes in this PR, can you run mvn spotless:apply and mvn spotless:check and then I can give it a more detailed review.

Ah, thanks for the tip (I can be a lil' scatterbrained sometimes). I already fixed it dude! About the duplicate PR, I closed the later one and am keeping just this one. As for SonarLint, I fixed only those that are considered critical and major (usually related to some complex functions that need to be broken down to improve code maintenance or something related to performance and security). Personally, not all the smells pointed out by SonarLint make sense. Once again, thank you so much for the tips dude!

@brendandburns
Copy link
Copy Markdown
Contributor

/lgtm
/approve

It would be great to have a fatjar test at somepoint but that can be a later PR.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 14, 2023
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, lobocode

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 14, 2023
@k8s-ci-robot k8s-ci-robot merged commit b0630bd into kubernetes-client:master Apr 14, 2023
@scovl scovl deleted the fix-issue1659 branch April 18, 2023 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants