JarFileUtil { @SuppressWarnings("squid:S1166") public static void readJarFile(File base, Map parameters, ClassHandler classHandler) { checkNotNull(base, "Jar file must be given"); LOGGER.info("Reading JAR file: {}", FileNameUtil.getCanonicalPath(base.getAbsolutePath())); try { readJarFile(new JarFile(base), parameters, classHandler); } catch (IOException e) { LOGGER.error("Error reading jar file: {}: {}", FileNameUtil.getCanonicalPath(base.getAbsolutePath()), e.getMessage()); } } private  JarFileUtil(); @SuppressWarnings("squid:S1166") // wants log or rethrow exception. It's logged well enough here. static void readJarFile(File base, Map parameters, ClassHandler classHandler); static boolean isJarEntry(String name);  }
@Test public void testFindClassFiles() { File jarFile = getJarFile("src/test/resources/jars/qav-doc-generator.jar"); Map<String, String> parameters = new HashMap<>(); parameters.put("includes", "**/*.class"); final Map<String, Integer> entries = new HashMap<>(); ClassHandler classHandler = (name, content) -> entries.put(name, content.length); JarFileUtil.readJarFile(jarFile, parameters, classHandler); assertThat(entries.size(), is(14)); }
@Test public void testFindNestedJarFiles() { File jarFile = getJarFile("src/test/resources/jars/nesting.jar"); Map<Object, Object> parameters = new HashMap<>(); parameters.put("includes", Lists.newArrayList("**/qav-doc-gen*.jar", "**/*.txt")); final Map<String, Integer> entries = new HashMap<>(); ClassHandler classHandler = (name, content) -> entries.put(name, content.length); JarFileUtil.readJarFile(jarFile, parameters, classHandler); assertThat(entries.size(), is(1)); assertThat(entries.get("WEB-INF/classes/my-resource.txt"), is(24)); }