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

(-)versioning/apichanges.xml (+15 lines)
Lines 111-116 Link Here
111
        
111
        
112
        <change>
112
        <change>
113
            <api name="versioning_spi"/>
113
            <api name="versioning_spi"/>
114
            <summary>beforeCopy(), doCopy() and afterCopy() methods added to VCSInterceptor</summary>
115
            <version major="1" minor="18"/>
116
            <date day="27" month="8" year="2010"/>
117
            <author login="tstupka"/>
118
            <compatibility addition="yes"/>
119
            <description>
120
                <code>VCSInterceptor.beforeCopy</code>, <code>VCSInterceptor.doCopy</code>,
121
                and <code>VCSInterceptor.afterCopy</code> allow a version control system
122
                to better control a copy operation on a file.
123
            </description>
124
            <class package="org.netbeans.modules.versioning.spi" name="VCSInterceptor"/>
125
            <issue number="189921"/>
126
        </change>
127
        <change>
128
            <api name="versioning_spi"/>
114
            <summary>refreshRecursively() method added to VCSInterceptor</summary>
129
            <summary>refreshRecursively() method added to VCSInterceptor</summary>
115
            <version major="1" minor="17"/>
130
            <version major="1" minor="17"/>
116
            <date day="19" month="4" year="2010"/>
131
            <date day="19" month="4" year="2010"/>
(-)versioning/src/org/netbeans/modules/versioning/FilesystemInterceptor.java (-12 / +71 lines)
Lines 302-311 Link Here
302
302
303
    private IOHandler getMoveHandlerIntern(File from, File to) {
303
    private IOHandler getMoveHandlerIntern(File from, File to) {
304
        DelegatingInterceptor dic = getInterceptor(from, to, "beforeMove", "doMove"); // NOI18N
304
        DelegatingInterceptor dic = getInterceptor(from, to, "beforeMove", "doMove"); // NOI18N
305
        return dic.beforeMove() ? dic : null;
305
        return dic.beforeMove() ? dic.getMoveHandler() : null;
306
    }
306
    }
307
307
308
    @Override
308
    @Override
309
    public void moveSuccess(FileObject from, File to) {
310
        getInterceptor(FileUtil.toFile(from), to, "afterMove").afterMove();
311
    }
312
313
    @Override
309
    public void fileRenamed(FileRenameEvent fe) {
314
    public void fileRenamed(FileRenameEvent fe) {
310
        LOG.log(Level.FINE, "fileRenamed {0}", fe.getFile());
315
        LOG.log(Level.FINE, "fileRenamed {0}", fe.getFile());
311
        removeFromDeletedFiles(fe.getFile());
316
        removeFromDeletedFiles(fe.getFile());
Lines 318-323 Link Here
318
        // not interested
323
        // not interested
319
    }
324
    }
320
325
326
    // ==================================================================================================
327
    // COPY
328
    // ==================================================================================================
329
330
    @Override
331
    public IOHandler getCopyHandler(File from, File to) {
332
        LOG.log(Level.FINE, "getCopyHandler {0}, {1}", new Object[] {from, to});
333
        return getCopyHandlerIntern(from, to);
334
    }
335
336
    private IOHandler getCopyHandlerIntern(File from, File to) {
337
        DelegatingInterceptor dic = getInterceptor(from, to, "beforeCopy", "doCopy"); // NOI18N
338
        return dic.beforeCopy() ? dic.getCopyHandler() : null;
339
    }
340
341
    @Override
342
    public void beforeCopy(FileObject from, File to) { }
343
344
    @Override
345
    public void copySuccess(FileObject from, File to) {
346
        getInterceptor(FileUtil.toFile(from), to, "afterCopy").afterCopy();
347
    }
348
349
    @Override
350
    public void copyFailure(FileObject from, File to) { }
351
321
    /**
352
    /**
322
     * There is a contract that says that when a file is locked, it is expected to be changed. This is what openide/text
353
     * There is a contract that says that when a file is locked, it is expected to be changed. This is what openide/text
323
     * does when it creates a Document. A versioning system is expected to make the file r/w.
354
     * does when it creates a Document. A versioning system is expected to make the file r/w.
Lines 407-413 Link Here
407
        public void beforeEdit() { }
438
        public void beforeEdit() { }
408
        public void afterChange() {  }
439
        public void afterChange() {  }
409
        public void afterMove() {  }
440
        public void afterMove() {  }
410
        public void handle() throws IOException {  }
411
        public boolean delete(File file) {  throw new UnsupportedOperationException();  }
441
        public boolean delete(File file) {  throw new UnsupportedOperationException();  }
412
    };
442
    };
413
443
Lines 418-424 Link Here
418
     */
