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.URL ; 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import javax.swing.event.ChangeListener ; 29 import org.netbeans.api.java.queries.JavadocForBinaryQuery; 30 import org.netbeans.modules.apisupport.project.NbModuleProject; 31 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider; 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.URLMapper; 36 37 41 public final class JavadocForBinaryImpl implements JavadocForBinaryQueryImplementation { 42 43 private static final String NB_ALL_INFIX = "nbbuild" + File.separatorChar + "build" + File.separatorChar + "javadoc" + File.separatorChar; private static final String EXT_INFIX = "build" + File.separatorChar + "javadoc" + File.separatorChar; 46 47 static boolean ignoreNonexistentRoots = true; 48 49 private final NbModuleProject project; 50 51 public JavadocForBinaryImpl(NbModuleProject project) { 52 this.project = project; 53 } 54 55 public JavadocForBinaryQuery.Result findJavadoc(URL binaryRoot) { 56 if (!binaryRoot.equals(Util.urlForJar(project.getModuleJarLocation()))) { 57 return null; 58 } 59 String cnbdashes = project.getCodeNameBase().replace('.', '-'); 60 try { 61 final List <URL > candidates = new ArrayList (); 62 NbPlatform platform = project.getPlatform(false); 63 if (platform == null) { 64 return null; 65 } 66 URL [] roots = platform.getJavadocRoots(); 67 for (int i = 0; i < roots.length; i++) { 68 candidates.add(new URL (roots[i], cnbdashes + "/")); } 70 File dir; 71 NbModuleProvider.NbModuleType type = Util.getModuleType(project); 72 if (type == NbModuleProvider.NETBEANS_ORG) { 73 dir = project.getNbrootFile(NB_ALL_INFIX + cnbdashes); 74 } else { 75 dir = new File (project.getProjectDirectoryFile(), EXT_INFIX + cnbdashes); 76 } 77 candidates.add(Util.urlForDir(dir)); 78 if (ignoreNonexistentRoots) { 79 Iterator it = candidates.iterator(); 80 while (it.hasNext()) { 81 URL u = (URL ) it.next(); 82 if (URLMapper.findFileObject(u) == null) { 83 it.remove(); 84 } 85 } 86 } 87 return new JavadocForBinaryQuery.Result() { 88 public URL [] getRoots() { 89 return (URL []) candidates.toArray(new URL [candidates.size()]); 90 } 91 public void addChangeListener(ChangeListener l) {} 92 public void removeChangeListener(ChangeListener l) {} 93 }; 94 } catch (MalformedURLException e) { 95 throw new AssertionError (e); 96 } 97 } 98 99 } 100 | Popular Tags |