diff -r 850fe3f0316a openide.filesystems/src/org/openide/filesystems/FileBasedFileSystems.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.filesystems/src/org/openide/filesystems/FileBasedFileSystems.java Tue Feb 12 11:45:31 2008 +0100 @@ -0,0 +1,106 @@ +/* + * 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 2008 Sun Microsystems, Inc. + */ +package org.openide.filesystems; + +import java.util.ArrayList; +import java.util.Collection; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +/** + * + * @author rmatous + */ +/** + */ +public final class FileBasedFileSystems { + private FileBasedFileSystemsSPI filesystems; + private final Collection listeners = new ArrayList(); + private final Collection fss = new ArrayList(); + + FileBasedFileSystems() { + filesystems = FileUtil.getFileBasedFileSystemsSPI(); + fss.addAll(filesystems.getFileSystems().values()); + } + + public Collection getFileSystems() { + return fss; + } + + /** Adds new listener. + * @param list the listener + */ + public void addFileChangeListener(FileChangeListener list) { + listeners.add(list); + for (FileSystem fs : fss) { + fs.addFileChangeListener(list); + } + } + + /** Removes listener. + * @param list the listener + */ + public void removeFileChangeListener(FileChangeListener list) { + listeners.remove(list); + for (FileSystem fs : fss) { + fs.removeFileChangeListener(list); + } + } + + private void changedFileSystems() { + Collection n = filesystems.getFileSystems().values(); + for (FileChangeListener fcl : listeners) { + for (FileSystem fs : fss) { + fs.removeFileChangeListener(fcl); + } + for (FileSystem fs : n) { + fs.addFileChangeListener(fcl); + } + } + fss.clear(); + fss.addAll(n); + } + + private class ChangeListenerImpl implements ChangeListener { + + public void stateChanged(ChangeEvent e) { + changedFileSystems(); + } + } +} diff -r 850fe3f0316a openide.filesystems/src/org/openide/filesystems/FileBasedFileSystemsSPI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.filesystems/src/org/openide/filesystems/FileBasedFileSystemsSPI.java Tue Feb 12 11:45:31 2008 +0100 @@ -0,0 +1,77 @@ +/* + * 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 2008 Sun Microsystems, Inc. + */ +package org.openide.filesystems; + +import java.io.File; +import java.util.Map; +import javax.swing.event.ChangeListener; + +/** + * + * @author rmatous + */ +/** + * SPI + * Keeps an unordered collection of filesystems. + */ +public abstract class FileBasedFileSystemsSPI { + + /** + * @return all filesystems {@link FileSystem} + */ + public abstract Map getFileSystems(); + + /** + * Refreshes all necessary filesystems. Not all instances of FileObject are refreshed + * but just those that represent passed files and their children recursively. + * @param files + */ + public abstract void refreshFor(File[] files); + + + /** Adds new listener. + * @param list the listener + */ + public abstract void addChangeListener(ChangeListener list); + + /** Removes listener. + * @param list the listener + */ + public abstract void removeChangeListener(ChangeListener list); +} diff -r 850fe3f0316a openide.filesystems/src/org/openide/filesystems/FileUtil.java --- a/openide.filesystems/src/org/openide/filesystems/FileUtil.java Fri Feb 08 12:01:59 2008 +0100 +++ b/openide.filesystems/src/org/openide/filesystems/FileUtil.java Tue Feb 12 11:45:31 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; @@ -121,7 +122,8 @@ public final class FileUtil extends Obje /** Cache for {@link #isArchiveFile(FileObject)}. */ private static final Map archiveFileCache = new WeakHashMap(); - private static FileSystem diskFileSystem; + private static FileBasedFileSystemsSPI filesystems; + private static FileBasedFileSystems fsSupport; private FileUtil() { } @@ -133,24 +135,45 @@ public final class FileUtil extends Obje * @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; - } + FileBasedFileSystemsSPI fbs = getFileBasedFileSystemsSPI(); + fbs.refreshFor(files); + } + + /** + * + * @return + */ + static FileBasedFileSystemsSPI getFileBasedFileSystemsSPI() { + synchronized (FileUtil.class) { + if (filesystems != null) { + return filesystems; } } - if (fs != null) { - try { - fs.getRoot().setAttribute("request_for_refreshing_files_be_aware_this_is_not_public_api", files); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); + FileBasedFileSystemsSPI tmp = null; + Lookup.Result res = Lookup.getDefault().lookup(new Lookup.Template(FileBasedFileSystemsSPI.class)); + Iterator> it = res.allItems().iterator(); + for (; it.hasNext();) { + Lookup.Item item = it.next(); + if (item != null && item.getId().contains("org.netbeans.modules.masterfs.filebasedfs")) {//NOI18N + tmp = item.getInstance(); + break; } - } - } + } + synchronized (FileUtil.class) { + if (filesystems == null) { + filesystems = tmp; + } + return filesystems; + } + } + + public static FileBasedFileSystems getFileBasedFileSystems() { + if (fsSupport == null) { + fsSupport = new FileBasedFileSystems(); + } + return fsSupport; + } + /** * Executes atomic action. For more info see {@link FileSystem#runAtomicAction}. @@ -630,17 +653,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; } @@ -1873,20 +1885,5 @@ public final class FileUtil extends Obje public File createFileObject(String path) { return wrapFileNoCanonicalize(delegate.createFileObject(path)); } - } - - 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; - } - } } }