Lines 13-18
Link Here
|
13 |
|
13 |
|
14 |
package org.netbeans.spi.project.support.ant; |
14 |
package org.netbeans.spi.project.support.ant; |
15 |
|
15 |
|
|
|
16 |
import java.beans.PropertyChangeEvent; |
17 |
import java.beans.PropertyChangeListener; |
16 |
import java.io.ByteArrayInputStream; |
18 |
import java.io.ByteArrayInputStream; |
17 |
import java.io.File; |
19 |
import java.io.File; |
18 |
import java.io.FileInputStream; |
20 |
import java.io.FileInputStream; |
Lines 30-40
Link Here
|
30 |
import java.util.Properties; |
32 |
import java.util.Properties; |
31 |
import javax.swing.event.ChangeEvent; |
33 |
import javax.swing.event.ChangeEvent; |
32 |
import javax.swing.event.ChangeListener; |
34 |
import javax.swing.event.ChangeListener; |
|
|
35 |
import org.netbeans.api.project.ProjectManager; |
33 |
import org.netbeans.junit.NbTestCase; |
36 |
import org.netbeans.junit.NbTestCase; |
|
|
37 |
import org.openide.filesystems.FileChangeAdapter; |
34 |
import org.openide.filesystems.FileLock; |
38 |
import org.openide.filesystems.FileLock; |
35 |
import org.openide.filesystems.FileObject; |
39 |
import org.openide.filesystems.FileObject; |
36 |
import org.openide.filesystems.FileSystem; |
40 |
import org.openide.filesystems.FileSystem; |
37 |
import org.openide.filesystems.FileUtil; |
41 |
import org.openide.filesystems.FileUtil; |
|
|
42 |
import org.openide.util.Mutex; |
43 |
import org.openide.util.RequestProcessor; |
38 |
import org.openide.util.Utilities; |
44 |
import org.openide.util.Utilities; |
39 |
|
45 |
|
40 |
/** |
46 |
/** |
Lines 544-549
Link Here
|
544 |
assertEquals("right main-2-b", "main-2-b-val+main-1-b-val+pre-b-val", defs.get("main-2-b")); |
550 |
assertEquals("right main-2-b", "main-2-b-val+main-1-b-val+pre-b-val", defs.get("main-2-b")); |
545 |
} |
551 |
} |
546 |
|
552 |
|
|
|
553 |
|
554 |
public void testNoFiringUnderWriteAccess() throws Exception { |
555 |
File propFile = FileUtil.normalizeFile(new File(System.getProperty("java.io.tmpdir"), "build.properties")); |
556 |
final FileObject propFileObject = FileUtil.toFileObject( propFile ); |
557 |
|
558 |
class TestFileObjectListener extends FileChangeAdapter { |
559 |
|
560 |
public int fileChangeCount; |
561 |
|
562 |
public synchronized void fileChanged(org.openide.filesystems.FileEvent fe) { |
563 |
fileChangeCount++; |
564 |
propFileObject.removeFileChangeListener( this ); |
565 |
assertFalse( "Don't fire events under write access", ProjectManager.mutex().isWriteAccess() ); |
566 |
} |
567 |
} |
568 |
|
569 |
TestFileObjectListener tfol = new TestFileObjectListener(); |
570 |
propFileObject.addFileChangeListener( tfol ); |
571 |
|
572 |
EditableProperties p = new EditableProperties(); |
573 |
p.setProperty("key1", "val1"); |
574 |
p.setProperty("key2", "val2"); |
575 |
PropertyUtils.putGlobalProperties(p); |
576 |
|
577 |
assertEquals( "File listener call count", 1, tfol.fileChangeCount ); |
578 |
|
579 |
} |
580 |
|
581 |
|
582 |
public void testFiringInRightThread() throws Exception { |
583 |
File propFile = FileUtil.normalizeFile(new File(System.getProperty("java.io.tmpdir"), "build.properties")); |
584 |
FileObject propFileObject = FileUtil.toFileObject( propFile ); |
585 |
|
586 |
final EditableProperties p = new EditableProperties(); |
587 |
final Thread current = Thread.currentThread(); |
588 |
|
589 |
class TestFileObjectListener extends FileChangeAdapter implements Runnable, PropertyChangeListener { |
590 |
|
591 |
public int fileChangeCount; |
592 |
public int stateChangeCount; |
593 |
public Error error; |
594 |
public PropertyEvaluator peval; |
595 |
|
596 |
|
597 |
public synchronized void fileChanged(org.openide.filesystems.FileEvent fe) { |
598 |
fileChangeCount++; |
599 |
RequestProcessor.getDefault().post( this ); |
600 |
try { |
601 |
wait(); |
602 |
} |
603 |
catch( InterruptedException e ) { |
604 |
fail( "nasty exception" ); |
605 |
} |
606 |
} |
607 |
|
608 |
public void propertyChange( PropertyChangeEvent evt ) { |
609 |
if ( Thread.currentThread() != current ) { |
610 |
fail( "Bad thread, expected: " + current + " real " + Thread.currentThread() ); |
611 |
} |
612 |
stateChangeCount++; |
613 |
} |
614 |
|
615 |
public void run() { |
616 |
try { |
617 |
assertEquals( null, peval.getProperty( "key1") ); |
618 |
assertEquals( null, peval.getProperty( "key2") ); |
619 |
} |
620 |
catch( Error e ) { |
621 |
error = e; |
622 |
} |
623 |
finally { |
624 |
synchronized ( this ) { |
625 |
notify(); |
626 |
} |
627 |
} |
628 |
} |
629 |
} |
630 |
|
631 |
TestFileObjectListener tfol = new TestFileObjectListener(); |
632 |
propFileObject.getFileSystem().addFileChangeListener( tfol ); |
633 |
final PropertyProvider pp = PropertyUtils.propertiesFilePropertyProvider( propFile ); |
634 |
tfol.peval = PropertyUtils.sequentialPropertyEvaluator(pp, new PropertyProvider[0]); |
635 |
tfol.peval.addPropertyChangeListener( tfol ); |
636 |
|
637 |
|
638 |
//ProjectManager.mutex().writeAccess( new Mutex.ExceptionAction() { |
639 |
// public Object run() throws IOException { |
640 |
p.setProperty("key1", "val1"); |
641 |
p.setProperty("key2", "val2"); |
642 |
PropertyUtils.putGlobalProperties(p); |
643 |
// return null; |
644 |
//} |
645 |
//} ); |
646 |
|
647 |
assertEquals( "File listener call count", 1, tfol.fileChangeCount ); |
648 |
|
649 |
if ( tfol.error != null ) { |
650 |
throw tfol.error; |
651 |
} |
652 |
|
653 |
assertEquals( "StateChange listener call count", 2, tfol.stateChangeCount ); |
654 |
} |
655 |
|
547 |
private static final class TestMutablePropertyProvider implements PropertyProvider { |
656 |
private static final class TestMutablePropertyProvider implements PropertyProvider { |
548 |
|
657 |
|
549 |
public final Map/*<String,String>*/ defs; |
658 |
public final Map/*<String,String>*/ defs; |
Lines 574-578
Link Here
|
574 |
} |
683 |
} |
575 |
|
684 |
|
576 |
} |
685 |
} |
|
|
686 |
|
577 |
|
687 |
|
578 |
} |
688 |
} |