Skip to content

Commit 946036d

Browse files
committed
Use Path instead of a File for plugin.dir
1 parent 7950d8e commit 946036d

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

core/trino-main/src/main/java/io/trino/server/ServerPluginsProvider.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
import com.google.inject.Inject;
1717
import io.trino.server.PluginManager.PluginsProvider;
1818

19-
import java.io.File;
2019
import java.io.IOException;
2120
import java.io.UncheckedIOException;
2221
import java.net.MalformedURLException;
2322
import java.net.URL;
2423
import java.nio.file.DirectoryStream;
24+
import java.nio.file.Files;
2525
import java.nio.file.Path;
2626
import java.util.List;
2727
import java.util.concurrent.Callable;
@@ -36,7 +36,7 @@
3636
public class ServerPluginsProvider
3737
implements PluginsProvider
3838
{
39-
private final List<File> installedPluginsDirs;
39+
private final List<Path> installedPluginsDirs;
4040
private final Executor executor;
4141

4242
@Inject
@@ -53,28 +53,28 @@ public void loadPlugins(Loader loader, ClassLoaderFactory createClassLoader)
5353
executor,
5454
installedPluginsDirs.stream()
5555
.flatMap(installedPluginsDir -> listFiles(installedPluginsDir).stream())
56-
.filter(File::isDirectory)
57-
.map(file -> (Callable<?>) () -> {
58-
loader.load(file.getAbsolutePath(), () ->
59-
createClassLoader.create(file.getName(), buildClassPath(file)));
56+
.filter(Files::isDirectory)
57+
.map(Path::toAbsolutePath)
58+
.map(path -> (Callable<?>) () -> {
59+
String name = path.getFileName().toString();
60+
loader.load(name, () -> createClassLoader.create(name, buildClassPath(path)));
6061
return null;
6162
})
6263
.collect(toImmutableList()));
6364
}
6465

65-
private static List<URL> buildClassPath(File path)
66+
private static List<URL> buildClassPath(Path path)
6667
{
6768
return listFiles(path).stream()
6869
.map(ServerPluginsProvider::fileToUrl)
6970
.collect(toImmutableList());
7071
}
7172

72-
private static List<File> listFiles(File path)
73+
private static List<Path> listFiles(Path path)
7374
{
7475
try {
75-
try (DirectoryStream<Path> directoryStream = newDirectoryStream(path.toPath())) {
76+
try (DirectoryStream<Path> directoryStream = newDirectoryStream(path)) {
7677
return stream(directoryStream)
77-
.map(Path::toFile)
7878
.sorted()
7979
.collect(toImmutableList());
8080
}
@@ -84,10 +84,10 @@ private static List<File> listFiles(File path)
8484
}
8585
}
8686

87-
private static URL fileToUrl(File file)
87+
private static URL fileToUrl(Path file)
8888
{
8989
try {
90-
return file.toURI().toURL();
90+
return file.toUri().toURL();
9191
}
9292
catch (MalformedURLException e) {
9393
throw new UncheckedIOException(e);

core/trino-main/src/main/java/io/trino/server/ServerPluginsProviderConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@
1818
import io.airlift.configuration.ConfigDescription;
1919
import io.airlift.configuration.validation.FileExists;
2020

21-
import java.io.File;
21+
import java.nio.file.Path;
2222
import java.util.List;
2323

2424
public class ServerPluginsProviderConfig
2525
{
26-
private List<File> installedPluginsDirs = ImmutableList.of(new File("plugin"));
26+
private List<Path> installedPluginsDirs = ImmutableList.of(Path.of("plugin"));
2727

28-
public List<@FileExists File> getInstalledPluginsDirs()
28+
public List<@FileExists Path> getInstalledPluginsDirs()
2929
{
3030
return installedPluginsDirs;
3131
}
3232

3333
@Config("plugin.dir")
3434
@ConfigDescription("Comma separated list of root directories where the plugins are located")
35-
public ServerPluginsProviderConfig setInstalledPluginsDirs(List<File> installedPluginsDirs)
35+
public ServerPluginsProviderConfig setInstalledPluginsDirs(List<Path> installedPluginsDirs)
3636
{
3737
this.installedPluginsDirs = ImmutableList.copyOf(installedPluginsDirs);
3838
return this;

core/trino-main/src/test/java/io/trino/server/TestServerPluginsProviderConfig.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.junit.jupiter.api.Test;
1818
import org.junit.jupiter.api.io.TempDir;
1919

20-
import java.io.File;
2120
import java.nio.file.Path;
2221
import java.util.List;
2322
import java.util.Map;
@@ -32,7 +31,7 @@ public class TestServerPluginsProviderConfig
3231
public void testDefaults()
3332
{
3433
assertRecordedDefaults(recordDefaults(ServerPluginsProviderConfig.class)
35-
.setInstalledPluginsDirs(List.of(new File("plugin"))));
34+
.setInstalledPluginsDirs(List.of(Path.of("plugin"))));
3635
}
3736

3837
@Test
@@ -41,7 +40,7 @@ public void testExplicitPropertyMappings(@TempDir Path tempDir)
4140
Map<String, String> properties = ImmutableMap.of("plugin.dir", tempDir.toString());
4241

4342
ServerPluginsProviderConfig expected = new ServerPluginsProviderConfig()
44-
.setInstalledPluginsDirs(List.of(tempDir.toFile()));
43+
.setInstalledPluginsDirs(List.of(tempDir));
4544

4645
assertFullMapping(properties, expected);
4746
}
@@ -52,7 +51,7 @@ public void testExplicitPropertyMappingMultiDir(@TempDir Path tempDir1, @TempDir
5251
Map<String, String> properties = ImmutableMap.of("plugin.dir", tempDir1.toString() + "," + tempDir2.toString());
5352

5453
ServerPluginsProviderConfig expected = new ServerPluginsProviderConfig()
55-
.setInstalledPluginsDirs(List.of(tempDir1.toFile(), tempDir2.toFile()));
54+
.setInstalledPluginsDirs(List.of(tempDir1, tempDir2));
5655

5756
assertFullMapping(properties, expected);
5857
}

testing/trino-plugin-reader/src/main/java/io/trino/server/PluginLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import io.trino.spi.Plugin;
1818
import io.trino.spi.classloader.ThreadContextClassLoader;
1919

20-
import java.io.File;
20+
import java.nio.file.Path;
2121
import java.util.List;
2222
import java.util.ServiceLoader;
2323
import java.util.function.Supplier;
@@ -67,7 +67,7 @@ public static void printPluginFeatures(Plugin plugin)
6767
plugin.getExchangeManagerFactories().forEach(factory -> System.out.println(EXCHANGE_MANAGER + factory.getName()));
6868
}
6969

70-
public static List<Plugin> loadPlugins(List<File> path)
70+
public static List<Plugin> loadPlugins(List<Path> path)
7171
{
7272
ServerPluginsProviderConfig config = new ServerPluginsProviderConfig();
7373
config.setInstalledPluginsDirs(path);

testing/trino-plugin-reader/src/main/java/io/trino/server/PluginReader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.File;
2323
import java.io.IOException;
2424
import java.nio.file.Files;
25+
import java.nio.file.Path;
2526
import java.util.List;
2627
import java.util.Map;
2728
import java.util.Optional;
@@ -46,7 +47,7 @@ public class PluginReader
4647
private Optional<File> impactedModulesFile;
4748

4849
@Option(names = {"-p", "--plugin-dir"}, description = "Trino plugin directories", arity = "1..*")
49-
private List<File> pluginDirs = List.of(new File("plugin"));
50+
private List<Path> pluginDirs = List.of(Path.of("plugin"));
5051

5152
@Option(names = {"-r", "--root-pom"}, description = "Trino root module pom.xml")
5253
private File rootPom = new File("pom.xml");

0 commit comments

Comments
 (0)