1 19 20 package org.netbeans.modules.java.j2seplatform.platformdefinition; 21 22 import java.io.File ; 23 import java.io.FileOutputStream ; 24 import java.io.IOException ; 25 import java.io.OutputStream ; 26 import java.net.URI ; 27 import java.net.URL ; 28 import java.util.ArrayList ; 29 import java.util.jar.JarOutputStream ; 30 import java.util.zip.ZipEntry ; 31 import junit.framework.Test; 32 import junit.framework.TestCase; 33 import junit.framework.TestSuite; 34 import org.netbeans.api.java.classpath.ClassPath; 35 import org.netbeans.api.java.platform.JavaPlatform; 36 import org.netbeans.api.java.queries.JavadocForBinaryQuery; 37 import org.netbeans.api.project.TestUtil; 38 import org.netbeans.junit.NbTestCase; 39 import org.openide.filesystems.FileLock; 40 import org.openide.filesystems.FileObject; 41 import org.openide.filesystems.FileSystem; 42 import org.openide.filesystems.FileUtil; 43 import org.openide.filesystems.URLMapper; 44 import org.openide.util.Lookup; 45 import org.openide.util.Utilities; 46 import org.openide.util.lookup.Lookups; 47 import org.netbeans.core.startup.layers.ArchiveURLMapper; 48 import org.netbeans.modules.masterfs.MasterURLMapper; 49 50 52 57 public class JavadocForBinaryQueryPlatformImplTest extends NbTestCase implements Lookup.Provider { 58 59 60 public JavadocForBinaryQueryPlatformImplTest(java.lang.String testName) { 61 super(testName); 62 TestUtil.setLookup (Lookups.proxy(this)); 63 } 64 65 private Lookup lookup; 66 67 protected void setUp() throws Exception { 68 System.setProperty("netbeans.user", getWorkDirPath()); 69 super.setUp(); 70 clearWorkDir(); 71 } 72 73 private File getBaseDir() throws Exception { 74 File dir = getWorkDir(); 75 if (Utilities.isWindows()) { 76 dir = new File (dir.getCanonicalPath()); 77 } 78 return dir; 79 } 80 81 public void testQuery() throws Exception { 82 JavaPlatform platform = JavaPlatform.getDefault(); 83 84 ClassPath cp = platform.getBootstrapLibraries(); 85 ClassPath.Entry entry = (ClassPath.Entry)cp.entries().iterator().next(); 86 URL url = entry.getURL(); 87 if (FileUtil.getArchiveFile(url) != null) { 88 url = FileUtil.getArchiveFile(url); 89 } 90 File root = new File (url.getFile()); 91 92 FileObject pfo = cp.getRoots()[0]; 93 URL u = URLMapper.findURL(pfo, URLMapper.EXTERNAL); 94 URL urls[] = JavadocForBinaryQuery.findJavadoc(u).getRoots(); 95 assertEquals(0, urls.length); 96 97 ArrayList l = new ArrayList (); 98 File javadocFile = getBaseDir(); 99 l.add(javadocFile.toURI().toURL()); 100 J2SEPlatformImpl platformImpl = (J2SEPlatformImpl)platform; 101 platformImpl.setJavadocFolders(l); 102 urls = JavadocForBinaryQuery.findJavadoc(u).getRoots(); 103 assertEquals(1, urls.length); 104 assertEquals(javadocFile.toURI().toURL(), urls[0]); 105 } 106 107 public synchronized Lookup getLookup() { 108 if (lookup == null) { 109 lookup = Lookups.fixed(new Object [] { 110 new JavaPlatformProviderImpl (), 111 new ArchiveURLMapper(), 112 new JavadocForBinaryQueryPlatformImpl(), 113 new MasterURLMapper(), 114 }); 115 } 116 return lookup; 117 } 118 119 } 120 | Popular Tags |