Skip to content

Allow adding custom external jars to classpath #2726

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

Merged
merged 9 commits into from
Apr 7, 2025

Conversation

Trigtrig
Copy link
Contributor

@Trigtrig Trigtrig commented Mar 21, 2025

User description

This is a draft showing the described changes to allow adding external jars to the classpath. I'm happy to add this functionality to the remaining images if you agree.

Description

Adds a new environment variable SE_EXTRA_LIBS which allows to add custom external jars to the classpath.

Motivation and Context

Selenium makes it possible to customize a node. While this works pretty well when running a node as shown in the documentation, it is not possible to achieve the same using the Docker images. Right now --node-implementation can be passed to the start-*.sh script using SE_OPTS, but there is no way to pass --ext to it.

Introducing a new environment variable representing --ext named SE_EXTRA_LIBS would allow to extend the classpath in a simple way. The desired jars could then be added to the Docker container in the user's preferred way:

  • Create a customized image based on Seleniums images
  • Mount the jars
  • ...

This mechanism can be applied in the same way to all images.

Fixes #2714

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement, Documentation


Description

  • Introduced SE_EXTRA_LIBS environment variable to add custom jars.

  • Enhanced classpath enrichment logic across all components.

  • Updated logging to display enriched classpath details.

  • Documented the new SE_EXTRA_LIBS variable in ENV_VARIABLES.md.


Changes walkthrough 📝

Relevant files
Enhancement
10 files
start-selenium-grid-distributor.sh
Add support for custom jars in Distributor                             
+12/-3   
start-selenium-grid-eventbus.sh
Add support for custom jars in EventBus                                   
+12/-3   
start-selenium-grid-hub.sh
Add support for custom jars in Hub                                             
+12/-3   
start-selenium-node.sh
Add support for custom jars in NodeBase                                   
+12/-3   
start-selenium-grid-docker.sh
Add support for custom jars in NodeDocker                               
+12/-3   
start-selenium-grid-router.sh
Add support for custom jars in Router                                       
+12/-3   
start-selenium-grid-session-queue.sh
Add support for custom jars in SessionQueue                           
+12/-3   
start-selenium-grid-sessions.sh
Add support for custom jars in Sessions                                   
+15/-6   
start-selenium-standalone.sh
Add support for custom jars in Standalone                               
+12/-3   
start-selenium-grid-docker.sh
Add support for custom jars in StandaloneDocker                   
+12/-3   
Documentation
1 files
ENV_VARIABLES.md
Document SE_EXTRA_LIBS environment variable                           
+1/-0     

Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @Trigtrig
    Copy link
    Contributor Author

    Trigtrig commented Apr 4, 2025

    @VietND96 Do you have some thoughts on this? Shall I continue to work on it?

    @VietND96
    Copy link
    Member

    VietND96 commented Apr 4, 2025

    There are people also try to add extra classpath, we can help in env var for them to append, but jars and classpath.txt (or text) need to be prepared and mounted to the container.

    @VietND96 VietND96 marked this pull request as ready for review April 7, 2025 09:55
    Copy link

    qodo-merge-pro bot commented Apr 7, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Missing --ext Flag

    The Sessions script has a different pattern for handling EXTRA_LIBS compared to other scripts. It doesn't add the "--ext" flag in the initial SE_EXTRA_LIBS handling, which could cause inconsistent behavior.

    if [ -n "${SE_EXTRA_LIBS}" ]; then
      EXTRA_LIBS="--ext ${SE_EXTRA_LIBS}"
    fi
    Redundant Condition

    The conditional check at line 152 is redundant since EXTRA_LIBS will already have the "--ext" prefix if it's non-empty, unlike other scripts where this check is necessary.

    if [ -n "${EXTRA_LIBS}" ]; then
      echo "Classpath will be enriched with these external jars : ${EXTRA_LIBS}"
    fi

    Copy link

    qodo-merge-pro bot commented Apr 7, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix inconsistent prefix handling

    The EXTRA_LIBS variable is being set with the --ext prefix in the elif
    condition, but this prefix should be added only once before passing to the Java
    command. This inconsistency could cause command-line parsing errors.

    Sessions/start-selenium-grid-sessions.sh [142-150]

     if [ "${SE_SESSIONS_MAP_EXTERNAL_DATASTORE}" = "true" ]; then
       echo "External datastore for sessions map is enabled"
       EXTERNAL_JARS=$(</external_jars/.classpath_session_map.txt)
       if [ -n "${EXTRA_LIBS}" ] && [ -n "${EXTERNAL_JARS}" ]; then
         EXTRA_LIBS="${EXTRA_LIBS}:${EXTERNAL_JARS}"
       elif [ -z "${EXTRA_LIBS}" ] && [ -n "${EXTERNAL_JARS}" ]; then
    -    EXTRA_LIBS="--ext ${EXTERNAL_JARS}"
    +    EXTRA_LIBS="${EXTERNAL_JARS}"
       fi
     fi
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion correctly identifies a critical inconsistency in how the --ext prefix is handled in the Sessions script compared to other scripts. This could cause command-line parsing errors as the prefix would be duplicated when EXTRA_LIBS is used later. The fix ensures consistent behavior across all scripts.

    Medium
    • More

    @VietND96
    Copy link
    Member

    VietND96 commented Apr 7, 2025

    @Trigtrig, can you review this once?

    @VietND96 VietND96 merged commit 5e7ebb2 into SeleniumHQ:trunk Apr 7, 2025
    24 of 27 checks passed
    @Trigtrig
    Copy link
    Contributor Author

    Trigtrig commented Apr 7, 2025

    @VietND96 Looks good to me 👍🏼

    @Trigtrig
    Copy link
    Contributor Author

    Trigtrig commented Apr 7, 2025

    Ah, one minute too late. Thanks for merging!

    @Trigtrig Trigtrig deleted the extra-libs branch April 7, 2025 11:25
    @VietND96
    Copy link
    Member

    VietND96 commented Apr 7, 2025

    Thanks for your feedback. Since I moved fast to deploy new images soon 😄

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

    Successfully merging this pull request may close these issues.

    [🐛 Bug]: Event Bus container unable to use telemetry Java Agents
    2 participants