448
     */
419
    private final Set<File> deletedFiles = new HashSet<File>(5);
449
    private final Set<File> deletedFiles = new HashSet<File>(5);
420
450
421
    private class DelegatingInterceptor implements IOHandler, DeleteHandler {
451
    private class DelegatingInterceptor implements DeleteHandler {
422
452
423
        final Collection<VCSInterceptor> interceptors;
453
        final Collection<VCSInterceptor> interceptors;
424
        final VCSInterceptor  interceptor;
454
        final VCSInterceptor  interceptor;
Lines 426-431 Link Here
426
        final File            file;
456
        final File            file;
427
        final File            to;
457
        final File            to;
428
        private final boolean isDirectory;
458
        private final boolean isDirectory;
459
        private IOHandler moveHandler;
460
        private IOHandler copyHandler;
429
461
430
        private DelegatingInterceptor() {
462
        private DelegatingInterceptor() {
431
            this((VCSInterceptor) null, null, null, null, false);
463
            this((VCSInterceptor) null, null, null, null, false);
Lines 488-493 Link Here
488
            interceptor.afterMove(file, to);
520
            interceptor.afterMove(file, to);
489
        }
521
        }
490
522
523
        public boolean beforeCopy() {
524
            lhInterceptor.beforeCopy(file, to);
525
            return interceptor.beforeCopy(file, to);
526
        }
527
528
        public void doCopy() throws IOException {
529
            lhInterceptor.doCopy(file, to);
530
            interceptor.doCopy(file, to);
531
        }
532
533
        public void afterCopy() {
534
            lhInterceptor.afterCopy(file, to);
535
            interceptor.afterCopy(file, to);
536
        }
537
491
        public boolean beforeCreate() {
538
        public boolean beforeCreate() {
492
            lhInterceptor.beforeCreate(file, isDirectory);
539
            lhInterceptor.beforeCreate(file, isDirectory);
493
            return interceptor.beforeCreate(file, isDirectory);
540
            return interceptor.beforeCreate(file, isDirectory);
Lines 518-535 Link Here
518
            interceptor.beforeEdit(file);
565
            interceptor.beforeEdit(file);
519
        }
566
        }
520
567
521
        /**
568
        private IOHandler getMoveHandler() {
522
         * We are doing MOVE here, inspite of the generic name of the method.
569
            if(moveHandler == null) {
523
         *
570
                moveHandler = new IOHandler() {
524
         * @throws IOException
571
                    @Override
525
         */
526
        public void handle() throws IOException {
572
        public void handle() throws IOException {
527
            lhInterceptor.doMove(file, to);
573
                        doMove();
528
            interceptor.doMove(file, to);
529
            lhInterceptor.afterMove(file, to);
530
            interceptor.afterMove(file, to);
531
        }
574
        }
575
                };
576
            }
577
            return moveHandler;
578
        }
532
579
580
        private IOHandler getCopyHandler() {
581
            if(copyHandler == null) {
582
                copyHandler = new IOHandler() {
583
                    @Override
584
                    public void handle() throws IOException {
585
                        doCopy();
586
                    }
587
                };
588
            }
589
            return copyHandler;
590
        }
591
533
        /**
592
        /**
534
         * This must act EXACTLY like java.io.File.delete(). This means:
593
         * This must act EXACTLY like java.io.File.delete(). This means:
535
594
(-)versioning/src/org/netbeans/modules/versioning/spi/VCSInterceptor.java (+39 lines)
Lines 162-167 Link Here
162
    }
162
    }
163
    
163
    
164
    // ==================================================================================================
164
    // ==================================================================================================
165
    // COPY
166
    // ==================================================================================================
167
168
    /**
169
     * Notifies the interceptor that the file or folder is about to be copied. The interceptor MUST NOT copy
170
     * the file here.
171
     *
172
     * @param from the file or folder to be copied
173
     * @param to destination of the file being copied
174
     * @return true if this interceptor wants to handle this operation (doCopy will be called), false otherwise
175
     * @since 1.18
176
     */
177
    public boolean beforeCopy(File from, File to) {
178
        return false;
179
    }
180
181
    /**
182
     * Called if beforeCopy() returns true and delegates the copy operation to this interceptor.
183
     *
184
     * @param from the file or folder to be copied
185
     * @param to destination of the file being copied
186
     * @throws IOException if the copy operation failed
187
     * @since 1.18
188
     */
189
    public void doCopy(File from, File to) throws IOException {
190
    }
191
192
    /**
193
     * Called after a file or folder has been copied. In case the file was copied outside IDE, this method is not called
194
     * and only afterCreate() is called instead.
195
     *
196
     * @param from original location of the file
197
     * @param to current location of the file
198
     * @since 1.18
199
     */
