# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /doma/jarda/netbeans-src/core # 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: src/org/netbeans/core/LoaderPoolNode.java *** /doma/jarda/netbeans-src/core/src/org/netbeans/core/LoaderPoolNode.java Base (1.92) --- /doma/jarda/netbeans-src/core/src/org/netbeans/core/LoaderPoolNode.java Locally Modified (Based On 1.92) *************** *** 167,172 **** --- 167,173 ---- */ public static void waitFinished() { getNbLoaderPool().fireTask.waitFinished(); + err.log(Level.FINE, "waitFinished"); } /** Adds new loader when previous and following are specified. *************** *** 202,207 **** --- 203,209 ---- loaders.add (l); l.removePropertyChangeListener (getNbLoaderPool ()); l.addPropertyChangeListener (getNbLoaderPool ()); + err.log(Level.FINE, "Adding listener {0}", l); String cname = c.getName(); names2Loaders.put(cname, l); *************** *** 644,660 **** if (lp != null && installationFinished) { lp.superFireChangeEvent(); } - - if (lp != null) { - Enumeration e = lp.allLoaders(); - while (e.hasMoreElements()) { - DataLoader l = (DataLoader)e.nextElement(); - // so the pool is there only once - l.removePropertyChangeListener(lp); - l.addPropertyChangeListener(lp); } - } - } /** Removes the loader. It is only removed from the list but --- 646,652 ---- *************** *** 676,681 **** --- 668,674 ---- installBefores.remove(cname); installAfters.remove(cname); dl.removePropertyChangeListener (getNbLoaderPool ()); + err.log(Level.FINE, "Removing listener {0}", dl); if (updatingBatch) { updatingBatchUsed = true; *************** *** 844,870 **** private transient RequestProcessor.Task fireTask; ! private transient Lookup.Result mimeResolvers; private static RequestProcessor rp = new RequestProcessor("Refresh Loader Pool"); // NOI18N public NbLoaderPool() { fireTask = rp.create(this, true); mimeResolvers = Lookup.getDefault().lookupResult(MIMEResolver.class); mimeResolvers.addLookupListener(this); } /** Enumerates all loaders. Loaders are taken from children * structure of LoaderPoolNode. */ protected Enumeration loaders () { - - // // prevents from extensive copying - // - DataLoader[] arr = loadersArray; if (arr == null) { synchronized (LoaderPoolNode.class) { ! arr = loadersArray = loaders.toArray (new DataLoader[loaders.size()]); } } return org.openide.util.Enumerations.array (arr); --- 837,865 ---- private transient RequestProcessor.Task fireTask; ! private final Lookup.Result mimeResolvers; ! private final Lookup.Result metaInf; private static RequestProcessor rp = new RequestProcessor("Refresh Loader Pool"); // NOI18N public NbLoaderPool() { fireTask = rp.create(this, true); mimeResolvers = Lookup.getDefault().lookupResult(MIMEResolver.class); mimeResolvers.addLookupListener(this); + metaInf = Lookup.getDefault().lookupResult(DataLoader.class); + metaInf.addLookupListener(this); } /** Enumerates all loaders. Loaders are taken from children * structure of LoaderPoolNode. */ protected Enumeration loaders () { // prevents from extensive copying DataLoader[] arr = loadersArray; if (arr == null) { + ArrayList l = new ArrayList(); + l.addAll(metaInf.allInstances()); synchronized (LoaderPoolNode.class) { ! l.addAll(loaders); ! arr = loadersArray = l.toArray (new DataLoader[l.size()]); } } return org.openide.util.Enumerations.array (arr); *************** *** 875,880 **** --- 870,876 ---- public void propertyChange (PropertyChangeEvent ev) { DataLoader l = (DataLoader)ev.getSource(); String prop = ev.getPropertyName (); + err.log(Level.FINE, "Property change {0}", prop); if (DataLoader.PROP_ACTIONS.equals (prop) && ev.getNewValue () == null) { // skip this change as this means the loader is using new storage mechanism return; *************** *** 903,909 **** --- 899,914 ---- err.fine("going to fire change in loaders"); // NOI18N super.fireChangeEvent(new ChangeEvent (this)); err.fine("change event fired"); // NOI18N + Enumeration e = allLoaders(); + while (e.hasMoreElements()) { + DataLoader l = (DataLoader)e.nextElement(); + // so the pool is there only once + l.removePropertyChangeListener(this); + l.addPropertyChangeListener(this); + err.log(Level.FINE, "Adding listener {0} in update", l); } + err.fine("listeners updated"); // NOI18N + } /** Write the object. *************** *** 927,933 **** public void resultChanged(LookupEvent ev) { if (org.netbeans.core.startup.Main.isInitialized()) { ! superFireChangeEvent(); } } } // end of NbLoaderPool --- 932,938 ---- public void resultChanged(LookupEvent ev) { if (org.netbeans.core.startup.Main.isInitialized()) { ! update(); } } } // end of NbLoaderPool Index: test/unit/src/org/netbeans/core/LoaderPoolNodeMetaInfTest.java *** /doma/jarda/netbeans-src/core/test/unit/src/org/netbeans/core/LoaderPoolNodeMetaInfTest.java No Base Revision --- /doma/jarda/netbeans-src/core/test/unit/src/org/netbeans/core/LoaderPoolNodeMetaInfTest.java Locally New *************** *** 1,0 **** --- 1,148 ---- + /* + * 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.core; + + import java.io.*; + import java.util.*; + import java.util.logging.Level; + import java.util.logging.Logger; + import org.netbeans.core.LoaderPoolNode.NbLoaderPool; + import org.netbeans.core.startup.Main; + import org.netbeans.core.startup.MainLookup; + import org.openide.filesystems.*; + import org.openide.actions.*; + import org.openide.loaders.DataLoaderPool; + import org.openide.util.actions.SystemAction; + + + /** + * + * @author Jaroslav Tulach + */ + public class LoaderPoolNodeMetaInfTest extends org.netbeans.junit.NbTestCase { + private OldStyleLoader oldL; + private NewStyleLoader newL; + private Logger LOG; + + static { + Main.getModuleSystem(); + } + + public LoaderPoolNodeMetaInfTest (String testName) { + super (testName); + } + + protected Level logLevel() { + return Level.FINE; + } + + protected void setUp () throws java.lang.Exception { + LOG = Logger.getLogger("test.LoaderPoolNodeMetaInfTest." + getName()); + + assertEquals(NbLoaderPool.class, DataLoaderPool.getDefault().getClass()); + LoaderPoolNode.installationFinished(); + + oldL = OldStyleLoader.getLoader(OldStyleLoader.class); + newL = NewStyleLoader.getLoader(NewStyleLoader.class); + LOG.info("Register old"); + MainLookup.register(oldL); + LOG.info("Register new"); + MainLookup.register(newL); + LOG.info("Register done"); + + assertEquals(NbLoaderPool.class, DataLoaderPool.getDefault().getClass()); + LoaderPoolNode.waitFinished(); + LOG.info("Running with " + getWorkDirPath()); + } + + protected void tearDown () throws java.lang.Exception { + LOG.info("Unregister old"); + MainLookup.unregister(oldL); + LOG.info("Unregister new"); + MainLookup.unregister(newL); + LOG.info("Unregister done"); + LoaderPoolNode.waitFinished(); + LOG.info("end of tearDown"); + } + + public void testOldLoaderThatChangesActionsBecomesModified () throws Exception { + assertFalse ("Not modified at begining", LoaderPoolNode.isModified (oldL)); + Object actions = oldL.getActions (); + assertNotNull ("Some actions there", actions); + assertTrue ("Default actions called", oldL.defaultActionsCalled); + assertFalse ("Still not modified", LoaderPoolNode.isModified (oldL)); + + ArrayList list = new ArrayList (); + list.add (OpenAction.get (OpenAction.class)); + list.add (NewAction.get (NewAction.class)); + LOG.info("Doing a change"); + oldL.setActions ((SystemAction[])list.toArray (new SystemAction[0])); + LOG.info("After a change"); + + assertTrue ("Now it is modified", LoaderPoolNode.isModified (oldL)); + List l = Arrays.asList (oldL.getActions ()); + assertEquals ("Actions are the same", list, l); + } + + public void testNewLoaderThatChangesActionsBecomesModified () throws Exception { + assertFalse ("Not modified at begining", LoaderPoolNode.isModified (newL)); + Object actions = newL.getActions (); + assertNotNull ("Some actions there", actions); + assertTrue ("Default actions called", newL.defaultActionsCalled); + assertFalse ("Still not modified", LoaderPoolNode.isModified (newL)); + + ArrayList list = new ArrayList (); + list.add (OpenAction.get (OpenAction.class)); + list.add (NewAction.get (NewAction.class)); + newL.setActions ((SystemAction[])list.toArray (new SystemAction[0])); + + assertFalse ("Even if we changed actions, it is not modified", LoaderPoolNode.isModified (newL)); + List l = Arrays.asList (newL.getActions ()); + assertEquals ("But actions are changed", list, l); + } + + public static class OldStyleLoader extends org.openide.loaders.UniFileLoader { + boolean defaultActionsCalled; + + public OldStyleLoader () { + super (org.openide.loaders.MultiDataObject.class); + } + + protected org.openide.loaders.MultiDataObject createMultiObject (FileObject fo) throws IOException { + throw new IOException ("Not implemented"); + } + + protected SystemAction[] defaultActions () { + defaultActionsCalled = true; + SystemAction[] retValue; + + retValue = super.defaultActions(); + return retValue; + } + + + } + + public static final class NewStyleLoader extends OldStyleLoader { + protected String actionsContext () { + return "Loaders/IamTheNewBeggining"; + } + } + }