1 19 20 package org.netbeans.modules.apisupport.project.ui; 21 22 import java.awt.EventQueue ; 23 import java.util.Arrays ; 24 import javax.swing.JDialog ; 25 import org.apache.tools.ant.module.api.support.ActionUtils; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.modules.apisupport.project.DialogDisplayerImpl; 28 import org.netbeans.modules.apisupport.project.InstalledFileLocatorImpl; 29 import org.netbeans.modules.apisupport.project.NbModuleProject; 30 import org.netbeans.modules.apisupport.project.TestBase; 31 import org.netbeans.modules.apisupport.project.layers.LayerTestBase; 32 import org.netbeans.spi.project.ActionProvider; 33 import org.netbeans.spi.project.support.ProjectOperations; 34 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 35 import org.netbeans.spi.project.ui.support.CommonProjectActions; 36 import org.openide.DialogDescriptor; 37 import org.openide.DialogDisplayer; 38 import org.openide.filesystems.FileObject; 39 import org.openide.filesystems.FileUtil; 40 import org.openide.util.ContextGlobalProvider; 41 import org.openide.util.Lookup; 42 import org.openide.util.NbBundle; 43 import org.openide.util.lookup.Lookups; 44 45 50 public class ModuleOperationsTest extends TestBase { 51 52 private static ContextGlobalProviderImpl cgpi = new ContextGlobalProviderImpl(); 53 54 static { 55 System.setProperty("org.netbeans.core.startup.ModuleSystem.CULPRIT", "true"); 56 LayerTestBase.Lkp.setLookup(new Object [] { 57 cgpi, 58 }); 59 DialogDisplayerImpl.returnFromNotify(DialogDescriptor.NO_OPTION); 60 } 61 62 public ModuleOperationsTest(String name) { 63 super(name); 64 } 65 66 protected void setUp() throws Exception { 67 super.setUp(); 68 InstalledFileLocatorImpl.registerDestDir(destDirF); 69 } 70 71 public void testDelete() throws Exception { 72 NbModuleProject project = generateStandaloneModule("module"); 73 project.open(); 74 ActionProvider ap = (ActionProvider) project.getLookup().lookup(ActionProvider.class); 75 assertNotNull("have an action provider", ap); 76 assertTrue("delete action is enabled", ap.isActionEnabled(ActionProvider.COMMAND_DELETE, null)); 77 78 FileObject prjDir = project.getProjectDirectory(); 79 80 FileObject buildXML = prjDir.getFileObject(GeneratedFilesHelper.BUILD_XML_PATH); 81 prjDir.createData(".cvsignore"); 82 83 ActionUtils.runTarget(buildXML, new String [] { "compile" }, null).waitFinished(); 85 assertNotNull("project was build", prjDir.getFileObject("build")); 86 87 FileObject[] expectedMetadataFiles = new FileObject[] { 88 buildXML, 89 prjDir.getFileObject("manifest.mf"), 90 prjDir.getFileObject("nbproject"), 91 prjDir.getFileObject(".cvsignore"), 92 }; 93 assertEquals("correct metadata files", Arrays.asList(expectedMetadataFiles), ProjectOperations.getMetadataFiles(project)); 94 95 FileObject[] expectedDataFiles = new FileObject[] { 96 prjDir.getFileObject("src"), 97 prjDir.getFileObject("test"), 98 }; 99 assertEquals("correct data files", Arrays.asList(expectedDataFiles), ProjectOperations.getDataFiles(project)); 100 101 ProjectOperations.notifyDeleting(project); 103 prjDir.getFileSystem().refresh(true); 104 assertNull(prjDir.getFileObject("build")); 105 } 106 107 public void testOperationActions() throws Exception { NbModuleProject project = generateStandaloneModule("module"); 109 cgpi.setProject(project); 110 DialogDisplayerImpl dd = (DialogDisplayerImpl) Lookup.getDefault().lookup(DialogDisplayer.class); 111 dd.setDialog(new JDialog () { 112 public void setVisible(boolean b) { } 113 }); 114 FileObject lock = FileUtil.createData(project.getProjectDirectory(), "build/testuserdir/lock"); 115 EventQueue.invokeAndWait(new Runnable () { 116 public void run() { 117 CommonProjectActions.deleteProjectAction().actionPerformed(null); 118 } 119 }); 120 assertNotNull("warning message emitted", dd.getLastNotifyDescriptor()); 121 assertEquals("warning message emitted", dd.getLastNotifyDescriptor().getMessage(), 122 NbBundle.getMessage(ModuleOperationsTest.class, "ERR_ModuleIsBeingRun")); 123 dd.reset(); 124 lock.delete(); 125 EventQueue.invokeAndWait(new Runnable () { 126 public void run() { 127 CommonProjectActions.deleteProjectAction().actionPerformed(null); 128 } 129 }); 130 assertNull("no warning message", dd.getLastNotifyDescriptor()); 131 } 132 133 static final class ContextGlobalProviderImpl implements ContextGlobalProvider { 134 135 private Lookup contextLookup; 136 137 void setProject(final Project project) { 138 contextLookup = Lookups.singleton(project); 139 } 140 141 public Lookup createGlobalContext() { 142 return contextLookup; 143 } 144 145 } 146 147 } 148 | Popular Tags |