Search in sources :

Example 1 with PluginMetadata

use of org.jenkinsci.test.acceptance.update_center.PluginMetadata 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;
}
Also used : MockUpdateCenter(org.jenkinsci.test.acceptance.update_center.MockUpdateCenter) AssumptionViolatedException(org.junit.AssumptionViolatedException) ArrayList(java.util.ArrayList) VersionNumber(hudson.util.VersionNumber) PluginSpec(org.jenkinsci.test.acceptance.update_center.PluginSpec) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) UnableToResolveDependencies(org.jenkinsci.test.acceptance.update_center.UpdateCenterMetadata.UnableToResolveDependencies) PluginMetadata(org.jenkinsci.test.acceptance.update_center.PluginMetadata)

Example 2 with PluginMetadata

use of org.jenkinsci.test.acceptance.update_center.PluginMetadata in project acceptance-test-harness by jenkinsci.

the class TSRPluginManager 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.
 */
@Deprecated
public void installPlugins(final String... specs) {
    final Map<String, String> candidates = getMapShortNamesVersion(specs);
    if (uploadPlugins) {
        for (PluginMetadata newPlugin : ucmd.get().transitiveDependenciesOf(candidates.keySet())) {
            final String name = newPlugin.name;
            final String claimedVersion = candidates.get(name);
            String currentSpec;
            if (StringUtils.isNotEmpty(claimedVersion)) {
                currentSpec = name + "@" + claimedVersion;
            } else {
                currentSpec = name;
            }
            if (!isInstalled(currentSpec)) {
                // we need to override existing "old" plugins
                try {
                    newPlugin.uploadTo(jenkins, injector, null);
                } catch (IOException | ArtifactResolutionException e) {
                    throw new AssertionError("Failed to upload plugin: " + newPlugin, e);
                }
            }
        }
        // TODO: Use better detection if this is actually necessary
        try {
            waitForCond(new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    return isInstalled(specs);
                }
            }, 5);
        } catch (TimeoutException e) {
            jenkins.restart();
        }
    } else {
        if (!updated)
            checkForUpdates();
        OUTER: for (final String n : candidates.keySet()) {
            for (int attempt = 0; attempt < 2; attempt++) {
                // # of installations attempted, considering retries
                visit("available");
                check(find(by.xpath("//input[starts-with(@name,'plugin.%s.')]", n)));
                clickButton("Install");
                sleep(1000);
                try {
                    new UpdateCenter(jenkins).waitForInstallationToComplete(n);
                } catch (InstallationFailedException e) {
                    if (e.getMessage().contains("Failed to download from")) {
                        // retry
                        continue;
                    }
                }
                // installation completed
                continue OUTER;
            }
        }
    }
}
Also used : InstallationFailedException(org.jenkinsci.test.acceptance.po.UpdateCenter.InstallationFailedException) IOException(java.io.IOException) IOException(java.io.IOException) TimeoutException(org.openqa.selenium.TimeoutException) InstallationFailedException(org.jenkinsci.test.acceptance.po.UpdateCenter.InstallationFailedException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) PluginMetadata(org.jenkinsci.test.acceptance.update_center.PluginMetadata) TimeoutException(org.openqa.selenium.TimeoutException)

Aggregations

ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)2 PluginMetadata (org.jenkinsci.test.acceptance.update_center.PluginMetadata)2 VersionNumber (hudson.util.VersionNumber)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 InstallationFailedException (org.jenkinsci.test.acceptance.po.UpdateCenter.InstallationFailedException)1 MockUpdateCenter (org.jenkinsci.test.acceptance.update_center.MockUpdateCenter)1 PluginSpec (org.jenkinsci.test.acceptance.update_center.PluginSpec)1 UnableToResolveDependencies (org.jenkinsci.test.acceptance.update_center.UpdateCenterMetadata.UnableToResolveDependencies)1 AssumptionViolatedException (org.junit.AssumptionViolatedException)1 TimeoutException (org.openqa.selenium.TimeoutException)1