diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginException.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginException.java index 1de6079..caa194a 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginException.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginException.java @@ -15,6 +15,8 @@ */ package ro.fortsoft.pf4j; +import ro.fortsoft.pf4j.util.StringUtils; + /** * An exception used to indicate that a plugin problem occurred. * @@ -40,4 +42,12 @@ public class PluginException extends Exception { super(message, cause); } + public PluginException(Throwable cause, String message, Object... args) { + super(StringUtils.format(message, args), cause); + } + + public PluginException(String message, Object... args) { + super(StringUtils.format(message, args)); + } + } diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/util/StringUtils.java b/pf4j/src/main/java/ro/fortsoft/pf4j/util/StringUtils.java index 6096086..62afecc 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/util/StringUtils.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/util/StringUtils.java @@ -28,4 +28,13 @@ public class StringUtils { return !isEmpty(str); } + /** + * Format the string. Replace "{}" with %s and format the string using {@link String#format(String, Object...)}. + */ + public static String format(String str, Object... args) { + str = str.replaceAll("\\{}", "%s"); + + return String.format(str, args); + } + }