Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 146072 | Differences between
and this patch

Collapse All | Expand All

(-)java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/J2SEConfigurationProviderTest.java (-5 / +27 lines)
 Lines 212-234    Link Here 
212
    }
212
    }
213
213
214
    public void testInitialListening() throws Exception { // #84781
214
    public void testInitialListening() throws Exception { // #84781
215
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
215
        class Action implements Mutex.ExceptionAction<Void> {
216
            int stage = 0;
217
            Properties props;
218
            TestListener l;
219
            
216
            public Void run() throws Exception {
220
            public Void run() throws Exception {
217
                TestListener l = new TestListener();
221
                switch (stage++) {
222
                    case 0: initWrite(); break;
223
                    case 1: sndWrite(); break;
224
                    case 2: rest(); break;
225
                    default: fail(); break;
226
                }
227
                return null;
228
            }
229
            private void initWrite() throws Exception {
230
                l = new TestListener();
218
                pcp.addPropertyChangeListener(l);
231
                pcp.addPropertyChangeListener(l);
219
                Properties props = new Properties();
232
                props = new Properties();
220
                props.setProperty("$label", "X");
233
                props.setProperty("$label", "X");
221
                write(props, d, "nbproject/configs/x.properties");
234
                write(props, d, "nbproject/configs/x.properties");
235
            }
236
237
            private void sndWrite() throws Exception {
222
                props = new Properties();
238
                props = new Properties();
223
                props.setProperty("config", "x");
239
                props.setProperty("config", "x");
224
                write(props, d, "nbproject/private/config.properties");
240
                write(props, d, "nbproject/private/config.properties");
241
            }
242
243
            private void rest() throws Exception {
225
                assertEquals(new HashSet<String>(Arrays.asList(ProjectConfigurationProvider.PROP_CONFIGURATIONS, ProjectConfigurationProvider.PROP_CONFIGURATION_ACTIVE)),
244
                assertEquals(new HashSet<String>(Arrays.asList(ProjectConfigurationProvider.PROP_CONFIGURATIONS, ProjectConfigurationProvider.PROP_CONFIGURATION_ACTIVE)),
226
                        l.events());
245
                        l.events());
227
                assertEquals(2, pcp.getConfigurations().size());
246
                assertEquals(2, pcp.getConfigurations().size());
228
                assertEquals("X", pcp.getActiveConfiguration().getDisplayName());
247
                assertEquals("X", pcp.getActiveConfiguration().getDisplayName());
229
                return null;
230
            }
248
            }
231
        });
249
        }
250
        Action action = new Action();
251
        ProjectManager.mutex().writeAccess(action);
252
        ProjectManager.mutex().writeAccess(action);
253
        ProjectManager.mutex().writeAccess(action);
232
    }
254
    }
233
255
234
    private void write(Properties p, FileObject d, String path) throws IOException {
256
    private void write(Properties p, FileObject d, String path) throws IOException {
(-)project.ant/src/org/netbeans/modules/project/ant/FileChangeSupport.java (-9 / +9 lines)
 Lines 158-164    Link Here 
158
            }
158
            }
159
        }
159
        }
160
160
161
        private void someChange(FileObject modified) {
161
        private void someChange(FileEvent orig, FileObject modified) {
162
            FileChangeSupportListener listener;
162
            FileChangeSupportListener listener;
163
            FileObject oldCurrent, nueCurrent;
163
            FileObject oldCurrent, nueCurrent;
164
            File oldCurrentF, nueCurrentF;
164
            File oldCurrentF, nueCurrentF;
 Lines 177-215    Link Here 
177
                nueCurrentF = currentF;
177
                nueCurrentF = currentF;
178
            }
178
            }
179
            if (modified != null && modified == nueCurrent) {
179
            if (modified != null && modified == nueCurrent) {
180
                FileChangeSupportEvent event = new FileChangeSupportEvent(DEFAULT, FileChangeSupportEvent.EVENT_MODIFIED, path);
180
                FileChangeSupportEvent event = new FileChangeSupportEvent(orig, DEFAULT, FileChangeSupportEvent.EVENT_MODIFIED, path);
181
                listener.fileModified(event);
181
                listener.fileModified(event);
182
            } else {
182
            } else {
183
                boolean oldWasCorrect = path.equals(oldCurrentF);
183
                boolean oldWasCorrect = path.equals(oldCurrentF);
184
                boolean nueIsCorrect = path.equals(nueCurrentF);
184
                boolean nueIsCorrect = path.equals(nueCurrentF);
185
                if (oldWasCorrect && !nueIsCorrect) {
185
                if (oldWasCorrect && !nueIsCorrect) {
186
                    FileChangeSupportEvent event = new FileChangeSupportEvent(DEFAULT, FileChangeSupportEvent.EVENT_DELETED, path);
186
                    FileChangeSupportEvent event = new FileChangeSupportEvent(orig, DEFAULT, FileChangeSupportEvent.EVENT_DELETED, path);
187
                    listener.fileDeleted(event);
187
                    listener.fileDeleted(event);
188
                } else if (nueIsCorrect && !oldWasCorrect) {
188
                } else if (nueIsCorrect && !oldWasCorrect) {
189
                    FileChangeSupportEvent event = new FileChangeSupportEvent(DEFAULT, FileChangeSupportEvent.EVENT_CREATED, path);
189
                    FileChangeSupportEvent event = new FileChangeSupportEvent(orig, DEFAULT, FileChangeSupportEvent.EVENT_CREATED, path);
190
                    listener.fileCreated(event);
190
                    listener.fileCreated(event);
191
                }
191
                }
192
            }
192
            }
