1 19 package org.netbeans.modules.j2ee.ejbjarproject.queries; 20 import java.net.URL ; 21 import org.netbeans.api.project.FileOwnerQuery; 22 import org.netbeans.api.project.Project; 23 import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation; 24 import org.netbeans.modules.j2ee.ejbjarproject.SourceRoots; 25 import org.openide.filesystems.FileObject; 26 27 public class UnitTestForSourceQueryImpl implements MultipleRootsUnitTestForSourceQueryImplementation { 28 29 private final SourceRoots sourceRoots; 30 private final SourceRoots testRoots; 31 32 public UnitTestForSourceQueryImpl(SourceRoots sourceRoots, SourceRoots testRoots) { 33 this.sourceRoots = sourceRoots; 34 this.testRoots = testRoots; 35 } 36 37 public URL [] findUnitTests(FileObject source) { 38 return find(source, sourceRoots, testRoots); } 40 41 public URL [] findSources(FileObject unitTest) { 42 return find(unitTest, testRoots, sourceRoots); } 44 45 private URL [] find(FileObject file, SourceRoots from, SourceRoots to) { 46 Project p = FileOwnerQuery.getOwner(file); 47 if (p == null) { 48 return null; 49 } 50 FileObject[] fromRoots = from.getRoots(); 51 for (int i = 0; i < fromRoots.length; i++) { 52 if (fromRoots[i].equals(file)) { 53 return to.getRootURLs(); 54 } 55 } 56 return null; 57 } 58 59 } 60 | Popular Tags |