diff -r 1d9ffd559d83 api.java/src/org/netbeans/api/java/classpath/ClassPath.java --- a/api.java/src/org/netbeans/api/java/classpath/ClassPath.java Tue Feb 19 18:50:13 2008 +0100 +++ b/api.java/src/org/netbeans/api/java/classpath/ClassPath.java Tue Feb 19 19:19:48 2008 +0100 @@ -44,7 +44,6 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; -import java.io.File; import java.io.IOException; import java.lang.ref.Reference; import java.lang.ref.SoftReference; @@ -58,7 +57,6 @@ import java.util.Collection; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -76,7 +74,6 @@ import org.openide.filesystems.FileObjec import org.openide.filesystems.FileObject; import org.openide.filesystems.FileRenameEvent; import org.openide.filesystems.FileStateInvalidException; -import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; import org.openide.util.Exceptions; @@ -930,17 +927,7 @@ public final class ClassPath { public void addRoot (URL url) { if (!isInitialized()) { - FileSystem[] fss = getFileSystems (); - if (fss != null && fss.length > 0) { - for (FileSystem fs : fss) { - if (fs != null) { - fs.addFileChangeListener (this); - } - } - setInitialized(true); - } else { - LOG.warning("Cannot find file system, not able to listen on changes."); - } + FileUtil.getMasterFileSystem().addFileChangeListener(this); } if ("jar".equals(url.getProtocol())) { //NOI18N url = FileUtil.getArchiveFile(url); @@ -965,12 +952,7 @@ public final class ClassPath { public void removeAllRoots () { this.roots.clear(); - FileSystem[] fss = getFileSystems (); - for (FileSystem fs : fss) { - if (fs != null) { - fs.removeFileChangeListener (this); - } - } + FileUtil.getMasterFileSystem().removeFileChangeListener(this); initialized = false; //Already synchronized } @@ -1013,11 +995,7 @@ public final class ClassPath { public void run() { if (isInitialized()) { - for (FileSystem fs : getFileSystems()) { - if (fs != null) { - fs.removeFileChangeListener (this); - } - } + FileUtil.getMasterFileSystem().removeFileChangeListener(this); } } @@ -1071,43 +1049,6 @@ public final class ClassPath { private synchronized void setInitialized (boolean newValue) { this.initialized = newValue; - } - - //copy - paste programming - //http://ant.netbeans.org/source/browse/ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java.diff?r1=1.15&r2=1.16 - //http:/java.netbeans.org/source/browse/java/javacore/src/org/netbeans/modules/javacore/Util.java - //http://core.netbeans.org/source/browse/core/ui/src/org/netbeans/core/ui/MenuWarmUpTask.java - //http://core.netbeans.org/source/browse/core/src/org/netbeans/core/actions/RefreshAllFilesystemsAction.java - //http://java.netbeans.org/source/browse/java/api/src/org/netbeans/api/java/classpath/ClassPath.java - - private static FileSystem[] fileSystems; - - private static FileSystem[] getFileSystems() { - if (fileSystems != null) { - return fileSystems; - } - File[] roots = File.listRoots(); - Set allRoots = new LinkedHashSet(); - assert roots != null && roots.length > 0 : "Could not list file roots"; // NOI18N - - for (File root : roots) { - FileObject random = FileUtil.toFileObject(root); - if (random == null) continue; - - FileSystem fs; - try { - fs = random.getFileSystem(); - allRoots.add(fs); - } catch (FileStateInvalidException e) { - throw new AssertionError(e); - } - } - FileSystem[] retVal = new FileSystem [allRoots.size()]; - allRoots.toArray(retVal); - assert retVal.length > 0 : "Could not get any filesystem"; // NOI18N - - return fileSystems = retVal; - } + } } - } diff -r 1d9ffd559d83 core.ui/src/org/netbeans/core/ui/warmup/MenuWarmUpTask.java --- a/core.ui/src/org/netbeans/core/ui/warmup/MenuWarmUpTask.java Tue Feb 19 18:50:13 2008 +0100 +++ b/core.ui/src/org/netbeans/core/ui/warmup/MenuWarmUpTask.java Tue Feb 19 19:19:48 2008 +0100 @@ -48,17 +48,12 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; -import java.util.Set; -import java.util.LinkedHashSet; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.SwingUtilities; import org.openide.windows.WindowManager; import org.openide.util.RequestProcessor; -import org.openide.filesystems.FileSystem; -import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; -import org.openide.filesystems.FileStateInvalidException; /** * A menu preheating task. It is referenced from the layer and may be performed @@ -140,18 +135,11 @@ public final class MenuWarmUpTask implem } public void run() { - FileUtil.refreshFor(File.listRoots()); + FileUtil.getMasterFileSystem().refresh(true); synchronized (rp) { task = null; } - } - - //copy - paste programming - //http://ant.netbeans.org/source/browse/ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java.diff?r1=1.15&r2=1.16 - //http:/java.netbeans.org/source/browse/java/javacore/src/org/netbeans/modules/javacore/Util.java - //http://core.netbeans.org/source/browse/core/ui/src/org/netbeans/core/ui/MenuWarmUpTask.java - //http://core.netbeans.org/source/browse/core/src/org/netbeans/core/actions/RefreshAllFilesystemsAction.java - //http://java.netbeans.org/source/browse/java/api/src/org/netbeans/api/java/classpath/ClassPath.java + } } } diff -r 1d9ffd559d83 gsf/src/org/netbeans/modules/gsfret/source/usages/RepositoryUpdater.java --- a/gsf/src/org/netbeans/modules/gsfret/source/usages/RepositoryUpdater.java Tue Feb 19 18:50:13 2008 +0100 +++ b/gsf/src/org/netbeans/modules/gsfret/source/usages/RepositoryUpdater.java Tue Feb 19 19:19:48 2008 +0100 @@ -424,41 +424,11 @@ public class RepositoryUpdater implement private void registerFileSystemListener () { - final File[] roots = File.listRoots(); - final Set fss = new HashSet (); - for (File root : roots) { - final FileObject fo = FileUtil.toFileObject (root); - if (fo != null) { - try { - final FileSystem fs = fo.getFileSystem(); - if (!fss.contains(fs)) { - fs.addFileChangeListener (this); - fss.add(fs); - } - } catch (FileStateInvalidException e) { - Exceptions.printStackTrace(e); - } - } - } + FileUtil.getMasterFileSystem().addFileChangeListener(this); } private void unregisterFileSystemListener () { - final File[] roots = File.listRoots(); - final Set fss = new HashSet (); - for (File root : roots) { - final FileObject fo = FileUtil.toFileObject (root); - if (fo != null) { - try { - final FileSystem fs = fo.getFileSystem(); - if (!fss.contains(fs)) { - fs.removeFileChangeListener (this); - fss.add(fs); - } - } catch (FileStateInvalidException e) { - Exceptions.printStackTrace(e); - } - } - } + FileUtil.getMasterFileSystem().removeFileChangeListener(this); } private URL getOwningSourceRoot (final FileObject fo) { diff -r 1d9ffd559d83 java.source/src/org/netbeans/modules/java/source/usages/RepositoryUpdater.java --- a/java.source/src/org/netbeans/modules/java/source/usages/RepositoryUpdater.java Tue Feb 19 18:50:13 2008 +0100 +++ b/java.source/src/org/netbeans/modules/java/source/usages/RepositoryUpdater.java Tue Feb 19 19:19:48 2008 +0100 @@ -593,41 +593,11 @@ public class RepositoryUpdater implement private void registerFileSystemListener () { - final File[] roots = File.listRoots(); - final Set fss = new HashSet (); - for (File root : roots) { - final FileObject fo = FileUtil.toFileObject (root); - if (fo != null) { - try { - final FileSystem fs = fo.getFileSystem(); - if (!fss.contains(fs)) { - fs.addFileChangeListener (this); - fss.add(fs); - } - } catch (FileStateInvalidException e) { - Exceptions.printStackTrace(e); - } - } - } + FileUtil.getMasterFileSystem().addFileChangeListener(this); } private void unregisterFileSystemListener () { - final File[] roots = File.listRoots(); - final Set fss = new HashSet (); - for (File root : roots) { - final FileObject fo = FileUtil.toFileObject (root); - if (fo != null) { - try { - final FileSystem fs = fo.getFileSystem(); - if (!fss.contains(fs)) { - fs.removeFileChangeListener (this); - fss.add(fs); - } - } catch (FileStateInvalidException e) { - Exceptions.printStackTrace(e); - } - } - } + FileUtil.getMasterFileSystem().removeFileChangeListener(this); } private URL getOwningSourceRoot (final FileObject fo) { diff -r 1d9ffd559d83 o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java --- a/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java Tue Feb 19 18:50:13 2008 +0100 +++ b/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java Tue Feb 19 19:19:48 2008 +0100 @@ -333,14 +333,8 @@ public class BridgeImpl implements Bridg private static final RequestProcessor.Task refreshFilesystemsTask = RequestProcessor.getDefault().create(new Runnable() { public void run() { - //copy - paste programming - //http://ant.netbeans.org/source/browse/ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java.diff?r1=1.15&r2=1.16 - //http:/java.netbeans.org/source/browse/java/javacore/src/org/netbeans/modules/javacore/Util.java - //http://core.netbeans.org/source/browse/core/ui/src/org/netbeans/core/ui/MenuWarmUpTask.java - //http://core.netbeans.org/source/browse/core/src/org/netbeans/core/actions/RefreshAllFilesystemsAction.java - //http://java.netbeans.org/source/browse/java/api/src/org/netbeans/api/java/classpath/ClassPath.java Logger.getLogger(BridgeImpl.class.getName()).log(Level.FINE, "Refreshing filesystems"); - FileUtil.refreshFor(File.listRoots()); + FileUtil.getMasterFileSystem().refresh(true); } }); diff -r 1d9ffd559d83 versioning/src/org/netbeans/modules/versioning/VersioningAnnotationProvider.java --- a/versioning/src/org/netbeans/modules/versioning/VersioningAnnotationProvider.java Tue Feb 19 18:50:13 2008 +0100 +++ b/versioning/src/org/netbeans/modules/versioning/VersioningAnnotationProvider.java Tue Feb 19 19:19:48 2008 +0100 @@ -281,24 +281,7 @@ public class VersioningAnnotationProvide public void run() { clearMap(filesToRefresh); clearMap(parentsToRefresh); - - Set filesystems = new HashSet(1); - File[] allRoots = File.listRoots(); - for (int i = 0; i < allRoots.length; i++) { - File root = allRoots[i]; - FileObject fo = FileUtil.toFileObject(root); - if (fo != null) { - try { - filesystems.add(fo.getFileSystem()); - } catch (FileStateInvalidException e) { - // ignore invalid filesystems - } - } - } - for (Iterator i = filesystems.iterator(); i.hasNext();) { - FileSystem fileSystem = i.next(); - fireFileStatusChanged(new FileStatusEvent(fileSystem, true, true)); - } + fireFileStatusChanged(new FileStatusEvent(FileUtil.getMasterFileSystem(), true, true)); } }); diff -r 012c7d882cfe -r 1d9ffd559d83 masterfs/apichanges.xml --- a/masterfs/apichanges.xml Tue Feb 19 15:42:08 2008 +0100 +++ b/masterfs/apichanges.xml Tue Feb 19 18:50:13 2008 +0100 @@ -46,22 +46,6 @@ made subject to such option by the copyr MasterFileSystem API - - - One drive == one instance of filesystem on windows - - - - - - For every individual drive on windows now exists one filesystem. Every - instance of filesystem is created on demand. Before this change there was - one filesystem with virtual root containing all reachable drives as its - children. - - - - Fileobject instances are not issued after external changes diff -r 012c7d882cfe -r 1d9ffd559d83 masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedFileSystem.java --- a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedFileSystem.java Tue Feb 19 15:42:08 2008 +0100 +++ b/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedFileSystem.java Tue Feb 19 18:50:13 2008 +0100 @@ -63,17 +63,19 @@ import org.openide.util.Exceptions; import org.openide.util.Exceptions; import org.openide.util.Utilities; import org.openide.util.actions.SystemAction; +import org.openide.util.lookup.Lookups; /** * @author Radek Matous */ public final class FileBasedFileSystem extends FileSystem { - private static final FileBasedFileSystem INSTANCE = new FileBasedFileSystem(); + private static FileBasedFileSystem INSTANCE; transient private RootObj root; transient private final StatusImpl status = new StatusImpl(); transient private static int modificationInProgress; - FileBasedFileSystem() { + public FileBasedFileSystem() { + assert INSTANCE == null; if (Utilities.isWindows()) { RootObjWindows realRoot = new RootObjWindows(); root = new RootObj(realRoot); @@ -81,14 +83,15 @@ public final class FileBasedFileSystem e FileObjectFactory factory = FileObjectFactory.getInstance(new File("/"));//NOI18N root = new RootObj(factory.getRoot()); } + INSTANCE = this; } public synchronized static boolean isModificationInProgress() { return modificationInProgress == 0 ? false : true; } - private synchronized static void setModificationInProgress(boolean _inconsistent) { - if (_inconsistent) { + private synchronized static void setModificationInProgress(boolean started) { + if (started) { modificationInProgress++; } else { modificationInProgress--; @@ -138,6 +141,10 @@ public final class FileBasedFileSystem e public static FileBasedFileSystem getInstance() { + if (INSTANCE == null) { + Lookups.metaInfServices(FileBasedFileSystem.class.getClassLoader()).lookup(FileSystem.class); + assert INSTANCE != null; + } return INSTANCE; } diff -r 012c7d882cfe -r 1d9ffd559d83 masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FileObjectFactory.java --- a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FileObjectFactory.java Tue Feb 19 15:42:08 2008 +0100 +++ b/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FileObjectFactory.java Tue Feb 19 18:50:13 2008 +0100 @@ -630,11 +630,17 @@ public final class FileObjectFactory { public final void refresh(final boolean expected) { Statistics.StopWatch stopWatch = Statistics.getStopWatch(Statistics.REFRESH_FS); + final Runnable r = new Runnable() { + public void run() { + refreshAll(expected); + } + }; + stopWatch.start(); try { FileBasedFileSystem.getInstance().runAtomicAction(new FileSystem.AtomicAction() { public void run() throws IOException { - refreshAll(expected); + FileBasedFileSystem.runAsInconsistent(r); } }); } catch (IOException iex) {/*method refreshAll doesn't throw IOException*/ diff -r 012c7d882cfe -r 1d9ffd559d83 openide.filesystems/apichanges.xml --- a/openide.filesystems/apichanges.xml Tue Feb 19 15:42:08 2008 +0100 +++ b/openide.filesystems/apichanges.xml Tue Feb 19 18:50:13 2008 +0100 @@ -46,6 +46,23 @@ made subject to such option by the copyr Filesystems API + + + Add method FileUtil.getMasterFileSystem + + + + + +

+ Added method returning instance of FileSystem, + whose instances of FileObject + can be acquired by calling method FileUtil.toFileObject. +

+
+ + +
Add method FileUtil.refreshFor(File... files) diff -r 012c7d882cfe -r 1d9ffd559d83 openide.filesystems/manifest.mf --- a/openide.filesystems/manifest.mf Tue Feb 19 15:42:08 2008 +0100 +++ b/openide.filesystems/manifest.mf Tue Feb 19 18:50:13 2008 +0100 @@ -1,5 +1,5 @@ Manifest-Version: 1.0 Manifest-Version: 1.0 OpenIDE-Module: org.openide.filesystems -OpenIDE-Module-Specification-Version: 7.6 +OpenIDE-Module-Specification-Version: 7.7 OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties diff -r 012c7d882cfe -r 1d9ffd559d83 openide.filesystems/src/org/openide/filesystems/FileUtil.java --- a/openide.filesystems/src/org/openide/filesystems/FileUtil.java Tue Feb 19 15:42:08 2008 +0100 +++ b/openide.filesystems/src/org/openide/filesystems/FileUtil.java Tue Feb 19 18:50:13 2008 +0100 @@ -77,6 +77,7 @@ import org.openide.filesystems.FileSyste import org.openide.filesystems.FileSystem.AtomicAction; import org.openide.util.Exceptions; import org.openide.util.Lookup; +import org.openide.util.Lookup.Item; import org.openide.util.NbBundle; import org.openide.util.Utilities; import org.openide.util.WeakListeners; @@ -127,22 +128,34 @@ public final class FileUtil extends Obje } /** - * Refreshes all necessary filesystems. Not all instances of FileObject are refreshed - * but just those that represent passed files and their children recursively. + * @return instance of FileSystem, whose instances of FileObject + * can be acquired by calling method FileUtil.toFileObject + * @since 7.7 + */ + public static FileSystem getMasterFileSystem() { + FileSystem retval = null; + synchronized (FileUtil.class) { + retval = diskFileSystem; + } + if (retval == null) { + retval = initMasterFileSystem(); + synchronized (FileUtil.class) { + if (retval != null && diskFileSystem == null) { + diskFileSystem = retval; + } + } + } + return retval; + } + + /** + * Refreshes all necessary instances of FileObject that represent + * passed files and their children recursively. * @param files * @since 7.6 */ public static void refreshFor(File... files) { - FileSystem fs = getDiskFileSystem(); - if (fs == null) { - for (File file : files) { - FileObject fo = toFileObject(file); - fs = getDiskFileSystem(); - if (fs != null) { - break; - } - } - } + FileSystem fs = getMasterFileSystem(); if (fs != null) { try { fs.getRoot().setAttribute("request_for_refreshing_files_be_aware_this_is_not_public_api", files); @@ -151,7 +164,7 @@ public final class FileUtil extends Obje } } } - + /** * Executes atomic action. For more info see {@link FileSystem#runAtomicAction}. *

@@ -630,17 +643,6 @@ public final class FileUtil extends Obje /*probably temporary piece of code to catch the cause of #46630*/ } catch (MalformedURLException e) { retVal = null; - } - - if (retVal != null) { - if (getDiskFileSystem() == null) { - try { - FileSystem fs = retVal.getFileSystem(); - setDiskFileSystem(fs); - } catch (FileStateInvalidException ex) { - Exceptions.printStackTrace(ex); - } - } } return retVal; } @@ -1875,18 +1877,14 @@ public final class FileUtil extends Obje } } - private static FileSystem getDiskFileSystem() { - synchronized (FileUtil.class) { - return diskFileSystem; - } - } - - private static void setDiskFileSystem(FileSystem fs) { - Object o = fs.getRoot().getAttribute("SupportsRefreshForNoPublicAPI"); - if (o instanceof Boolean && ((Boolean) o).booleanValue()) { - synchronized (FileUtil.class) { - diskFileSystem = fs; + private static FileSystem initMasterFileSystem() { + Lookup.Result result = Lookup.getDefault().lookup(new Lookup.Template(FileSystem.class)); + Collection> c = result.allItems(); + for (Item item : c) { + if (item.getId().contains("org.netbeans.modules.masterfs")) {//NOI18N + return item.getInstance(); } } + return null; } }