@@ -70,8 +70,15 @@ public void createJarFrom(Path outputFile, Path sourceDirectory) throws IOExcept
7070 Files .walkFileTree (sourceDirectory , new SimpleFileVisitor <>() {
7171 @ Override
7272 public FileVisitResult visitFile (Path file , BasicFileAttributes attrs ) throws IOException {
73- var entry = fileToZipEntry (sourceDirectory , file );
74- jarStream .putNextEntry (entry );
73+
74+ // File names should be forward-slash delimited in ZIP files.
75+ var fileName = StreamSupport
76+ .stream (sourceDirectory .relativize (file ).spliterator (), false )
77+ .map (Path ::getFileName )
78+ .map (Path ::toString )
79+ .collect (Collectors .joining ("/" ));
80+
81+ jarStream .putNextEntry (new ZipEntry (fileName ));
7582 jarStream .write (Files .readAllBytes (file ));
7683 jarStream .closeEntry ();
7784 return FileVisitResult .CONTINUE ;
@@ -81,14 +88,4 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
8188 jarStream .finish ();
8289 }
8390 }
84-
85- private ZipEntry fileToZipEntry (Path sourceDirectory , Path file ) {
86- // Calculate the file name to use in the zip (forward-slash separated)
87- var fileName = StreamSupport
88- .stream (sourceDirectory .relativize (file ).spliterator (), false )
89- .map (Path ::getFileName )
90- .map (Path ::toString )
91- .collect (Collectors .joining ("/" ));
92- return new ZipEntry (fileName );
93- }
9491}
0 commit comments