Java Code Examples for hudson.util.VersionNumber#isOlderThan()

The following examples show how to use hudson.util.VersionNumber#isOlderThan() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginManager.java    From plugin-installation-manager-tool with MIT License 5 votes vote down vote up
/**
 * Compares the list of all requested plugins to the currently installed plugins to determine the final list of
 * plugins that will be downloaded
 *
 * @param requestedPlugins list of all requested plugins, determined from the highest required versions of the
 *                         initial user requested plugins and their recursive dependencies
 * @return list of plugins that will be downloaded when taking into account the already installed plugins and the
 * highest required versions of the same plugin
 */
public List<Plugin> findPluginsToDownload(Map<String, Plugin> requestedPlugins) {
    List<Plugin> pluginsToDownload = new ArrayList<>();
    for (Map.Entry<String, Plugin> requestedPlugin : requestedPlugins.entrySet()) {
        String pluginName = requestedPlugin.getKey();
        Plugin plugin = requestedPlugin.getValue();
        VersionNumber installedVersion = null;
        if (installedPluginVersions.containsKey(pluginName)) {
            installedVersion = installedPluginVersions.get(pluginName).getVersion();
        } else if (bundledPluginVersions.containsKey(pluginName)) {
            installedVersion = bundledPluginVersions.get(pluginName).getVersion();
        } else if (bundledPluginVersions.containsKey(pluginName) &&
                installedPluginVersions.containsKey(pluginName)) {
            installedVersion = bundledPluginVersions.get(pluginName).getVersion().
                    isNewerThan(installedPluginVersions.get(pluginName).getVersion()) ?
                    bundledPluginVersions.get(pluginName).getVersion() :
                    installedPluginVersions.get(pluginName).getVersion();
        }
        if (installedVersion == null) {
            pluginsToDownload.add(plugin);
        } else if (installedVersion.isOlderThan(plugin.getVersion())) {
            logVerbose(String.format(
                    "Installed version (%s) of %s is less than minimum required version of %s, bundled " +
                            "plugin will be upgraded", installedVersion, pluginName, plugin.getVersion()));
            pluginsToDownload.add(plugin);
        }
    }
    return pluginsToDownload;
}
 
Example 2
Source File: BackwardCompatibilityTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
private static String agentNameToCompareAgainst() {
    VersionNumber currentVersion = Jenkins.getStoredVersion();
    if (currentVersion == null) {
        throw new IllegalArgumentException("Couldn't get jenkins version");
    }
    return currentVersion.isOlderThan(MIN_VERSION_SYMBOL) ? "dumb" : "permanent";
}
 
Example 3
Source File: WithContainerStep.java    From docker-workflow-plugin with MIT License 4 votes vote down vote up
@Override public boolean start() throws Exception {
    EnvVars envReduced = new EnvVars(env);
    EnvVars envHost = computer.getEnvironment();
    envReduced.entrySet().removeAll(envHost.entrySet());

    // Remove PATH during cat.
    envReduced.remove("PATH");
    envReduced.remove("");

    LOGGER.log(Level.FINE, "reduced environment: {0}", envReduced);
    workspace.mkdirs(); // otherwise it may be owned by root when created for -v
    String ws = getPath(workspace);
    toolName = step.toolName;
    DockerClient dockerClient = launcher.isUnix()
        ? new DockerClient(launcher, node, toolName)
        : new WindowsDockerClient(launcher, node, toolName);

    VersionNumber dockerVersion = dockerClient.version();
    if (dockerVersion != null) {
        if (dockerVersion.isOlderThan(new VersionNumber("1.7"))) {
            throw new AbortException("The docker version is less than v1.7. Pipeline functions requiring 'docker exec' (e.g. 'docker.inside') or SELinux labeling will not work.");
        } else if (dockerVersion.isOlderThan(new VersionNumber("1.8"))) {
            listener.error("The docker version is less than v1.8. Running a 'docker.inside' from inside a container will not work.");
        } else if (dockerVersion.isOlderThan(new VersionNumber("1.13"))) {
            if (!launcher.isUnix())
                throw new AbortException("The docker version is less than v1.13. Running a 'docker.inside' from inside a Windows container will not work.");
        }
    } else {
        listener.error("Failed to parse docker version. Please note there is a minimum docker version requirement of v1.7.");
    }

    FilePath tempDir = tempDir(workspace);
    tempDir.mkdirs();
    String tmp = getPath(tempDir);

    Map<String, String> volumes = new LinkedHashMap<String, String>();
    Collection<String> volumesFromContainers = new LinkedHashSet<String>();
    Optional<String> containerId = dockerClient.getContainerIdIfContainerized();
    if (containerId.isPresent()) {
        listener.getLogger().println(node.getDisplayName() + " seems to be running inside container " + containerId.get());
        final Collection<String> mountedVolumes = dockerClient.getVolumes(env, containerId.get());
        final String[] dirs = {ws, tmp};
        for (String dir : dirs) {
            // check if there is any volume which contains the directory
            boolean found = false;
            for (String vol : mountedVolumes) {
                boolean dirStartsWithVol = launcher.isUnix()
                    ? dir.startsWith(vol) // Linux
                    : dir.toLowerCase().startsWith(vol.toLowerCase()); // Windows

                if (dirStartsWithVol) {
                    volumesFromContainers.add(containerId.get());
                    found = true;
                    break;
                }
            }
            if (!found) {
                listener.getLogger().println("but " + dir + " could not be found among " + mountedVolumes);
                volumes.put(dir, dir);
            }
        }
    } else {
        listener.getLogger().println(node.getDisplayName() + " does not seem to be running inside a container");
        volumes.put(ws, ws);
        volumes.put(tmp, tmp);
    }

    String command = launcher.isUnix() ? "cat" : "cmd.exe";
    container = dockerClient.run(env, step.image, step.args, ws, volumes, volumesFromContainers, envReduced, dockerClient.whoAmI(), /* expected to hang until killed */ command);
    final List<String> ps = dockerClient.listProcess(env, container);
    if (!ps.contains(command)) {
        listener.error(
            "The container started but didn't run the expected command. " +
                "Please double check your ENTRYPOINT does execute the command passed as docker run argument, " +
                "as required by official docker images (see https://github.com/docker-library/official-images#consistency for entrypoint consistency requirements).\n" +
                "Alternatively you can force image entrypoint to be disabled by adding option `--entrypoint=''`.");
    }

    ImageAction.add(step.image, run);
    getContext().newBodyInvoker().
            withContext(BodyInvoker.mergeLauncherDecorators(getContext().get(LauncherDecorator.class), new Decorator(container, envHost, ws, toolName, dockerVersion))).
            withCallback(new Callback(container, toolName)).
            start();
    return false;
}