Example #1
0
  /** TODO: revisit where/how to expose this. This is an experiment. */
  public void dynamicLoad(File arc)
      throws IOException, InterruptedException, RestartRequiredException {
    LOGGER.info("Attempting to dynamic load " + arc);
    final PluginWrapper p = strategy.createPluginWrapper(arc);
    String sn = p.getShortName();
    if (getPlugin(sn) != null)
      throw new RestartRequiredException(
          Messages._PluginManager_PluginIsAlreadyInstalled_RestartRequired(sn));

    if (p.supportsDynamicLoad() == YesNoMaybe.NO)
      throw new RestartRequiredException(
          Messages._PluginManager_PluginDoesntSupportDynamicLoad_RestartRequired(sn));

    // there's no need to do cyclic dependency check, because we are deploying one at a time,
    // so existing plugins can't be depending on this newly deployed one.

    plugins.add(p);
    activePlugins.add(p);

    try {
      p.resolvePluginDependencies();
      strategy.load(p);

      Jenkins.getInstance().refreshExtensions();

      p.getPlugin().postInitialize();
    } catch (Exception e) {
      failedPlugins.add(new FailedPlugin(sn, e));
      activePlugins.remove(p);
      plugins.remove(p);
      throw new IOException("Failed to install " + sn + " plugin", e);
    }

    // run initializers in the added plugin
    Reactor r = new Reactor(InitMilestone.ordering());
    r.addAll(
        new InitializerFinder(p.classLoader) {
          @Override
          protected boolean filter(Method e) {
            return e.getDeclaringClass().getClassLoader() != p.classLoader || super.filter(e);
          }
        }.discoverTasks(r));
    try {
      new InitReactorRunner().run(r);
    } catch (ReactorException e) {
      throw new IOException("Failed to initialize " + sn + " plugin", e);
    }
    LOGGER.info("Plugin " + sn + " dynamically installed");
  }