1 19 20 package org.netbeans.modules.ruby.railsprojects; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.ArrayList ; 25 import java.util.Arrays ; 26 import java.util.List ; 27 import java.util.Properties ; 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 47 public class RailsProjectOperations implements DeleteOperationImplementation, CopyOperationImplementation, MoveOperationImplementation { 48 private RailsProject project; 49 50 public RailsProjectOperations(RailsProject project) { 51 this.project = project; 52 } 53 54 private static void addFile(FileObject projectDirectory, String fileName, List result) { 55 FileObject file = projectDirectory.getFileObject(fileName); 56 57 if (file != null) { 58 result.add(file); 59 } 60 } 61 62 public List <FileObject> getMetadataFiles() { 63 FileObject projectDirectory = project.getProjectDirectory(); 64 List <FileObject> files = new ArrayList <FileObject>(); 65 66 addFile(projectDirectory, "nbproject", files); addFile(projectDirectory, "build.xml", files); addFile(projectDirectory, "xml-resources", files); addFile(projectDirectory, "catalog.xml", files); 71 return files; 72 } 73 74 public List <FileObject> getDataFiles() { 75 List <FileObject> files = new ArrayList <FileObject>(); 76 files.addAll(Arrays.asList(project.getSourceRoots().getRoots())); 77 files.addAll(Arrays.asList(project.getTestSourceRoots().getRoots())); 78 addFile(project.getProjectDirectory(), "manifest.mf", files); return files; 80 } 81 82 public void notifyDeleting() throws IOException { 83 RailsActionProvider ap = project.getLookup().lookup(RailsActionProvider.class); 84 85 assert ap != null; 86 87 } 97 98 public void notifyDeleted() throws IOException { 99 project.getRakeProjectHelper().notifyDeleted(); 100 } 101 102 public void notifyCopying() { 103 } 105 106 public void notifyCopied(Project original, File originalPath, String nueName) { 107 if (original == null) { 108 return ; 110 } 111 112 fixDistJarProperty (nueName); 113 project.getReferenceHelper().fixReferences(originalPath); 114 115 project.setName(nueName); 116 } 117 118 public void notifyMoving() throws IOException { 119 if (!this.project.getUpdateHelper().requestSave()) { 120 throw new IOException (NbBundle.getMessage(RailsProjectOperations.class, 121 "MSG_OldProjectMetadata")); 122 } 123 notifyDeleting(); 124 } 125 126 public void notifyMoved(Project original, File originalPath, String nueName) { 127 if (original == null) { 128 project.getRakeProjectHelper().notifyDeleted(); 129 return ; 130 } 131 132 fixDistJarProperty (nueName); 133 project.setName(nueName); 134 project.getReferenceHelper().fixReferences(originalPath); 135 } 136 137 private static boolean isParent(File folder, File fo) { 138 if (folder.equals(fo)) 139 return false; 140 141 while (fo != null) { 142 if (fo.equals(folder)) 143 return true; 144 145 fo = fo.getParentFile(); 146 } 147 148 return false; 149 } 150 151 private void fixDistJarProperty (final String newName) { 152 ProjectManager.mutex().writeAccess(new Runnable () { 153 public void run () { 154 ProjectInformation pi = (ProjectInformation) project.getLookup().lookup(ProjectInformation.class); 155 String oldDistJar = pi == null ? null : "${dist.dir}/"+PropertyUtils.getUsablePropertyName(pi.getDisplayName())+".jar"; EditableProperties ep = project.getUpdateHelper().getProperties (RakeProjectHelper.PROJECT_PROPERTIES_PATH); 157 String propValue = ep.getProperty("dist.jar"); if (oldDistJar != null && oldDistJar.equals (propValue)) { 159 ep.put ("dist.jar","${dist.dir}/"+PropertyUtils.getUsablePropertyName(newName)+".jar"); project.getUpdateHelper().putProperties (RakeProjectHelper.PROJECT_PROPERTIES_PATH,ep); 161 } 162 } 163 }); 164 } 165 } 166 | Popular Tags |