Skip to content

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

Open
david-stephan wants to merge 6 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#611
david-stephan wants to merge 6 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 a critical issue where keywords defined within an Automation Package (AP) library were not being correctly referenced, leading to functional failures. The changes introduce a robust mechanism to identify the origin of keywords (whether from the main AP or an associated library) during the scanning process. This allows for the correct assignment of the library JAR as the scriptFile for library-based keywords, ensuring they are properly loaded and executed. The solution involves refactoring core components related to AP reading, keyword extraction, and resource application, along with the addition of a specific test case to validate the fix.

Highlights

  • Keyword Origin Identification: Implemented a new mechanism to detect if a keyword is declared within the main Automation Package (AP) or an associated AP library by marking it with a custom field.
  • Correct Script File Assignment: Ensured that keywords originating from an AP library correctly reference the library JAR as their primary script file, resolving the issue of keywords not being found.
  • Refactored AP Reading Logic: Updated the JavaAutomationPackageReader to pass the full archive to the keyword extraction process, enabling the determination of a keyword's source (main AP or library).
  • Enhanced Test Coverage: Added a dedicated test case to validate the correct script file assignment for library-based keywords, ensuring the fix behaves as expected.
Changelog
  • pom.xml
    • Updated step-framework.version to 0.0.0-SED-4497-SNAPSHOT.
  • step-automation-packages/step-automation-packages-controller/src/test/java/step/automation/packages/AutomationPackageManagerOSTest.java
    • Added a test assertion to confirm that keywords from an AP library correctly reference the library as their script file.
  • step-automation-packages/step-automation-packages-manager/src/main/java/step/automation/packages/JavaAutomationPackageReader.java
    • Removed unused import LocalFunctionPlugin.
    • Added imports for URI, URISyntaxException, and $_MARK_AS_KEYWORD_FROM_AUTOMATION_PACKAGE_LIBRARY.
    • Modified fillAutomationPackageWithAnnotatedKeywordsAndPlans to pass the archive object to extractAnnotatedKeywords.
    • Updated extractAnnotatedKeywords method signature and added Javadoc explaining the new logic.
    • Implemented logic to detect keywords from the library JAR and mark them with a custom field for later processing.
  • step-core/src/main/java/step/automation/packages/AutomationPackageArchive.java
    • Removed unused logging imports.
    • Renamed keywordLibFile field to libraryFile for consistency.
    • Renamed getKeywordLibFile() method to getLibraryFile().
  • step-core/src/main/java/step/automation/packages/JavaAutomationPackageArchive.java
    • Updated classLoaderForApAndLibraries to be explicitly URLClassLoader.
    • Clarified comments regarding the combined class loader's role in loading classes from both the AP and its libraries.
    • Adjusted createAnnotationScanner to use the refined URLClassLoader type directly.
  • step-functions-plugins/step-functions-plugins-java/step-functions-plugins-java-def/src/main/java/step/plugins/java/GeneralScriptFunction.java
    • Defined a new constant $_MARK_AS_KEYWORD_FROM_AUTOMATION_PACKAGE_LIBRARY.
    • Updated applyAutomationPackageContext to use this new flag to differentiate between keywords from the main AP and those from the library, assigning the correct script and library resources accordingly.
    • Improved error messages for inconsistent states during script file assignment.
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 addresses an issue where keywords from an automation package library were not working correctly. The fix involves a two-step process: first, identifying and marking keywords that originate from a library JAR during package reading, and second, using this marker to correctly set the script and library files for the keyword.

My review focuses on the implementation of this logic. The changes are well-structured and include corresponding test updates. I've suggested a minor refactoring in GeneralScriptFunction to improve code readability and reduce redundancy. Overall, the changes look good and effectively solve the described problem.

Comment on lines +103 to 120
if (getCustomField($_MARK_AS_KEYWORD_FROM_AUTOMATION_PACKAGE_LIBRARY) != null) {
getCustomFields().remove($_MARK_AS_KEYWORD_FROM_AUTOMATION_PACKAGE_LIBRARY);
if (ap.getAutomationPackageLibraryResourceRevision() != null && !ap.getAutomationPackageLibraryResourceRevision().isEmpty()) {
setScriptFile(new DynamicValue<>(ap.getAutomationPackageLibraryResourceRevision()));
} else {
throw new RuntimeException("Inconsistent state: the annotated Keyword '" + this.getAttribute(NAME) + "' was detected in an Automation Package Library, but the library resource does not exists.");
}
} else {
//Keyword annotated in main AP file
if (ap.getAutomationPackageResourceRevision() != null && !ap.getAutomationPackageResourceRevision().isEmpty()) {
setScriptFile(new DynamicValue<>(ap.getAutomationPackageResourceRevision()));
} else {
throw new RuntimeException("Inconsistent state: the annotated Keyword '" + this.getAttribute(NAME) + "' was detected in an Automation Package, but the package resource does not exists.");
}
if (ap.getAutomationPackageLibraryResourceRevision() != null && !ap.getAutomationPackageLibraryResourceRevision().isEmpty()) {
setLibrariesFile(new DynamicValue<>(ap.getAutomationPackageLibraryResourceRevision()));
}
}

Choose a reason for hiding this comment

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

medium

This block of logic can be made more readable and less repetitive by extracting the resource revision strings and their non-empty checks into local variables. This would also be a good opportunity to correct a minor grammatical error in the exception messages (exists should be exist).

            final String libraryRevision = ap.getAutomationPackageLibraryResourceRevision();
            final boolean hasLibrary = libraryRevision != null && !libraryRevision.isEmpty();

            if (getCustomField($_MARK_AS_KEYWORD_FROM_AUTOMATION_PACKAGE_LIBRARY) != null) {
                getCustomFields().remove($_MARK_AS_KEYWORD_FROM_AUTOMATION_PACKAGE_LIBRARY);
                if (hasLibrary) {
                    setScriptFile(new DynamicValue<>(libraryRevision));
                } else {
                    throw new RuntimeException("Inconsistent state: the annotated Keyword '" + getAttribute(NAME) + "' was detected in an Automation Package Library, but the library resource does not exist.");
                }
            } else {
                //Keyword annotated in main AP file
                final String packageRevision = ap.getAutomationPackageResourceRevision();
                if (packageRevision != null && !packageRevision.isEmpty()) {
                    setScriptFile(new DynamicValue<>(packageRevision));
                } else {
                    throw new RuntimeException("Inconsistent state: the annotated Keyword '" + getAttribute(NAME) + "' was detected in an Automation Package, but the package resource does not exist.");
                }
                if (hasLibrary) {
                    setLibrariesFile(new DynamicValue<>(libraryRevision));
                }
            }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code refactored

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