1 19 20 package org.netbeans.modules.java.source.classpath; 21 22 import java.io.FileNotFoundException ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.io.OutputStream ; 26 import java.util.Date ; 27 import java.util.Enumeration ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import junit.framework.*; 31 import java.io.File ; 32 import java.net.URI ; 33 import java.net.URL ; 34 import javax.swing.event.ChangeListener ; 35 import org.netbeans.api.java.classpath.ClassPath; 36 import org.netbeans.api.java.queries.SourceForBinaryQuery; 37 import org.netbeans.api.java.source.ClasspathInfo; 38 import org.netbeans.junit.NbTestCase; 39 import org.netbeans.modules.java.source.usages.ClasspathInfoAccessor; 40 import org.netbeans.modules.java.source.usages.IndexUtil; 41 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 42 import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; 43 import org.openide.filesystems.FileChangeListener; 44 import org.openide.filesystems.FileLock; 45 import org.openide.filesystems.FileObject; 46 import org.openide.filesystems.FileStateInvalidException; 47 import org.openide.filesystems.FileSystem; 48 import org.openide.filesystems.FileUtil; 49 50 54 public class CacheSourceForBinaryQueryImplTest extends NbTestCase { 55 56 FileObject[] srcRoots; 57 ClasspathInfo cpInfo; 58 CacheSourceForBinaryQueryImpl sfbq; 59 60 public CacheSourceForBinaryQueryImplTest(String testName) { 61 super(testName); 62 } 63 64 protected @Override void setUp() throws Exception { 65 this.clearWorkDir(); 66 File fwd = this.getWorkDir(); 67 FileObject wd = FileUtil.toFileObject(fwd); 68 assertNotNull(wd); 69 File cacheFolder = new File (fwd,"cache"); cacheFolder.mkdirs(); 71 IndexUtil.setCacheFolder (cacheFolder); 72 this.srcRoots = new FileObject [2]; 73 this.srcRoots[0] = wd.createFolder("src1"); this.srcRoots[1] = wd.createFolder("src2"); ClassPath bootPath = ClassPathSupport.createClassPath(new URL [0]); 76 ClassPath compilePath = ClassPathSupport.createClassPath(new URL [0]); 77 ClassPath srcPath = ClassPathSupport.createClassPath(srcRoots); 78 this.cpInfo = ClasspathInfo.create(bootPath,compilePath,srcPath); 79 this.sfbq = new CacheSourceForBinaryQueryImpl (); 80 } 81 82 protected @Override void tearDown() throws Exception { 83 this.cpInfo = null; 84 } 85 86 public void testFindSourceRoots() throws Exception { 87 ClassPath outCp = this.cpInfo.getClassPath(ClasspathInfo.PathKind.OUTPUT); 88 assertNotNull(outCp); 89 assertEquals(srcRoots.length,outCp.entries().size()); 90 Iterator <ClassPath.Entry> it = ((List <ClassPath.Entry>)outCp.entries()).iterator(); 91 for (int i=0; it.hasNext(); i++) { 92 ClassPath.Entry entry = it.next(); 93 URL url = entry.getURL(); 94 SourceForBinaryQuery.Result result = this.sfbq.findSourceRoots(url); 95 FileObject[] sourceRoots = result.getRoots(); 96 assertNotNull(sourceRoots); 97 assertEquals(1,sourceRoots.length); 98 assertEquals(srcRoots[i],sourceRoots[0]); 99 } 100 } 101 102 } 103 | Popular Tags |