You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/10/29 05:21:05 UTC

[GitHub] lkishalmi closed pull request #965: For multi-release modular jars, use the newest module-info available …

lkishalmi closed pull request #965: For multi-release modular jars, use the newest module-info available …
URL: https://github.com/apache/incubator-netbeans/pull/965
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/ModuleNames.java b/java/java.source.base/src/org/netbeans/modules/java/source/ModuleNames.java
index 8073c10e6c..b4b7562afb 100644
--- a/java/java.source.base/src/org/netbeans/modules/java/source/ModuleNames.java
+++ b/java/java.source.base/src/org/netbeans/modules/java/source/ModuleNames.java
@@ -129,7 +129,28 @@ public String getModuleName(
             final FileObject root = URLMapper.findFileObject(rootUrl);
             if (root != null) {
                 final FileObject file = FileUtil.getArchiveFile(root);
-                final FileObject moduleInfo = root.getFileObject(FileObjects.MODULE_INFO, FileObjects.CLASS);
+                FileObject moduleInfo = null;
+                //try versioned module-infos, as the source/target level is not available here,
+                //use the most up-to-date version:
+                FileObject versions = root.getFileObject("META-INF/versions");
+                if (versions != null) {
+                    int version = -1;
+                    for (FileObject c : versions.getChildren()) {
+                        try {
+                            int currentVersion = Integer.parseInt(c.getNameExt());
+                            FileObject currentMI = c.getFileObject(FileObjects.MODULE_INFO, FileObjects.CLASS);
+                            if (currentVersion > version && currentMI != null) {
+                                moduleInfo = currentMI;
+                                version = currentVersion;
+                            }
+                        } catch (NumberFormatException ex) {
+                            //ok, ignore
+                        }
+                    }
+                }
+                if (moduleInfo == null) {
+                    moduleInfo = root.getFileObject(FileObjects.MODULE_INFO, FileObjects.CLASS);
+                }
                 if (moduleInfo != null) {
                     try {
                         final String modName = readModuleName(moduleInfo);
diff --git a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/ModuleNamesTest.java b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/ModuleNamesTest.java
index 1fd092e98c..d177add42f 100644
--- a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/ModuleNamesTest.java
+++ b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/ModuleNamesTest.java
@@ -432,6 +432,45 @@ public void testAutomaticProject() throws IOException {
         }
     }
 
+    public void testVersionedModuleInfo() throws IOException {
+        final TraceHandler th = TraceHandler.register();
+        try {
+            FileObject mod = FileUtil.getArchiveRoot(jar(
+                    wd,
+                    "dist.jar", //NOI18N
+                    () -> Collections.singleton(Pair.of(
+                            "META-INF/versions/9/module-info.class",    //NOI18N
+                            moduleInfoClz(moduleInfoJava("org.me.app", Collections.emptyList())).get()))        //NOI18N
+                    ).get());
+            String moduleName = names.getModuleName(mod.toURL(), false);
+            assertEquals("org.me.app", moduleName);    //NOI18N
+            assertTrue(th.isCalculated());
+            th.reset();
+            mod = FileUtil.getArchiveRoot(jar(
+                    wd,
+                    "dist2.jar", //NOI18N
+                    () -> Arrays.asList(Pair.of(
+                            "META-INF/versions/9/module-info.class",    //NOI18N
+                            moduleInfoClz(moduleInfoJava("org.me.app", Collections.emptyList())).get()),        //NOI18N
+                            Pair.of(
+                            "META-INF/versions/12/module-info.class",    //NOI18N
+                            moduleInfoClz(moduleInfoJava("org.me.app2", Collections.emptyList())).get()),        //NOI18N
+                            Pair.of(
+                            "META-INF/versions/broken/module-info.class",    //NOI18N
+                            moduleInfoClz(moduleInfoJava("broken", Collections.emptyList())).get()),        //NOI18N
+                            Pair.of(
+                            "module-info.class",    //NOI18N
+                            moduleInfoClz(moduleInfoJava("old", Collections.emptyList())).get()))        //NOI18N
+                    ).get());
+            moduleName = names.getModuleName(mod.toURL(), false);
+            assertEquals("org.me.app2", moduleName);    //NOI18N
+            assertTrue(th.isCalculated());
+            th.reset();
+        } finally {
+            th.unregister();
+        }
+    }
+
     public void testPlatform() throws Exception {
         final TraceHandler th = TraceHandler.register();
         final URL JAVA_BASE = new URL("nbjrt:file:/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/!/modules/java.base/");   //NOI18N


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists