1 19 20 package org.netbeans.modules.apisupport.project.queries; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.net.URI ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 import org.netbeans.api.project.Project; 28 import org.netbeans.api.project.ProjectManager; 29 import org.netbeans.modules.apisupport.project.Util; 30 import org.netbeans.modules.apisupport.project.universe.ModuleEntry; 31 import org.netbeans.modules.apisupport.project.universe.ModuleList; 32 import org.netbeans.modules.apisupport.project.universe.TestEntry; 33 import org.netbeans.spi.project.FileOwnerQueryImplementation; 34 import org.openide.ErrorManager; 35 import org.openide.filesystems.FileObject; 36 import org.openide.filesystems.FileUtil; 37 38 42 public final class UpdateTrackingFileOwnerQuery implements FileOwnerQueryImplementation { 43 44 45 public UpdateTrackingFileOwnerQuery() {} 46 47 public Project getOwner(URI file) { 48 if (!ModuleList.existKnownEntries()) { 49 return null; } 51 if (file.getScheme().equals("file")) { return getOwner(new File (file)); 53 } else { 54 return null; 55 } 56 } 57 58 public Project getOwner(FileObject file) { 59 if (!ModuleList.existKnownEntries()) { 60 return null; } 62 File f = FileUtil.toFile(file); 63 if (f != null) { 64 return getOwner(f); 65 } else { 66 return null; 67 } 68 } 69 70 private Project getOwner(File file) { 71 Set <ModuleEntry> entries = ModuleList.getKnownEntries(file); 72 Iterator it = entries.iterator(); 73 while (it.hasNext()) { 74 File sourcedir = ((ModuleEntry) it.next()).getSourceLocation(); 75 if (sourcedir != null) { 76 FileObject sourcedirFO = FileUtil.toFileObject(sourcedir); 77 if (sourcedirFO != null) { 78 try { 79 Project p = ProjectManager.getDefault().findProject(sourcedirFO); 80 if (p != null) { 81 return p; 82 } 83 } catch (IOException e) { 84 Util.err.notify(ErrorManager.INFORMATIONAL, e); 85 } 86 } 87 } 88 } 89 TestEntry test = TestEntry.get(file); 91 if (test != null) { 92 Project p = test.getProject() ; 93 if (p != null) { 94 return p; 95 } 96 } 97 return null; 98 } 99 100 } 101 | Popular Tags |