2424import java .util .List ;
2525import java .util .Locale ;
2626import java .util .Objects ;
27+ import java .util .Set ;
2728import java .util .jar .JarEntry ;
2829import java .util .jar .JarFile ;
2930import java .util .stream .Collectors ;
@@ -190,6 +191,8 @@ private byte[] getJarEntryContents(JarFile jarFile, JarEntry entry) {
190191 * @param wildcardPathExclusions
191192 * wildcard exclusions that are used to check each path against
192193 * before copying
194+ * @return names of the files that were either copied or already existed in
195+ * the output directory
193196 * @throws IllegalArgumentException
194197 * if jar file specified is not a file or does not exist or if
195198 * output directory is not a directory or does not exist
@@ -199,7 +202,7 @@ private byte[] getJarEntryContents(JarFile jarFile, JarEntry entry) {
199202 * if {@link IOException} occurs during the operation, for
200203 * instance, when jar file specified is not a jar file
201204 */
202- public void copyFilesFromJarTrimmingBasePath (File jar ,
205+ public Set < String > copyFilesFromJarTrimmingBasePath (File jar ,
203206 String jarDirectoryToCopyFrom , File outputDirectory ,
204207 String ... wildcardPathExclusions ) {
205208 requireFileExistence (jar );
@@ -213,13 +216,16 @@ public void copyFilesFromJarTrimmingBasePath(File jar,
213216 String basePath = normalizeJarBasePath (jarDirectoryToCopyFrom );
214217
215218 try (JarFile jarFile = new JarFile (jar , false )) {
216- jarFile .stream ().filter (file -> !file .isDirectory ())
219+ Set <String > handledFiles = jarFile .stream ()
220+ .filter (file -> !file .isDirectory ())
217221 .filter (file -> file .getName ().toLowerCase (Locale .ENGLISH )
218222 .startsWith (basePath .toLowerCase (Locale .ENGLISH )))
219223 .filter (file -> isFileIncluded (file ,
220224 wildcardPathExclusions ))
221- .forEach (jarEntry -> copyJarEntryTrimmingBasePath (jarFile ,
222- jarEntry , basePath , outputDirectory ));
225+ .map (jarEntry -> copyJarEntryTrimmingBasePath (jarFile ,
226+ jarEntry , basePath , outputDirectory ))
227+ .collect (Collectors .toSet ());
228+ return handledFiles ;
223229 } catch (IOException e ) {
224230 throw new UncheckedIOException (String .format (
225231 "Failed to extract files from jarFile '%s' to directory '%s'" ,
@@ -243,6 +249,8 @@ public void copyFilesFromJarTrimmingBasePath(File jar,
243249 * @param wildcardPathInclusions
244250 * wildcard inclusions that are used to check each path against
245251 * before copying
252+ * @return names of the files that were either copied or already existed in
253+ * the output directory
246254 * @throws IllegalArgumentException
247255 * if jar file specified is not a file or does not exist or if
248256 * output directory is not a directory or does not exist
@@ -252,7 +260,7 @@ public void copyFilesFromJarTrimmingBasePath(File jar,
252260 * if {@link IOException} occurs during the operation, for
253261 * instance, when jar file specified is not a jar file
254262 */
255- public void copyIncludedFilesFromJarTrimmingBasePath (File jar ,
263+ public Set < String > copyIncludedFilesFromJarTrimmingBasePath (File jar ,
256264 String jarDirectoryToCopyFrom , File outputDirectory ,
257265 String ... wildcardPathInclusions ) {
258266 requireFileExistence (jar );
@@ -266,12 +274,15 @@ public void copyIncludedFilesFromJarTrimmingBasePath(File jar,
266274 String basePath = normalizeJarBasePath (jarDirectoryToCopyFrom );
267275
268276 try (JarFile jarFile = new JarFile (jar , false )) {
269- jarFile .stream ().filter (file -> !file .isDirectory ())
277+ Set <String > handledFiles = jarFile .stream ()
278+ .filter (file -> !file .isDirectory ())
270279 .filter (file -> file .getName ().toLowerCase (Locale .ENGLISH )
271280 .startsWith (basePath .toLowerCase (Locale .ENGLISH )))
272281 .filter (file -> includeFile (file , wildcardPathInclusions ))
273- .forEach (jarEntry -> copyJarEntryTrimmingBasePath (jarFile ,
274- jarEntry , basePath , outputDirectory ));
282+ .map (jarEntry -> copyJarEntryTrimmingBasePath (jarFile ,
283+ jarEntry , basePath , outputDirectory ))
284+ .collect (Collectors .toSet ());
285+ return handledFiles ;
275286 } catch (IOException e ) {
276287 throw new UncheckedIOException (String .format (
277288 "Failed to extract files from jarFile '%s' to directory '%s'" ,
@@ -300,7 +311,7 @@ private boolean includeFile(ZipEntry file, String... pathInclusions) {
300311 .wildcardMatch (filePath , inclusionRule ));
301312 }
302313
303- private void copyJarEntryTrimmingBasePath (JarFile jarFile ,
314+ private String copyJarEntryTrimmingBasePath (JarFile jarFile ,
304315 ZipEntry jarEntry , String basePath , File outputDirectory ) {
305316 String fullPath = jarEntry .getName ();
306317 String relativePath = fullPath
@@ -315,6 +326,7 @@ private void copyJarEntryTrimmingBasePath(JarFile jarFile,
315326 FileUtils .copyInputStreamToFile (
316327 jarFile .getInputStream (jarEntry ), target );
317328 }
329+ return relativePath ;
318330 } catch (IOException e ) {
319331 throw new UncheckedIOException (String .format (
320332 "Failed to extract jar entry '%s' from jarFile" , jarEntry ),
0 commit comments