1 19 20 package org.netbeans.modules.j2ee.earproject; 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.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.ProjectManager; 31 import org.netbeans.modules.j2ee.earproject.ui.customizer.EarProjectProperties; 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.openide.filesystems.FileObject; 40 import org.openide.util.Lookup; 41 import org.openide.util.lookup.Lookups; 42 43 46 public class EarProjectOperations implements DeleteOperationImplementation, CopyOperationImplementation, MoveOperationImplementation { 47 48 private final EarProject project; 49 50 public EarProjectOperations(EarProject project) { 51 this.project = project; 52 } 53 54 private static void addFile(FileObject projectDirectory, String fileName, List <FileObject> result) { 55 FileObject file = projectDirectory.getFileObject(fileName); 56 if (file != null) { 57 result.add(file); 58 } 59 } 60 61 public List getMetadataFiles() { 62 FileObject projectDirectory = project.getProjectDirectory(); 63 List <FileObject> files = new ArrayList <FileObject>(); 64 65 addFile(projectDirectory, "nbproject", files); addFile(projectDirectory, "build.xml", files); addFile(projectDirectory, "src", files); addFile(projectDirectory, ".cvsignore", files); 70 return files; 71 } 72 73 public List <FileObject> getDataFiles() { 74 return Collections.emptyList(); 75 } 76 77 public void notifyDeleting() throws IOException { 78 EarActionProvider ap = (EarActionProvider) project.getLookup().lookup(EarActionProvider.class); 79 80 assert ap != null; 81 82 Lookup context = Lookups.fixed(new Object [0]); 83 Properties p = new Properties (); 84 String [] targetNames = ap.getTargetNames(ActionProvider.COMMAND_CLEAN, context, p); 85 FileObject buildXML = project.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH); 86 87 assert targetNames != null; 88 assert targetNames.length > 0; 89 90 ActionUtils.runTarget(buildXML, targetNames, p).waitFinished(); 91 } 92 93 public void notifyDeleted() throws IOException { 94 project.getAntProjectHelper().notifyDeleted(); 95 } 96 97 public void notifyCopying() { 98 } 100 101 public void notifyCopied(Project original, File originalPath, String nueName) { 102 if (original == null) { 103 return ; 105 } 106 107 project.setName(nueName); 108 } 109 110 public void notifyMoving() throws IOException { 111 notifyDeleting(); 112 } 113 114 public void notifyMoved(Project original, File originalPath, final String newName) { 115 if (original == null) { 116 project.getAntProjectHelper().notifyDeleted(); 117 return ; 118 } 119 120 final String oldProjectName = project.getName(); 121 122 project.setName(newName); 123 124 ProjectManager.mutex().writeAccess(new Runnable () { 125 public void run() { 126 AntProjectHelper helper = project.getAntProjectHelper(); 127 EditableProperties projectProps = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 128 129 String earName = (String ) projectProps.get(EarProjectProperties.JAR_NAME); 130 String oldName = earName.substring(0, earName.length() - 4); 131 if (earName.endsWith(".ear") && oldName.equals(oldProjectName)) projectProps.put(EarProjectProperties.JAR_NAME, newName + ".ear"); 134 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProps); 135 } 136 }); 137 138 } 139 140 } 141 | Popular Tags |