1 19 20 package org.netbeans.modules.apisupport.project.queries; 21 22 import java.io.File ; 23 import java.net.MalformedURLException ; 24 import java.net.URI ; 25 import java.net.URL ; 26 import java.util.ArrayList ; 27 import java.util.Arrays ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import javax.swing.event.ChangeListener ; 31 import org.netbeans.api.java.queries.JavadocForBinaryQuery; 32 import org.netbeans.modules.apisupport.project.Util; 33 import org.netbeans.modules.apisupport.project.universe.NbPlatform; 34 import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; 35 import org.openide.filesystems.FileUtil; 36 import org.openide.filesystems.URLMapper; 37 import org.openide.modules.InstalledFileLocator; 38 39 44 public final class GlobalJavadocForBinaryImpl implements JavadocForBinaryQueryImplementation { 45 46 public JavadocForBinaryQuery.Result findJavadoc(URL binaryRoot) { 47 try { 48 if (!binaryRoot.getProtocol().equals("jar")) { Util.err.log(binaryRoot + " is not an archive file."); return null; 52 } 53 URL jar = FileUtil.getArchiveFile(binaryRoot); 54 if (!jar.getProtocol().equals("file")) { Util.err.log(binaryRoot + " is not an archive file."); return null; 57 } 58 if (jar.toExternalForm().endsWith("/xtest/lib/junit.jar")) { File f = InstalledFileLocator.getDefault().locate("modules/ext/junit-3.8.2.jar", "org.netbeans.modules.junit", false); if (f == null) { 62 f = InstalledFileLocator.getDefault().locate("modules/ext/junit-3.8.1.jar", "org.netbeans.modules.junit", false); } 65 if (f != null) { 66 return JavadocForBinaryQuery.findJavadoc(FileUtil.getArchiveRoot(f.toURI().toURL())); 67 } 68 } 69 File binaryRootF = new File (URI.create(jar.toExternalForm())); 70 NbPlatform supposedPlaf = null; 71 for (Iterator it = NbPlatform.getPlatforms().iterator(); it.hasNext(); ) { 72 NbPlatform plaf = (NbPlatform) it.next(); 73 if (binaryRootF.getAbsolutePath().startsWith(plaf.getDestDir().getAbsolutePath())) { 74 supposedPlaf = plaf; 75 break; 76 } 77 } 78 if (supposedPlaf == null) { 79 Util.err.log(binaryRootF + " does not correspond to a known platform"); return null; 81 } 82 String n = binaryRootF.getName(); 84 if (!n.endsWith(".jar")) { Util.err.log(binaryRootF + " is not a *.jar"); return null; 87 } 88 String cnbdashes = n.substring(0, n.length() - 4); 89 final List <URL > candidates = new ArrayList (); 90 URL [] roots = supposedPlaf.getJavadocRoots(); 91 Util.err.log("Platform in " + supposedPlaf.getDestDir() + " claimed to have Javadoc roots " + Arrays.asList(roots)); 92 for (int i = 0; i < roots.length; i++) { 93 candidates.add(roots[i]); 95 candidates.add(new URL (roots[i], cnbdashes + '/')); 97 } 98 Iterator it = candidates.iterator(); 99 while (it.hasNext()) { 100 URL u = (URL ) it.next(); 101 if (URLMapper.findFileObject(u) == null) { 102 Util.err.log("No such Javadoc candidate URL " + u); 103 it.remove(); 104 } 105 } 106 return new JavadocForBinaryQuery.Result() { 107 public URL [] getRoots() { 108 return (URL []) candidates.toArray(new URL [candidates.size()]); 109 } 110 public void addChangeListener(ChangeListener l) {} 111 public void removeChangeListener(ChangeListener l) {} 112 }; 113 } catch (MalformedURLException e) { 114 throw new AssertionError (e); 115 } 116 } 117 118 } 119 | Popular Tags |