# This patch file was generated by NetBeans IDE # This patch can be applied using context Tools: Apply Diff Patch action on respective folder. # It uses platform neutral UTF-8 encoding. # Above lines and this line are ignored by the patching process. Index: openide/fs/apichanges.xml --- openide/fs/apichanges.xml Base (1.16) +++ openide/fs/apichanges.xml Locally Modified (Based On 1.16) @@ -46,6 +46,24 @@ Filesystems API + + + Simple way to run atomic action without having a fileobject + + + + + +

+ Simple way to run atomic action without having a fileobject is ensured by + adding two methods: FileUtil.runAtomicAction. + All events about filesystem changes (related to events on all affected instances of FileSystem) + are postponed after the whole code runned in atomic block is executed. +

+
+ + +
Added method to test if file is locked Index: openide/fs/manifest.mf --- openide/fs/manifest.mf Base (1.12) +++ openide/fs/manifest.mf Locally Modified (Based On 1.12) @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.filesystems -OpenIDE-Module-Specification-Version: 7.4 +OpenIDE-Module-Specification-Version: 7.5 OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties Index: openide/fs/src/org/openide/filesystems/FileUtil.java --- openide/fs/src/org/openide/filesystems/FileUtil.java Base (1.49) +++ openide/fs/src/org/openide/filesystems/FileUtil.java Locally Modified (Based On 1.49) @@ -74,6 +74,7 @@ import javax.swing.JFileChooser; import javax.swing.SwingUtilities; import javax.swing.filechooser.FileSystemView; +import org.openide.filesystems.FileSystem.AtomicAction; import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.NbBundle; @@ -125,6 +126,43 @@ } /** + * Executes atomic action. For more info see {@link FileSystem#runAtomicAction}. + *

+ * All events about filesystem changes (related to events on all affected instances of FileSystem) + * are postponed after the whole atomicCode + * is executed. + *

+ * @param atomicCode code that is supposed to be run as atomic action. See {@link FileSystem#runAtomicAction} + * @throws java.io.IOException + * @since 7.5 + */ + public static final void runAtomicAction(final AtomicAction atomicCode) throws IOException { + Repository.getDefault().getDefaultFileSystem().runAtomicAction(atomicCode); + } + + /** + * Executes atomic action. For more info see {@link FileSystem#runAtomicAction}. + *

+ * All events about filesystem changes (related to events on all affected instances of FileSystem) + * are postponed after the whole atomicCode + * is executed. + *

+ * @param atomicCode code that is supposed to be run as atomic action. See {@link FileSystem#runAtomicAction} + * @since 7.5 + */ + public static final void runAtomicAction(final Runnable atomicCode) { + final AtomicAction action = new FileSystem.AtomicAction() { + public void run() throws IOException { + atomicCode.run(); + } + }; + try { + FileUtil.runAtomicAction(action); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + /** * Returns FileObject for a folder. * If such a folder does not exist then it is created, including any necessary but nonexistent parent * folders. Note that if this operation fails it may have succeeded in creating some of the necessary Index: openide/fs/test/unit/src/org/openide/filesystems/FileUtilTestHidden.java --- openide/fs/test/unit/src/org/openide/filesystems/FileUtilTestHidden.java Base (1.5) +++ openide/fs/test/unit/src/org/openide/filesystems/FileUtilTestHidden.java Locally Modified (Based On 1.5) @@ -43,9 +43,11 @@ import java.io.File; +import java.io.IOException; import java.net.URL; import java.util.List; import java.util.ArrayList; +import org.openide.util.Exceptions; import org.openide.util.Utilities; public class FileUtilTestHidden extends TestBaseHid { @@ -77,6 +79,40 @@ super(name); } + private static class TestListener extends FileChangeAdapter { + boolean wasCalled = false; + public void fileFolderCreated(FileEvent fe) { + wasCalled = true; + } + } + + public void testRunAtomicAction() throws Exception { + if (this.testedFS.isReadOnly()) return; + + final FileSystem defSystem = Repository.getDefault().getDefaultFileSystem(); + final TestListener l = new TestListener(); + try { + defSystem.addFileChangeListener(l); + testedFS.addFileChangeListener(l); + assertFalse(l.wasCalled); + FileUtil.runAtomicAction(new FileSystem.AtomicAction() { + public void run() throws IOException { + assertFalse(l.wasCalled); + assertNull(defSystem.getRoot().getFileObject(getName())); + assertNotNull(FileUtil.createFolder(defSystem.getRoot(), getName())); + assertNull(testedFS.getRoot().getFileObject(getName())); + assertNotNull(FileUtil.createFolder(testedFS.getRoot(), getName())); + assertFalse(l.wasCalled); + } + }); + assertTrue(l.wasCalled); + } finally { + defSystem.removeFileChangeListener(l); + testedFS.removeFileChangeListener(l); + } + } + + public void testCreateFolder () throws Exception { if (this.testedFS instanceof JarFileSystem) return;