# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /space/work/allprefs # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: xtest/nbjunit/src/org/netbeans/junit/MemoryPreferencesFactory.java *** /space/work/allprefs/xtest/nbjunit/src/org/netbeans/junit/MemoryPreferencesFactory.java No Base Revision --- /space/work/allprefs/xtest/nbjunit/src/org/netbeans/junit/MemoryPreferencesFactory.java Locally New *************** *** 1,0 **** --- 1,103 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.netbeans.junit; + + import java.util.Properties; + import java.util.prefs.AbstractPreferences; + import java.util.prefs.BackingStoreException; + import java.util.prefs.Preferences; + import java.util.prefs.PreferencesFactory; + + /** + * + * @author Radek Matous + */ + public class MemoryPreferencesFactory implements PreferencesFactory { + /** Creates a new instance */ + public MemoryPreferencesFactory() {} + + public Preferences userRoot() { + return NbPreferences.userRootImpl(); + } + + public Preferences systemRoot() { + return userRoot(); + } + + private static class NbPreferences extends AbstractPreferences { + private static Preferences USER_ROOT; + /*private*/Properties properties; + + static Preferences userRootImpl() { + if (USER_ROOT == null) { + USER_ROOT = new NbPreferences(); + } + return USER_ROOT; + } + + private NbPreferences() { + super(null, ""); + } + + /** Creates a new instance of PreferencesImpl */ + private NbPreferences(NbPreferences parent, String name) { + super(parent, name); + newNode = true; + } + + protected final String getSpi(String key) { + return (String)properties().getProperty(key); + } + + protected final String[] childrenNamesSpi() throws BackingStoreException { + return new String[0]; + } + + protected final String[] keysSpi() throws BackingStoreException { + return (String[])properties().keySet().toArray(new String[0]); + } + + protected final void putSpi(String key, String value) { + properties().put(key,value); + } + + protected final void removeSpi(String key) { + properties().remove(key); + } + + protected final void removeNodeSpi() throws BackingStoreException {} + protected void flushSpi() throws BackingStoreException {} + protected void syncSpi() throws BackingStoreException { + properties().clear(); + } + + Properties properties() { + if (properties == null) { + properties = new Properties(); + } + return properties; + } + + protected AbstractPreferences childSpi(String name) { + return new NbPreferences(this, name); + } + } + + } Index: core/startup/src/org/netbeans/core/startup/preferences/NbPreferences.java *** /space/work/allprefs/core/startup/src/org/netbeans/core/startup/preferences/NbPreferences.java Base (1.2) --- /space/work/allprefs/core/startup/src/org/netbeans/core/startup/preferences/NbPreferences.java Locally Modified (Based On 1.2) *************** *** 29,35 **** /** * ! * @author Radek Mlatous */ public abstract class NbPreferences extends AbstractPreferences { private static Preferences USER_ROOT; --- 29,35 ---- /** * ! * @author Radek Matous */ public abstract class NbPreferences extends AbstractPreferences { private static Preferences USER_ROOT; *************** *** 129,134 **** --- 129,135 ---- protected void syncSpi() throws BackingStoreException { try { + properties.clear(); properties().putAll(fileStorage.load()); } catch (IOException ex) { throw new BackingStoreException(ex); *************** *** 167,172 **** --- 168,174 ---- if (fileStorage.isReadOnly()) { throw new BackingStoreException("Unsupported operation: read-only storage");//NOI18N } else { + flushTask.waitFinished(); super.sync(); } } Index: core/startup/test/unit/src/org/netbeans/core/startup/preferences/NbPreferencesTest.java *** /space/work/allprefs/core/startup/test/unit/src/org/netbeans/core/startup/preferences/NbPreferencesTest.java Base (1.2) --- /space/work/allprefs/core/startup/test/unit/src/org/netbeans/core/startup/preferences/NbPreferencesTest.java Locally Modified (Based On 1.2) *************** *** 61,75 **** protected void setUp() throws Exception { super.setUp(); ! NbPreferencesFactory.doRegistration(); Statistics.CHILDREN_NAMES.reset(); Statistics.FLUSH.reset(); Statistics.LOAD.reset(); Statistics.REMOVE_NODE.reset(); } } } --- 61,79 ---- protected void setUp() throws Exception { super.setUp(); ! //NbPreferencesFactory.doRegistration(); Statistics.CHILDREN_NAMES.reset(); Statistics.FLUSH.reset(); Statistics.LOAD.reset(); Statistics.REMOVE_NODE.reset(); } + + protected Class getPreferencesFactoryClass() { + return NbPreferencesFactory.class; } } + } Index: xtest/nbjunit/src/org/netbeans/junit/NbTestCase.java *** /space/work/allprefs/xtest/nbjunit/src/org/netbeans/junit/NbTestCase.java Base (1.56) --- /space/work/allprefs/xtest/nbjunit/src/org/netbeans/junit/NbTestCase.java Locally Modified (Based On 1.56) *************** *** 200,206 **** --- 200,215 ---- return sb.toString(); } + protected void setUp() throws Exception { + super.setUp(); + System.setProperty("java.util.prefs.PreferencesFactory",getPreferencesFactoryClass().getName());//NOI18N + } + protected Class getPreferencesFactoryClass() { + return MemoryPreferencesFactory.class; + } + + /** * Runs the bare test sequence. It checks {@link #runInEQ} and possibly * schedules the call of setUp, runTest and tearDown Index: xtest/nbjunit/test/unit/src/org/netbeans/junit/NbTestCaseTest.java *** /space/work/allprefs/xtest/nbjunit/test/unit/src/org/netbeans/junit/NbTestCaseTest.java Base (1.5) --- /space/work/allprefs/xtest/nbjunit/test/unit/src/org/netbeans/junit/NbTestCaseTest.java Locally Modified (Based On 1.5) *************** *** 22,27 **** --- 22,28 ---- import java.lang.ref.WeakReference; import java.util.logging.Level; import java.util.logging.Logger; + import java.util.prefs.Preferences; import junit.framework.TestResult; /** Regular test of the behaviour. *************** *** 61,66 **** --- 62,75 ---- } + public void testIsNotPersistent() throws Exception { + Preferences pref = Preferences.userNodeForPackage(getClass()); + assertNotNull(pref); + pref.put("key", "value"); + assertEquals("value", pref.get("key", null)); + pref.sync(); + assertEquals(null, pref.get("key", null)); + } public void testLoggingUtil() throws Exception { CharSequence seq = Log.enable("", Level.WARNING); Index: core/startup/test/unit/src/org/netbeans/core/startup/preferences/TestPreferences.java *** /space/work/allprefs/core/startup/test/unit/src/org/netbeans/core/startup/preferences/TestPreferences.java Base (1.2) --- /space/work/allprefs/core/startup/test/unit/src/org/netbeans/core/startup/preferences/TestPreferences.java Locally Modified (Based On 1.2) *************** *** 345,350 **** --- 345,360 ---- } } + public void testIsPersistent() throws BackingStoreException,InterruptedException { + NbPreferences pref = (NbPreferences)getPreferencesNode(); + assertNotNull(pref); + assertEquals(NbPreferences.UserPreferences.class, pref.getClass()); + pref.put("key", "value"); + assertEquals("value", pref.get("key", null)); + pref.sync(); + assertEquals("value", pref.get("key", null)); + } + protected int timeOut() { return 20000; }