1313import java .util .Map .Entry ;
1414import java .util .Optional ;
1515import java .util .Set ;
16+ import java .util .TreeMap ;
1617import java .util .function .Predicate ;
1718import java .util .jar .Attributes ;
1819import java .util .jar .Manifest ;
@@ -105,6 +106,7 @@ protected static void copyFiles(ApplicationArchive archive, ArchiveCreator archi
105106 Map <String , List <byte []>> services ,
106107 Predicate <String > ignoredEntriesPredicate ) throws IOException {
107108 try {
109+ Map <String , Path > pathsToCopy = new TreeMap <>();
108110 archive .accept (tree -> {
109111 tree .walk (new PathVisitor () {
110112 @ Override
@@ -114,32 +116,35 @@ public void visitPath(PathVisit visit) {
114116 if (relativePath .isEmpty () || ignoredEntriesPredicate .test (relativePath )) {
115117 return ;
116118 }
117- try {
118- if (Files .isDirectory (visit .getPath ())) {
119- archiveCreator .addDirectory (relativePath );
120- } else {
121- if (relativePath .startsWith ("META-INF/services/" ) && relativePath .length () > 18
122- && services != null ) {
123- final byte [] content ;
124- try {
125- content = Files .readAllBytes (visit .getPath ());
126- } catch (IOException e ) {
127- throw new UncheckedIOException (e );
128- }
129- services .computeIfAbsent (relativePath , (u ) -> new ArrayList <>()).add (content );
130- } else if (!relativePath .equals ("META-INF/INDEX.LIST" )) {
131- //TODO: auto generate INDEX.LIST
132- //this may have implications for Camel though, as they change the layout
133- //also this is only really relevant for the thin jar layout
134- archiveCreator .addFileIfNotExists (visit .getPath (), relativePath );
119+ if (Files .isDirectory (visit .getPath ())) {
120+ pathsToCopy .put (relativePath , visit .getPath ());
121+ } else {
122+ if (relativePath .startsWith ("META-INF/services/" ) && relativePath .length () > 18
123+ && services != null ) {
124+ final byte [] content ;
125+ try {
126+ content = Files .readAllBytes (visit .getPath ());
127+ } catch (IOException e ) {
128+ throw new UncheckedIOException (e );
135129 }
130+ services .computeIfAbsent (relativePath , (u ) -> new ArrayList <>()).add (content );
131+ } else if (!relativePath .equals ("META-INF/INDEX.LIST" )) {
132+ //TODO: auto generate INDEX.LIST
133+ //this may have implications for Camel though, as they change the layout
134+ //also this is only really relevant for the thin jar layout
135+ pathsToCopy .put (relativePath , visit .getPath ());
136136 }
137- } catch (IOException e ) {
138- throw new UncheckedIOException (e );
139137 }
140138 }
141139 });
142140 });
141+ for (Entry <String , Path > pathEntry : pathsToCopy .entrySet ()) {
142+ if (Files .isDirectory (pathEntry .getValue ())) {
143+ archiveCreator .addDirectory (pathEntry .getKey ());
144+ } else {
145+ archiveCreator .addFileIfNotExists (pathEntry .getValue (), pathEntry .getKey ());
146+ }
147+ }
143148 } catch (RuntimeException re ) {
144149 final Throwable cause = re .getCause ();
145150 if (cause instanceof IOException ) {
0 commit comments