193
        }
193
        }
194
194
195
        public void fileChanged(FileEvent fe) {
195
        public void fileChanged(FileEvent fe) {
196
            someChange(fe.getFile());
196
            someChange(fe, fe.getFile());
197
        }
197
        }
198
        
198
        
199
        public void fileDeleted(FileEvent fe) {
199
        public void fileDeleted(FileEvent fe) {
200
            someChange(null);
200
            someChange(fe, null);
201
        }
201
        }
202
202
203
        public void fileDataCreated(FileEvent fe) {
203
        public void fileDataCreated(FileEvent fe) {
204
            someChange(null);
204
            someChange(fe, null);
205
        }
205
        }
206
206
207
        public void fileFolderCreated(FileEvent fe) {
207
        public void fileFolderCreated(FileEvent fe) {
208
            someChange(null);
208
            someChange(fe, null);
209
        }
209
        }
210
210
211
        public void fileRenamed(FileRenameEvent fe) {
211
        public void fileRenamed(FileRenameEvent fe) {
212
            someChange(null);
212
            someChange(fe, null);
213
        }
213
        }
214
        
214
        
215
        public void fileAttributeChanged(FileAttributeEvent fe) {
215
        public void fileAttributeChanged(FileAttributeEvent fe) {
(-)project.ant/src/org/netbeans/modules/project/ant/FileChangeSupportEvent.java (-1 / +9 lines)
 Lines 44-49    Link Here 
44
44
45
import java.util.EventObject;
45
import java.util.EventObject;
46
46
47
import org.openide.filesystems.FileEvent;
47
import org.openide.filesystems.FileObject;
48
import org.openide.filesystems.FileObject;
48
49
49
import org.openide.filesystems.FileUtil;
50
import org.openide.filesystems.FileUtil;
 Lines 60-70    Link Here 
60
61
61
    private final int type;
62
    private final int type;
62
    private final File path;
63
    private final File path;
64
    private final FileEvent original;
63
    
65
    
64
    FileChangeSupportEvent(FileChangeSupport support, int type, File path) {
66
    FileChangeSupportEvent(FileEvent orig, FileChangeSupport support, int type, File path) {
65
        super(support);
67
        super(support);
66
        this.type = type;
68
        this.type = type;
67
        this.path = path;
69
        this.path = path;
70
        this.original = orig;
68
    }
71
    }
69
    
72
    
70
    public int getType() {
73
    public int getType() {
 Lines 78-84    Link Here 
78
    public FileObject getFileObject() {
81
    public FileObject getFileObject() {
79
        return FileUtil.toFileObject(path);
82
        return FileUtil.toFileObject(path);
80
    }
83
    }
84
85
    public FileEvent getOriginal() {
86
        return original;
87
    }
81
    
88
    
89
    @Override
82
    public String toString() {
90
    public String toString() {
83
        return "FCSE[" + "CDM".charAt(type) + ":" + path + "]"; // NOI18N
91
        return "FCSE[" + "CDM".charAt(type) + ":" + path + "]"; // NOI18N
84
    }
92
    }
(-)project.ant/src/org/netbeans/spi/project/support/ant/ProjectProperties.java (-8 / +13 lines)
 Lines 207-213    Link Here 
207
                } else {
207
                } else {
208
                    properties = null;
208
                    properties = null;
209
                }
209
                }
210
                fireChange();
210
                fireChange(null);
211
            }
211
            }
212
            return modifying;
212
            return modifying;
213
        }
213
        }
 Lines 282-288    Link Here 
282
                                    private void reload() {
282
                                    private void reload() {
283
                                        helper.cancelPendingHook();
283
                                        helper.cancelPendingHook();
284
                                        // Revert the save.
284
                                        // Revert the save.
285
                                        diskChange();
285
                                        diskChange(null);
286
                                    }
286
                                    }
