1 19 20 package org.netbeans.modules.ant.freeform; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.ArrayList ; 25 import java.util.Collections ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import org.netbeans.api.project.Project; 29 import org.netbeans.api.project.ProjectManager; 30 import org.netbeans.modules.ant.freeform.spi.support.Util; 31 import org.netbeans.spi.project.CopyOperationImplementation; 32 import org.netbeans.spi.project.DeleteOperationImplementation; 33 import org.netbeans.spi.project.MoveOperationImplementation; 34 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 35 import org.openide.ErrorManager; 36 import org.openide.filesystems.FileObject; 37 import org.openide.filesystems.FileUtil; 38 import org.w3c.dom.Element ; 39 40 44 public class FreeformProjectOperations implements DeleteOperationImplementation, CopyOperationImplementation, MoveOperationImplementation { 45 46 private FreeformProject project; 47 48 public FreeformProjectOperations(FreeformProject project) { 49 this.project = project; 50 } 51 52 private static void addFile(FileObject projectDirectory, String fileName, List <FileObject> result) { 53 FileObject file = projectDirectory.getFileObject(fileName); 54 55 if (file != null) { 56 result.add(file); 57 } 58 } 59 60 public List <FileObject> getMetadataFiles() { 61 FileObject projectDirectory = project.getProjectDirectory(); 62 List <FileObject> files = new ArrayList <FileObject>(); 63 64 addFile(projectDirectory, "nbproject", files); 66 return files; 67 } 68 69 public List <FileObject> getDataFiles() { 70 Element genldata = project.getPrimaryConfigurationData(); 71 Element foldersEl = Util.findElement(genldata, "folders", FreeformProjectType.NS_GENERAL); List <Element > folders = foldersEl != null ? Util.findSubElements(foldersEl) : Collections.<Element >emptyList(); 73 List <FileObject> result = new ArrayList <FileObject>(); 74 75 for (Element el : folders) { 76 if ("source-folder".equals(el.getLocalName()) && FreeformProjectType.NS_GENERAL.equals(el.getNamespaceURI())) { addFile(el, result); 78 } 79 } 80 81 addFile(project.getProjectDirectory(), "build.xml", result); 83 return result; 84 } 85 86 private void addFile(Element folder, List <FileObject> result) { 87 Element location = Util.findElement(folder, "location", FreeformProjectType.NS_GENERAL); 89 if (location == null) { 90 return ; 91 } 92 93 PropertyEvaluator evaluator = project.evaluator(); 94 String val = evaluator.evaluate(Util.findText(location)); 95 96 if (val == null) { 97 return ; 98 } 99 100 File f = project.helper().resolveFile(val); 101 102 if (f == null) { 103 return ; 104 } 105 106 FileObject fo = FileUtil.toFileObject(f); 107 108 if (fo != null && FileUtil.isParentOf(project.getProjectDirectory(), fo)) { 109 result.add(fo); 110 } 111 } 112 113 public void notifyDeleting() throws IOException { 114 } 116 117 public void notifyDeleted() throws IOException { 118 project.helper().notifyDeleted(); 119 } 120 121 public void notifyCopying() throws IOException { 122 } 123 124 public void notifyCopied(Project original, File originalPath, String nueName) throws IOException { 125 if (original != null) { 126 project.setName(nueName); 127 } 128 } 129 130 public void notifyMoving() throws IOException { 131 } 132 133 public void notifyMoved(Project original, File originalPath, String nueName) throws IOException { 134 if (original != null) { 135 project.setName(nueName); 136 } else { 137 project.helper().notifyDeleted(); 138 } 139 } 140 141 } 142 | Popular Tags |