# This patch file was generated by NetBeans IDE # This patch can be applied using context Tools: Apply Diff Patch action on respective folder. # It uses platform neutral UTF-8 encoding. # Above lines and this line are ignored by the patching process. Index: ide/manifest.mf --- ide/manifest.mf No Base Revision +++ ide/manifest.mf Locally New @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +OpenIDE-Module: IDE + Index: ide/nbproject/project.properties --- ide/nbproject/project.properties Base (1.7) +++ ide/nbproject/project.properties Locally Modified (Based On 1.7) @@ -37,6 +37,8 @@ # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. +javac.compilerargs=-Xlint -Xlint:-serial +javac.source=1.5 #test.unit.cp.extra= #test.unit.run.cp.extra= test.qa-functional.cp.extra=${openide/windows.dir}/modules/org-openide-windows.jar:\ Index: ide/test/qa-functional/src/org/netbeans/test/ide/IDECommitValidation.java --- ide/test/qa-functional/src/org/netbeans/test/ide/IDECommitValidation.java Base (1.2) +++ ide/test/qa-functional/src/org/netbeans/test/ide/IDECommitValidation.java Locally Modified (Based On 1.2) @@ -60,6 +60,7 @@ public static NbTestSuite suite() { NbTestSuite suite = new NbTestSuite(); + suite.addTest(new IDEValidation("testInitGCProjects")); suite.addTest(new IDEValidation("testMainMenu")); suite.addTest(new IDEValidation("testHelp")); suite.addTest(new IDEValidation("testOptions")); @@ -84,6 +85,7 @@ suite.addTest(new IDEValidation("testWindowSystem")); // temporary removed because new code has replaced Update Center Wizard and Module Manager //suite.addTest(new IDEValidation("testModuleInstallation")); + suite.addTest(new IDEValidation("testGCProjects")); return suite; } Index: ide/test/qa-functional/src/org/netbeans/test/ide/IDEValidation.java --- ide/test/qa-functional/src/org/netbeans/test/ide/IDEValidation.java Base (1.5) +++ ide/test/qa-functional/src/org/netbeans/test/ide/IDEValidation.java Locally Modified (Based On 1.5) @@ -49,6 +49,7 @@ import java.awt.event.KeyEvent; import java.io.File; import java.io.IOException; +import java.util.logging.Level; import javax.swing.JTextField; import javax.swing.KeyStroke; import javax.swing.UIManager; @@ -115,6 +116,7 @@ import org.netbeans.junit.NbTestSuite; import org.netbeans.junit.ide.ProjectSupport; +import org.openide.util.Lookup; import org.openide.windows.Mode; import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; @@ -133,6 +135,7 @@ public static NbTestSuite suite() { NbTestSuite suite = new NbTestSuite(); + suite.addTest(new IDEValidation("testInitGCProjects")); suite.addTest(new IDEValidation("testMainMenu")); suite.addTest(new IDEValidation("testHelp")); suite.addTest(new IDEValidation("testOptions")); @@ -1420,6 +1423,15 @@ pluginManagerOper.close(); } + public void testInitGCProjects() throws Exception { + WatchProjects.initialize(); + } + + + public void testGCProjects() throws Exception { + WatchProjects.assertProjects(); + } + /** Closes help window if any. It should not stay open between test cases. * Otherwise it can break next tests. */ Index: ide/test/qa-functional/src/org/netbeans/test/ide/WatchProjects.java --- ide/test/qa-functional/src/org/netbeans/test/ide/WatchProjects.java No Base Revision +++ ide/test/qa-functional/src/org/netbeans/test/ide/WatchProjects.java Locally New @@ -0,0 +1,144 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ + +package org.netbeans.test.ide; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.ref.WeakReference; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.logging.Logger; +import junit.framework.Assert; +import org.netbeans.junit.NbTestCase; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; +import org.openide.util.WeakSet; + +/** + * + * @author Jaroslav Tulach + */ +final class WatchProjects implements PropertyChangeListener { + private static Logger LOG = Logger.getLogger(WatchProjects.class.getName()); + + + private Method getProjects; + private Method closeProjects; + private Object projectManager; + + private static int maxCount; + private static Set projects = new WeakSet(); + private static Exception failure; + private static WatchProjects INST; + + private WatchProjects() throws Exception { + final ClassLoader loader = Lookup.getDefault().lookup(ClassLoader.class); + Assert.assertNotNull("Classloader must exists", loader); + LOG.fine("Classloader: " + loader); + Class pmClass = Class.forName( + "org.netbeans.api.project.ui.OpenProjects", false, loader); //NOI18N + LOG.fine("class: " + pmClass); + Method add = pmClass.getMethod("addPropertyChangeListener", PropertyChangeListener.class); + LOG.fine(" add: " + add); + Method getDefault = pmClass.getMethod("getDefault"); + LOG.fine(" getDefault: " + getDefault); + projectManager = getDefault.invoke(null); + add.invoke(projectManager, this); + LOG.info("listening on " + projectManager); + + getProjects = pmClass.getMethod("getOpenProjects"); + LOG.fine("getOpenProjects: " + getProjects); + + Class projectArray = Class.forName("[Lorg.netbeans.api.project.Project;"); + + closeProjects = pmClass.getMethod("close", projectArray); + LOG.fine("getOpenProjects: " + getProjects); + } + + public static void initialize() throws Exception { + INST = new WatchProjects(); + } + + public static void assertProjects() throws Exception { + INST.closeProjects.invoke( + INST.projectManager, + INST.getProjects.invoke(INST.projectManager) + ); + + Set> refs = new HashSet>(); + for (Object project : projects) { + refs.add(new WeakReference(project)); + } + projects.clear(); + + for (WeakReference weakReference : refs) { + NbTestCase.assertGC("Can project be GCed?", weakReference); + } + + + if (maxCount == 0) { + Assert.fail("No projects were opened or closed and that is strange"); + } + + if (failure != null) { + throw failure; + } + } + + public void propertyChange(PropertyChangeEvent evt) { + try { + LOG.fine("event: " + evt.getPropertyName()); + Object[] arr = (Object[]) getProjects.invoke(projectManager); + projects.addAll(Arrays.asList(arr)); + LOG.finest("existing projects: " + projects); + + int p = projects.size(); + if (p > maxCount) { + maxCount = p; + } + } catch (Exception ex) { + failure = ex; + } + } + +}