org.apache.commons.collections4.EnumerationUtils Java Examples
The following examples show how to use
org.apache.commons.collections4.EnumerationUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JarScanner.java From swagger-brake with Apache License 2.0 | 5 votes |
/** * Scans a JAR file for a single entry based on the predicate given. * @param jarFile the {@link File} object pointing to the JAR file. * @param criteria the predicate that the entries will be matched against. * @return An {@link Optional} {@link JarEntry} that matched the predicate given * @throws IOException if an I/O error has occurred */ public Optional<JarEntry> find(File jarFile, Predicate<JarEntry> criteria) throws IOException { Optional<JarEntry> result = Optional.empty(); try (JarFile jar = new JarFile(jarFile)) { List<JarEntry> jarEntries = EnumerationUtils.toList(jar.entries()); for (JarEntry entry : jarEntries) { if (criteria.test(entry)) { result = Optional.of(entry); } } } return result; }
Example #2
Source File: PluginsZipTest.java From gocd with Apache License 2.0 | 5 votes |
@Test void shouldCreateAZipWithOneCopyOfEachJar_ForAPluginBundleWithMultiplePluginsInIt() throws IOException { File bundledPluginJarLocation = createPluginFile(bundledPluginsDir, "bundled-multi-plugin-1.jar", "Bundled1"); File externalPluginJarLocation = createPluginFile(externalPluginsDir, "external-multi-plugin-1.jar", "External1"); bundledTaskPlugin = new GoPluginBundleDescriptor( getPluginDescriptor("bundled-plugin-1", bundledPluginJarLocation, true), getPluginDescriptor("bundled-plugin-2", bundledPluginJarLocation, true) ); externalTaskPlugin = new GoPluginBundleDescriptor( getPluginDescriptor("external-plugin-1", externalPluginJarLocation, false), getPluginDescriptor("external-plugin-2", externalPluginJarLocation, false) ); when(pluginManager.plugins()).thenReturn(Arrays.asList( bundledTaskPlugin.descriptors().get(0), bundledTaskPlugin.descriptors().get(1), externalTaskPlugin.descriptors().get(0), externalTaskPlugin.descriptors().get(1) )); when(pluginManager.isPluginOfType("task", "bundled-plugin-1")).thenReturn(true); when(pluginManager.isPluginOfType("scm", "bundled-plugin-2")).thenReturn(true); when(pluginManager.isPluginOfType("task", "external-plugin-1")).thenReturn(true); when(pluginManager.isPluginOfType("artifact", "external-plugin-2")).thenReturn(true); pluginsZip = spy(new PluginsZip(systemEnvironment, pluginManager)); pluginsZip.create(); ZipFile zipFile = new ZipFile(expectedZipPath); assertThat(new File(expectedZipPath).exists()).as(expectedZipPath + " should exist").isTrue(); assertThat(EnumerationUtils.toList(zipFile.entries()).size()).isEqualTo(2); assertThat(zipFile.getEntry("bundled/bundled-multi-plugin-1.jar")).isNotNull(); assertThat(zipFile.getEntry("external/external-multi-plugin-1.jar")).isNotNull(); zipFile.close(); }