|
@@ -27,8 +27,7 @@ import org.slf4j.LoggerFactory;
|
|
|
*/
|
|
|
public class ExtensionLoader<T> {
|
|
|
|
|
|
- private static final Logger logger = LoggerFactory
|
|
|
- .getLogger(ExtensionLoader.class);
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(ExtensionLoader.class);
|
|
|
|
|
|
private static final String SERVICES_DIRECTORY = "META-INF/services/";
|
|
|
|
|
@@ -36,8 +35,7 @@ public class ExtensionLoader<T> {
|
|
|
|
|
|
private static final String DEFAULT_CLASSLOADER_POLICY = "internal";
|
|
|
|
|
|
- private static final Pattern NAME_SEPARATOR = Pattern
|
|
|
- .compile("\\s*[,]+\\s*");
|
|
|
+ private static final Pattern NAME_SEPARATOR = Pattern.compile("\\s*[,]+\\s*");
|
|
|
|
|
|
private static final ConcurrentMap<Class<?>, ExtensionLoader<?>> EXTENSION_LOADERS = new ConcurrentHashMap<>();
|
|
|
|
|
@@ -173,8 +171,7 @@ public class ExtensionLoader<T> {
|
|
|
return instance;
|
|
|
} catch (Throwable t) {
|
|
|
throw new IllegalStateException("Extension instance(name: " + name + ", class: " + type
|
|
|
- + ") could not be instantiated: " + t.getMessage(),
|
|
|
- t);
|
|
|
+ + ") could not be instantiated: " + t.getMessage(), t);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -194,8 +191,7 @@ public class ExtensionLoader<T> {
|
|
|
return instance;
|
|
|
} catch (Throwable t) {
|
|
|
throw new IllegalStateException("Extension instance(name: " + name + ", class: " + type
|
|
|
- + ") could not be instantiated: " + t.getMessage(),
|
|
|
- t);
|
|
|
+ + ") could not be instantiated: " + t.getMessage(), t);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -334,10 +330,12 @@ public class ExtensionLoader<T> {
|
|
|
// Class.forName(line, true,
|
|
|
// classLoader);
|
|
|
if (!type.isAssignableFrom(clazz)) {
|
|
|
- throw new IllegalStateException(
|
|
|
- "Error when load extension class(interface: " + type
|
|
|
- + ", class line: " + clazz.getName()
|
|
|
- + "), class " + clazz.getName()
|
|
|
+ throw new IllegalStateException("Error when load extension class(interface: "
|
|
|
+ + type
|
|
|
+ + ", class line: "
|
|
|
+ + clazz.getName()
|
|
|
+ + "), class "
|
|
|
+ + clazz.getName()
|
|
|
+ "is not subtype of interface.");
|
|
|
} else {
|
|
|
try {
|
|
@@ -355,9 +353,9 @@ public class ExtensionLoader<T> {
|
|
|
extensionClasses.put(n, clazz);
|
|
|
} else if (c != clazz) {
|
|
|
cachedNames.remove(clazz);
|
|
|
- throw new IllegalStateException(
|
|
|
- "Duplicate extension " + type.getName() + " name "
|
|
|
- + n + " on "
|
|
|
+ throw new IllegalStateException("Duplicate extension "
|
|
|
+ + type.getName()
|
|
|
+ + " name " + n + " on "
|
|
|
+ c.getName() + " and "
|
|
|
+ clazz.getName());
|
|
|
}
|
|
@@ -367,9 +365,12 @@ public class ExtensionLoader<T> {
|
|
|
}
|
|
|
}
|
|
|
} catch (Throwable t) {
|
|
|
- IllegalStateException e = new IllegalStateException(
|
|
|
- "Failed to load extension class(interface: " + type + ", class line: "
|
|
|
- + line + ") in " + url
|
|
|
+ IllegalStateException e = new IllegalStateException("Failed to load extension class(interface: "
|
|
|
+ + type
|
|
|
+ + ", class line: "
|
|
|
+ + line
|
|
|
+ + ") in "
|
|
|
+ + url
|
|
|
+ ", cause: "
|
|
|
+ t.getMessage(),
|
|
|
t);
|
|
@@ -384,18 +385,17 @@ public class ExtensionLoader<T> {
|
|
|
}
|
|
|
} catch (Throwable t) {
|
|
|
logger.error("Exception when load extension class(interface: " + type + ", class file: " + url
|
|
|
- + ") in " + url,
|
|
|
- t);
|
|
|
+ + ") in " + url, t);
|
|
|
}
|
|
|
} // end of while urls
|
|
|
}
|
|
|
} catch (Throwable t) {
|
|
|
- logger.error(
|
|
|
- "Exception when load extension class(interface: " + type + ", description file: " + fileName + ").",
|
|
|
- t);
|
|
|
+ logger.error("Exception when load extension class(interface: " + type + ", description file: " + fileName
|
|
|
+ + ").", t);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressWarnings("unused")
|
|
|
private static ClassLoader findClassLoader() {
|
|
|
return ExtensionLoader.class.getClassLoader();
|
|
|
}
|