KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > common > ProjectUtil


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.ui.common;
21
22 import java.io.File JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Set JavaDoc;
25 import java.util.StringTokenizer JavaDoc;
26 import java.util.Vector JavaDoc;
27
28 import org.netbeans.api.project.Project;
29 import org.netbeans.spi.project.SubprojectProvider;
30 import org.netbeans.spi.project.support.ant.AntProjectHelper;
31 import org.openide.ErrorManager;
32
33 /**
34  * @author radval
35  *
36  * Netbeans Project related utility operations
37  */

38 public class ProjectUtil {
39
40
41     public static Set JavaDoc getClasspathProjects(Project p) {
42         Set JavaDoc classpathProjects = new HashSet JavaDoc();
43         try {
44             SubprojectProvider sp = (SubprojectProvider) p.getLookup().lookup(SubprojectProvider.class);
45             Set JavaDoc ls = sp.getSubprojects();
46             if (ls.size() < 1) {
47                 return classpathProjects;
48             }
49
50             Project[] sps = (Project[])ls.toArray(new Project[ls.size()]);
51             String JavaDoc[] spn = new String JavaDoc[sps.length];
52             for (int i = 0; i < sps.length; i++) {
53                 spn[i] = sps[i].getProjectDirectory().getPath().toLowerCase();
54             }
55
56             String JavaDoc sroot = p.getProjectDirectory().getPath();
57             AntProjectHelper ah = (AntProjectHelper) p.getLookup().lookup(AntProjectHelper.class);
58             String JavaDoc src = ah.getStandardPropertyEvaluator().getProperty("javac.classpath");//NOI18N
59
StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(src, ";");//NOI18N
60
Vector JavaDoc v = new Vector JavaDoc();
61             while (st.hasMoreTokens()) {
62                 String JavaDoc spath = st.nextToken();
63                 File JavaDoc sfile = new File JavaDoc(sroot+"/"+spath);//NOI18N
64
v.add(sfile.getCanonicalPath().replace('\\', '/').toLowerCase());
65             }
66             String JavaDoc[] vs = (String JavaDoc[]) v.toArray(new String JavaDoc[0]);
67
68             v.removeAllElements();
69             for (int i = 0; i < vs.length; i++) {
70                 for (int j =0; j <sps.length; j++) {
71                     if (vs[i].startsWith(spn[j])) {
72                         v.add(sps[j]);
73                         break;
74                     }
75                 }
76             }
77             
78             classpathProjects.addAll(v);
79             return classpathProjects;
80         } catch(Exception JavaDoc exception) {
81             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exception);
82         }
83
84         return classpathProjects;
85     }
86
87 }
88
Popular Tags