mbien commented on code in PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#discussion_r2242568598


##########
java/maven/src/org/netbeans/modules/maven/nodes/DependencyNode.java:
##########
@@ -1425,43 +1428,42 @@ public void actionPerformed(ActionEvent e) {
                 FileObject jar = FileUtil.getArchiveFile(fil);
                 FileObject root = FileUtil.getArchiveRoot(jar);
                 String rel = FileUtil.getRelativePath(root, fil);
-                rel = rel.replaceAll("[.]class$", ".html"); //NOI18N
-                JavadocForBinaryQuery.Result res = 
JavadocForBinaryQuery.findJavadoc(root.toURL());
-                if (fil.isFolder()) {
-                    rel = rel + "/package-summary.html"; //NOI18N
+                if (rel == null) {
+                    return;
                 }
-                URL javadocUrl = findJavadoc(rel, res.getRoots());
-                if (javadocUrl != null) {
-                    HtmlBrowser.URLDisplayer.getDefault().showURL(javadocUrl);
-                } else {
-                    
StatusDisplayer.getDefault().setStatusText(ERR_No_Javadoc_Found(fil.getPath()));
+                if (rel.endsWith(".class")) {
+                    rel = rel.substring(0, rel.length() - 6);
                 }
-            }
-
-            /**
-             * Locates a javadoc page by a relative name and an array of 
javadoc roots
-             * @param resource the relative name of javadoc page
-             * @param urls the array of javadoc roots
-             * @return the URL of found javadoc page or null if there is no 
such a page.
-             */
-            URL findJavadoc(String resource, URL[] urls) {
-                for (int i = 0; i < urls.length; i++) {
-                    String base = urls[i].toExternalForm();
-                    if (!base.endsWith("/")) { // NOI18N
-                        base = base + "/"; // NOI18N
-                    }
-                    try {
-                        URL u = new URL(base + resource);
-                        FileObject fo = URLMapper.findFileObject(u);
-                        if (fo != null) {
-                            return u;
+                String fqn = rel.replace('/', '.').replace("$", ".");
+                ClasspathInfo cpInfo = ClasspathInfo.create(root);
+                JavaSource js = JavaSource.create(cpInfo);
+                try {
+                    js.runUserActionTask(cc -> {
+                        cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
+                        Elements elements = cc.getElements();
+                        Element element;
+                        if (fil.isFolder()) {
+                            element = elements.getPackageElement(fqn);
+                        } else {
+                            element = elements.getTypeElement(fqn);
                         }
-                    } catch (MalformedURLException ex) {
-//                            
ErrorManager.getDefault().log(ErrorManager.ERROR, "Cannot create URL for 
"+base+resource+". "+ex.toString());   //NOI18N
-                        continue;
-                    }
+                        if (element != null) {
+                            RP.post(() -> {
+                                URL javadocUrl = 
SourceUtils.getPreferredJavadoc(element);

Review Comment:
   this call will likely have to be moved back into `runUserActionTask`, since 
javac api is single threaded AFAIK:
   
   ```java
                               URL javadocUrl = 
SourceUtils.getPreferredJavadoc(element);
                               if (javadocUrl != null) {
                                   RP.post(() -> {
                                       
HtmlBrowser.URLDisplayer.getDefault().showURL(javadocUrl);
                                   });
                               } else {
                                   
StatusDisplayer.getDefault().setStatusText(ERR_No_Javadoc_Found(fil.getPath()));
                               }
   ```



##########
java/maven/src/org/netbeans/modules/maven/nodes/DependencyNode.java:
##########
@@ -1425,43 +1428,42 @@ public void actionPerformed(ActionEvent e) {
                 FileObject jar = FileUtil.getArchiveFile(fil);
                 FileObject root = FileUtil.getArchiveRoot(jar);
                 String rel = FileUtil.getRelativePath(root, fil);
-                rel = rel.replaceAll("[.]class$", ".html"); //NOI18N
-                JavadocForBinaryQuery.Result res = 
JavadocForBinaryQuery.findJavadoc(root.toURL());
-                if (fil.isFolder()) {
-                    rel = rel + "/package-summary.html"; //NOI18N
+                if (rel == null) {
+                    return;
                 }
-                URL javadocUrl = findJavadoc(rel, res.getRoots());
-                if (javadocUrl != null) {
-                    HtmlBrowser.URLDisplayer.getDefault().showURL(javadocUrl);
-                } else {
-                    
StatusDisplayer.getDefault().setStatusText(ERR_No_Javadoc_Found(fil.getPath()));
+                if (rel.endsWith(".class")) {
+                    rel = rel.substring(0, rel.length() - 6);
                 }
-            }
-
-            /**
-             * Locates a javadoc page by a relative name and an array of 
javadoc roots
-             * @param resource the relative name of javadoc page
-             * @param urls the array of javadoc roots
-             * @return the URL of found javadoc page or null if there is no 
such a page.
-             */
-            URL findJavadoc(String resource, URL[] urls) {
-                for (int i = 0; i < urls.length; i++) {
-                    String base = urls[i].toExternalForm();
-                    if (!base.endsWith("/")) { // NOI18N
-                        base = base + "/"; // NOI18N
-                    }
-                    try {
-                        URL u = new URL(base + resource);
-                        FileObject fo = URLMapper.findFileObject(u);
-                        if (fo != null) {
-                            return u;
+                String fqn = rel.replace('/', '.').replace("$", ".");
+                ClasspathInfo cpInfo = ClasspathInfo.create(root);

Review Comment:
   `root` seems to be correct, but `cpInfo` returns some cached value which 
contains the outdated dependency.
   
   ```
                   System.out.println("->   "+root);
                   System.out.println("->   
"+cpInfo.getClassPath(ClasspathInfo.PathKind.COMPILE));
   ```
   
   ```
   ->   AbstractFileObject@432bd603[root of 
/home/mbien/.m2/repository/jakarta/servlet/jakarta.servlet-api/4.0.3/jakarta.servlet-api-4.0.3.jar[org.openide.filesystems.JarFileSystem@5d21f28f]]
   ->   
/home/mbien/NetBeansProjects/nb-reprorepo/performance/fields/target/test-classes:/home/mbien/NetBeansProjects/nb-reprorepo/performance/classes/target/classes:/tmp/mavenproject1/target/test-classes:/tmp/mavenproject1/target/classes:/home/mbien/NetBeansProjects/nb-reprorepo/performance/classes/target/test-classes:/home/mbien/NetBeansProjects/nb-reprorepo/performance/fields/target/classes:/home/mbien/.m2/repository/jakarta/servlet/jakarta.servlet-api/4.0.2/jakarta.servlet-api-4.0.2.jar
   
   ```
   after switch from 4.0.3 to 4.0.2.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to