1 19 20 package org.netbeans.modules.java.j2seproject; 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.apache.tools.ant.module.api.support.ActionUtils; 29 import org.netbeans.api.project.Project; 30 import org.netbeans.api.project.ProjectInformation; 31 import org.netbeans.api.project.ProjectManager; 32 import org.netbeans.spi.project.ActionProvider; 33 import org.netbeans.spi.project.CopyOperationImplementation; 34 import org.netbeans.spi.project.DeleteOperationImplementation; 35 import org.netbeans.spi.project.MoveOperationImplementation; 36 import org.netbeans.spi.project.support.ant.AntProjectHelper; 37 import org.netbeans.spi.project.support.ant.EditableProperties; 38 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 39 import org.netbeans.spi.project.support.ant.PropertyUtils; 40 import org.openide.filesystems.FileObject; 41 import org.openide.util.Lookup; 42 import org.openide.util.NbBundle; 43 44 48 public class J2SEProjectOperations implements DeleteOperationImplementation, CopyOperationImplementation, MoveOperationImplementation { 49 50 private J2SEProject project; 51 52 public J2SEProjectOperations(J2SEProject project) { 53 this.project = project; 54 } 55 56 private static void addFile(FileObject projectDirectory, String fileName, List result) { 57 FileObject file = projectDirectory.getFileObject(fileName); 58 59 if (file != null) { 60 result.add(file); 61 } 62 } 63 64 public List <FileObject> getMetadataFiles() { 65 FileObject projectDirectory = project.getProjectDirectory(); 66 List <FileObject> files = new ArrayList <FileObject>(); 67 68 addFile(projectDirectory, "nbproject", files); addFile(projectDirectory, "build.xml", files); addFile(projectDirectory, "xml-resources", files); addFile(projectDirectory, "catalog.xml", files); 73 return files; 74 } 75 76 public List <FileObject> getDataFiles() { 77 List <FileObject> files = new ArrayList <FileObject>(); 78 files.addAll(Arrays.asList(project.getSourceRoots().getRoots())); 79 files.addAll(Arrays.asList(project.getTestSourceRoots().getRoots())); 80 addFile(project.getProjectDirectory(), "manifest.mf", files); return files; 82 } 83 84 public void notifyDeleting() throws IOException { 85 J2SEActionProvider ap = project.getLookup().lookup(J2SEActionProvider.class); 86 87 assert ap != null; 88 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 { 100 project.getAntProjectHelper().notifyDeleted(); 101 } 102 103 public void notifyCopying() { 104 } 106 107 public void notifyCopied(Project original, File originalPath, String nueName) { 108 if (original == null) { 109 return ; 111 } 112 113 fixDistJarProperty (nueName); 114 project.getReferenceHelper().fixReferences(originalPath); 115 116 project.setName(nueName); 117 } 118 119 public void notifyMoving() throws IOException { 120 if (!this.project.getUpdateHelper().requestSave()) { 121 throw new IOException (NbBundle.getMessage(J2SEProjectOperations.class, 122 "MSG_OldProjectMetadata")); 123 } 124 notifyDeleting(); 125 } 126 127 public void notifyMoved(Project original, File originalPath, String nueName) { 128 if (original == null) { 129 project.getAntProjectHelper().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 folder, File 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 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"; EditableProperties ep = project.getUpdateHelper().getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH); 158 String propValue = ep.getProperty("dist.jar"); if (oldDistJar != null && oldDistJar.equals (propValue)) { 160 ep.put ("dist.jar","${dist.dir}/"+PropertyUtils.getUsablePropertyName(newName)+".jar"); project.getUpdateHelper().putProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH,ep); 162 } 163 } 164 }); 165 } 166 167 } 168 | Popular Tags |