@Test public void bundledPluginsTest() { URL warURL = this.getClass().getResource("/bundledplugintest.war"); File testWar = new File(warURL.getFile()); Config config = Config.builder() .withJenkinsWar(testWar.toString()) .build(); PluginManager pluginManager = new PluginManager(config); Map<String, Plugin> actualPlugins = pluginManager.bundledPlugins(); assertThat(actualPlugins.values()) .containsExactlyInAnyOrder( new Plugin("credentials","2.1.18", null, null), new Plugin("display-url-api","2.0", null, null), new Plugin("github-branch-source", "1.8", null, null)); }
@SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "PATH_TRAVERSAL_IN"}) public Map<String, Plugin> bundledPlugins() { Map<String, Plugin> bundledPlugins = new HashMap<>(); if (jenkinsWarFile.exists()) { Path path = Paths.get(jenkinsWarFile.toString()); URI jenkinsWarUri; try { jenkinsWarUri = new URI("jar:" + path.toUri()); } catch (URISyntaxException e) { throw new WarBundledPluginException("Unable to open war file to extract bundled plugin information", e); } try (FileSystem warFS = FileSystems.newFileSystem(jenkinsWarUri, Collections.emptyMap())) { Path warPath = warFS.getPath("/").getRoot(); PathMatcher matcher = warFS.getPathMatcher("regex:.*[^detached-]plugins.*\\.\\w+pi"); Stream<Path> walk = Files.walk(warPath); for (Iterator<Path> it = walk.iterator(); it.hasNext(); ) { Path file = it.next(); if (matcher.matches(file)) { Path fileName = file.getFileName(); if (fileName != null) { InputStream in = Files.newInputStream(file); final Path tempFile = Files.createTempFile("PREFIX", "SUFFIX"); try (FileOutputStream out = new FileOutputStream(tempFile.toFile())) { IOUtils.copy(in, out); } String pluginVersion = getPluginVersion(tempFile.toFile()); Files.delete(tempFile); String pluginName = FilenameUtils.getBaseName(fileName.toString()); bundledPlugins .put(pluginName, new Plugin(pluginName, pluginVersion, null, null)); } } } } catch (IOException e) { throw new WarBundledPluginException("Unable to open war file to extract bundled plugin information", e); } } else { System.out.println("War not found, installing all plugins: " + jenkinsWarFile.toString()); } return bundledPlugins; }
PluginManager { @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "PATH_TRAVERSAL_IN"}) public Map<String, Plugin> bundledPlugins() { Map<String, Plugin> bundledPlugins = new HashMap<>(); if (jenkinsWarFile.exists()) { Path path = Paths.get(jenkinsWarFile.toString()); URI jenkinsWarUri; try { jenkinsWarUri = new URI("jar:" + path.toUri()); } catch (URISyntaxException e) { throw new WarBundledPluginException("Unable to open war file to extract bundled plugin information", e); } try (FileSystem warFS = FileSystems.newFileSystem(jenkinsWarUri, Collections.emptyMap())) { Path warPath = warFS.getPath("/").getRoot(); PathMatcher matcher = warFS.getPathMatcher("regex:.*[^detached-]plugins.*\\.\\w+pi"); Stream<Path> walk = Files.walk(warPath); for (Iterator<Path> it = walk.iterator(); it.hasNext(); ) { Path file = it.next(); if (matcher.matches(file)) { Path fileName = file.getFileName(); if (fileName != null) { InputStream in = Files.newInputStream(file); final Path tempFile = Files.createTempFile("PREFIX", "SUFFIX"); try (FileOutputStream out = new FileOutputStream(tempFile.toFile())) { IOUtils.copy(in, out); } String pluginVersion = getPluginVersion(tempFile.toFile()); Files.delete(tempFile); String pluginName = FilenameUtils.getBaseName(fileName.toString()); bundledPlugins .put(pluginName, new Plugin(pluginName, pluginVersion, null, null)); } } } } catch (IOException e) { throw new WarBundledPluginException("Unable to open war file to extract bundled plugin information", e); } } else { System.out.println("War not found, installing all plugins: " + jenkinsWarFile.toString()); } return bundledPlugins; } }
PluginManager { @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "PATH_TRAVERSAL_IN"}) public Map<String, Plugin> bundledPlugins() { Map<String, Plugin> bundledPlugins = new HashMap<>(); if (jenkinsWarFile.exists()) { Path path = Paths.get(jenkinsWarFile.toString()); URI jenkinsWarUri; try { jenkinsWarUri = new URI("jar:" + path.toUri()); } catch (URISyntaxException e) { throw new WarBundledPluginException("Unable to open war file to extract bundled plugin information", e); } try (FileSystem warFS = FileSystems.newFileSystem(jenkinsWarUri, Collections.emptyMap())) { Path warPath = warFS.getPath("/").getRoot(); PathMatcher matcher = warFS.getPathMatcher("regex:.*[^detached-]plugins.*\\.\\w+pi"); Stream<Path> walk = Files.walk(warPath); for (Iterator<Path> it = walk.iterator(); it.hasNext(); ) { Path file = it.next(); if (matcher.matches(file)) { Path fileName = file.getFileName(); if (fileName != null) { InputStream in = Files.newInputStream(file); final Path tempFile = Files.createTempFile("PREFIX", "SUFFIX"); try (FileOutputStream out = new FileOutputStream(tempFile.toFile())) { IOUtils.copy(in, out); } String pluginVersion = getPluginVersion(tempFile.toFile()); Files.delete(tempFile); String pluginName = FilenameUtils.getBaseName(fileName.toString()); bundledPlugins .put(pluginName, new Plugin(pluginName, pluginVersion, null, null)); } } } } catch (IOException e) { throw new WarBundledPluginException("Unable to open war file to extract bundled plugin information", e); } } else { System.out.println("War not found, installing all plugins: " + jenkinsWarFile.toString()); } return bundledPlugins; } @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "we want the user to be able to specify a path")  PluginManager(Config cfg); }
PluginManager { @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "PATH_TRAVERSAL_IN"}) public Map<String, Plugin> bundledPlugins() { Map<String, Plugin> bundledPlugins = new HashMap<>(); if (jenkinsWarFile.exists()) { Path path = Paths.get(jenkinsWarFile.toString()); URI jenkinsWarUri; try { jenkinsWarUri = new URI("jar:" + path.toUri()); } catch (URISyntaxException e) { throw new WarBundledPluginException("Unable to open war file to extract bundled plugin information", e); } try (FileSystem warFS = FileSystems.newFileSystem(jenkinsWarUri, Collections.emptyMap())) { Path warPath = warFS.getPath("/").getRoot(); PathMatcher matcher = warFS.getPathMatcher("regex:.*[^detached-]plugins.*\\.\\w+pi"); Stream<Path> walk = Files.walk(warPath); for (Iterator<Path> it = walk.iterator(); it.hasNext(); ) { Path file = it.next(); if (matcher.matches(file)) { Path fileName = file.getFileName(); if (fileName != null) { InputStream in = Files.newInputStream(file); final Path tempFile = Files.createTempFile("PREFIX", "SUFFIX"); try (FileOutputStream out = new FileOutputStream(tempFile.toFile())) { IOUtils.copy(in, out); } String pluginVersion = getPluginVersion(tempFile.toFile()); Files.delete(tempFile); String pluginName = FilenameUtils.getBaseName(fileName.toString()); bundledPlugins .put(pluginName, new Plugin(pluginName, pluginVersion, null, null)); } } } } catch (IOException e) { throw new WarBundledPluginException("Unable to open war file to extract bundled plugin information", e); } } else { System.out.println("War not found, installing all plugins: " + jenkinsWarFile.toString()); } return bundledPlugins; } @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 { @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "PATH_TRAVERSAL_IN"}) public Map<String, Plugin> bundledPlugins() { Map<String, Plugin> bundledPlugins = new HashMap<>(); if (jenkinsWarFile.exists()) { Path path = Paths.get(jenkinsWarFile.toString()); URI jenkinsWarUri; try { jenkinsWarUri = new URI("jar:" + path.toUri()); } catch (URISyntaxException e) { throw new WarBundledPluginException("Unable to open war file to extract bundled plugin information", e); } try (FileSystem warFS = FileSystems.newFileSystem(jenkinsWarUri, Collections.emptyMap())) { Path warPath = warFS.getPath("/").getRoot(); PathMatcher matcher = warFS.getPathMatcher("regex:.*[^detached-]plugins.*\\.\\w+pi"); Stream<Path> walk = Files.walk(warPath); for (Iterator<Path> it = walk.iterator(); it.hasNext(); ) { Path file = it.next(); if (matcher.matches(file)) { Path fileName = file.getFileName(); if (fileName != null) { InputStream in = Files.newInputStream(file); final Path tempFile = Files.createTempFile("PREFIX", "SUFFIX"); try (FileOutputStream out = new FileOutputStream(tempFile.toFile())) { IOUtils.copy(in, out); } String pluginVersion = getPluginVersion(tempFile.toFile()); Files.delete(tempFile); String pluginName = FilenameUtils.getBaseName(fileName.toString()); bundledPlugins .put(pluginName, new Plugin(pluginName, pluginVersion, null, null)); } } } } catch (IOException e) { throw new WarBundledPluginException("Unable to open war file to extract bundled plugin information", e); } } else { System.out.println("War not found, installing all plugins: " + jenkinsWarFile.toString()); } return bundledPlugins; } @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();  }