Exemplo n.º 1
0
  /** Performs the installation of the plugins. */
  public void doInstall(StaplerRequest req, StaplerResponse rsp)
      throws IOException, ServletException {
    boolean dynamicLoad = req.getParameter("dynamicLoad") != null;

    Enumeration<String> en = req.getParameterNames();
    while (en.hasMoreElements()) {
      String n = en.nextElement();
      if (n.startsWith("plugin.")) {
        n = n.substring(7);
        if (n.indexOf(".") > 0) {
          String[] pluginInfo = n.split("\\.");
          UpdateSite.Plugin p =
              Jenkins.getInstance()
                  .getUpdateCenter()
                  .getById(pluginInfo[1])
                  .getPlugin(pluginInfo[0]);
          if (p == null) throw new Failure("No such plugin: " + n);
          p.deploy(dynamicLoad);
        }
      }
    }
    rsp.sendRedirect("../updateCenter/");
  }
Exemplo n.º 2
0
 /**
  * Prepares plugins for some expected XML configuration. If the configuration (typically a job’s
  * {@code config.xml}) needs some plugins to be installed (or updated), those jobs will be
  * triggered. Plugins are dynamically loaded whenever possible. Requires {@link
  * Jenkins#ADMINISTER}.
  *
  * @param configXml configuration that might be uploaded
  * @return an empty list if all is well, else a list of submitted jobs which must be completed
  *     before this configuration can be fully read
  * @throws IOException if loading or parsing the configuration failed
  * @see ItemGroupMixIn#createProjectFromXML
  * @see AbstractItem#updateByXml(javax.xml.transform.Source)
  * @see XStream2
  * @see hudson.model.UpdateSite.Plugin#deploy(boolean)
  * @see PluginWrapper#supportsDynamicLoad
  * @see hudson.model.UpdateCenter.DownloadJob.SuccessButRequiresRestart
  * @since 1.483
  */
 public List<Future<UpdateCenter.UpdateCenterJob>> prevalidateConfig(InputStream configXml)
     throws IOException {
   Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
   List<Future<UpdateCenter.UpdateCenterJob>> jobs =
       new ArrayList<Future<UpdateCenter.UpdateCenterJob>>();
   UpdateCenter uc = Jenkins.getInstance().getUpdateCenter();
   // TODO call uc.updateAllSites() when available? perhaps not, since we should not block on
   // network here
   for (Map.Entry<String, VersionNumber> requestedPlugin :
       parseRequestedPlugins(configXml).entrySet()) {
     PluginWrapper pw = getPlugin(requestedPlugin.getKey());
     if (pw == null) { // install new
       UpdateSite.Plugin toInstall = uc.getPlugin(requestedPlugin.getKey());
       if (toInstall == null) {
         LOGGER.log(WARNING, "No such plugin {0} to install", requestedPlugin.getKey());
         continue;
       }
       if (new VersionNumber(toInstall.version).compareTo(requestedPlugin.getValue()) < 0) {
         LOGGER.log(
             WARNING,
             "{0} can only be satisfied in @{1}",
             new Object[] {requestedPlugin, toInstall.version});
       }
       if (toInstall.isForNewerHudson()) {
         LOGGER.log(
             WARNING,
             "{0}@{1} was built for a newer Jenkins",
             new Object[] {toInstall.name, toInstall.version});
       }
       jobs.add(toInstall.deploy(true));
     } else if (pw.isOlderThan(requestedPlugin.getValue())) { // upgrade
       UpdateSite.Plugin toInstall = uc.getPlugin(requestedPlugin.getKey());
       if (toInstall == null) {
         LOGGER.log(WARNING, "No such plugin {0} to upgrade", requestedPlugin.getKey());
         continue;
       }
       if (!pw.isOlderThan(new VersionNumber(toInstall.version))) {
         LOGGER.log(
             WARNING,
             "{0}@{1} is no newer than what we already have",
             new Object[] {toInstall.name, toInstall.version});
         continue;
       }
       if (new VersionNumber(toInstall.version).compareTo(requestedPlugin.getValue()) < 0) {
         LOGGER.log(
             WARNING,
             "{0} can only be satisfied in @{1}",
             new Object[] {requestedPlugin, toInstall.version});
       }
       if (toInstall.isForNewerHudson()) {
         LOGGER.log(
             WARNING,
             "{0}@{1} was built for a newer Jenkins",
             new Object[] {toInstall.name, toInstall.version});
       }
       if (!toInstall.isCompatibleWithInstalledVersion()) {
         LOGGER.log(
             WARNING,
             "{0}@{1} is incompatible with the installed @{2}",
             new Object[] {toInstall.name, toInstall.version, pw.getVersion()});
       }
       jobs.add(
           toInstall.deploy(
               true)); // dynamicLoad=true => sure to throw RestartRequiredException, but at least
                       // message is nicer
     } // else already good
   }
   return jobs;
 }
Exemplo n.º 3
0
 /**
  * If the plugin has {@link #getUpdateInfo() an update}, returns the {@link
  * hudson.model.UpdateSite.Plugin} object.
  *
  * @return This method may return null &mdash; for example, the user may have installed a plugin
  *     locally developed.
  */
 public UpdateSite.Plugin getUpdateInfo() {
   UpdateCenter uc = Jenkins.getInstance().getUpdateCenter();
   UpdateSite.Plugin p = uc.getPlugin(getShortName());
   if (p != null && p.isNewerThan(getVersion())) return p;
   return null;
 }