KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > rubyproject > RubyProjectOperations


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.rubyproject;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Properties JavaDoc;
28 import org.netbeans.api.project.Project;
29 import org.netbeans.api.project.ProjectInformation;
30 import org.netbeans.api.project.ProjectManager;
31 import org.netbeans.spi.project.ActionProvider;
32 import org.netbeans.spi.project.CopyOperationImplementation;
33 import org.netbeans.spi.project.DeleteOperationImplementation;
34 import org.netbeans.spi.project.MoveOperationImplementation;
35 import org.netbeans.modules.ruby.spi.project.support.rake.RakeProjectHelper;
36 import org.netbeans.modules.ruby.spi.project.support.rake.EditableProperties;
37 import org.netbeans.modules.ruby.spi.project.support.rake.GeneratedFilesHelper;
38 import org.netbeans.modules.ruby.spi.project.support.rake.PropertyUtils;
39 import org.openide.filesystems.FileObject;
40 import org.openide.util.Lookup;
41 import org.openide.util.NbBundle;
42
43 /**
44  *
45  * @author Jan Lahoda
46  */

47 public class RubyProjectOperations implements DeleteOperationImplementation, CopyOperationImplementation, MoveOperationImplementation {
48     
49     private RubyProject project;
50     
51     public RubyProjectOperations(RubyProject project) {
52         this.project = project;
53     }
54     
55     private static void addFile(FileObject projectDirectory, String JavaDoc fileName, List JavaDoc/*<FileObject>*/ result) {
56         FileObject file = projectDirectory.getFileObject(fileName);
57         
58         if (file != null) {
59             result.add(file);
60         }
61     }
62     
63     public List JavaDoc<FileObject> getMetadataFiles() {
64         FileObject projectDirectory = project.getProjectDirectory();
65         List JavaDoc<FileObject> files = new ArrayList JavaDoc<FileObject>();
66         
67         addFile(projectDirectory, "nbproject", files); // NOI18N
68
// addFile(projectDirectory, "build.xml", files); // NOI18N
69
// addFile(projectDirectory, "xml-resources", files); //NOI18N
70
// addFile(projectDirectory, "catalog.xml", files); //NOI18N
71

72         return files;
73     }
74     
75     public List JavaDoc<FileObject> getDataFiles() {
76         List JavaDoc<FileObject> files = new ArrayList JavaDoc<FileObject>();
77         files.addAll(Arrays.asList(project.getSourceRoots().getRoots()));
78         files.addAll(Arrays.asList(project.getTestSourceRoots().getRoots()));
79 // addFile(project.getProjectDirectory(), "manifest.mf", files); // NOI18N
80
return files;
81     }
82     
83     public void notifyDeleting() throws IOException JavaDoc {
84         RubyActionProvider ap = project.getLookup().lookup(RubyActionProvider.class);
85         
86         assert ap != null;
87         
88         // TODO: Clean
89
// Properties p = new Properties();
90
// String[] targetNames = ap.getTargetNames(ActionProvider.COMMAND_CLEAN, Lookup.EMPTY, p);
91
// FileObject buildXML = project.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH);
92
//
93
// assert targetNames != null;
94
// assert targetNames.length > 0;
95
//
96
// ActionUtils.runTarget(buildXML, targetNames, p).waitFinished();
97
}
98     
99     public void notifyDeleted() throws IOException JavaDoc {
100         project.getRakeProjectHelper().notifyDeleted();
101     }
102     
103     public void notifyCopying() {
104         //nothing.
105
}
106     
107     public void notifyCopied(Project original, File JavaDoc originalPath, String JavaDoc nueName) {
108         if (original == null) {
109             //do nothing for the original project.
110
return ;
111         }
112         
113         fixDistJarProperty (nueName);
114         project.getReferenceHelper().fixReferences(originalPath);
115         
116         project.setName(nueName);
117     }
118     
119     public void notifyMoving() throws IOException JavaDoc {
120         if (!this.project.getUpdateHelper().requestSave()) {
121             throw new IOException JavaDoc (NbBundle.getMessage(RubyProjectOperations.class,
122                 "MSG_OldProjectMetadata"));
123         }
124         notifyDeleting();
125     }
126     
127     public void notifyMoved(Project original, File JavaDoc originalPath, String JavaDoc nueName) {
128         if (original == null) {
129             project.getRakeProjectHelper().notifyDeleted();
130             return ;
131         }
132         
133         fixDistJarProperty (nueName);
134         project.setName(nueName);
135         project.getReferenceHelper().fixReferences(originalPath);
136     }
137     
138     private static boolean isParent(File JavaDoc folder, File JavaDoc fo) {
139         if (folder.equals(fo))
140             return false;
141         
142         while (fo != null) {
143             if (fo.equals(folder))
144                 return true;
145             
146             fo = fo.getParentFile();
147         }
148         
149         return false;
150     }
151     
152     private void fixDistJarProperty (final String JavaDoc newName) {
153 // ProjectManager.mutex().writeAccess(new Runnable () {
154
// public void run () {
155
// ProjectInformation pi = (ProjectInformation) project.getLookup().lookup(ProjectInformation.class);
156
// String oldDistJar = pi == null ? null : "${dist.dir}/"+PropertyUtils.getUsablePropertyName(pi.getDisplayName())+".jar"; //NOI18N
157
// EditableProperties ep = project.getUpdateHelper().getProperties (RakeProjectHelper.PROJECT_PROPERTIES_PATH);
158
// String propValue = ep.getProperty("dist.jar"); //NOI18N
159
// if (oldDistJar != null && oldDistJar.equals (propValue)) {
160
// ep.put ("dist.jar","${dist.dir}/"+PropertyUtils.getUsablePropertyName(newName)+".jar"); //NOI18N
161
// project.getUpdateHelper().putProperties (RakeProjectHelper.PROJECT_PROPERTIES_PATH,ep);
162
// }
163
// }
164
// });
165
}
166     
167 }
168
Popular Tags