aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDecebal Suiu <decebal.suiu@gmail.com>2022-01-24 00:42:20 +0200
committerDecebal Suiu <decebal.suiu@gmail.com>2022-01-24 00:42:20 +0200
commit00a461f0a7972478a5e88ebdc097924f09111d50 (patch)
tree8dc04bae72c0b75cf327f9da53714e23aa8e356e
parent7b634117c7f41d781e89c854539ea407f5cecb04 (diff)
downloadpf4j-00a461f0a7972478a5e88ebdc097924f09111d50.tar.gz
pf4j-00a461f0a7972478a5e88ebdc097924f09111d50.zip
Optional for add path/file in PluginClassLoader
-rw-r--r--pf4j/src/main/java/org/pf4j/PluginClassLoader.java39
1 files changed, 35 insertions, 4 deletions
diff --git a/pf4j/src/main/java/org/pf4j/PluginClassLoader.java b/pf4j/src/main/java/org/pf4j/PluginClassLoader.java
index 0106acb..b69c5dc 100644
--- a/pf4j/src/main/java/org/pf4j/PluginClassLoader.java
+++ b/pf4j/src/main/java/org/pf4j/PluginClassLoader.java
@@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
+import java.io.UncheckedIOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Path;
@@ -80,21 +81,51 @@ public class PluginClassLoader extends URLClassLoader {
super.addURL(url);
}
+ /**
+ * Shortcut for {@code addPath(path, true)}.
+ */
public void addPath(Path path) {
+ addPath(path, true);
+ }
+
+ /**
+ * Add a path.
+ * If {@code optional} is {@code true} then if something is wrong a warning message is added to the log.
+ * Otherwise, {@link UncheckedIOException} is thrown.
+ */
+ public void addPath(Path path, boolean optional) {
try {
addURL(path.toUri().toURL());
} catch (IOException e) {
-// throw new UncheckedIOException("Cannot add path '" + path + "'", e);
- log.warn("Cannot add path '" + path + "'", e);
+ if (optional) {
+ log.warn("Cannot add path '" + path + "'", e);
+ } else {
+ throw new UncheckedIOException("Cannot add path '" + path + "'", e);
+ }
}
}
+ /**
+ * Shortcut for {@code addFile(file, true)}.
+ */
public void addFile(File file) {
+ addFile(file, true);
+ }
+
+ /**
+ * Add a file.
+ * If {@code optional} is {@code true} then if something is wrong a warning message is added to the log.
+ * Otherwise, {@link UncheckedIOException} is thrown.
+ */
+ public void addFile(File file, boolean optional) {
try {
addURL(file.getCanonicalFile().toURI().toURL());
} catch (IOException e) {
-// throw new UncheckedIOException("Cannot add file '" + file + "'", e);
- log.warn("Cannot add file '" + file + "'", e);
+ if (optional) {
+ log.warn("Cannot add file '" + file + "'", e);
+ } else {
+ throw new UncheckedIOException("Cannot add file '" + file + "'", e);
+ }
}
}