@Test public void resolveDependenciesFromManifestExceptionTest() { Plugin testPlugin = new Plugin("test", "latest", null, null); setTestUcJson(); assertThat(pm.resolveDependenciesFromManifest(testPlugin)).isEmpty(); }
public List<Plugin> resolveDependenciesFromManifest(Plugin plugin) { List<Plugin> dependentPlugins = new ArrayList<>(); try { File tempFile = Files.createTempFile(FilenameUtils.getName(plugin.getName()), ".jpi").toFile(); logVerbose( String.format("%nResolving dependencies of %s by downloading plugin to temp file %s and parsing " + "MANIFEST.MF", plugin.getName(), tempFile.toString())); if (!downloadPlugin(plugin, tempFile)) { Files.delete(tempFile.toPath()); throw new DownloadPluginException("Unable to resolve dependencies for " + plugin.getName()); } if (plugin.getVersion().toString().equals("latest") || plugin.getVersion().toString().equals("experimental")) { String version = getAttributeFromManifest(tempFile, "Plugin-Version"); if (!StringUtils.isEmpty(version)) { plugin.setVersion(new VersionNumber(version)); } } String dependencyString = getAttributeFromManifest(tempFile, "Plugin-Dependencies"); if (StringUtils.isEmpty(dependencyString)) { logVerbose("\n" + plugin.getName() + " has no dependencies"); return dependentPlugins; } String[] dependencies = dependencyString.split(","); for (String dependency : dependencies) { if (!dependency.contains("resolution:=optional")) { String[] pluginInfo = dependency.split(":"); String pluginName = pluginInfo[0]; String pluginVersion = pluginInfo[1]; Plugin dependentPlugin = new Plugin(pluginName, pluginVersion, null, null); if (useLatestSpecified && plugin.isLatest() || useLatestAll) { VersionNumber latestPluginVersion = getLatestPluginVersion(pluginName); dependentPlugin.setVersion(latestPluginVersion); dependentPlugin.setLatest(true); } dependentPlugins.add(dependentPlugin); dependentPlugin.setParent(plugin); } } logVerbose(dependentPlugins.isEmpty() ? String.format("%n%s has no dependencies", plugin.getName()) : String.format("%n%s depends on: %n", plugin.getName()) + dependentPlugins.stream() .map(p -> p.getName() + " " + p.getVersion()) .collect(Collectors.joining("\n"))); plugin.setJenkinsVersion(getAttributeFromManifest(tempFile, "Jenkins-Version")); Files.delete(tempFile.toPath()); return dependentPlugins; } catch (IOException e) { System.out.println(String.format("Unable to resolve dependencies for %s", plugin.getName())); if (verbose) { e.printStackTrace(); } return dependentPlugins; } }
PluginManager { public List<Plugin> resolveDependenciesFromManifest(Plugin plugin) { List<Plugin> dependentPlugins = new ArrayList<>(); try { File tempFile = Files.createTempFile(FilenameUtils.getName(plugin.getName()), ".jpi").toFile(); logVerbose( String.format("%nResolving dependencies of %s by downloading plugin to temp file %s and parsing " + "MANIFEST.MF", plugin.getName(), tempFile.toString())); if (!downloadPlugin(plugin, tempFile)) { Files.delete(tempFile.toPath()); throw new DownloadPluginException("Unable to resolve dependencies for " + plugin.getName()); } if (plugin.getVersion().toString().equals("latest") || plugin.getVersion().toString().equals("experimental")) { String version = getAttributeFromManifest(tempFile, "Plugin-Version"); if (!StringUtils.isEmpty(version)) { plugin.setVersion(new VersionNumber(version)); } } String dependencyString = getAttributeFromManifest(tempFile, "Plugin-Dependencies"); if (StringUtils.isEmpty(dependencyString)) { logVerbose("\n" + plugin.getName() + " has no dependencies"); return dependentPlugins; } String[] dependencies = dependencyString.split(","); for (String dependency : dependencies) { if (!dependency.contains("resolution:=optional")) { String[] pluginInfo = dependency.split(":"); String pluginName = pluginInfo[0]; String pluginVersion = pluginInfo[1]; Plugin dependentPlugin = new Plugin(pluginName, pluginVersion, null, null); if (useLatestSpecified && plugin.isLatest() || useLatestAll) { VersionNumber latestPluginVersion = getLatestPluginVersion(pluginName); dependentPlugin.setVersion(latestPluginVersion); dependentPlugin.setLatest(true); } dependentPlugins.add(dependentPlugin); dependentPlugin.setParent(plugin); } } logVerbose(dependentPlugins.isEmpty() ? String.format("%n%s has no dependencies", plugin.getName()) : String.format("%n%s depends on: %n", plugin.getName()) + dependentPlugins.stream() .map(p -> p.getName() + " " + p.getVersion()) .collect(Collectors.joining("\n"))); plugin.setJenkinsVersion(getAttributeFromManifest(tempFile, "Jenkins-Version")); Files.delete(tempFile.toPath()); return dependentPlugins; } catch (IOException e) { System.out.println(String.format("Unable to resolve dependencies for %s", plugin.getName())); if (verbose) { e.printStackTrace(); } return dependentPlugins; } } }
PluginManager { public List<Plugin> resolveDependenciesFromManifest(Plugin plugin) { List<Plugin> dependentPlugins = new ArrayList<>(); try { File tempFile = Files.createTempFile(FilenameUtils.getName(plugin.getName()), ".jpi").toFile(); logVerbose( String.format("%nResolving dependencies of %s by downloading plugin to temp file %s and parsing " + "MANIFEST.MF", plugin.getName(), tempFile.toString())); if (!downloadPlugin(plugin, tempFile)) { Files.delete(tempFile.toPath()); throw new DownloadPluginException("Unable to resolve dependencies for " + plugin.getName()); } if (plugin.getVersion().toString().equals("latest") || plugin.getVersion().toString().equals("experimental")) { String version = getAttributeFromManifest(tempFile, "Plugin-Version"); if (!StringUtils.isEmpty(version)) { plugin.setVersion(new VersionNumber(version)); } } String dependencyString = getAttributeFromManifest(tempFile, "Plugin-Dependencies"); if (StringUtils.isEmpty(dependencyString)) { logVerbose("\n" + plugin.getName() + " has no dependencies"); return dependentPlugins; } String[] dependencies = dependencyString.split(","); for (String dependency : dependencies) { if (!dependency.contains("resolution:=optional")) { String[] pluginInfo = dependency.split(":"); String pluginName = pluginInfo[0]; String pluginVersion = pluginInfo[1]; Plugin dependentPlugin = new Plugin(pluginName, pluginVersion, null, null); if (useLatestSpecified && plugin.isLatest() || useLatestAll) { VersionNumber latestPluginVersion = getLatestPluginVersion(pluginName); dependentPlugin.setVersion(latestPluginVersion); dependentPlugin.setLatest(true); } dependentPlugins.add(dependentPlugin); dependentPlugin.setParent(plugin); } } logVerbose(dependentPlugins.isEmpty() ? String.format("%n%s has no dependencies", plugin.getName()) : String.format("%n%s depends on: %n", plugin.getName()) + dependentPlugins.stream() .map(p -> p.getName() + " " + p.getVersion()) .collect(Collectors.joining("\n"))); plugin.setJenkinsVersion(getAttributeFromManifest(tempFile, "Jenkins-Version")); Files.delete(tempFile.toPath()); return dependentPlugins; } catch (IOException e) { System.out.println(String.format("Unable to resolve dependencies for %s", plugin.getName())); if (verbose) { e.printStackTrace(); } return dependentPlugins; } } @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "we want the user to be able to specify a path")  PluginManager(Config cfg); }
PluginManager { public List<Plugin> resolveDependenciesFromManifest(Plugin plugin) { List<Plugin> dependentPlugins = new ArrayList<>(); try { File tempFile = Files.createTempFile(FilenameUtils.getName(plugin.getName()), ".jpi").toFile(); logVerbose( String.format("%nResolving dependencies of %s by downloading plugin to temp file %s and parsing " + "MANIFEST.MF", plugin.getName(), tempFile.toString())); if (!downloadPlugin(plugin, tempFile)) { Files.delete(tempFile.toPath()); throw new DownloadPluginException("Unable to resolve dependencies for " + plugin.getName()); } if (plugin.getVersion().toString().equals("latest") || plugin.getVersion().toString().equals("experimental")) { String version = getAttributeFromManifest(tempFile, "Plugin-Version"); if (!StringUtils.isEmpty(version)) { plugin.setVersion(new VersionNumber(version)); } } String dependencyString = getAttributeFromManifest(tempFile, "Plugin-Dependencies"); if (StringUtils.isEmpty(dependencyString)) { logVerbose("\n" + plugin.getName() + " has no dependencies"); return dependentPlugins; } String[] dependencies = dependencyString.split(","); for (String dependency : dependencies) { if (!dependency.contains("resolution:=optional")) { String[] pluginInfo = dependency.split(":"); String pluginName = pluginInfo[0]; String pluginVersion = pluginInfo[1]; Plugin dependentPlugin = new Plugin(pluginName, pluginVersion, null, null); if (useLatestSpecified && plugin.isLatest() || useLatestAll) { VersionNumber latestPluginVersion = getLatestPluginVersion(pluginName); dependentPlugin.setVersion(latestPluginVersion); dependentPlugin.setLatest(true); } dependentPlugins.add(dependentPlugin); dependentPlugin.setParent(plugin); } } logVerbose(dependentPlugins.isEmpty() ? String.format("%n%s has no dependencies", plugin.getName()) : String.format("%n%s depends on: %n", plugin.getName()) + dependentPlugins.stream() .map(p -> p.getName() + " " + p.getVersion()) .collect(Collectors.joining("\n"))); plugin.setJenkinsVersion(getAttributeFromManifest(tempFile, "Jenkins-Version")); Files.delete(tempFile.toPath()); return dependentPlugins; } catch (IOException e) { System.out.println(String.format("Unable to resolve dependencies for %s", plugin.getName())); if (verbose) { e.printStackTrace(); } return dependentPlugins; } } @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> resolveDependenciesFromManifest(Plugin plugin) { List<Plugin> dependentPlugins = new ArrayList<>(); try { File tempFile = Files.createTempFile(FilenameUtils.getName(plugin.getName()), ".jpi").toFile(); logVerbose( String.format("%nResolving dependencies of %s by downloading plugin to temp file %s and parsing " + "MANIFEST.MF", plugin.getName(), tempFile.toString())); if (!downloadPlugin(plugin, tempFile)) { Files.delete(tempFile.toPath()); throw new DownloadPluginException("Unable to resolve dependencies for " + plugin.getName()); } if (plugin.getVersion().toString().equals("latest") || plugin.getVersion().toString().equals("experimental")) { String version = getAttributeFromManifest(tempFile, "Plugin-Version"); if (!StringUtils.isEmpty(version)) { plugin.setVersion(new VersionNumber(version)); } } String dependencyString = getAttributeFromManifest(tempFile, "Plugin-Dependencies"); if (StringUtils.isEmpty(dependencyString)) { logVerbose("\n" + plugin.getName() + " has no dependencies"); return dependentPlugins; } String[] dependencies = dependencyString.split(","); for (String dependency : dependencies) { if (!dependency.contains("resolution:=optional")) { String[] pluginInfo = dependency.split(":"); String pluginName = pluginInfo[0]; String pluginVersion = pluginInfo[1]; Plugin dependentPlugin = new Plugin(pluginName, pluginVersion, null, null); if (useLatestSpecified && plugin.isLatest() || useLatestAll) { VersionNumber latestPluginVersion = getLatestPluginVersion(pluginName); dependentPlugin.setVersion(latestPluginVersion); dependentPlugin.setLatest(true); } dependentPlugins.add(dependentPlugin); dependentPlugin.setParent(plugin); } } logVerbose(dependentPlugins.isEmpty() ? String.format("%n%s has no dependencies", plugin.getName()) : String.format("%n%s depends on: %n", plugin.getName()) + dependentPlugins.stream() .map(p -> p.getName() + " " + p.getVersion()) .collect(Collectors.joining("\n"))); plugin.setJenkinsVersion(getAttributeFromManifest(tempFile, "Jenkins-Version")); Files.delete(tempFile.toPath()); return dependentPlugins; } catch (IOException e) { System.out.println(String.format("Unable to resolve dependencies for %s", plugin.getName())); if (verbose) { e.printStackTrace(); } return dependentPlugins; } } @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();  }