use of com.google.gerrit.pgm.init.api.InitStep in project gerrit by GerritCodeReview.
the class InitPluginStepsLoader method loadInitStep.
private InitStep loadInitStep(Path jar) {
try {
URLClassLoader pluginLoader = URLClassLoader.newInstance(new URL[] { jar.toUri().toURL() }, InitPluginStepsLoader.class.getClassLoader());
try (JarFile jarFile = new JarFile(jar.toFile())) {
Attributes jarFileAttributes = jarFile.getManifest().getMainAttributes();
String initClassName = jarFileAttributes.getValue("Gerrit-InitStep");
if (initClassName == null) {
return null;
}
@SuppressWarnings("unchecked") Class<? extends InitStep> initStepClass = (Class<? extends InitStep>) pluginLoader.loadClass(initClassName);
return getPluginInjector(jar).getInstance(initStepClass);
} catch (ClassCastException e) {
ui.message("WARN: InitStep from plugin %s does not implement %s (Exception: %s)\n", jar.getFileName(), InitStep.class.getName(), e.getMessage());
return null;
} catch (NoClassDefFoundError e) {
ui.message("WARN: Failed to run InitStep from plugin %s (Missing class: %s)\n", jar.getFileName(), e.getMessage());
return null;
}
} catch (Exception e) {
ui.message("WARN: Cannot load and get plugin init step for %s (Exception: %s)\n", jar, e.getMessage());
return null;
}
}
Aggregations