KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > universe > AbstractEntryWithSources


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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