Returns latest install/upgrade job for the given plugin.
@return InstallationJob or null if not found
320129
public InstallationJob getJob(Plugin plugin) {
        List<UpdateCenterJob> jobList = getJobs();
        Collections.reverse(jobList);
        for (UpdateCenterJob job : jobList)
            if (job instanceof InstallationJob) {
                InstallationJob ij = (InstallationJob)job;
                if (ij.plugin.name.equals(plugin.name) && ij.plugin.sourceId.equals(plugin.sourceId))
                    return ij;
            }
        return null;
    }
178492
public static @Nonnull String getLastExecVersion() {
        File lastExecVersionFile = getLastExecVersionFile();
        if (lastExecVersionFile.exists()) {
            try {
                String version = FileUtils.readFileToString(lastExecVersionFile);
                // JENKINS-37438 blank will force the setup
                // wizard regardless of current state of the system
                if (StringUtils.isBlank(version)) {
                    return FORCE_NEW_INSTALL_VERSION.toString();
                }
                return version;
            } catch (IOException e) {
                LOGGER.log(SEVERE, "Unexpected Error. Unable to read " + lastExecVersionFile.getAbsolutePath(), e);
                LOGGER.log(WARNING, "Unable to determine the last running version (see error above). Treating this as a restart. No plugins will be updated.");
                return getCurrentExecVersion();
            }
        } else {
            // Backward compatibility. Use the last version stored in the top level config.xml.
            // Going to read the value directly from the config.xml file Vs hoping that the
            // Jenkins startup sequence has moved far enough along that it has loaded the
            // global config. It can't load the global config until well into the startup
            // sequence because the unmarshal requires numerous objects to be created e.g.
            // it requires the Plugin Manager. It happens too late and it's too risky to
            // change how it currently works.
            File configFile = getConfigFile();
            if (configFile.exists()) {
                try {
                    String lastVersion = XMLUtils.getValue("/hudson/version", configFile);
                    if (lastVersion.length() > 0) {
                        LOGGER.log(Level.FINE, "discovered serialized lastVersion {0}", lastVersion);
                        return lastVersion;
                    }
                } catch (Exception e) {
                    LOGGER.log(SEVERE, "Unexpected error reading global config.xml", e);
                }
            }
            return NEW_INSTALL_VERSION.toString();
        }
    }
628490
public function isVagrantPluginInstalled($plugin) {
    $installed = (bool) $this->executor->execute("vagrant plugin list | grep '$plugin'")
      ->interactive(FALSE)
      ->silent(TRUE)
      ->run()
      ->getMessage();

    return $installed;
  }
726722
public function getRequiredBy($plugin)
    {
        $requiredBy = [];
        $plugin = $this->getBundle($plugin);

        foreach ($this->getInstalledBundles() as $bundle) {
            $requirements = $bundle['instance']->getRequiredPlugins();
            if (in_array(get_class($plugin), $requirements)) {
                $requiredBy[] = get_class($bundle['instance']);
            }
        }

        return $requiredBy;
    }
264796
public static synchronized void persistInstallStatus(List<UpdateCenterJob> installingPlugins) {
        File installingPluginsFile = getInstallingPluginsFile();
	if(installingPlugins == null || installingPlugins.isEmpty()) {
		installingPluginsFile.delete();
		return;
	}
	LOGGER.fine("Writing install state to: " + installingPluginsFile.getAbsolutePath());
	Map<String,String> statuses = new HashMap<>();
	for(UpdateCenterJob j : installingPlugins) {
		if(j instanceof InstallationJob && j.getCorrelationId() != null) { // only include install jobs with a correlation id (directly selected)
			InstallationJob ij = (InstallationJob)j;
			InstallationStatus status = ij.status;
			String statusText = status.getType();
			if(status instanceof Installing) { // flag currently installing plugins as pending
				statusText = "Pending";
			}
			statuses.put(ij.plugin.name, statusText);
		}
	}
        try {
		String installingPluginXml = new XStream().toXML(statuses);
            FileUtils.write(installingPluginsFile, installingPluginXml);
        } catch (IOException e) {
            LOGGER.log(SEVERE, "Failed to save " + installingPluginsFile.getAbsolutePath(), e);
        }
    }
1107959
protected function _initJob()
    {
        $jobCode = $this->getRequest()->getParam('job_code', null);
        $job = Mage::getModel('aoe_scheduler/job')->load($jobCode);
        Mage::register('current_job_instance', $job);
        return $job;
    }
