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 189921
Collapse All | Expand All

(-)masterfs/apichanges.xml (+13 lines)
Lines 49-54 Link Here
49
        <apidef name="masterfs">MasterFileSystem API</apidef>
49
        <apidef name="masterfs">MasterFileSystem API</apidef>
50
    </apidefs>
50
    </apidefs>
51
    <changes>
51
    <changes>
52
        <change id="copy-handler">
53
            <api name="masterfs"/>
54
            <summary>Delegate FileObject.copy() to ProvidedExtensions</summary>
55
            <version major="2" minor="28"/>
56
            <date day="27" month="8" year="2010"/>
57
            <author login="tstupka"/>
58
            <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no" modification="no"/>
59
            <description>
60
                ProvidedExtensions.getCopyHandler() allows to delegate a copy operation.
61
            </description>
62
            <class package="org.netbeans.modules.masterfs.providers" name="ProvidedExtensions"/>
63
            <issue number="189921"/>
64
        </change>
52
        <change id="event-order">
65
        <change id="event-order">
53
            <api name="masterfs"/>
66
            <api name="masterfs"/>
54
            <summary>Guaranteed event order when deleting and creating files and new calls in ProvidedExtensions</summary>
67
            <summary>Guaranteed event order when deleting and creating files and new calls in ProvidedExtensions</summary>
(-)masterfs/src/org/netbeans/modules/masterfs/ProvidedExtensionsProxy.java (+59 lines)
Lines 72-77 Link Here
72
        this.annotationProviders = annotationProviders;
72
        this.annotationProviders = annotationProviders;
73
    }
73
    }
74
    
74
    
75
    @Override
76
    public IOHandler getCopyHandler(File from, File to) {
77
        IOHandler retValue = null;
78
        for (Iterator it = annotationProviders.iterator(); it.hasNext() && retValue == null;) {
79
            AnnotationProvider provider = (AnnotationProvider) it.next();
80
            final InterceptionListener iListener = (provider != null) ?  provider.getInterceptionListener() : null;
81
            if (iListener instanceof ProvidedExtensions) {
82
                ProvidedExtensions.IOHandler delgate = ((ProvidedExtensions)iListener).getCopyHandler(from, to);
83
                retValue = delgate != null ? new DelegatingIOHandler(delgate) : null;
84
            }
85
        }
86
        return retValue;
87
    }
88
75
    public ProvidedExtensions.DeleteHandler getDeleteHandler(final File f) {
89
    public ProvidedExtensions.DeleteHandler getDeleteHandler(final File f) {
76
        ProvidedExtensions.DeleteHandler retValue = null;
90
        ProvidedExtensions.DeleteHandler retValue = null;
77
        for (Iterator it = annotationProviders.iterator(); it.hasNext() && retValue == null;) {
91
        for (Iterator it = annotationProviders.iterator(); it.hasNext() && retValue == null;) {
Lines 386-391 Link Here
386
        }
400
        }
387
   }
401
   }
388
    
402
    
403
    @Override
404
    public void beforeCopy(final FileObject from, final File to) {
405
        for (Iterator it = annotationProviders.iterator(); it.hasNext();) {
406
            AnnotationProvider provider = (AnnotationProvider) it.next();
407
            final InterceptionListener iListener = (provider != null) ?  provider.getInterceptionListener() : null;
408
            if (iListener instanceof ProvidedExtensions) {
409
                runCheckCode(new Runnable() {
410
                    public void run() {
411
                        ((ProvidedExtensions)iListener).beforeCopy(from, to);
412
                    }
413
                });
414
            }
415
        }
416
    }
417
418
    @Override
419
    public void copySuccess(final FileObject from, final File to) {
420
        for (Iterator it = annotationProviders.iterator(); it.hasNext();) {
421
            AnnotationProvider provider = (AnnotationProvider) it.next();
422
            final InterceptionListener iListener = (provider != null) ?  provider.getInterceptionListener() : null;
423
            if (iListener instanceof ProvidedExtensions) {
424
                runCheckCode(new Runnable() {
425
                    public void run() {
426
                        ((ProvidedExtensions)iListener).copySuccess(from, to);
427
                    }
428
                });
429
            }
430
        }
431
    }
432
433
    @Override
