use of org.jenkinsci.test.acceptance.update_center.MockUpdateCenter in project acceptance-test-harness by jenkinsci.
the class PluginManager method installPlugins.
/**
* Installs specified plugins.
*
* @deprecated Please be encouraged to use {@link WithPlugins} annotations to statically declare
* the required plugins you need. If you really do need to install plugins in the middle
* of a test, as opposed to be in the beginning, then this is the right method.
* <p/>
* The deprecation marker is to call attention to {@link WithPlugins}. This method
* is not really deprecated.
* @return Always false.
*/
@Deprecated
public boolean installPlugins(final PluginSpec... specs) throws UnableToResolveDependencies, IOException {
final Map<String, String> candidates = getMapShortNamesVersion(specs);
if (!updated) {
checkForUpdates();
}
if (uploadPlugins) {
LOGGER.warning("Installing plugins by direct upload. Better to use the default MockUpdateCenter.");
// First check to see whether we need to do anything.
// If not, do not consider transitive dependencies of the requested plugins,
// which might force updates (and thus restarts) even though we already have
// a sufficiently new version of the requested plugin.
boolean someChangeRequired = false;
for (PluginSpec spec : specs) {
if (installationStatus(spec) != InstallationStatus.UP_TO_DATE) {
someChangeRequired = true;
break;
}
}
if (!someChangeRequired) {
return false;
}
List<PluginMetadata> pluginToBeInstalled = ucmd.get(jenkins).transitiveDependenciesOf(jenkins, Arrays.asList(specs));
for (PluginMetadata newPlugin : pluginToBeInstalled) {
final String name = newPlugin.getName();
String requiredVersion = candidates.get(name);
String availableVersion = newPlugin.getVersion();
if (requiredVersion == null) {
// a dependency
requiredVersion = availableVersion;
}
final String currentSpec = StringUtils.isNotEmpty(requiredVersion) ? name + "@" + requiredVersion : name;
InstallationStatus status = installationStatus(currentSpec);
if (status != InstallationStatus.UP_TO_DATE) {
if (new VersionNumber(requiredVersion).compareTo(new VersionNumber(availableVersion)) > 0) {
throw new AssumptionViolatedException(name + " has version " + availableVersion + " but " + requiredVersion + " was requested");
}
try {
newPlugin.uploadTo(jenkins, injector, availableVersion);
} catch (ArtifactResolutionException x) {
throw new UnableToResolveDependencies(x);
}
}
}
} else {
// JENKINS-50790 It seems that this page takes too much time to load when running in the new ci.jenkins.io
try {
driver.manage().timeouts().pageLoadTimeout(time.seconds(240), TimeUnit.MILLISECONDS);
visit("available");
} finally {
driver.manage().timeouts().pageLoadTimeout(time.seconds(FallbackConfig.PAGE_LOAD_TIMEOUT), TimeUnit.MILLISECONDS);
}
// End JENKINS-50790
final ArrayList<PluginSpec> update = new ArrayList<>();
for (final PluginSpec n : specs) {
switch(installationStatus(n)) {
case NOT_INSTALLED:
tickPluginToInstall(n);
break;
case OUTDATED:
update.add(n);
break;
case UP_TO_DATE:
// Nothing to do
break;
default:
assert false : "Unreachable";
}
}
clickButton("Install");
// Plugins that are already installed in older version will be updated
System.out.println("Plugins to be updated: " + update);
if (!update.isEmpty()) {
// Updates tab
visit("");
for (PluginSpec n : update) {
tickPluginToInstall(n);
}
clickButton("Download now and install after restart");
}
}
// Jenkins will be restarted if necessary
boolean hasBeenRestarted = new UpdateCenter(jenkins).waitForInstallationToComplete(specs);
if (!hasBeenRestarted && specs.length > 0 && jenkins.getVersion().isNewerThan(new VersionNumber("2.188"))) {
jenkins.getLogger("all").waitForLogged(Pattern.compile("Completed installation of .*"), 1000);
}
return false;
}
Aggregations