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 org.netbeans.api.project.FileOwnerQuery; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.modules.apisupport.project.NbModuleProject; 28 import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation; 29 import org.netbeans.spi.project.support.ant.AntProjectHelper; 30 import org.openide.filesystems.FileObject; 31 32 public class UnitTestForSourceQueryImpl implements MultipleRootsUnitTestForSourceQueryImplementation { 33 34 private NbModuleProject project; 35 36 public UnitTestForSourceQueryImpl(NbModuleProject project) { 37 this.project = project; 38 } 39 40 public URL [] findUnitTests(FileObject source) { 41 return find(source, "src.dir", "test.unit.src.dir"); } 43 44 public URL [] findSources(FileObject unitTest) { 45 return find(unitTest, "test.unit.src.dir", "src.dir"); } 47 48 private URL [] find(FileObject file, String from, String to) { 49 Project p = FileOwnerQuery.getOwner(file); 50 if (p == null) { 51 return null; 52 } 53 AntProjectHelper helper = project.getHelper(); 54 String val = project.evaluator().getProperty(from); 55 assert val != null : "No value for " + from + " in " + project; 56 FileObject fromRoot = helper.resolveFileObject(val); 57 if (!file.equals(fromRoot)) { 58 return null; 59 } 60 val = project.evaluator().getProperty(to); 61 assert val != null : "No value for " + to + " in " + project; 62 String path = helper.resolvePath(val); 63 try { 64 File f = helper.resolveFile(path); 65 if (!f.exists()) { 66 return null; 67 } 68 else { 69 return new URL [] {f.toURI().normalize().toURL()}; 70 } 71 } catch (MalformedURLException e) { 72 throw new AssertionError (e); 73 } 74 } 75 76 } 77 | Popular Tags |