434
    public void copyFailure(final FileObject from, final File to) {
435
        for (Iterator it = annotationProviders.iterator(); it.hasNext();) {
436
            AnnotationProvider provider = (AnnotationProvider) it.next();
437
            final InterceptionListener iListener = (provider != null) ?  provider.getInterceptionListener() : null;
438
            if (iListener instanceof ProvidedExtensions) {
439
                runCheckCode(new Runnable() {
440
                    public void run() {
441
                        ((ProvidedExtensions)iListener).copyFailure(from, to);
442
                    }
443
                });
444
            }
445
        }
446
   }
447
    
389
    public static void checkReentrancy() {
448
    public static void checkReentrancy() {
390
        if (reentrantCheck.get() != null) {            
449
        if (reentrantCheck.get() != null) {            
391
            Logger.getLogger("org.netbeans.modules.masterfs.ProvidedExtensionsProxy").log(Level.INFO,"Unexpected reentrant call", new Throwable());//NOI18N
450
            Logger.getLogger("org.netbeans.modules.masterfs.ProvidedExtensionsProxy").log(Level.INFO,"Unexpected reentrant call", new Throwable());//NOI18N
(-)masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/BaseFileObj.java (-8 / +47 lines)
Lines 214-223 Link Here
214
    }
214
    }
215
     
215
     
216
    @Override
216
    @Override
217
    public FileObject copy(FileObject target, String name, String ext) throws IOException {
218
        ProvidedExtensions extensions = getProvidedExtensions();
219
220
        File to = getToFile(target, name, ext);
221
222
        extensions.beforeCopy(target, to);
223
        FileObject result = null;
224
        try {
225
            final IOHandler copyHandler = extensions.getCopyHandler(getFileName().getFile(), to);
226
            if (copyHandler != null) {
227
                if (target instanceof FolderObj) {
228
                    result = handleMoveCopy((FolderObj)target, name, ext, copyHandler);
229
                } else {
230
                    copyHandler.handle();
231
                    refresh(true);
232
                    //perfromance bottleneck to call refresh on folder
233
                    //(especially for many files to be copied)
234
                    target.refresh(true); // XXX ?
235
                    result = target.getFileObject(name, ext); // XXX ?
236
                    assert result != null : "Cannot find " + target + " with " + name + "." + ext;
237
                }
238
                FileUtil.copyAttributes(this, result);
239
            } else {
240
                result = super.copy(target, name, ext);
241
            }
242
        } catch (IOException ioe) {
243
            extensions.copyFailure(this, to);
244
            throw ioe;
245
        }
246
        extensions.copySuccess(this, to);
247
        return result;
248
    }
249
250
    @Override
217
    public final FileObject move(FileLock lock, FileObject target, String name, String ext) throws IOException {
251
    public final FileObject move(FileLock lock, FileObject target, String name, String ext) throws IOException {
218
        ProvidedExtensions extensions = getProvidedExtensions();
252
        ProvidedExtensions extensions = getProvidedExtensions();
219
        File to = (target instanceof FolderObj) ? new File(((BaseFileObj) target).getFileName().getFile(), FileInfo.composeName(name, ext)) :
253
        File to = getToFile(target, name, ext);
220
            new File(FileUtil.toFile(target), FileInfo.composeName(name, ext));
221
254
222
        extensions.beforeMove(this, to);
255
        extensions.beforeMove(this, to);
223
        FileObject result = null;
256
        FileObject result = null;
Lines 253-260 Link Here
253
    }
286
    }
254
    
287
    
255
    public BaseFileObj move(FileLock lock, FolderObj target, String name, String ext, ProvidedExtensions.IOHandler moveHandler) throws IOException {
288
    public BaseFileObj move(FileLock lock, FolderObj target, String name, String ext, ProvidedExtensions.IOHandler moveHandler) throws IOException {
256
        moveHandler.handle();
289
        return handleMoveCopy(target, name, ext, moveHandler);
257
        String nameExt = FileInfo.composeName(name,ext);
290
    }
291
292
    private File getToFile(FileObject target, String name, String ext) {
293
        File to = (target instanceof FolderObj) ? new File(((BaseFileObj) target).getFileName().getFile(), FileInfo.composeName(name, ext)) : new File(FileUtil.toFile(target), FileInfo.composeName(name, ext));
294
        return to;
295
    }
296
297
    private BaseFileObj handleMoveCopy(FolderObj target, String name, String ext, IOHandler handler) throws IOException {
298
        handler.handle();
299
        String nameExt = FileInfo.composeName(name, ext);
258
        target.getChildrenCache().getChild(nameExt, true);
300
        target.getChildrenCache().getChild(nameExt, true);
259
        //TODO: review
301
        //TODO: review
260
        BaseFileObj result = null;
302
        BaseFileObj result = null;
Lines 268-276 Link Here
268
                    result.fireFileFolderCreatedEvent(false);
310
                    result.fireFileFolderCreatedEvent(false);
269
                }
311
                }
270
                break;
312
                break;
271
            }
313
            } // is not yet ready. We wait max. 1000 ms.
