Skip to content

Commit

Permalink
Enhance DevelopmentPluginsProvider to handle plugin directories
Browse files Browse the repository at this point in the history
  • Loading branch information
xkrogen authored and losipiuk committed Nov 14, 2024
1 parent 3d1aac6 commit 2909782
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ IntelliJ, using `$MODULE_DIR$` accomplishes this automatically.
If `VM options` doesn't exist in the dialog, you need to select `Modify options`
and enable `Add VM options`.

To adjust which plugins are enabled for the development server, adjust the value of
`plugin.bundles` in `config.properties`. Each entry in this list must represent a plugin
specified by one of the following options:
* A path to a `pom.xml` or `*.pom` file describing a Maven project that produces a plugin.
* Maven coordinates, in the form `<groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>`. The plugin will be loaded via Maven and therefore must be available in your local repository or a remote repository.
* A path to a plugin directory containing JAR files. See [Deploying a custom plugin](https://trino.io/docs/current/develop/spi-overview.html#deploying-a-custom-plugin) for more details.

If you want to use a plugin in a catalog, you must add a corresponding
`<catalog_name>.properties` file to `testing/trino-server-dev/etc/catalog`.

### Running the CLI

Start the CLI to connect to the server and run SQL queries:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.function.Function;
import java.util.stream.Stream;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static io.trino.server.PluginDiscovery.discoverPlugins;
Expand Down Expand Up @@ -83,7 +87,12 @@ private PluginClassLoader doBuildClassLoader(String plugin, Function<List<URL>,
if (file.isFile() && (file.getName().equals("pom.xml") || file.getName().endsWith(".pom"))) {
return buildClassLoaderFromPom(file, classLoaderFactory);
}
return buildClassLoaderFromCoordinates(plugin, classLoaderFactory);
else if (file.isDirectory()) {
return buildClassLoaderFromDirectory(file, classLoaderFactory);
}
else {
return buildClassLoaderFromCoordinates(plugin, classLoaderFactory);
}
}

private PluginClassLoader buildClassLoaderFromPom(File pomFile, Function<List<URL>, PluginClassLoader> classLoaderFactory)
Expand All @@ -103,6 +112,24 @@ private PluginClassLoader buildClassLoaderFromPom(File pomFile, Function<List<UR
return classLoader;
}

private static PluginClassLoader buildClassLoaderFromDirectory(File pluginDirectory, Function<List<URL>, PluginClassLoader> classLoaderFactory)
throws IOException
{
Function<Path, URL> pathToUrl = path -> {
try {
return path.toUri().toURL();
}
catch (MalformedURLException e) {
throw new UncheckedIOException(e);
}
};
List<URL> jars;
try (Stream<Path> paths = Files.list(pluginDirectory.toPath())) {
jars = paths.map(pathToUrl).collect(toImmutableList());
}
return classLoaderFactory.apply(jars);
}

private PluginClassLoader buildClassLoaderFromCoordinates(String coordinates, Function<List<URL>, PluginClassLoader> classLoaderFactory)
throws IOException
{
Expand Down

0 comments on commit 2909782

Please sign in to comment.