200
    public void afterCopy(File from, File to) {
201
    }
202
    
203
    // ==================================================================================================
165
    // CREATE
204
    // CREATE
166
    // ==================================================================================================
205
    // ==================================================================================================
167
206
(-)versioning/test/unit/src/org/netbeans/modules/versioning/FSInterceptorTest.java (-1 / +58 lines)
Lines 59-64 Link Here
59
import org.openide.filesystems.FileObject;
59
import org.openide.filesystems.FileObject;
60
import org.openide.filesystems.FileRenameEvent;
60
import org.openide.filesystems.FileRenameEvent;
61
import org.openide.filesystems.FileUtil;
61
import org.openide.filesystems.FileUtil;
62
import org.openide.util.Exceptions;
62
63
63
/**
64
/**
64
 *
65
 *
Lines 224-230 Link Here
224
                }
225
                }
225
            }
226
            }
226
        };
227
        };
227
        w.test(new String[] {"doMove", "afterMove"});
228
        w.test(new String[] {"beforeMove", "doMove"});
228
229
229
        // afterMove
230
        // afterMove
230
        w = new W() {
231
        w = new W() {
Lines 232-239 Link Here
232
                fi.fileRenamed(new FileRenameEvent(FileUtil.toFileObject(wFile), "wFile", null));
233
                fi.fileRenamed(new FileRenameEvent(FileUtil.toFileObject(wFile), "wFile", null));
233
            }
234
            }
234
        };
235
        };
236
        w.test(new String[] {"afterMove"});
237
        w = new W() {
238
            void callInterceptorMethod(FilesystemInterceptor fi) {
239
                fi.moveSuccess(FileUtil.toFileObject(wFile), wFile);
240
            }
241
        };
242
        w.test(new String[] {"afterMove"});
243
244
        // beforeCopy
245
        w = new W() {
246
            void callInterceptorMethod(FilesystemInterceptor fi) {
247
                try {
248
                    fi.getCopyHandler(wFile, wFile).handle();
249
                } catch (IOException ex) {
250
                    throw new IllegalStateException(ex);
251
                }
252
            }
253
        };
235
        w.test();
254
        w.test();
236
255
256
        // doCopy
257
        w = new W() {
258
            void callInterceptorMethod(FilesystemInterceptor fi) {
259
                try {
260
                    fi.getCopyHandler(wFile, wFile).handle();
261
                } catch (IOException ex) {
262
                    throw new IllegalStateException(ex);
263
                }
264
            }
265
        };
266
        w.test(new String[] {"doCopy", "beforeCopy"});
267
268
        // afterCopy
269
        w = new W() {
270
            void callInterceptorMethod(FilesystemInterceptor fi) {
271
                fi.copySuccess(FileUtil.toFileObject(wFile), wFile);
272
            }
273
        };
274
        w.test(new String[] {"afterCopy"});
275
237
        // fileLocked
276
        // fileLocked
238
        w = new W() {
277
        w = new W() {
239
            void callInterceptorMethod(FilesystemInterceptor fi) {
278
            void callInterceptorMethod(FilesystemInterceptor fi) {
Lines 354-359 Link Here
354
        }
393
        }
355
394
356
        @Override
395
        @Override
396
        public void afterCopy(File from, File to) {
397
            storeMethodName();
398
            super.afterCopy(from, to);
399
        }
400
401
        @Override
357
        public void afterMove(File from, File to) {
402
        public void afterMove(File from, File to) {
358
            storeMethodName();
403
            storeMethodName();
359
            super.afterMove(from, to);
404
            super.afterMove(from, to);
Lines 384-389 Link Here
384
        }
429
        }
385
430
386
        @Override
431
        @Override
432
        public boolean beforeCopy(File from, File to) {
433
            storeMethodName();
434
            return true;
435
        }
436
437
        @Override
387
        public boolean beforeMove(File from, File to) {
438
        public boolean beforeMove(File from, File to) {
388
            storeMethodName();
439
            storeMethodName();
389
            return true;
440
            return true;
Lines 402-407 Link Here
402
        }
453
        }
403
454
404
        @Override
455
        @Override
456
        public void doCopy(File from, File to) throws IOException {
457
            storeMethodName();
458
            super.doMove(from, to);
459
        }
460
461
        @Override
405
        public void doMove(File from, File to) throws IOException {
462
        public void doMove(File from, File to) throws IOException {
406
            storeMethodName();
463
            storeMethodName();
407
            super.doMove(from, to);
464
            super.doMove(from, to);
(-)versioning/test/unit/src/org/netbeans/modules/versioning/spi/VCSInterceptorTest.java (+16 lines)
Lines 196-201 Link Here
196
        assertTrue(inteceptor.getDeletedFiles().contains(file2));
196
        assertTrue(inteceptor.getDeletedFiles().contains(file2));
197
    }
197
    }
198
198
199
    public void testFileCopied() throws IOException {
200
        File f = new File(dataRootDir, "workdir/root-test-versioned");
201
        FileObject fo = FileUtil.toFileObject(f);
202
        fo = fo.createData("copyme.txt");
203
        File from = FileUtil.toFile(fo);
204
205
        FileObject fto = fo.copy(fo.getParent(), "copymeto", "txt");
206
207
        assertTrue(inteceptor.getBeforeCopyFiles().contains(from));
208
        assertTrue(inteceptor.getBeforeCopyFiles().contains(FileUtil.toFile(fo)));
209
        assertTrue(inteceptor.getDoCopyFiles().contains(from));
210
        assertTrue(inteceptor.getDoCopyFiles().contains(FileUtil.toFile(fo)));
211
        assertTrue(inteceptor.getAfterCopyFiles().contains(from));
212
        assertTrue(inteceptor.getAfterCopyFiles().contains(FileUtil.toFile(fo)));
213
    }
214
199
    private void deleteRecursively(File f) {
215
    private void deleteRecursively(File f) {
200
        if(f.isFile()) {
216
        if(f.isFile()) {
201
            f.delete();
217
            f.delete();
(-)versioning/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSInterceptor.java (+33 lines)
Lines 48-53 Link Here
48
import java.io.File;
48
import java.io.File;
49
import java.io.IOException;
49
import java.io.IOException;
50
import java.util.*;
50
import java.util.*;
51
import org.netbeans.modules.versioning.util.FileUtils;
51
52
52
/**
53
/**
53
 * @author Maros Sandor
54
 * @author Maros Sandor
Lines 62-67 Link Here
62
    private final List<File>    deletedFiles = new ArrayList<File>();
63
    private final List<File>    deletedFiles = new ArrayList<File>();
63
    private final List<File>    beforeMoveFiles = new ArrayList<File>();
64
    private final List<File>    beforeMoveFiles = new ArrayList<File>();
64
    private final List<File>    afterMoveFiles = new ArrayList<File>();
65
    private final List<File>    afterMoveFiles = new ArrayList<File>();
66
    private final List<File>    beforeCopyFiles = new ArrayList<File>();
67
    private final List<File>    afterCopyFiles = new ArrayList<File>();
68
    private final List<File>    doCopyFiles = new ArrayList<File>();
65
    private final List<File>    beforeEditFiles = new ArrayList<File>();
69
    private final List<File>    beforeEditFiles = new ArrayList<File>();
66
    private final List<File>    beforeChangeFiles = new ArrayList<File>();
70
    private final List<File>    beforeChangeFiles = new ArrayList<File>();
67
    private final List<File>    afterChangeFiles = new ArrayList<File>();
71
    private final List<File>    afterChangeFiles = new ArrayList<File>();
Lines 143-148 Link Here
143
        afterMoveFiles.add(from);
147
        afterMoveFiles.add(from);
144
    }
148
    }
145
149
150
    public boolean beforeCopy(File from, File to) {
151
        beforeCopyFiles.add(from);
152
        beforeCopyFiles.add(to);
153
        return true;
154
    }
155
156
    public void doCopy(File from, File to) throws IOException {
157
        doCopyFiles.add(from);
158
        doCopyFiles.add(to);
159
        FileUtils.copyFile(from, to);
160
    }
161
162
    public void afterCopy(File from, File to) {
163
        afterCopyFiles.add(from);
164
        afterCopyFiles.add(to);
165
    }
166
146
    public void beforeEdit(File file) {
167
    public void beforeEdit(File file) {
147
        beforeEditFiles.add(file);
168
        beforeEditFiles.add(file);
148
    }
169
    }
Lines 183-188 Link Here
183
        return afterMoveFiles;
204
        return afterMoveFiles;
184
    }
205
    }
185
206
207
    public List<File> getBeforeCopyFiles() {
208
        return beforeCopyFiles;
209
    }
210
211
    public List<File> getDoCopyFiles() {
212
        return doCopyFiles;
213
    }
214
215
    public List<File> getAfterCopyFiles() {
216
        return afterCopyFiles;
217
    }
218
186
    public List<File> getBeforeEditFiles() {
219
    public List<File> getBeforeEditFiles() {
187
        return beforeEditFiles;
220
        return beforeEditFiles;
188
    }
221
    }

Return to bug 189921