272
            // #179109 - result is sometimes null, probably when moved file
273
            // is not yet ready. We wait max. 1000 ms.
274
            try {
314
            try {
275
                Thread.sleep(100);
315
                Thread.sleep(100);
276
            } catch (InterruptedException ex) {
316
            } catch (InterruptedException ex) {
Lines 288-294 Link Here
288
        return result;
328
        return result;
289
    }
329
    }
290
330
291
292
    void rename(final FileLock lock, final String name, final String ext, final ProvidedExtensions.IOHandler handler) throws IOException {
331
    void rename(final FileLock lock, final String name, final String ext, final ProvidedExtensions.IOHandler handler) throws IOException {
293
        if (!checkLock(lock)) {
332
        if (!checkLock(lock)) {
294
            FSException.io("EXC_InvalidLock", lock, getPath()); // NOI18N
333
            FSException.io("EXC_InvalidLock", lock, getPath()); // NOI18N
(-)masterfs/src/org/netbeans/modules/masterfs/providers/ProvidedExtensions.java (+45 lines)
Lines 67-74 Link Here
67
 * @author Radek Matous
67
 * @author Radek Matous
68
 */
68
 */
69
public class ProvidedExtensions implements InterceptionListener {
69
public class ProvidedExtensions implements InterceptionListener {
70
70
    /**
71
    /**
71
     * Return instance of {@link ProvidedExtensions.IOHandler}
72
     * Return instance of {@link ProvidedExtensions.IOHandler}
73
     * that is responsible for copying the file or null.
74
     *
75
     * Just the first non null instance of <code>IOHandler</code> is used by
76
     *  <code>MasterFileSystem</code>
77
     *
78
     * @param from file to be copied
79
     * @param to target to copy this file to
80
     * @return instance of {@link ProvidedExtensions.IOHandler}
81
     * that is responsible for copying the file or null
82
     */
83
    public ProvidedExtensions.IOHandler getCopyHandler(
84
            File from, File to) {
85
        return null;
86
    }
87
88
    /**
89
     * Return instance of {@link ProvidedExtensions.IOHandler}
72
     * that is responsible for moving the file or null.
90
     * that is responsible for moving the file or null.
73
     *
91
     *
74
     * Just the first non null instance of <code>IOHandler</code> is used by
92
     * Just the first non null instance of <code>IOHandler</code> is used by
Lines 170-175 Link Here
170
188
171
    /**
189
    /**
172
     * Called by <code>MasterFileSystem</code> before <code>FileObject</code>
190
     * Called by <code>MasterFileSystem</code> before <code>FileObject</code>
191
     * is copied
192
     * @param from FileObject to be moved
193
     * @param to File target to move this file to
194
     * @since 2.28
195
     */
196
    public void beforeCopy(FileObject from, File to) {}
197
198
    /**
199
     * Called by <code>MasterFileSystem</code> after <code>FileObject</code>
200
     * was successfully copied
201
     * @param from FileObject to be moved
202
     * @param to File target to move this file to
203
     * @since 2.28
204
     */
205
    public void copySuccess(FileObject from, File to) {}
206
207
    /**
208
     * Called by <code>MasterFileSystem</code> after a <code>FileObject</code>
209
     * copy failed
210
     * @param from FileObject to be moved
211
     * @param to File target to move this file to
212
     * @since 2.28
213
     */
214
    public void copyFailure(FileObject from, File to) {}
215
216
    /**
217
     * Called by <code>MasterFileSystem</code> before <code>FileObject</code>
173
     * is moved
218
     * is moved
174
     * @param from FileObject to be moved
219
     * @param from FileObject to be moved
175
     * @param to File target to move this file to
220
     * @param to File target to move this file to
(-)masterfs/test/unit/src/org/netbeans/modules/masterfs/providers/ProvidedExtensionsTest.java (+54 lines)
Lines 336-341 Link Here
336
        }
336
        }
337
    }
337
    }
338
338
339
    public void testCopy_BeforeSuccessFailure() throws IOException {
340
        FileObject fromFolder = FileUtil.toFileObject(getWorkDir()).createFolder("copyFrom");
341
        FileObject toFolder = FileUtil.toFileObject(getWorkDir()).createFolder("copyTo");
342
        assertNotNull(fromFolder);
343
        assertNotNull(toFolder);
344
        FileObject fromCopy = fromFolder.createData("aa");
345
        assertNotNull(fromCopy);
346
        iListener.clear();
347
348
        assertNotNull(iListener);
349
        assertEquals(0,iListener.beforeCopyCalls);
350
        assertEquals(0,iListener.copySuccessCalls);
351
        assertEquals(0,iListener.copyFailureCalls);
352
353
        // copy
354
        fromCopy.copy(toFolder, fromCopy.getName(), fromCopy.getExt());
355
        assertTrue(fromCopy.isValid());
356
        assertEquals(1,iListener.beforeCopyCalls);
357
        assertEquals(1,iListener.copySuccessCalls);
358
359
        iListener.clear();
360
        try {
361
            // success
362
            assertEquals(0,iListener.copySuccessCalls);
363
            assertEquals(0,iListener.copyFailureCalls);
364
365
            // move to itself => failure
366
            fromCopy.copy(toFolder, fromCopy.getName(), fromCopy.getExt());
367
            fail();
368
        } catch (IOException ex) {
369
            // failure
370
            assertEquals(0,iListener.copySuccessCalls);
371
            assertEquals(1,iListener.copyFailureCalls);
372
        }
373
    }
374
339
    public void testImplsRename2() throws IOException {
375
    public void testImplsRename2() throws IOException {
340
        final List events = new ArrayList();
376
        final List events = new ArrayList();
341
        FileObject fo = FileUtil.toFileObject(getWorkDir());
377
        FileObject fo = FileUtil.toFileObject(getWorkDir());
Lines 559-564 Link Here
559
        private int beforeMoveCalls;
595
        private int beforeMoveCalls;
560
        private int moveSuccessCalls;
596
        private int moveSuccessCalls;
561
        private int moveFailureCalls;
597
        private int moveFailureCalls;
598
        private int beforeCopyCalls;
599
        private int copySuccessCalls;
600
        private int copyFailureCalls;
562
        
601
        
563
        private static  boolean implsMoveRetVal = true;
602
        private static  boolean implsMoveRetVal = true;
564
        private static boolean implsRenameRetVal = true;
603
        private static boolean implsRenameRetVal = true;
Lines 600-605 Link Here
600
            beforeMoveCalls = 0;
639
            beforeMoveCalls = 0;
601
            moveSuccessCalls = 0;
640
            moveSuccessCalls = 0;
602
            moveFailureCalls = 0;
641
            moveFailureCalls = 0;
642
            beforeCopyCalls = 0;
643
            copySuccessCalls = 0;
644
            copyFailureCalls = 0;
603
            implsFileLockCalls = 0;
645
            implsFileLockCalls = 0;
604
            implsCanWriteCalls = 0;
646
            implsCanWriteCalls = 0;
605
        }
647
        }
Lines 659-664 Link Here
659
            moveFailureCalls++;
701
            moveFailureCalls++;
660
        }
702
        }
661
703
704
        public void beforeCopy(FileObject fo, File to) {
705
            beforeCopyCalls++;
706
        }
707
708
        public void copySuccess(FileObject fo, File to) {
709
            copySuccessCalls++;
710
        }
711
712
        public void copyFailure(FileObject fo, File to) {
713
            copyFailureCalls++;
714
        }
715
662
        public static void nextRefreshCall(File forDir, long retValue, File... toAdd) {
716
        public static void nextRefreshCall(File forDir, long retValue, File... toAdd) {
663
            refreshCallForDir = forDir;
717
            refreshCallForDir = forDir;
664
            refreshCallRetValue = retValue;
718
            refreshCallRetValue = retValue;

Return to bug 189921