1 19 20 package org.netbeans.modules.apisupport.project.queries; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.Collections ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.Set ; 29 import javax.swing.event.ChangeListener ; 30 import org.netbeans.api.project.FileOwnerQuery; 31 import org.netbeans.api.project.Project; 32 import org.netbeans.api.project.ProjectManager; 33 import org.netbeans.api.project.ant.AntArtifact; 34 import org.netbeans.api.project.ant.AntArtifactQuery; 35 import org.netbeans.modules.apisupport.project.NbModuleProject; 36 import org.netbeans.modules.apisupport.project.NbModuleProjectType; 37 import org.netbeans.modules.apisupport.project.Util; 38 import org.netbeans.modules.apisupport.project.universe.ModuleEntry; 39 import org.netbeans.modules.apisupport.project.universe.ModuleList; 40 import org.netbeans.spi.project.SubprojectProvider; 41 import org.netbeans.spi.project.support.ant.PropertyUtils; 42 import org.openide.ErrorManager; 43 import org.openide.filesystems.FileObject; 44 import org.openide.filesystems.FileUtil; 45 import org.w3c.dom.Element ; 46 47 52 public final class SubprojectProviderImpl implements SubprojectProvider { 53 54 private final NbModuleProject project; 55 56 public SubprojectProviderImpl(NbModuleProject project) { 57 this.project = project; 58 } 59 60 public Set getSubprojects() { 61 Set <Project> s = new HashSet (); 63 ModuleList ml; 64 try { 65 ml = project.getModuleList(); 66 } catch (IOException e) { 67 Util.err.notify(ErrorManager.INFORMATIONAL, e); 68 return Collections.EMPTY_SET; 69 } 70 Element data = project.getPrimaryConfigurationData(); 71 Element moduleDependencies = Util.findElement(data, 72 "module-dependencies", NbModuleProjectType.NAMESPACE_SHARED); List <Element > deps = Util.findSubElements(moduleDependencies); 74 Iterator it = deps.iterator(); 75 while (it.hasNext()) { 76 Element dep = (Element )it.next(); 77 83 Element cnbEl = Util.findElement(dep, "code-name-base", NbModuleProjectType.NAMESPACE_SHARED); 85 String cnb = Util.findText(cnbEl); 86 ModuleEntry module = ml.getEntry(cnb); 87 if (module == null) { 88 Util.err.log(ErrorManager.WARNING, "Warning - could not find dependent module " + cnb + " for " + project); 89 continue; 90 } 91 File moduleProjectDirF = module.getSourceLocation(); 92 if (moduleProjectDirF == null) { 93 Util.err.log(ErrorManager.WARNING, "Warning - could not find sources for dependent module " + cnb + " for " + project); 94 continue; 95 } 96 FileObject moduleProjectDir = FileUtil.toFileObject(moduleProjectDirF); 97 if (moduleProjectDir == null) { 98 Util.err.log(ErrorManager.WARNING, "Warning - could not load sources for dependent module " + cnb + " for " + project); 99 continue; 100 } 101 try { 102 Project moduleProject = ProjectManager.getDefault().findProject(moduleProjectDir); 103 if (moduleProject == null) { 104 Util.err.log(ErrorManager.WARNING, "Warning - dependent module " + cnb + " for " + project + " is not projectized"); 105 continue; 106 } 107 s.add(moduleProject); 108 } catch (IOException e) { 109 Util.err.notify(e); 110 } 111 } 112 List <Element > cpexts = Util.findSubElements(data); 114 it = cpexts.iterator(); 115 while (it.hasNext()) { 116 Element cpext = (Element ) it.next(); 117 if (!cpext.getTagName().equals("class-path-extension")) { continue; 119 } 120 Element binorig = Util.findElement(cpext, "binary-origin", NbModuleProjectType.NAMESPACE_SHARED); if (binorig == null) { 122 continue; 123 } 124 String text = Util.findText(binorig); 125 String eval = project.evaluator().evaluate(text); 126 if (eval == null) { 127 continue; 128 } 129 File jar = project.getHelper().resolveFile(eval); 130 AntArtifact aa = AntArtifactQuery.findArtifactFromFile(jar); 131 if (aa != null) { 132 Project owner = aa.getProject(); 133 if (owner != null) { 134 s.add(owner); 135 } 136 } 137 } 138 String eval = project.evaluator().getProperty("cp.extra"); if (eval != null) { 140 String [] pieces = PropertyUtils.tokenizePath(eval); 141 for (int i = 0; i < pieces.length; i++) { 142 File jar = project.getHelper().resolveFile(pieces[i]); 143 Project owner = FileOwnerQuery.getOwner(jar.toURI()); 144 if (owner != null) { 145 s.add(owner); 146 } 147 } 148 } 149 return s; 150 } 151 152 public void addChangeListener(ChangeListener listener) { 153 } 155 156 public void removeChangeListener(ChangeListener listener) { 157 } 159 160 } 161 | Popular Tags |