KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > classpath > AppClientProjectClassPathExtenderTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.j2ee.clientproject.classpath;
20
21 import java.io.File JavaDoc;
22 import java.util.concurrent.CountDownLatch JavaDoc;
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 /**
41  *
42  * @author Jan Lahoda
43  */

44 public class AppClientProjectClassPathExtenderTest extends NbTestCase {
45
46     private String JavaDoc serverID;
47     private FileObject workDir;
48
49     public AppClientProjectClassPathExtenderTest(String JavaDoc testName) {
50         super(testName);
51     }
52
53     protected void setUp() throws Exception JavaDoc {
54         super.setUp();
55         workDir = TestUtil.makeScratchDir(this);
56         serverID = TestUtil.registerSunAppServer(this);
57     }
58
59     public void testPropertyChangeDeadlock74204() throws Exception JavaDoc {
60         File JavaDoc prjDirF = new File JavaDoc(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 JavaDoc privateLock = new Object JavaDoc();
66         final CountDownLatch JavaDoc sync = new CountDownLatch JavaDoc(2);
67         
68         FileChangeListener l = new FileChangeAdapter() {
69             public @Override JavaDoc void fileChanged(FileEvent fe) {
70                 try {
71                     sync.countDown();
72                     sync.await();
73                     synchronized (privateLock) {}
74                 } catch (InterruptedException JavaDoc 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 JavaDoc() {
85             public void run() {
86                 synchronized (privateLock) {
87                     try {
88                         sync.countDown();
89                         sync.await();
90                         ProjectManager.mutex().readAccess(new Action() {
91                             public Object JavaDoc run() {
92                                 return null;
93                             }
94                         });
95                     } catch (InterruptedException JavaDoc 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