diff --git a/src/main/java/com/cloudbees/sdk/extensibility/ExtensionFinder.java b/src/main/java/com/cloudbees/sdk/extensibility/ExtensionFinder.java index 1333a19..30a4beb 100644 --- a/src/main/java/com/cloudbees/sdk/extensibility/ExtensionFinder.java +++ b/src/main/java/com/cloudbees/sdk/extensibility/ExtensionFinder.java @@ -19,7 +19,9 @@ import com.google.inject.AbstractModule; import com.google.inject.Module; import java.io.IOException; +import java.io.UncheckedIOException; import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationTargetException; import java.util.HashSet; import java.util.Set; import java.util.logging.Logger; @@ -53,7 +55,7 @@ protected void configure() { } for (Class c : Index.list(a.asSubclass(Annotation.class), cl, Class.class)) { if (seen.add(c)) { // ... so that we don't bind the same class twice - for (Class ext : listExtensionPoint(c, new HashSet())) { + for (Class ext : listExtensionPoint(c, new HashSet<>())) { bind(c, ext); } } @@ -82,11 +84,26 @@ protected ExtensionLoaderModule createLoaderModule(Class extensionPoin if (ep != null) { if (ep.loader() != ExtensionLoaderModule.Default.class) { try { - return ep.loader().newInstance(); + return ep.loader().getDeclaredConstructor().newInstance(); } catch (InstantiationException e) { throw (Error) new InstantiationError().initCause(e); } catch (IllegalAccessException e) { throw (Error) new IllegalAccessError().initCause(e); + } catch (NoSuchMethodException e) { + throw (Error) new NoSuchMethodError().initCause(e); + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } else if (t instanceof IOException) { + throw new UncheckedIOException((IOException) t); + } else if (t instanceof Exception) { + throw new RuntimeException(t); + } else if (t instanceof Error) { + throw (Error) t; + } else { + throw new Error(e); + } } } } diff --git a/src/main/java/com/cloudbees/sdk/extensibility/ExtensionModule.java b/src/main/java/com/cloudbees/sdk/extensibility/ExtensionModule.java index 7a89d7f..c58e428 100644 --- a/src/main/java/com/cloudbees/sdk/extensibility/ExtensionModule.java +++ b/src/main/java/com/cloudbees/sdk/extensibility/ExtensionModule.java @@ -19,6 +19,8 @@ import com.google.inject.Binder; import com.google.inject.Injector; import com.google.inject.Module; +import java.io.UncheckedIOException; +import java.lang.reflect.InvocationTargetException; /** * Marks {@link Module}s to be loaded when the world is assembled. @@ -46,11 +48,26 @@ class Loader extends ExtensionLoaderModule { @Override protected void configure() { try { - install(impl.newInstance()); + install(impl.getDeclaredConstructor().newInstance()); } catch (InstantiationException e) { throw (Error) new InstantiationError().initCause(e); } catch (IllegalAccessException e) { throw (Error) new IllegalAccessError().initCause(e); + } catch (NoSuchMethodException e) { + throw (Error) new NoSuchMethodError().initCause(e); + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } else if (t instanceof IOException) { + throw new UncheckedIOException((IOException) t); + } else if (t instanceof Exception) { + throw new RuntimeException(t); + } else if (t instanceof Error) { + throw (Error) t; + } else { + throw new Error(e); + } } } } diff --git a/src/main/java/com/cloudbees/sdk/extensibility/lifecycle/PeriodicService.java b/src/main/java/com/cloudbees/sdk/extensibility/lifecycle/PeriodicService.java index 1ff19b8..e4662bc 100644 --- a/src/main/java/com/cloudbees/sdk/extensibility/lifecycle/PeriodicService.java +++ b/src/main/java/com/cloudbees/sdk/extensibility/lifecycle/PeriodicService.java @@ -55,8 +55,6 @@ public void run() { /** * Run from the web interface. - * - * @throws Exception */ public void doRun() throws Exception { if (inProgress.compareAndSet(false, true)) {