1 19 package org.netbeans.modules.j2ee.clientproject.classpath; 20 21 import java.io.File ; 22 import java.util.concurrent.CountDownLatch ; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.api.project.ProjectManager; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.modules.j2ee.clientproject.api.AppClientProjectGenerator; 27 import org.netbeans.modules.j2ee.clientproject.test.TestUtil; 28 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; 29 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 30 import org.netbeans.spi.project.support.ant.AntProjectHelper; 31 import org.netbeans.spi.project.support.ant.EditableProperties; 32 import org.openide.ErrorManager; 33 import org.openide.filesystems.FileChangeAdapter; 34 import org.openide.filesystems.FileChangeListener; 35 import org.openide.filesystems.FileEvent; 36 import org.openide.filesystems.FileObject; 37 import org.openide.filesystems.FileUtil; 38 import org.openide.util.Mutex.Action; 39 40 44 public class AppClientProjectClassPathExtenderTest extends NbTestCase { 45 46 private String serverID; 47 private FileObject workDir; 48 49 public AppClientProjectClassPathExtenderTest(String testName) { 50 super(testName); 51 } 52 53 protected void setUp() throws Exception { 54 super.setUp(); 55 workDir = TestUtil.makeScratchDir(this); 56 serverID = TestUtil.registerSunAppServer(this); 57 } 58 59 public void testPropertyChangeDeadlock74204() throws Exception { 60 File prjDirF = new File (FileUtil.toFile(workDir), "test"); 61 AntProjectHelper helper = AppClientProjectGenerator.createProject(prjDirF, "test-project", 62 "test.MyMain", J2eeModule.JAVA_EE_5, serverID); 63 final Project project = ProjectManager.getDefault().findProject(helper.getProjectDirectory()); 64 65 final Object privateLock = new Object (); 66 final CountDownLatch sync = new CountDownLatch (2); 67 68 FileChangeListener l = new FileChangeAdapter() { 69 public @Override void fileChanged(FileEvent fe) { 70 try { 71 sync.countDown(); 72 sync.await(); 73 synchronized (privateLock) {} 74 } catch (InterruptedException ex) { 75 ErrorManager.getDefault().notify(ex); 76 } 77 } 78 }; 79 80 project.getProjectDirectory().getFileObject("nbproject").getChildren(); 81 project.getProjectDirectory().getFileObject("nbproject").addFileChangeListener(l); 82 project.getProjectDirectory().getFileObject("nbproject/project.properties").addFileChangeListener(l); 83 84 new Thread () { 85 public void run() { 86 synchronized (privateLock) { 87 try { 88 sync.countDown(); 89 sync.await(); 90 ProjectManager.mutex().readAccess(new Action() { 91 public Object run() { 92 return null; 93 } 94 }); 95 } catch (InterruptedException ex) { 96 ErrorManager.getDefault().notify(ex); 97 } 98 } 99 } 100 }.start(); 101 102 EditableProperties ep = new EditableProperties(); 103 104 ep.put(AppClientProjectProperties.JAVAC_CLASSPATH, "y"); 105 106 helper.putProperties(helper.PROJECT_PROPERTIES_PATH, ep); 107 } 108 109 } 110 | Popular Tags |