Index: openide/fs/apichanges.xml =================================================================== RCS file: /shared/data/ccvs/repository/openide/fs/apichanges.xml,v retrieving revision 1.11 diff -u -r1.11 apichanges.xml --- openide/fs/apichanges.xml 7 Sep 2006 08:43:36 -0000 1.11 +++ openide/fs/apichanges.xml 5 Mar 2007 15:11:44 -0000 @@ -23,6 +23,27 @@ Filesystems API + + + Allow modules to dynamically add/remove layer content + + + + + +

+ Repository.getDefaultFileSystem's content can now be + influenced by adding own + FileSystems + into global + Lookup.getDefault(). + This is supposed to work in a standalone mode as well + as inside NetBeans Platform. +

+
+ + +
Added additional methods FileUtil.createData Index: openide/fs/manifest.mf =================================================================== RCS file: /shared/data/ccvs/repository/openide/fs/manifest.mf,v retrieving revision 1.8 diff -u -r1.8 manifest.mf --- openide/fs/manifest.mf 31 May 2006 15:42:10 -0000 1.8 +++ openide/fs/manifest.mf 5 Mar 2007 15:11:44 -0000 @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.filesystems -OpenIDE-Module-Specification-Version: 7.0 +OpenIDE-Module-Specification-Version: 7.1 OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties Index: openide/fs/src/org/openide/filesystems/ExternalUtil.java =================================================================== RCS file: /shared/data/ccvs/repository/openide/fs/src/org/openide/filesystems/ExternalUtil.java,v retrieving revision 1.7 diff -u -r1.7 ExternalUtil.java --- openide/fs/src/org/openide/filesystems/ExternalUtil.java 28 Oct 2006 21:57:38 -0000 1.7 +++ openide/fs/src/org/openide/filesystems/ExternalUtil.java 5 Mar 2007 15:11:44 -0000 @@ -18,10 +18,14 @@ */ package org.openide.filesystems; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import org.openide.util.Exceptions; import org.openide.util.Lookup; +import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; /** Contains utility methods to deal with repository and error manager, @@ -120,7 +124,29 @@ if (repository == null) { // if not provided use default one - repository = new Repository(FileUtil.createMemoryFileSystem()); + repository = new Repository(new MainFS()); } } + + private static final class MainFS extends MultiFileSystem implements LookupListener { + private static final Lookup.Result ALL = Lookup.getDefault().lookupResult(FileSystem.class); + private static final FileSystem MEMORY = FileUtil.createMemoryFileSystem(); + + public MainFS() { + super(computeDelegates()); + ALL.addLookupListener(this); + } + + private static FileSystem[] computeDelegates() { + List arr = new ArrayList(); + arr.add(MEMORY); + arr.addAll(ALL.allInstances()); + return arr.toArray(new FileSystem[0]); + } + + + public void resultChanged(LookupEvent ev) { + setDelegates(computeDelegates()); + } + } // end of MainFS } Index: openide/fs/test/unit/src/org/openide/filesystems/RepositoryTest.java =================================================================== RCS file: openide/fs/test/unit/src/org/openide/filesystems/RepositoryTest.java diff -N openide/fs/test/unit/src/org/openide/filesystems/RepositoryTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openide/fs/test/unit/src/org/openide/filesystems/RepositoryTest.java 5 Mar 2007 15:11:44 -0000 @@ -0,0 +1,65 @@ +/* + * 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.openide.filesystems; + +import junit.framework.TestCase; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; + +/** + * + * @author Jaroslav Tulach + */ +public class RepositoryTest extends TestCase { + static { + System.setProperty("org.openide.util.Lookup", MainLookup.class.getName()); + } + + + public RepositoryTest(String testName) { + super(testName); + } + + + public void testContentOfFileSystemIsInfluencedByLookup () throws Exception { + FileSystem mem = FileUtil.createMemoryFileSystem(); + String dir = "/yarda/own/file"; + org.openide.filesystems.FileUtil.createFolder (mem.getRoot (), dir); + + assertNull ("File is not there yet", Repository.getDefault ().getDefaultFileSystem ().findResource (dir)); + MainLookup.ic.add(mem); + try { + assertNotNull ("The file is there now", Repository.getDefault ().getDefaultFileSystem ().findResource (dir)); + } finally { + MainLookup.ic.remove(mem); + } + assertNull ("File is no longer there", Repository.getDefault ().getDefaultFileSystem ().findResource (dir)); + } + + + public static final class MainLookup extends AbstractLookup { + static final InstanceContent ic = new InstanceContent(); + + + public MainLookup() { + super(ic); + } + } +} Index: core/startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java =================================================================== RCS file: /shared/data/ccvs/repository/core/startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java,v retrieving revision 1.8 diff -u -r1.8 SystemFileSystem.java --- core/startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java 3 Aug 2006 09:57:27 -0000 1.8 +++ core/startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java 5 Mar 2007 15:11:45 -0000 @@ -29,6 +29,8 @@ import java.io.ObjectStreamException; import java.io.Serializable; import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.MissingResourceException; @@ -42,13 +44,15 @@ import org.openide.filesystems.LocalFileSystem; import org.openide.filesystems.MultiFileSystem; import org.openide.filesystems.Repository; +import org.openide.util.Lookup; import org.openide.util.NbBundle; /** The system FileSystem - represents system files under $NETBEANS_HOME/system. * * @author Jan Jancura, Ian Formanek, Petr Hamernik */ -public final class SystemFileSystem extends MultiFileSystem implements FileSystem.Status { +public final class SystemFileSystem extends MultiFileSystem +implements FileSystem.Status, org.openide.util.LookupListener { // Must be public for BeanInfo to work: #11186. /** generated Serialized Version UID */ @@ -65,6 +69,11 @@ /** name of file attribute with URL to 32x32 color icon */ private static final String ATTR_ICON_32 = "SystemFileSystem.icon32"; // NOI18N + /** lookup result we listen on */ + private static Lookup.Result result = Lookup.getDefault().lookupResult(FileSystem.class); + /** the set of layers provided by the system */ + private static FileSystem[] layers; + /** user fs */ private ModuleLayeredFileSystem user; /** home fs */ @@ -73,13 +82,15 @@ /** @param fss list of file systems to delegate to */ @SuppressWarnings("deprecation") - private SystemFileSystem (FileSystem[] fss) throws PropertyVetoException { - super (fss); - user = (ModuleLayeredFileSystem) fss[0]; - home = fss.length > 2 ? (ModuleLayeredFileSystem) fss[1] : null; - - setSystemName (SYSTEM_NAME); - setHidden (true); + private SystemFileSystem() throws PropertyVetoException { + super(computeLayers()); + user = (ModuleLayeredFileSystem) layers[0]; + home = layers.length > 2 ? (ModuleLayeredFileSystem) layers[1] : null; + + setSystemName(SYSTEM_NAME); + setHidden(true); + + result.addLookupListener(this); } @@ -113,8 +124,9 @@ else s.add (arr[i]); + layers = (FileSystem[])arr.clone(); // create own internal copy of passed filesystems - setDelegates(arr.clone()); + setDelegates(computeLayers()); firePropertyChange ("layers", null, null); // NOI18N } @@ -127,6 +139,19 @@ // don't return reference to internal buffer return getDelegates().clone(); } + + private synchronized static FileSystem[] computeLayers () { + FileSystem[] fromLookup = (FileSystem[])result.allInstances ().toArray (new FileSystem[0]); + + if (fromLookup.length > 0) { + ArrayList arr = new ArrayList(layers.length + fromLookup.length); + arr.addAll (Arrays.asList (layers)); + arr.addAll (Arrays.asList (fromLookup)); + return (FileSystem[])arr.toArray (new FileSystem[0]); + } + + return layers; + } protected FileSystem createWritableOnForRename (String oldName, String newName) throws IOException { return createWritableOn (oldName); @@ -280,7 +305,8 @@ ("org.netbeans.core.projects.FixedFileSystem", "Automatic Manifest Installation"); // NOI18N arr[home == null ? 1 : 2] = FixedFileSystem.deflt; - return new SystemFileSystem (arr); + layers = arr; + return new SystemFileSystem (); } /** Notification that a file has migrated from one file system @@ -297,9 +323,14 @@ } // --- SAFETY --- - private Object writeReplace () throws ObjectStreamException { - new NotSerializableException ("WARNING - SystemFileSystem is not designed to be serialized").printStackTrace (); // NOI18N - return new SingletonSerializer (); + private Object writeReplace() throws ObjectStreamException { + new NotSerializableException("WARNING - SystemFileSystem is not designed to be serialized").printStackTrace(); // NOI18N + return new SingletonSerializer(); + } + + /** Refresh layers */ + public synchronized void resultChanged(org.openide.util.LookupEvent ev) { + setDelegates(computeLayers()); } private static final class SingletonSerializer extends Object implements Serializable { Index: core/test/unit/src/org/netbeans/core/projects/SystemFileSystemTest.java =================================================================== RCS file: /shared/data/ccvs/repository/core/test/unit/src/org/netbeans/core/projects/SystemFileSystemTest.java,v retrieving revision 1.5 diff -u -r1.5 SystemFileSystemTest.java --- core/test/unit/src/org/netbeans/core/projects/SystemFileSystemTest.java 1 Jul 2006 08:53:28 -0000 1.5 +++ core/test/unit/src/org/netbeans/core/projects/SystemFileSystemTest.java 5 Mar 2007 15:11:45 -0000 @@ -20,12 +20,10 @@ package org.netbeans.core.projects; import org.netbeans.junit.*; -import junit.textui.TestRunner; import org.netbeans.Module; import org.netbeans.ModuleManager; import org.netbeans.core.startup.ModuleHistory; -import org.netbeans.core.NbTopManager; import org.openide.util.Mutex; import org.openide.util.MutexException; import org.openide.filesystems.FileObject; @@ -36,11 +34,13 @@ import java.util.Collections; import java.awt.Toolkit; import java.awt.Image; -import java.awt.image.BufferedImage; import java.net.URL; import java.beans.BeanInfo; import java.awt.image.PixelGrabber; import java.awt.image.ImageObserver; +import org.netbeans.core.startup.MainLookup; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; /** Test operation of the SystemFileSystem. * For now, just display attributes. @@ -93,6 +93,21 @@ FileObject bar = Repository.getDefault().getDefaultFileSystem().findResource("foo/bar.txt"); Node n = DataObject.find(bar).getNodeDelegate(); assertEquals("correct localized data object name", "Localized Name", n.getDisplayName()); + } + + public void testContentOfFileSystemIsInfluencedByLookup () throws Exception { + FileSystem mem = FileUtil.createMemoryFileSystem(); + String dir = "/yarda/own/file"; + org.openide.filesystems.FileUtil.createFolder (mem.getRoot (), dir); + + assertNull ("File is not there yet", Repository.getDefault ().getDefaultFileSystem ().findResource (dir)); + MainLookup.register (mem); + try { + assertNotNull ("The file is there now", Repository.getDefault ().getDefaultFileSystem ().findResource (dir)); + } finally { + MainLookup.unregister (mem); + } + assertNull ("File is no longer there", Repository.getDefault ().getDefaultFileSystem ().findResource (dir)); } public void testIconFromURL() throws Exception {