This is an automated email from the ASF dual-hosted git repository.

jlahoda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 4f168de  For multi-release modular jars, use the newest module-info 
available when detecting module name.
4f168de is described below

commit 4f168de17f3936ae5c5b2eab694b60b984037066
Author: Jan Lahoda <jlah...@netbeans.org>
AuthorDate: Thu Oct 4 07:31:39 2018 +0200

    For multi-release modular jars, use the newest module-info available when 
detecting module name.
---
 .../netbeans/modules/java/source/ModuleNames.java  | 23 ++++++++++++-
 .../modules/java/source/ModuleNamesTest.java       | 39 ++++++++++++++++++++++
 2 files changed, 61 insertions(+), 1 deletion(-)

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 8073c10..b4b7562 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 final class ModuleNames {
             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 1fd092e..d177add 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 class ModuleNamesTest extends NbTestCase {
         }
     }
 
+    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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

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

Reply via email to