@Test public void getPluginDependencyJsonArrayTest1() { JSONObject updateCenterJson = new JSONObject(); JSONObject plugins = new JSONObject(); JSONObject awsCodebuild = new JSONObject(); awsCodebuild.put("buildDate", "Jun 20, 2019"); awsCodebuild.put("version", "0.42"); awsCodebuild.put("requiredCore", "1.642,3"); JSONArray awsCodebuildDependencies = array( dependency("workflow-step-api", false, "2.5"), dependency("cloudbees-folder", false, "6.1.0"), dependency("credentials", false, "2.1.14"), dependency("script-security", false, "1.29")); awsCodebuild.put("dependencies", awsCodebuildDependencies); JSONObject awsGlobalConfig = new JSONObject(); awsGlobalConfig.put("buildDate", "Mar 27, 2019"); awsGlobalConfig.put("version", "1.3"); awsGlobalConfig.put("requiredCore", "2.121.1"); JSONArray awsGlobalConfigDependencies = array( dependency("aws-credentials", false, "1.23"), dependency("structs", false, "1.14")); awsGlobalConfig.put("dependencies", awsGlobalConfigDependencies); plugins.put("aws-global-configuration", awsGlobalConfig); plugins.put("aws-codebuild", awsCodebuild); updateCenterJson.put("plugins", plugins); Plugin awsCodeBuildPlugin = new Plugin("aws-codebuild", "1.2", null , null); Plugin awsGlobalConfigPlugin = new Plugin("aws-global-configuration", "1.1", null, null); Plugin gitPlugin = new Plugin("structs", "1.17", null, null); JSONArray gitJson = pm.getPluginDependencyJsonArray(gitPlugin, updateCenterJson); assertThat(gitJson).isNull(); JSONArray awsCodeBuildJson = pm.getPluginDependencyJsonArray(awsCodeBuildPlugin, updateCenterJson); assertThat(awsCodeBuildJson).hasToString(awsCodebuildDependencies.toString()); JSONArray awsGlobalConfJson = pm.getPluginDependencyJsonArray(awsGlobalConfigPlugin, updateCenterJson); assertThat(awsGlobalConfJson).hasToString(awsGlobalConfigDependencies.toString()); }
public JSONArray getPluginDependencyJsonArray(Plugin plugin, JSONObject ucJson) { JSONObject plugins = ucJson.getJSONObject("plugins"); if (!plugins.has(plugin.getName())) { return null; } JSONObject pluginInfo = (JSONObject) plugins.get(plugin.getName()); if (ucJson.equals(pluginInfoJson)) { if (pluginInfo.has(plugin.getVersion().toString())) { JSONObject specificVersionInfo = pluginInfo.getJSONObject(plugin.getVersion().toString()); plugin.setJenkinsVersion(specificVersionInfo.getString("requiredCore")); return (JSONArray) specificVersionInfo.get("dependencies"); } } else { plugin.setJenkinsVersion(pluginInfo.getString("requiredCore")); String version = pluginInfo.getString("version"); plugin.setVersion(new VersionNumber(version)); return (JSONArray) pluginInfo.get("dependencies"); } return null; }
PluginManager { public JSONArray getPluginDependencyJsonArray(Plugin plugin, JSONObject ucJson) { JSONObject plugins = ucJson.getJSONObject("plugins"); if (!plugins.has(plugin.getName())) { return null; } JSONObject pluginInfo = (JSONObject) plugins.get(plugin.getName()); if (ucJson.equals(pluginInfoJson)) { if (pluginInfo.has(plugin.getVersion().toString())) { JSONObject specificVersionInfo = pluginInfo.getJSONObject(plugin.getVersion().toString()); plugin.setJenkinsVersion(specificVersionInfo.getString("requiredCore")); return (JSONArray) specificVersionInfo.get("dependencies"); } } else { plugin.setJenkinsVersion(pluginInfo.getString("requiredCore")); String version = pluginInfo.getString("version"); plugin.setVersion(new VersionNumber(version)); return (JSONArray) pluginInfo.get("dependencies"); } return null; } }
PluginManager { public JSONArray getPluginDependencyJsonArray(Plugin plugin, JSONObject ucJson) { JSONObject plugins = ucJson.getJSONObject("plugins"); if (!plugins.has(plugin.getName())) { return null; } JSONObject pluginInfo = (JSONObject) plugins.get(plugin.getName()); if (ucJson.equals(pluginInfoJson)) { if (pluginInfo.has(plugin.getVersion().toString())) { JSONObject specificVersionInfo = pluginInfo.getJSONObject(plugin.getVersion().toString()); plugin.setJenkinsVersion(specificVersionInfo.getString("requiredCore")); return (JSONArray) specificVersionInfo.get("dependencies"); } } else { plugin.setJenkinsVersion(pluginInfo.getString("requiredCore")); String version = pluginInfo.getString("version"); plugin.setVersion(new VersionNumber(version)); return (JSONArray) pluginInfo.get("dependencies"); } return null; } @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "we want the user to be able to specify a path")  PluginManager(Config cfg); }
PluginManager { public JSONArray getPluginDependencyJsonArray(Plugin plugin, JSONObject ucJson) { JSONObject plugins = ucJson.getJSONObject("plugins"); if (!plugins.has(plugin.getName())) { return null; } JSONObject pluginInfo = (JSONObject) plugins.get(plugin.getName()); if (ucJson.equals(pluginInfoJson)) { if (pluginInfo.has(plugin.getVersion().toString())) { JSONObject specificVersionInfo = pluginInfo.getJSONObject(plugin.getVersion().toString()); plugin.setJenkinsVersion(specificVersionInfo.getString("requiredCore")); return (JSONArray) specificVersionInfo.get("dependencies"); } } else { plugin.setJenkinsVersion(pluginInfo.getString("requiredCore")); String version = pluginInfo.getString("version"); plugin.setVersion(new VersionNumber(version)); return (JSONArray) pluginInfo.get("dependencies"); } return null; } @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 JSONArray getPluginDependencyJsonArray(Plugin plugin, JSONObject ucJson) { JSONObject plugins = ucJson.getJSONObject("plugins"); if (!plugins.has(plugin.getName())) { return null; } JSONObject pluginInfo = (JSONObject) plugins.get(plugin.getName()); if (ucJson.equals(pluginInfoJson)) { if (pluginInfo.has(plugin.getVersion().toString())) { JSONObject specificVersionInfo = pluginInfo.getJSONObject(plugin.getVersion().toString()); plugin.setJenkinsVersion(specificVersionInfo.getString("requiredCore")); return (JSONArray) specificVersionInfo.get("dependencies"); } } else { plugin.setJenkinsVersion(pluginInfo.getString("requiredCore")); String version = pluginInfo.getString("version"); plugin.setVersion(new VersionNumber(version)); return (JSONArray) pluginInfo.get("dependencies"); } return null; } @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();  }