1 19 20 package org.netbeans.modules.apisupport.project.universe; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.HashSet ; 25 import java.util.Set ; 26 import java.util.TreeSet ; 27 import org.netbeans.api.project.ProjectManager; 28 import org.netbeans.modules.apisupport.project.ManifestManager; 29 import org.netbeans.modules.apisupport.project.NbModuleProject; 30 import org.netbeans.modules.apisupport.project.NbModuleProjectType; 31 import org.netbeans.modules.apisupport.project.Util; 32 import org.openide.ErrorManager; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.FileUtil; 35 import org.w3c.dom.Element ; 36 37 abstract class AbstractEntryWithSources extends AbstractEntry { 38 39 private LocalizedBundleInfo bundleInfo; 40 private Set <String > allPackageNames; 41 42 protected LocalizedBundleInfo getBundleInfo() { 43 if (bundleInfo == null) { 44 bundleInfo = ModuleList.loadBundleInfo(getSourceLocation()); 45 } 46 return bundleInfo; 47 } 48 49 protected Set <String > computePublicClassNamesInMainModule() throws IOException { 50 Set <String > result = new HashSet <String >(); 51 File src = new File (getSourceLocation(), "src"); for (ManifestManager.PackageExport p : getPublicPackages()) { 53 String pkg = p.getPackage(); 54 scanForClasses(result, pkg, new File (src, pkg.replace('.', File.separatorChar)), p.isRecursive()); 55 } 56 return result; 57 } 58 59 public synchronized Set <String > getAllPackageNames() { 60 if (allPackageNames == null) { 61 allPackageNames = Util.scanProjectForPackageNames(getSourceLocation()); 62 } 63 return allPackageNames; 64 } 65 66 private void scanForClasses(Set <String > result, String pkg, File dir, boolean recurse) throws IOException { 67 if (!dir.isDirectory()) { 68 return; 69 } 70 File [] kids = dir.listFiles(); 71 if (kids == null) { 72 throw new IOException (dir.getAbsolutePath()); 73 } 74 for (File kid : kids) { 75 String name = kid.getName(); 76 if (name.endsWith(".java")) { String basename = name.substring(0, name.length() - 5); 78 result.add(pkg + '.' + basename); 79 } 81 if (recurse && kid.isDirectory()) { 82 scanForClasses(result, pkg + '.' + name, kid, true); 83 } 84 } 85 } 86 87 public String [] getRunDependencies() { 88 Set <String > deps = new TreeSet <String >(); 89 FileObject source = FileUtil.toFileObject(getSourceLocation()); 90 if (source == null) { return new String [0]; 92 } 93 NbModuleProject project; 94 try { 95 project = (NbModuleProject) ProjectManager.getDefault().findProject(source); 96 } catch (IOException e) { 97 Util.err.notify(ErrorManager.INFORMATIONAL, e); 98 return new String [0]; 99 } 100 Element data = project.getPrimaryConfigurationData(); 101 Element moduleDependencies = Util.findElement(data, 102 "module-dependencies", NbModuleProjectType.NAMESPACE_SHARED); for (Element dep : Util.findSubElements(moduleDependencies)) { 104 if (Util.findElement(dep, "run-dependency", NbModuleProjectType.NAMESPACE_SHARED) == null) { 106 continue; 107 } 108 Element cnbEl = Util.findElement(dep, "code-name-base", NbModuleProjectType.NAMESPACE_SHARED); 110 String cnb = Util.findText(cnbEl); 111 deps.add(cnb); 112 } 113 return deps.toArray(new String [deps.size()]); 114 } 115 116 public String getSpecificationVersion() { 117 FileObject source = FileUtil.toFileObject(getSourceLocation()); 118 if (source != null) { 119 NbModuleProject project; 120 try { 121 project = (NbModuleProject) ProjectManager.getDefault().findProject(source); 122 if (project != null) { 123 return project.getSpecVersion(); 124 } 125 } catch (IOException e) { 126 Util.err.notify(ErrorManager.INFORMATIONAL, e); 127 } 128 } 129 return null; 130 } 131 132 } 133 | Popular Tags |