jorsol commented on code in PR #57:
URL: https://github.com/apache/maven-jar-plugin/pull/57#discussion_r1085261280


##########
src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java:
##########
@@ -225,23 +237,24 @@ public File createArchive()
         jarContentFileSet.setIncludes( Arrays.asList( getIncludes() ) );
         jarContentFileSet.setExcludes( Arrays.asList( getExcludes() ) );
 
-        boolean containsModuleDescriptor = false;
         String[] includedFiles = fileSetManager.getIncludedFiles( 
jarContentFileSet );
-        for ( String includedFile : includedFiles )
+
+        // May give false positives if the files is named as module descriptor
+        // but is not in the root of the archive or in the versioned area
+        // (and hence not actually a module descriptor).
+        // That is fine since the modular Jar archiver will gracefully
+        // handle such case.
+        // And also such case is unlikely to happen as file ending
+        // with "module-info.class" is unlikely to be included in Jar file
+        // unless it is a module descriptor.
+        boolean containsModuleDescriptor =
+            Arrays.stream( includedFiles ).anyMatch( p -> p.endsWith( 
MODULE_DESCRIPTOR_FILE_NAME ) );
+
+        if ( detectMultiReleaseJar && Arrays.stream( includedFiles ).anyMatch( 
p -> p.startsWith( "META-INF" + SEPARATOR
+            + "versions" + SEPARATOR ) ) )
         {
-            // May give false positives if the files is named as module 
descriptor
-            // but is not in the root of the archive or in the versioned area
-            // (and hence not actually a module descriptor).
-            // That is fine since the modular Jar archiver will gracefully
-            // handle such case.
-            // And also such case is unlikely to happen as file ending
-            // with "module-info.class" is unlikely to be included in Jar file
-            // unless it is a module descriptor.
-            if ( includedFile.endsWith( MODULE_DESCRIPTOR_FILE_NAME ) )
-            {
-                containsModuleDescriptor = true;
-                break;
-            }
+            getLog().debug( "Adding 'Multi-Release: true' manifest entry." );
+            archive.addManifestEntry( "Multi-Release", "true" );
         }
 
         String archiverName = containsModuleDescriptor ? "mjar" : "jar";

Review Comment:
   `mjar` is for detecting a "Modular JAR", it contains a module descriptor 
(`module-info.class`), but it can be a normal "Modular JAR" (the module 
descriptor is located in the root) or a "Multi-Release Modular JAR" (the module 
descriptor is located in the versioned area).
   
   Here, we are trying to detect if the versioned area exists, independently if 
it contains a module descriptor or not.



-- 
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: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to