@Test public void findPluginsToDownloadTest() { Map<String, Plugin> requestedPlugins = new HashMap<>(); Map<String, Plugin> installedPlugins = new HashMap<>(); Map<String, Plugin> bundledPlugins = new HashMap<>(); List<Plugin> actualPlugins; requestedPlugins.put("git", new Plugin("git", "1.0.0", null, null)); pm.setInstalledPluginVersions(installedPlugins); pm.setBundledPluginVersions(bundledPlugins); actualPlugins = pm.findPluginsToDownload(requestedPlugins); assertThat(actualPlugins) .containsExactly(new Plugin("git", "1.0.0", null, null)); requestedPlugins.put("credentials", new Plugin("credentials", "2.1.14", null, null)); requestedPlugins.put("structs", new Plugin("structs", "1.18", null, null)); requestedPlugins.put("ssh-credentials", new Plugin("ssh-credentials", "1.13", null, null)); installedPlugins.put("git", new Plugin("git", "1.1.1", null, null)); installedPlugins.put("git-client", new Plugin("git-client","2.7.5", null, null)); bundledPlugins.put("structs", new Plugin("structs", "1.16", null, null)); pm.setInstalledPluginVersions(installedPlugins); pm.setBundledPluginVersions(bundledPlugins); actualPlugins = pm.findPluginsToDownload(requestedPlugins); assertThat(actualPlugins) .containsExactlyInAnyOrder( new Plugin("credentials", "2.1.14", null, null), new Plugin("structs", "1.18", null, null), new Plugin("ssh-credentials", "1.13", null, null)); }
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; }
PluginManager { 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; } }
PluginManager { 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; } @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "we want the user to be able to specify a path")  PluginManager(Config cfg); }
PluginManager { 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; } @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "we want the user to be able to specify a path")  PluginManager(Config cfg); void start(); void start(boolean downloadUc); List<Plugin> findPluginsToDownload(Map<String, Plugin> requestedPlugins); Map<String, Plugin> findEffectivePlugins(List<Plugin> pluginsToBeDownloaded); void listPlugins(); void logPlugins(String description, List<Plugin> plugins); Map<String, List<SecurityWarning>> getSecurityWarnings(); void showAllSecurityWarnings(); void showSpecificSecurityWarnings(List<Plugin> plugins); List<Plugin> getLatestVersionsOfPlugins(List<Plugin> plugins); boolean warningExists(Plugin plugin); void checkVersionCompatibility(VersionNumber jenkinsVersion, List<Plugin> pluginsToBeDownloaded); void downloadPlugins(List<Plugin> plugins); Map<String, Plugin> findPluginsAndDependencies(List<Plugin> requestedPlugins); void outputPluginReplacementInfo(Plugin lowerVersion, Plugin higherVersion); @Deprecated JSONObject getJson(String urlString); JSONObject getJson(URL url, String cacheKey); void getUCJson(VersionNumber jenkinsVersion); JSONArray getPluginDependencyJsonArray(Plugin plugin, JSONObject ucJson); VersionNumber getLatestPluginVersion(String pluginName); List<Plugin> resolveDependenciesFromManifest(Plugin plugin); List<Plugin> resolveDependenciesFromJson(Plugin plugin, JSONObject pluginJson); List<Plugin> resolveDirectDependencies(Plugin plugin); Map<String, Plugin> resolveRecursiveDependencies(Plugin plugin); boolean downloadPlugin(Plugin plugin, File location); String getPluginDownloadUrl(Plugin plugin); boolean downloadToFile(String urlString, Plugin plugin, File fileLocation); @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "PATH_TRAVERSAL_IN"}) boolean downloadToFile(String urlString, Plugin plugin, File fileLocation, int maxRetries); String getAttributeFromManifest(File file, String key); VersionNumber getJenkinsVersionFromWar(); String getPluginVersion(File file); Map<String, Plugin> installedPlugins(); @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "PATH_TRAVERSAL_IN"}) Map<String, Plugin> bundledPlugins(); String getJenkinsUCLatest(); void setJenkinsUCLatest(String updateCenterLatest); void setInstalledPluginVersions(Map<String, Plugin> installedPlugins); void setBundledPluginVersions(Map<String, Plugin> bundledPlugins); void setAllPluginsAndDependencies(Map<String, Plugin> allPluginsAndDependencies); void setEffectivePlugins(Map<String, Plugin> effectivePlugins); void setPluginsToBeDownloaded(List<Plugin> pluginsToBeDownloaded); void logVerbose(String message); void setLatestUcJson(JSONObject latestUcJson); void setLatestUcPlugins(JSONObject latestPlugins); void setExperimentalUcJson(JSONObject experimentalUcJson); void setAllSecurityWarnings(Map<String, List<SecurityWarning>> securityWarnings); void setPluginInfoJson(JSONObject pluginInfoJson); void setCm(CacheManager cm); List<Plugin> getFailedPlugins(); }
PluginManager { 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; } @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "we want the user to be able to specify a path")  PluginManager(Config cfg); void start(); void start(boolean downloadUc); List<Plugin> findPluginsToDownload(Map<String, Plugin> requestedPlugins); Map<String, Plugin> findEffectivePlugins(List<Plugin> pluginsToBeDownloaded); void listPlugins(); void logPlugins(String description, List<Plugin> plugins); Map<String, List<SecurityWarning>> getSecurityWarnings(); void showAllSecurityWarnings(); void showSpecificSecurityWarnings(List<Plugin> plugins); List<Plugin> getLatestVersionsOfPlugins(List<Plugin> plugins); boolean warningExists(Plugin plugin); void checkVersionCompatibility(VersionNumber jenkinsVersion, List<Plugin> pluginsToBeDownloaded); void downloadPlugins(List<Plugin> plugins); Map<String, Plugin> findPluginsAndDependencies(List<Plugin> requestedPlugins); void outputPluginReplacementInfo(Plugin lowerVersion, Plugin higherVersion); @Deprecated JSONObject getJson(String urlString); JSONObject getJson(URL url, String cacheKey); void getUCJson(VersionNumber jenkinsVersion); JSONArray getPluginDependencyJsonArray(Plugin plugin, JSONObject ucJson); VersionNumber getLatestPluginVersion(String pluginName); List<Plugin> resolveDependenciesFromManifest(Plugin plugin); List<Plugin> resolveDependenciesFromJson(Plugin plugin, JSONObject pluginJson); List<Plugin> resolveDirectDependencies(Plugin plugin); Map<String, Plugin> resolveRecursiveDependencies(Plugin plugin); boolean downloadPlugin(Plugin plugin, File location); String getPluginDownloadUrl(Plugin plugin); boolean downloadToFile(String urlString, Plugin plugin, File fileLocation); @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "PATH_TRAVERSAL_IN"}) boolean downloadToFile(String urlString, Plugin plugin, File fileLocation, int maxRetries); String getAttributeFromManifest(File file, String key); VersionNumber getJenkinsVersionFromWar(); String getPluginVersion(File file); Map<String, Plugin> installedPlugins(); @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "PATH_TRAVERSAL_IN"}) Map<String, Plugin> bundledPlugins(); String getJenkinsUCLatest(); void setJenkinsUCLatest(String updateCenterLatest); void setInstalledPluginVersions(Map<String, Plugin> installedPlugins); void setBundledPluginVersions(Map<String, Plugin> bundledPlugins); void setAllPluginsAndDependencies(Map<String, Plugin> allPluginsAndDependencies); void setEffectivePlugins(Map<String, Plugin> effectivePlugins); void setPluginsToBeDownloaded(List<Plugin> pluginsToBeDownloaded); void logVerbose(String message); void setLatestUcJson(JSONObject latestUcJson); void setLatestUcPlugins(JSONObject latestPlugins); void setExperimentalUcJson(JSONObject experimentalUcJson); void setAllSecurityWarnings(Map<String, List<SecurityWarning>> securityWarnings); void setPluginInfoJson(JSONObject pluginInfoJson); void setCm(CacheManager cm); List<Plugin> getFailedPlugins();  }