Skip to content

Commit

Permalink
🐛 Fix startup error when the plugins directory includes spaces
Browse files Browse the repository at this point in the history
(cherry picked from commit 4bfdad5)
  • Loading branch information
ujibang committed Oct 3, 2023
1 parent ef6286a commit 5a0cbe3
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions core/src/main/java/org/restheart/plugins/PluginsScanner.java
Original file line number Diff line number Diff line change
@@ -27,8 +27,11 @@
import io.github.classgraph.ScanResult;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -48,6 +51,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import graphql.Assert;

/**
* this class is configured to be initialized at build time by native-image
* note: we cannot use logging in this class, otherwise native-image will fail
@@ -322,7 +327,7 @@ private static void removeRefToScanResult(AnnotationEnumValue obj) {
}

static class RuntimeClassGraph {
private static final Logger LOGGER = LoggerFactory.getLogger(PluginsFactory.class);
private static final Logger LOGGER = LoggerFactory.getLogger(PluginsScanner.class);

private ClassGraph classGraph;

@@ -376,11 +381,18 @@ private Path getPluginsDirectory() {
// relative to the jar (also working when running from classes)
var location = PluginsFactory.class.getProtectionDomain().getCodeSource().getLocation();

var locationFile = new File(location.getPath());
try {
var decodedLocation = URLDecoder.decode(location.getPath(), StandardCharsets.UTF_8.toString());

var locationFile = new File(decodedLocation);

pluginsDir = locationFile.getParent() + File.separator + pluginsDir;
pluginsDir = locationFile.getParent() + File.separator + pluginsDir;

return FileSystems.getDefault().getPath(pluginsDir);
return FileSystems.getDefault().getPath(pluginsDir);
} catch(UnsupportedEncodingException uee) {
Assert.assertShouldNeverHappen();
throw new RuntimeException(uee);
}
}
}

@@ -411,7 +423,7 @@ private URL[] findPluginsJars(Path pluginsDirectory) {
}

urls.add(jar);
LOGGER.info("Found plugin jar {}", jar);
LOGGER.info("Found plugin jar {}", URLDecoder.decode(jar.getPath(), StandardCharsets.UTF_8.toString()));
}
} catch (IOException ex) {
LOGGER.error("Cannot read jars in plugins directory {}", Bootstrapper.getConfiguration().coreModule().pluginsDirectory(), ex.getMessage());

0 comments on commit 5a0cbe3

Please sign in to comment.