637309
public function getJobType() {
		$sourceObject = ExternalContent::getDataObjectFor($this->sourceObjectID);
		if (!$sourceObject) {
			$this->addMessage("ERROR: Source object $this->sourceObjectID cannot be found");
			return QueuedJob::QUEUED;
		}

		// go a couple levels deep and see how many items we're looking at
		if (!$this->includeChildren) {
			return QueuedJob::QUEUED;
		}

		$children = $sourceObject->stageChildren();
		if (!$children) {
			return QueuedJob::QUEUED;
		}
		$count = 1;

		foreach ($children as $child) {
			$count++;
			if ($count > 20) {
				$this->totalSteps = $count;
				return QueuedJob::QUEUED;
			}

			$subChildren = $child->stageChildren();
			if ($subChildren) {
				foreach ($subChildren as $sub) {
					$count++;
					if ($count > 20) {
						$this->totalSteps = $count;
						return QueuedJob::QUEUED;
					}
				}
			}
		}
		$this->totalSteps = $count;
		return QueuedJob::QUEUED;
	}
96828
public static function getMigrationVersion()
    {
        if (self::isInstallerAvailable()) {
            $migrations = scandir(DOCROOT . '/install/migrations');
            $migration_file = end($migrations);
            $migration_class = 'migration_' . str_replace('.', '', substr($migration_file, 0, -4));
            return call_user_func(array($migration_class, 'getVersion'));
        }

        return false;
    }
1117567
public IJobDetail build ()
  {

    final JobDetail job = new JobDetail ();

    job.setJobClass (m_aJobClass);
    job.setDescription (m_sDescription);
    if (m_aKey == null)
      m_aKey = new JobKey (Key.createUniqueName (null), null);
    job.setKey (m_aKey);
    job.setDurability (m_bDurability);
    job.setRequestsRecovery (m_bShouldRecover);

    if (!m_aJobDataMap.isEmpty ())
      job.setJobDataMap (m_aJobDataMap);

    return job;
  }
709698
public JenkinsServer updateJob(String jobName, String jobXml, boolean crumbFlag) throws IOException {
        return updateJob(null, jobName, jobXml, crumbFlag);
    }
200164
public function getUpdater()
    {
        if (!is_string($this->updatedByAttribute) || empty($this->updatedByAttribute)) {
            return null;
        }
        $hostClass = $this->hostClass;
        $host = $hostClass::buildNoInitModel();
        /* @var $user BaseUserModel */
        return $this->hasOne($hostClass::className(), [$host->guidAttribute => 'updatedBy']);
    }
950460
@SuppressWarnings("unchecked")
	public static synchronized @CheckForNull Map<String,String> getPersistedInstallStatus() {
        File installingPluginsFile = getInstallingPluginsFile();
        if(installingPluginsFile == null || !installingPluginsFile.exists()) {
		return null;
        }
        return (Map<String,String>)new XStream().fromXML(installingPluginsFile);
    }
578353
protected function findNextJob(): ?Job
    {
        $next_at_timestamp = $this->getNextAtTimestamp();
        $cron_id = $this->getNextCronId();

        if (is_null($cron_id)) {
            return $this->getNextAtJob();
        }

        $next_cron_timestamp = $this->getCronTimestamp($cron_id);

        if ($next_at_timestamp <= $next_cron_timestamp) {
            return $this->getNextAtJob();
        }

        return $this->getNextCronJob();
    }
1026089
public function getUpdates()
    {
        if (!$this->loadRepositories()) {
            return Repository::STATUS_NO_REPOSITORIES;
        }

        $modules = $this->getModulesFromRepository();

        // Is a higher version of an already installed package available?
        foreach ($modules as $key => $module) {
            $version = $this->packageService->getVersion($module->name);

            if (!$version) {
                // Not installed at all.
                unset($modules[$key]);
            } elseif (version_compare($version, $module->version, '<')) {
                // Older version installed.
                $modules[$key]->versionInstalled = $version;
            } else {
                unset($modules[$key]);
            }
        }

        return $modules;
    }
322129
public function needs_upgrade( $current = null, $last = null ) {

		if ( null === $current ) {
			$current = self::$version;
		}

		if ( null === $last ) {
			$last = self::$version_last;
		}

		$upgrade_needed = false;

		if ( ! empty( $current ) ) {
			foreach ( self::$upgrades as $old_version => $new_version ) {
				/*
				if ( '2.1.0' === $new_version && ( is_developer() ) )
					continue;*/

				if ( version_compare( $last, $old_version, '>=' ) && version_compare( $last, $new_version, '<' ) && version_compare( $current, $new_version, '>=' ) && 1 !== self::$upgraded ) {
					$upgrade_needed = true;

					break;
				}
			}
		}

		return $upgrade_needed;
	}
673664
function get_update( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC, $newer_than = false ) {
            $this->_logger->entrance();

            if ( ! is_numeric( $plugin_id ) ) {
                $plugin_id = $this->_plugin->id;
            }

            $this->check_updates( true, $plugin_id, $flush, $expiration, $newer_than );
            $updates = $this->get_all_updates();

            return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
        }
696023
public synchronized Object getNextJob()
    {
        Object strJobDef = null;
        synchronized (this)
        {
            if (gvJobs.size() > 0)
                strJobDef = gvJobs.remove(0);
        }
        return strJobDef;
    }