287
                                });
287
                                });
288
                            }
288
                            }
 Lines 323-329    Link Here 
323
            cs.removeChangeListener(l);
323
            cs.removeChangeListener(l);
324
        }
324
        }
325
        
325
        
326
        private void fireChange() {
326
        private void fireChange(FileChangeSupportEvent ev) {
327
            if (!cs.hasListeners()) {
327
            if (!cs.hasListeners()) {
328
                return;
328
                return;
329
            }
329
            }
 Lines 333-338    Link Here 
333
                    return null;
333
                    return null;
334
                }
334
                }
335
            };
335
            };
336
            if (ev != null && ProjectManager.firedWithMutexAccess(ev.getOriginal())) {
337
                ProjectManager.mutex().readAccess(action);
338
                return;
339
            }
340
            
336
            if (ProjectManager.mutex().isWriteAccess()) {
341
            if (ProjectManager.mutex().isWriteAccess()) {
337
                // Run it right now. postReadRequest would be too late.
342
                // Run it right now. postReadRequest would be too late.
338
                ProjectManager.mutex().readAccess(action);
343
                ProjectManager.mutex().readAccess(action);
 Lines 349-375    Link Here 
349
            }
354
            }
350
        }
355
        }
351
        
356
        
352
        private void diskChange() {
357
        private void diskChange(FileChangeSupportEvent ev) {
353
            // XXX should check for a possible clobber from in-memory data
358
            // XXX should check for a possible clobber from in-memory data
354
            if (!writing) {
359
            if (!writing) {
355
                loaded = false;
360
                loaded = false;
356
            }
361
            }
357
            fireChange();
362
            fireChange(ev);
358
            if (!writing) {
363
            if (!writing) {
359
                helper.fireExternalChange(path);
364
                helper.fireExternalChange(path);
360
            }
365
            }
361
        }
366
        }
362
367
363
        public void fileCreated(FileChangeSupportEvent event) {
368
        public void fileCreated(FileChangeSupportEvent event) {
364
            diskChange();
369
            diskChange(event);
365
        }
370
        }
366
371
367
        public void fileDeleted(FileChangeSupportEvent event) {
372
        public void fileDeleted(FileChangeSupportEvent event) {
368
            diskChange();
373
            diskChange(event);
369
        }
374
        }
370
375
371
        public void fileModified(FileChangeSupportEvent event) {
376
        public void fileModified(FileChangeSupportEvent event) {
372
            diskChange();
377
            diskChange(event);
373
        }
378
        }
374
        
379
        
375
    }
380
    }
(-)projectapi/src/org/netbeans/api/project/ProjectManager.java (-8 / +32 lines)
 Lines 112-130    Link Here 
112
        return DEFAULT;
112
        return DEFAULT;
113
    }
113
    }
114
    
114
    
115
    private static final Executor FS_EXEC = new Executor() {
115
    private static final PostCommand FS_EXEC = new PostCommand();
116
        public void execute(final Runnable command) {
116
117
    private static class PostCommand implements Executor, FileSystem.AtomicAction {
118
        private Runnable run;
119
120
        public void execute(Runnable run) {
121
            PostCommand p = new PostCommand();
122
            p.run = run;
117
            try {
123
            try {
118
                FileUtil.runAtomicAction(new FileSystem.AtomicAction() {
124
                FileUtil.runAtomicAction(p);
119
                    public void run() throws IOException {
120
                        command.run();
121
                    }
122
                });
123
            } catch (IOException ex) {
125
            } catch (IOException ex) {
124
                throw (IllegalStateException) new IllegalStateException().initCause(ex);
126
                throw (IllegalStateException) new IllegalStateException().initCause(ex);
125
            }
127
            }
126
        }
128
        }
127
    };
129
130
        public void run() throws IOException {
131
            run.run();
132
        }
133
134
        @Override
135
        public int hashCode() {
136
            return getClass().hashCode();
137
        }
138
139
        @Override
140
        public boolean equals(Object obj) {
141
            if (obj == null) {
142
                return false;
143
            }
144
            return obj.getClass().equals(getClass());
145
        }
146
    }
147
148
    // XXX: apichange, maybe test in this module
149
    public static boolean firedWithMutexAccess(FileEvent ev) {
150
        return ev.firedFrom(FS_EXEC);
151
    }
128
152
129
    private static final Mutex MUTEX = new Mutex(new Mutex.Privileged(), FS_EXEC);
153
    private static final Mutex MUTEX = new Mutex(new Mutex.Privileged(), FS_EXEC);
130
    
154
    

Return to bug 146072
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo