elharo commented on code in PR #829:
URL:
https://github.com/apache/maven-shade-plugin/pull/829#discussion_r3848220769
##########
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:
This worries me a bit. It suggests there's a specific order to call methods,
and thread safety might be in play. Maybe forceMultiRelease and
forceAutomaticModuleName should be arguments instead of fields. Not sure, but
worth digging into
--
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]