Skip to content

Conversation

wendigo
Copy link
Contributor

@wendigo wendigo commented Oct 9, 2025

Just a cleanup

Description

Additional context and related issues

Release notes

(x) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

## Section
* Fix some things. ({issue}`issuenumber`)

Summary by Sourcery

Refactor plugin directory handling to use java.nio.file.Path instead of java.io.File across core and testing modules.

Enhancements:

  • Use Path in ServerPluginsProvider and update directory listing, classpath building, and URL conversion methods accordingly
  • Change ServerPluginsProviderConfig to accept Path lists for installedPluginsDirs instead of File
  • Adjust PluginLoader and PluginReader to use Path for plugin directory inputs

Tests:

  • Update TestServerPluginsProviderConfig to assert Path-based defaults and explicit plugin directory mappings

@cla-bot cla-bot bot added the cla-signed label Oct 9, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 9, 2025

Reviewer's Guide

Replace legacy File usage with java.nio.file.Path for plugin directory handling, refactoring loading logic to leverage NIO APIs and updating tests accordingly.

Class diagram for updated plugin directory handling

classDiagram
    class ServerPluginsProviderConfig {
        - List<Path> installedPluginsDirs
        + List<Path> getInstalledPluginsDirs()
        + ServerPluginsProviderConfig setInstalledPluginsDirs(List<Path> installedPluginsDirs)
    }
    class ServerPluginsProvider {
        - List<Path> installedPluginsDirs
        - Executor executor
        + void loadPlugins(Loader loader, ClassLoaderFactory createClassLoader)
        + static List<URL> buildClassPath(Path path)
        + static List<Path> listFiles(Path path)
        + static URL fileToUrl(Path file)
    }
    class PluginLoader {
        + static List<Plugin> loadPlugins(List<Path> path)
    }
    class PluginReader {
        - List<Path> pluginDirs
    }
    ServerPluginsProviderConfig --> ServerPluginsProvider : uses
    PluginLoader --> ServerPluginsProviderConfig : uses
    PluginReader --> PluginLoader : uses
Loading

File-Level Changes

Change Details Files
Migrate plugin directory type from File to Path in core provider and config
  • Change installedPluginsDirs field and getter/setter signatures to List
  • Update default initialization to use Path.of
  • Adjust @fileexists annotation to validate Path
  • Revise TestServerPluginsProviderConfig defaults and mappings to expect Path
core/trino-main/src/main/java/io/trino/server/ServerPluginsProvider.java
core/trino-main/src/main/java/io/trino/server/ServerPluginsProviderConfig.java
core/trino-main/src/test/java/io/trino/server/TestServerPluginsProviderConfig.java
Refactor plugin-loading workflow to use NIO Path APIs
  • Replace listFiles(File) with listFiles(Path) returning Path stream
  • Use Files::isDirectory instead of File::isDirectory
  • Stream Path entries via DirectoryStream
  • Map each Path to absolute path and extract file name for class loader
core/trino-main/src/main/java/io/trino/server/ServerPluginsProvider.java
Update classpath construction and URL conversion to accept Path
  • Change buildClassPath signature to accept Path
  • Remove File-to-URL conversion, use Path.toUri().toURL()
  • Drop obsolete Path.toFile() mapping
core/trino-main/src/main/java/io/trino/server/ServerPluginsProvider.java
Adjust testing utilities in plugin reader/loader to use Path
  • Change loadPlugins signature to List
  • Update PluginReader pluginDirs field to List with Path.of default
testing/trino-plugin-reader/src/main/java/io/trino/server/PluginLoader.java
testing/trino-plugin-reader/src/main/java/io/trino/server/PluginReader.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • ServerPluginsProvider now only passes the plugin name instead of its full path to loader.load—consider passing the absolute Path (or original Path) as the identifier to maintain the previous behavior and avoid name collisions.
  • PluginReader and PluginLoader still declare some File-based fields (rootPom, impactedModulesFile)—migrating these to Path would keep the API consistent across the plugin handling code.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- ServerPluginsProvider now only passes the plugin name instead of its full path to loader.load—consider passing the absolute Path (or original Path) as the identifier to maintain the previous behavior and avoid name collisions.
- PluginReader and PluginLoader still declare some File-based fields (rootPom, impactedModulesFile)—migrating these to Path would keep the API consistent across the plugin handling code.

## Individual Comments

### Comment 1
<location> `core/trino-main/src/main/java/io/trino/server/ServerPluginsProvider.java:56` </location>
<code_context>
-                        .map(file -> (Callable<?>) () -> {
-                            loader.load(file.getAbsolutePath(), () ->
-                                    createClassLoader.create(file.getName(), buildClassPath(file)));
+                        .filter(Files::isDirectory)
+                        .map(Path::toAbsolutePath)
+                        .map(path -> (Callable<?>) () -> {
</code_context>

<issue_to_address>
**issue (bug_risk):** Using Files::isDirectory may throw unchecked exceptions for inaccessible paths.

Handle potential exceptions from Files::isDirectory to prevent failures when accessing unreadable or restricted paths.
</issue_to_address>

### Comment 2
<location> `core/trino-main/src/main/java/io/trino/server/ServerPluginsProvider.java:87` </location>
<code_context>
     }

-    private static URL fileToUrl(File file)
+    private static URL fileToUrl(Path file)
     {
         try {
</code_context>

<issue_to_address>
**suggestion:** Renaming fileToUrl to pathToUrl would improve clarity.

The method parameter type has changed from File to Path, so updating the name to pathToUrl would better reflect its purpose.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

.map(file -> (Callable<?>) () -> {
loader.load(file.getAbsolutePath(), () ->
createClassLoader.create(file.getName(), buildClassPath(file)));
.filter(Files::isDirectory)
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Using Files::isDirectory may throw unchecked exceptions for inaccessible paths.

Handle potential exceptions from Files::isDirectory to prevent failures when accessing unreadable or restricted paths.

@wendigo wendigo merged commit 946036d into trinodb:master Oct 9, 2025
97 of 98 checks passed
@github-actions github-actions bot added this to the 478 milestone Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants