This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 247915
Collapse All | Expand All

(-)a/openide.filesystems/apichanges.xml (+16 lines)
Lines 49-54 Link Here
49
        <apidef name="filesystems">Filesystems API</apidef>
49
        <apidef name="filesystems">Filesystems API</apidef>
50
    </apidefs>
50
    </apidefs>
51
    <changes>
51
    <changes>
52
        <change id="FileLock.closeable">
53
            <api name="filesystems"/>
54
            <summary>FileLock implements AutoCloseable</summary>
55
            <version major="9" minor="2"/>
56
            <date year="2014" month="10" day="21"/>
57
            <author login="sdedic"/>
58
            <compatibility addition="yes" deletion="no" deprecation="no" source="compatible" binary="compatible"/>
59
            <description>
60
                <p>
61
                    <a href="@TOP@org/openide/filesystems/FileLock.html">FileLock</a>
62
                    implements AutoCloseable to work well in try-with-resources constructs.
63
                </p>
64
            </description>
65
            <class package="org.openide.filesystems" name="FileLock"/>
66
            <issue number="247915"/>
67
        </change>
52
        <change id="FileSystemStatus.icons2">
68
        <change id="FileSystemStatus.icons2">
53
            <api name="filesystems"/>
69
            <api name="filesystems"/>
54
            <summary>FileSystem.Status API removed</summary>
70
            <summary>FileSystem.Status API removed</summary>
(-)a/openide.filesystems/manifest.mf (-1 / +1 lines)
Lines 2-7 Link Here
2
OpenIDE-Module: org.openide.filesystems
2
OpenIDE-Module: org.openide.filesystems
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
5
OpenIDE-Module-Specification-Version: 9.1
5
OpenIDE-Module-Specification-Version: 9.2
6
6
7
7
(-)a/openide.filesystems/nbproject/project.properties (-1 / +1 lines)
Lines 41-47 Link Here
41
# made subject to such option by the copyright holder.
41
# made subject to such option by the copyright holder.
42
42
43
javac.compilerargs=-Xlint -Xlint:-serial
43
javac.compilerargs=-Xlint -Xlint:-serial
44
javac.source=1.6
44
javac.source=1.7
45
module.jar.dir=core
45
module.jar.dir=core
46
javadoc.main.page=org/openide/filesystems/doc-files/api.html
46
javadoc.main.page=org/openide/filesystems/doc-files/api.html
47
javadoc.arch=${basedir}/arch.xml
47
javadoc.arch=${basedir}/arch.xml
(-)a/openide.filesystems/src/org/openide/filesystems/FileLock.java (-3 / +14 lines)
Lines 55-68 Link Here
55
* Normally this is sufficient protection. If you really need an atomic read, you may
55
* Normally this is sufficient protection. If you really need an atomic read, you may
56
* simply lock the file, perform the read, and unlock it when done. The file will still
56
* simply lock the file, perform the read, and unlock it when done. The file will still
57
* be protected against writes, although the read operation did not request a lock.
57
* be protected against writes, although the read operation did not request a lock.
58
*
58
* <p/>
59
* The {@code FileLock} implements {@link AutoCloseable}, so it can be created within
60
* try-with-resources resource clause and the lock will be released at the end of the try block.
61
* 
59
* @see FileObject
62
* @see FileObject
60
*
63
* @since 9.2 implements {@code AutoCloseable} interface.
61
* @author Petr Hamernik, Jaroslav Tulach, Ian Formanek
64
* @author Petr Hamernik, Jaroslav Tulach, Ian Formanek
62
* @version 0.16, Jun 5, 1997
65
* @version 0.16, Jun 5, 1997
63
*
66
*
64
*/
67
*/
65
public class FileLock { // XXX JDK 7: implements AutoCloseable
68
public class FileLock implements AutoCloseable {
66
    // ========================= NONE file lock =====================================
69
    // ========================= NONE file lock =====================================
67
70
68
    /** Constant that can be used in filesystems that do not support locking.
71
    /** Constant that can be used in filesystems that do not support locking.
Lines 109-114 Link Here
109
        locked = false;
112
        locked = false;
110
    }
113
    }
111
114
115
    /**
116
     * Releases the lock. Equivalent to {@link #releaseLock} call.
117
     */
118
    @Override
119
    public void close() {
120
        releaseLock();
121
    }
122
    
112
    //  End of the original part
123
    //  End of the original part
113
    // ============================================================================
124
    // ============================================================================
114
125
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/FileObjectTestHid.java (-16 / +9 lines)
Lines 283-305 Link Here
283
        FileObject fold = getTestFolder1(root);
283
        FileObject fold = getTestFolder1(root);
284
        FileObject fo1 = getTestFile1(fold);
284
        FileObject fo1 = getTestFile1(fold);
285
285
286
        FileLock lock;
286
        // use the new AutoCloseable feature
287
        try {
287
        try (FileLock lock = fo1.lock()) {
288
            lock = fo1.lock();
288
            fo1.rename(lock, "Aaa", "java");
289
            assertEquals("Name is Aaa", "Aaa", fo1.getName());
290
            fo1.rename(lock, "bbb", "java");
291
            assertEquals("Name is bbb", "bbb", fo1.getName());
292
            fo1.rename(lock, "aaa", "java");
293
            assertEquals("Name is lowercase", "aaa", fo1.getName());
289
        } catch (IOException iex) {
294
        } catch (IOException iex) {
290
            fsAssert(
295
            fsAssert(
291
                "expected copy will success on writable FS",
296
                "expected copy will success on writable FS",
292
                fs.isReadOnly() || fo1.isReadOnly()
297
                fs.isReadOnly() || fo1.isReadOnly()
293
            );
298
            );
294
            return;
295
        }
299
        }
296
        fo1.rename(lock, "Aaa", "java");
297
        assertEquals("Name is Aaa", "Aaa", fo1.getName());
298
        fo1.rename(lock, "bbb", "java");
299
        assertEquals("Name is bbb", "bbb", fo1.getName());
300
        fo1.rename(lock, "aaa", "java");
301
        assertEquals("Name is lowercase", "aaa", fo1.getName());
302
        lock.releaseLock();
303
    }
300
    }
304
    
301
    
305
    /** Test of copy method, of class org.openide.filesystems.FileObject. */
302
    /** Test of copy method, of class org.openide.filesystems.FileObject. */
Lines 540-555 Link Here
540
        FileObject fold = getTestFolder1(root);
537
        FileObject fold = getTestFolder1(root);
541
        FileObject fo1 = getTestFile1(fold);
538
        FileObject fo1 = getTestFile1(fold);
542
        FileObject fo2 = getTestFile2(fold);
539
        FileObject fo2 = getTestFile2(fold);
543
        FileLock lock = null;
544
        
540
        
545
        try {
541
        try (FileLock lock = fo1.lock()) {
546
            lock = fo1.lock();
547
            fo1.move(lock, fold,fo2.getName(),fo2.getExt());
542
            fo1.move(lock, fold,fo2.getName(),fo2.getExt());
548
        } catch (IOException iex) {
543
        } catch (IOException iex) {
549
            /** Test passed*/
544
            /** Test passed*/
550
            return;
545
            return;
551
        } finally {
552
            if (lock != null) lock.releaseLock();            
553
        }
546
        }
554
        fsFail  ("move  should fire exception if file already exists");
547
        fsFail  ("move  should fire exception if file already exists");
555
    }
548
    }

Return to bug 247915