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

(-)ant/project/src/org/netbeans/spi/project/support/ant/GeneratedFilesHelper.java (-49 / +74 lines)
Lines 34-39 Link Here
34
import javax.xml.transform.stream.StreamResult;
34
import javax.xml.transform.stream.StreamResult;
35
import javax.xml.transform.stream.StreamSource;
35
import javax.xml.transform.stream.StreamSource;
36
import org.netbeans.api.project.ProjectManager;
36
import org.netbeans.api.project.ProjectManager;
37
import org.netbeans.modules.project.ant.UserQuestionHandler;
37
import org.openide.ErrorManager;
38
import org.openide.ErrorManager;
38
import org.openide.filesystems.FileLock;
39
import org.openide.filesystems.FileLock;
39
import org.openide.filesystems.FileObject;
40
import org.openide.filesystems.FileObject;
Lines 252-314 Link Here
252
                            } catch (TransformerException e) {
253
                            } catch (TransformerException e) {
253
                                throw (IOException)new IOException(e.toString()).initCause(e);
254
                                throw (IOException)new IOException(e.toString()).initCause(e);
254
                            }
255
                            }
255
                            try {
256
                            // Update genfiles.properties too.
256
                                FileLock lock = buildScriptXml.lock();
257
                            final EditableProperties p = new EditableProperties();
258
                            FileObject genfiles = dir.getFileObject(GENFILES_PROPERTIES_PATH);
259
                            if (genfiles != null && genfiles.isVirtual()) {
260
                                // #55164: deleted from CVS?
261
                                genfiles = null;
262
                            }
263
                            if (genfiles != null) {
264
                                is = genfiles.getInputStream();
257
                                try {
265
                                try {
258
                                    OutputStream os = new EolFilterOutputStream(buildScriptXml.getOutputStream(lock));
266
                                    p.load(is);
259
                                    try {
260
                                        os.write(resultData);
261
                                    } finally {
262
                                        os.close();
263
                                    }
264
                                } finally {
267
                                } finally {
265
                                    lock.releaseLock();
268
                                    is.close();
266
                                }
267
                                // Update genfiles.properties too.
268
                                EditableProperties p = new EditableProperties();
269
                                FileObject genfiles = dir.getFileObject(GENFILES_PROPERTIES_PATH);
270
                                if (genfiles != null && genfiles.isVirtual()) {
271
                                    // #55164: deleted from CVS?
272
                                    genfiles = null;
273
                                }
274
                                if (genfiles != null) {
275
                                    is = genfiles.getInputStream();
276
                                    try {
277
                                        p.load(is);
278
                                    } finally {
279
                                        is.close();
280
                                    }
281
                                }
282
                                p.setProperty(path + KEY_SUFFIX_DATA_CRC,
283
                                    getCrc32(new ByteArrayInputStream(projectXmlData), projectXml));
284
                                if (genfiles == null) {
285
                                    // New file, set a comment on it. XXX this puts comment in middle if write build-impl.xml before build.xml
286
                                    p.setComment(path + KEY_SUFFIX_DATA_CRC, new String[] {
287
                                        "# " + NbBundle.getMessage(GeneratedFilesHelper.class, "COMMENT_genfiles.properties_1"), // NOI18N
288
                                        "# " + NbBundle.getMessage(GeneratedFilesHelper.class, "COMMENT_genfiles.properties_2"), // NOI18N
289
                                    }, false);
290
                                }
269
                                }
291
                                p.setProperty(path + KEY_SUFFIX_STYLESHEET_CRC,
270
                            }
292
                                    getCrc32(new ByteArrayInputStream(stylesheetData), stylesheet));
271
                            p.setProperty(path + KEY_SUFFIX_DATA_CRC,
293
                                p.setProperty(path + KEY_SUFFIX_SCRIPT_CRC,
272
                                getCrc32(new ByteArrayInputStream(projectXmlData), projectXml));
294
                                    computeCrc32(new ByteArrayInputStream(resultData)));
273
                            if (genfiles == null) {
295
                                if (genfiles == null) {
274
                                // New file, set a comment on it. XXX this puts comment in middle if write build-impl.xml before build.xml
296
                                    genfiles = FileUtil.createData(dir, GENFILES_PROPERTIES_PATH);
275
                                p.setComment(path + KEY_SUFFIX_DATA_CRC, new String[] {
297
                                }
276
                                    "# " + NbBundle.getMessage(GeneratedFilesHelper.class, "COMMENT_genfiles.properties_1"), // NOI18N
298
                                lock = genfiles.lock();
277
                                    "# " + NbBundle.getMessage(GeneratedFilesHelper.class, "COMMENT_genfiles.properties_2"), // NOI18N
299
                                try {
278
                                }, false);
300
                                    OutputStream os = genfiles.getOutputStream(lock);
279
                            }
280
                            p.setProperty(path + KEY_SUFFIX_STYLESHEET_CRC,
281
                                getCrc32(new ByteArrayInputStream(stylesheetData), stylesheet));
282
                            p.setProperty(path + KEY_SUFFIX_SCRIPT_CRC,
283
                                computeCrc32(new ByteArrayInputStream(resultData)));
284
                            if (genfiles == null) {
285
                                genfiles = FileUtil.createData(dir, GENFILES_PROPERTIES_PATH);
286
                            }
287
                            final FileObject _genfiles = genfiles;
288
                            final FileSystem.AtomicAction body = new FileSystem.AtomicAction() {
289
                                public void run() throws IOException {
290
                                    // Try to acquire both locks together, since we need them both written.
291
                                    FileLock lock1 = buildScriptXml.lock();
301
                                    try {
292
                                    try {
302
                                        p.store(os);
293
                                        FileLock lock2 = _genfiles.lock();
294
                                        try {
295
                                            OutputStream os1 = new EolFilterOutputStream(buildScriptXml.getOutputStream(lock1));
296
                                            try {
297
                                                OutputStream os2 = _genfiles.getOutputStream(lock2);
298
                                                try {
299
                                                    os1.write(resultData);
300
                                                    p.store(os2);
301
                                                } finally {
302
                                                    os2.close();
303
                                                }
304
                                            } finally {
305
                                                os1.close();
306
                                            }
307
                                        } finally {
308
                                            lock2.releaseLock();
309
                                        }
303
                                    } finally {
310
                                    } finally {
304
                                        os.close();
311
                                        lock1.releaseLock();
305
                                    }
312
                                    }
306
                                } finally {
307
                                    lock.releaseLock();
308
                                }
313
                                }
314
                            };
315
                            try {
316
                                body.run();
309
                            } catch (UserQuestionException uqe) {
317
                            } catch (UserQuestionException uqe) {
310
                                // Don't bother asking to lock it; not important enough.
318
                                // #57480: need to regenerate build-impl.xml.
311
                                // Cf. #46089.
319
                                UserQuestionHandler.handle(uqe, new UserQuestionHandler.Callback() {
320
                                    public void accepted() {
321
                                        // Try again.
322
                                        try {
323
                                            body.run();
324
                                        } catch (IOException e) {
325
                                            // Oh well.
326
                                            ErrorManager.getDefault().notify(e);
327
                                        }
328
                                    }
329
                                    public void denied() {
330
                                        // OK, skip it.
331
                                    }
332
                                    public void error(IOException e) {
333
                                        ErrorManager.getDefault().notify(e);
334
                                        // Never mind.
335
                                    }
336
                                });
312
                            }
337
                            }
313
                        }
338
                        }
314
                    });
339
                    });

Return to bug 57480