KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > spi > project > support > rake > SubprojectProviderImpl


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.ruby.spi.project.support.rake;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Set JavaDoc;
27 import javax.swing.event.ChangeListener JavaDoc;
28 import org.netbeans.api.project.Project;
29 import org.netbeans.api.project.ProjectManager;
30 import org.netbeans.spi.project.SubprojectProvider;
31 import org.openide.ErrorManager;
32 import org.openide.filesystems.FileObject;
33 import org.openide.util.Mutex;
34
35 /**
36  * Translates a list of subproject names into actual subprojects
37  * for an Ant-based project.
38  * @author Jesse Glick
39  */

40 final class SubprojectProviderImpl implements SubprojectProvider {
41     
42     private final ReferenceHelper helper;
43     
44     SubprojectProviderImpl(ReferenceHelper helper) {
45         this.helper = helper;
46     }
47     
48     public Set JavaDoc<? extends Project> getSubprojects() {
49         return ProjectManager.mutex().readAccess(new Mutex.Action<Set JavaDoc<? extends Project>>() {
50             public Set JavaDoc<? extends Project> run() {
51                 // XXX could use a special set w/ lazy isEmpty() - cf. #58639 for freeform
52
Set JavaDoc<String JavaDoc> foreignProjectNames = new HashSet JavaDoc<String JavaDoc>();
53                 for (ReferenceHelper.RawReference ref : helper.getRawReferences()) {
54                     foreignProjectNames.add(ref.getForeignProjectName());
55                 }
56                 Set JavaDoc<Project> foreignProjects = new HashSet JavaDoc<Project>();
57                 for (String JavaDoc foreignProjectName : foreignProjectNames) {
58                     String JavaDoc prop = "project." + foreignProjectName; // NOI18N
59
RakeProjectHelper h = helper.getRakeProjectHelper();
60                     String JavaDoc foreignProjectDirS = helper.eval.getProperty(prop);
61                     if (foreignProjectDirS == null) {
62                         // Missing for some reason. Skip it.
63
continue;
64                     }
65                     FileObject foreignProjectDir = h.resolveFileObject(foreignProjectDirS);
66                     if (foreignProjectDir == null) {
67                         // Not present on disk, erroneous property, etc. Skip it.
68
continue;
69                     }
70                     try {
71                         Project p = ProjectManager.getDefault().findProject(foreignProjectDir);
72                         if (p != null) {
73                             // OK, got a real project.
74
foreignProjects.add(p);
75                         }
76                     } catch (IOException JavaDoc e) {
77                         ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
78                         // skip it
79
}
80                 }
81                 return foreignProjects;
82             }
83         });
84     }
85     
86     public void addChangeListener(ChangeListener JavaDoc listener) {
87         // XXX implement - listen to references added and removed
88
}
89     
90     public void removeChangeListener(ChangeListener JavaDoc listener) {
91         // XXX
92
}
93     
94 }
95
Popular Tags