Skip to content

Commit

Permalink
Miscellaneous code cleanup (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Sep 30, 2024
1 parent 0540708 commit d95d0e2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
21 changes: 19 additions & 2 deletions src/main/java/com/cloudbees/sdk/extensibility/ExtensionFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Class>())) {
for (Class ext : listExtensionPoint(c, new HashSet<>())) {
bind(c, ext);
}
}
Expand Down Expand Up @@ -82,11 +84,26 @@ protected <T> ExtensionLoaderModule<T> createLoaderModule(Class<T> 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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import com.google.inject.Binder;
import com.google.inject.Injector;
import com.google.inject.Module;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.InvocationTargetException;

/**
* Marks {@link Module}s to be loaded when the world is assembled.
Expand Down Expand Up @@ -46,11 +49,26 @@ class Loader extends ExtensionLoaderModule<ExtensionModule> {
@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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public void run() {

/**
* Run from the web interface.
*
* @throws Exception
*/
public void doRun() throws Exception {
if (inProgress.compareAndSet(false, true)) {
Expand Down

0 comments on commit d95d0e2

Please sign in to comment.