Skip to content

SED-4497-referencing-a-keyword-from-an-ap-library-doesnt-work#120

Open
david-stephan wants to merge 2 commits intomasterfrom
SED-4497-referencing-a-keyword-from-an-ap-library-doesnt-work
Open

SED-4497-referencing-a-keyword-from-an-ap-library-doesnt-work#120
david-stephan wants to merge 2 commits intomasterfrom
SED-4497-referencing-a-keyword-from-an-ap-library-doesnt-work

Conversation

@david-stephan
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where keywords from external libraries were not being correctly referenced. It enhances the AnnotationScanner by providing a robust mechanism to identify the classpath location of classes, ensuring that keywords from various sources, including AP libraries, can be reliably resolved and utilized.

Highlights

  • Classpath Resolution: Introduced a new public method, getClasspathElementUrl, in AnnotationScanner to accurately determine the classpath element URL for a given class, leveraging ClassGraph's scan metadata. This method is designed to provide a robust way to locate classes, especially those from external libraries, unaffected by security managers or JDK version differences.
  • Dependency Update: Added an import for io.github.classgraph.ClassInfo, indicating the integration of the ClassGraph library for enhanced and more reliable class scanning capabilities within the AnnotationScanner.
Changelog
  • step-framework-core/src/main/java/step/core/scanner/AnnotationScanner.java
    • Added a new public method getClasspathElementUrl to retrieve the classpath element URL for a given class.
    • Imported io.github.classgraph.ClassInfo to support the new functionality.
Activity
  • No activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a new utility method getClasspathElementUrl to the AnnotationScanner class. This method allows retrieving the source URL (e.g., JAR file) of a class from the classpath scan results. The implementation is correct and includes good documentation. However, the new public method is missing corresponding unit tests. Adding tests is crucial to validate its behavior and prevent future regressions. Additionally, since CachedAnnotationScanner acts as a cached wrapper for AnnotationScanner, you may want to consider exposing this new functionality through it as well for consistency.

Comment on lines +225 to +228
public URL getClasspathElementUrl(String className) {
ClassInfo classInfo = scanResult.getClassInfo(className);
return classInfo != null ? classInfo.getClasspathElementURL() : null;
}

Choose a reason for hiding this comment

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

medium

This new public method getClasspathElementUrl is not covered by unit tests. Please add a new test to AnnotationScannerTest.java to validate its functionality. A good test case would verify that a URL is returned for a known class and that null is returned for a class that does not exist in the scan results.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new method getClasspathElementUrl to the AnnotationScanner class, which allows retrieving the classpath URL for a given class name. The implementation is straightforward, but I've suggested an improvement to handle null input gracefully. Additionally, the new public method should be accompanied by unit tests to ensure its correctness and prevent future regressions.

* @param className the binary class name (e.g. {@code "com.example.MyKeywords"})
* @return the URL of the JAR or directory that contains the class, or {@code null}
*/
public URL getClasspathElementUrl(String className) {

Choose a reason for hiding this comment

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

medium

This new public method should be covered by unit tests in AnnotationScannerTest.java. Please add tests for at least the following cases:

  • A class that is found in the scan result.
  • A class that is not found in the scan result (should return null).
  • A null class name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Junit tests added

Comment on lines +226 to +227
ClassInfo classInfo = scanResult.getClassInfo(className);
return classInfo != null ? classInfo.getClasspathElementURL() : null;

Choose a reason for hiding this comment

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

medium

The scanResult.getClassInfo(className) method from the classgraph library will throw an IllegalArgumentException if className is null. To make this method more robust, it's a good practice to handle the null case explicitly by returning null, which is consistent with the behavior when a class is not found.

        if (className == null) {
            return null;
        }
        ClassInfo classInfo = scanResult.getClassInfo(className);
        return classInfo != null ? classInfo.getClasspathElementURL() : null;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Classname value check added, but we do not accept null value and now throw an IllegalArgumentException

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant