wilx commented on code in PR #829:
URL: 
https://github.com/apache/maven-shade-plugin/pull/829#discussion_r3855989280


##########
src/main/java/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.java:
##########
@@ -122,31 +174,42 @@ public boolean hasTransformedResource() {
 
     @Override
     public void modifyOutputStream(JarOutputStream jos) throws IOException {
-        // If we didn't find a manifest, then let's create one.
-        if (manifest == null) {
-            manifest = new Manifest();
-        }
-
-        Attributes attributes = manifest.getMainAttributes();
+        try {
+            Manifest outputManifest = manifest == null ? new Manifest() : new 
Manifest(manifest);
+            Attributes attributes = outputManifest.getMainAttributes();
+            if (attributes.getValue(Attributes.Name.MANIFEST_VERSION) == null) 
{
+                attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
+            }
 
-        if (mainClass != null) {
-            attributes.put(Attributes.Name.MAIN_CLASS, mainClass);
-        }
+            if (mainClass != null) {
+                attributes.put(Attributes.Name.MAIN_CLASS, mainClass);
+            }
 
-        if (manifestEntries != null) {
-            for (Map.Entry<String, Object> entry : manifestEntries.entrySet()) 
{
-                if (entry.getValue() == null) {
-                    attributes.remove(new Attributes.Name(entry.getKey()));
-                } else {
-                    attributes.put(new Attributes.Name(entry.getKey()), 
entry.getValue());
+            if (manifestEntries != null) {
+                for (Map.Entry<String, Object> entry : 
manifestEntries.entrySet()) {
+                    if (entry.getValue() == null) {
+                        attributes.remove(new Attributes.Name(entry.getKey()));
+                    } else {
+                        attributes.put(new Attributes.Name(entry.getKey()), 
entry.getValue());
+                    }
                 }
             }
-        }
 
-        JarEntry jarEntry = new JarEntry(JarFile.MANIFEST_NAME);
-        jarEntry.setTime(time);
-        jos.putNextEntry(jarEntry);
-        manifest.write(jos);
+            if (forceMultiRelease) {
+                attributes.putValue("Multi-Release", "true");
+            }
+            if (forceAutomaticModuleName != null) {
+                attributes.putValue("Automatic-Module-Name", 
forceAutomaticModuleName);
+            }
+
+            JarEntry jarEntry = new JarEntry(JarFile.MANIFEST_NAME);
+            jarEntry.setTime(time);
+            jos.putNextEntry(jarEntry);
+            outputManifest.write(jos);
+        } finally {
+            forceMultiRelease = false;

Review Comment:
   I have made a change to limit the fields change only around the call to 
`modifyOutputStream`.
   
   Threading should not be a problem. The transformers should be per-mojo 
invocation and within the invocation it is all a single thread. Unless the 
plugin itself spawns some threads.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to