@Test public void getPluginDownloadUrlTest() { Plugin plugin = new Plugin("pluginName", "pluginVersion", "pluginURL", null); assertThat(pm.getPluginDownloadUrl(plugin)).isEqualTo("pluginURL"); Plugin pluginNoUrl = new Plugin("pluginName", "latest", null, null); String latestUcUrl = "https: pm.setJenkinsUCLatest(latestUcUrl + "/update-center.json"); String latestUrl = latestUcUrl + "/latest/pluginName.hpi"; setTestUcJson(); Assert.assertEquals(latestUrl, pm.getPluginDownloadUrl(pluginNoUrl)); Plugin pluginNoVersion = new Plugin("pluginName", null, null, null); assertThat(pm.getPluginDownloadUrl(pluginNoVersion)).isEqualTo(latestUrl); Plugin pluginExperimentalVersion = new Plugin("pluginName", "experimental", null, null); String experimentalUrl = dirName(cfg.getJenkinsUcExperimental()) + "latest/pluginName.hpi"; Assert.assertEquals(experimentalUrl, pm.getPluginDownloadUrl(pluginExperimentalVersion)); Plugin pluginIncrementalRepo = new Plugin("pluginName", "2.19-rc289.d09828a05a74", null, "org.jenkins-ci.plugins.pluginName"); String incrementalUrl = cfg.getJenkinsIncrementalsRepoMirror() + "/org/jenkins-ci/plugins/pluginName/pluginName/2.19-rc289.d09828a05a74/pluginName-2.19-rc289.d09828a05a74.hpi"; assertThat(pm.getPluginDownloadUrl(pluginIncrementalRepo)).isEqualTo(incrementalUrl); Plugin pluginOtherVersion = new Plugin("pluginName", "otherversion", null, null); String otherURL = dirName(cfg.getJenkinsUc().toString()) + "download/plugins/pluginName/otherversion/pluginName.hpi"; assertThat(pm.getPluginDownloadUrl(pluginOtherVersion)).isEqualTo(otherURL); }
public String getPluginDownloadUrl(Plugin plugin) { String pluginName = plugin.getName(); String pluginVersion = plugin.getVersion().toString(); String pluginUrl = plugin.getUrl(); String urlString; if (StringUtils.isEmpty(pluginVersion)) { pluginVersion = "latest"; } String jenkinsUcDownload = System.getenv("JENKINS_UC_DOWNLOAD"); if (StringUtils.isNotEmpty(jenkinsUcDownload)) { urlString = appendPathOntoUrl(jenkinsUcDownload, "/download/plugins", pluginName, pluginVersion, pluginName + ".hpi"); } else if (StringUtils.isNotEmpty(pluginUrl)) { urlString = pluginUrl; } else if ((pluginVersion.equals("latest") || plugin.isLatest()) && !StringUtils.isEmpty(jenkinsUcLatest)) { JSONObject plugins = latestUcJson.getJSONObject("plugins"); if (plugins.has(plugin.getName())) { JSONObject pluginJson = plugins.getJSONObject(plugin.getName()); urlString = pluginJson.getString("url"); } else { urlString = appendPathOntoUrl(dirName(jenkinsUcLatest), "/latest", pluginName + ".hpi"); } } else if (pluginVersion.equals("experimental") || plugin.isExperimental()) { JSONObject plugins = experimentalUcJson.getJSONObject("plugins"); if (plugins.has(plugin.getName())) { JSONObject pluginJson = plugins.getJSONObject(plugin.getName()); urlString = pluginJson.getString("url"); } else { urlString = appendPathOntoUrl(dirName(cfg.getJenkinsUcExperimental()), "/latest", pluginName + ".hpi"); } } else if (!StringUtils.isEmpty(plugin.getGroupId())) { String groupId = plugin.getGroupId(); groupId = groupId.replace(".", "/"); String incrementalsVersionPath = String.format("%s/%s/%s-%s.hpi", pluginName, pluginVersion, pluginName, pluginVersion); urlString = appendPathOntoUrl(cfg.getJenkinsIncrementalsRepoMirror(), groupId, incrementalsVersionPath); } else { urlString = appendPathOntoUrl(removePath(cfg.getJenkinsUc()), "/download/plugins", pluginName, pluginVersion, pluginName + ".hpi"); } logVerbose(String.format("Will use url: %s to download %s plugin", urlString, plugin.getName())); return urlString; }
PluginManager { public String getPluginDownloadUrl(Plugin plugin) { String pluginName = plugin.getName(); String pluginVersion = plugin.getVersion().toString(); String pluginUrl = plugin.getUrl(); String urlString; if (StringUtils.isEmpty(pluginVersion)) { pluginVersion = "latest"; } String jenkinsUcDownload = System.getenv("JENKINS_UC_DOWNLOAD"); if (StringUtils.isNotEmpty(jenkinsUcDownload)) { urlString = appendPathOntoUrl(jenkinsUcDownload, "/download/plugins", pluginName, pluginVersion, pluginName + ".hpi"); } else if (StringUtils.isNotEmpty(pluginUrl)) { urlString = pluginUrl; } else if ((pluginVersion.equals("latest") || plugin.isLatest()) && !StringUtils.isEmpty(jenkinsUcLatest)) { JSONObject plugins = latestUcJson.getJSONObject("plugins"); if (plugins.has(plugin.getName())) { JSONObject pluginJson = plugins.getJSONObject(plugin.getName()); urlString = pluginJson.getString("url"); } else { urlString = appendPathOntoUrl(dirName(jenkinsUcLatest), "/latest", pluginName + ".hpi"); } } else if (pluginVersion.equals("experimental") || plugin.isExperimental()) { JSONObject plugins = experimentalUcJson.getJSONObject("plugins"); if (plugins.has(plugin.getName())) { JSONObject pluginJson = plugins.getJSONObject(plugin.getName()); urlString = pluginJson.getString("url"); } else { urlString = appendPathOntoUrl(dirName(cfg.getJenkinsUcExperimental()), "/latest", pluginName + ".hpi"); } } else if (!StringUtils.isEmpty(plugin.getGroupId())) { String groupId = plugin.getGroupId(); groupId = groupId.replace(".", "/"); String incrementalsVersionPath = String.format("%s/%s/%s-%s.hpi", pluginName, pluginVersion, pluginName, pluginVersion); urlString = appendPathOntoUrl(cfg.getJenkinsIncrementalsRepoMirror(), groupId, incrementalsVersionPath); } else { urlString = appendPathOntoUrl(removePath(cfg.getJenkinsUc()), "/download/plugins", pluginName, pluginVersion, pluginName + ".hpi"); } logVerbose(String.format("Will use url: %s to download %s plugin", urlString, plugin.getName())); return urlString; } }
PluginManager { public String getPluginDownloadUrl(Plugin plugin) { String pluginName = plugin.getName(); String pluginVersion = plugin.getVersion().toString(); String pluginUrl = plugin.getUrl(); String urlString; if (StringUtils.isEmpty(pluginVersion)) { pluginVersion = "latest"; } String jenkinsUcDownload = System.getenv("JENKINS_UC_DOWNLOAD"); if (StringUtils.isNotEmpty(jenkinsUcDownload)) { urlString = appendPathOntoUrl(jenkinsUcDownload, "/download/plugins", pluginName, pluginVersion, pluginName + ".hpi"); } else if (StringUtils.isNotEmpty(pluginUrl)) { urlString = pluginUrl; } else if ((pluginVersion.equals("latest") || plugin.isLatest()) && !StringUtils.isEmpty(jenkinsUcLatest)) { JSONObject plugins = latestUcJson.getJSONObject("plugins"); if (plugins.has(plugin.getName())) { JSONObject pluginJson = plugins.getJSONObject(plugin.getName()); urlString = pluginJson.getString("url"); } else { urlString = appendPathOntoUrl(dirName(jenkinsUcLatest), "/latest", pluginName + ".hpi"); } } else if (pluginVersion.equals("experimental") || plugin.isExperimental()) { JSONObject plugins = experimentalUcJson.getJSONObject("plugins"); if (plugins.has(plugin.getName())) { JSONObject pluginJson = plugins.getJSONObject(plugin.getName()); urlString = pluginJson.getString("url"); } else { urlString = appendPathOntoUrl(dirName(cfg.getJenkinsUcExperimental()), "/latest", pluginName + ".hpi"); } } else if (!StringUtils.isEmpty(plugin.getGroupId())) { String groupId = plugin.getGroupId(); groupId = groupId.replace(".", "/"); String incrementalsVersionPath = String.format("%s/%s/%s-%s.hpi", pluginName, pluginVersion, pluginName, pluginVersion); urlString = appendPathOntoUrl(cfg.getJenkinsIncrementalsRepoMirror(), groupId, incrementalsVersionPath); } else { urlString = appendPathOntoUrl(removePath(cfg.getJenkinsUc()), "/download/plugins", pluginName, pluginVersion, pluginName + ".hpi"); } logVerbose(String.format("Will use url: %s to download %s plugin", urlString, plugin.getName())); return urlString; } @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "we want the user to be able to specify a path")  PluginManager(Config cfg); }
PluginManager { public String getPluginDownloadUrl(Plugin plugin) { String pluginName = plugin.getName(); String pluginVersion = plugin.getVersion().toString(); String pluginUrl = plugin.getUrl(); String urlString; if (StringUtils.isEmpty(pluginVersion)) { pluginVersion = "latest"; } String jenkinsUcDownload = System.getenv("JENKINS_UC_DOWNLOAD"); if (StringUtils.isNotEmpty(jenkinsUcDownload)) { urlString = appendPathOntoUrl(jenkinsUcDownload, "/download/plugins", pluginName, pluginVersion, pluginName + ".hpi"); } else if (StringUtils.isNotEmpty(pluginUrl)) { urlString = pluginUrl; } else if ((pluginVersion.equals("latest") || plugin.isLatest()) && !StringUtils.isEmpty(jenkinsUcLatest)) { JSONObject plugins = latestUcJson.getJSONObject("plugins"); if (plugins.has(plugin.getName())) { JSONObject pluginJson = plugins.getJSONObject(plugin.getName()); urlString = pluginJson.getString("url"); } else { urlString = appendPathOntoUrl(dirName(jenkinsUcLatest), "/latest", pluginName + ".hpi"); } } else if (pluginVersion.equals("experimental") || plugin.isExperimental()) { JSONObject plugins = experimentalUcJson.getJSONObject("plugins"); if (plugins.has(plugin.getName())) { JSONObject pluginJson = plugins.getJSONObject(plugin.getName()); urlString = pluginJson.getString("url"); } else { urlString = appendPathOntoUrl(dirName(cfg.getJenkinsUcExperimental()), "/latest", pluginName + ".hpi"); } } else if (!StringUtils.isEmpty(plugin.getGroupId())) { String groupId = plugin.getGroupId(); groupId = groupId.replace(".", "/"); String incrementalsVersionPath = String.format("%s/%s/%s-%s.hpi", pluginName, pluginVersion, pluginName, pluginVersion); urlString = appendPathOntoUrl(cfg.getJenkinsIncrementalsRepoMirror(), groupId, incrementalsVersionPath); } else { urlString = appendPathOntoUrl(removePath(cfg.getJenkinsUc()), "/download/plugins", pluginName, pluginVersion, pluginName + ".hpi"); } logVerbose(String.format("Will use url: %s to download %s plugin", urlString, plugin.getName())); return urlString; } @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 String getPluginDownloadUrl(Plugin plugin) { String pluginName = plugin.getName(); String pluginVersion = plugin.getVersion().toString(); String pluginUrl = plugin.getUrl(); String urlString; if (StringUtils.isEmpty(pluginVersion)) { pluginVersion = "latest"; } String jenkinsUcDownload = System.getenv("JENKINS_UC_DOWNLOAD"); if (StringUtils.isNotEmpty(jenkinsUcDownload)) { urlString = appendPathOntoUrl(jenkinsUcDownload, "/download/plugins", pluginName, pluginVersion, pluginName + ".hpi"); } else if (StringUtils.isNotEmpty(pluginUrl)) { urlString = pluginUrl; } else if ((pluginVersion.equals("latest") || plugin.isLatest()) && !StringUtils.isEmpty(jenkinsUcLatest)) { JSONObject plugins = latestUcJson.getJSONObject("plugins"); if (plugins.has(plugin.getName())) { JSONObject pluginJson = plugins.getJSONObject(plugin.getName()); urlString = pluginJson.getString("url"); } else { urlString = appendPathOntoUrl(dirName(jenkinsUcLatest), "/latest", pluginName + ".hpi"); } } else if (pluginVersion.equals("experimental") || plugin.isExperimental()) { JSONObject plugins = experimentalUcJson.getJSONObject("plugins"); if (plugins.has(plugin.getName())) { JSONObject pluginJson = plugins.getJSONObject(plugin.getName()); urlString = pluginJson.getString("url"); } else { urlString = appendPathOntoUrl(dirName(cfg.getJenkinsUcExperimental()), "/latest", pluginName + ".hpi"); } } else if (!StringUtils.isEmpty(plugin.getGroupId())) { String groupId = plugin.getGroupId(); groupId = groupId.replace(".", "/"); String incrementalsVersionPath = String.format("%s/%s/%s-%s.hpi", pluginName, pluginVersion, pluginName, pluginVersion); urlString = appendPathOntoUrl(cfg.getJenkinsIncrementalsRepoMirror(), groupId, incrementalsVersionPath); } else { urlString = appendPathOntoUrl(removePath(cfg.getJenkinsUc()), "/download/plugins", pluginName, pluginVersion, pluginName + ".hpi"); } logVerbose(String.format("Will use url: %s to download %s plugin", urlString, plugin.getName())); return urlString; } @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();  }