diff --git a/platform/masterfs/nbproject/project.properties b/platform/masterfs/nbproject/project.properties index 02dca3374ff0..dd2d2d9e88e5 100644 --- a/platform/masterfs/nbproject/project.properties +++ b/platform/masterfs/nbproject/project.properties @@ -31,11 +31,11 @@ test.config.stableBTD.excludes=\ **/FileObjSymlinkTest.class,\ **/FolderObjTest.class,\ **/ChildrenSupportTest.class,\ - **/ProvidedExtensionsTest.class,\ - **/SlowRefreshAndPriorityIOTest.class,\ + **/ProvidedExtensionsTest.class + +test.unit.excludes=\ **/SlowRefreshSuspendableTest.class,\ - **/StatFilesTest.class -spec.version.base=2.90.0 + **/TwoFileNamesForASingleFileTest.class,\ + **/FolderObjCacheTest.class -# TODO remove SM usage in tests -test.jms.flags=-Djava.security.manager=allow +spec.version.base=2.90.0 diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshAndPriorityIOTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshAndPriorityIOTest.java index 25e775364cba..4910f0691a5d 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshAndPriorityIOTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshAndPriorityIOTest.java @@ -76,7 +76,6 @@ protected void setUp() throws Exception { testFolder = FileUtil.toFileObject(dir); assertNotNull("Test folder created", testFolder); - System.setSecurityManager(new FileChangedManager()); } public void testRefreshCanBeSuspendedByPriorityIO() throws Exception { diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshIncrementalTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshIncrementalTest.java index 473b7d708ee6..5aa05fb4c8d9 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshIncrementalTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshIncrementalTest.java @@ -73,7 +73,6 @@ protected void setUp() throws Exception { testFolder = FileUtil.toFileObject(dir); assertNotNull("Test folder created", testFolder); - System.setSecurityManager(new FileChangedManager()); } public void testChangesDeliveredSoonerThanEverythingIsChecked() throws Exception { diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshInterruptibleTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshInterruptibleTest.java index 8890e3a62fba..7a1954cd9bf6 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshInterruptibleTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshInterruptibleTest.java @@ -68,7 +68,6 @@ protected void setUp() throws Exception { testFolder = FileUtil.toFileObject(dir); assertNotNull("Test folder created", testFolder); - System.setSecurityManager(new FileChangedManager()); } @RandomlyFails // jglick: "No change detected expected:<0> but was:<1>" diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshPreferrableTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshPreferrableTest.java index dee3be2232ab..ba823edc8f9b 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshPreferrableTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshPreferrableTest.java @@ -66,8 +66,6 @@ protected void setUp() throws Exception { dir.mkdirs(); testFolder = FileUtil.toFileObject(dir); assertNotNull("Test folder created", testFolder); - - System.setSecurityManager(new FileChangedManager()); } public void testRefreshPrefersSuggestedFolders() throws Exception { diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshSuspendableTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshSuspendableTest.java index d57e76dc7df9..cd61bd21c509 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshSuspendableTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshSuspendableTest.java @@ -75,7 +75,6 @@ protected void setUp() throws Exception { testFolder = FileUtil.toFileObject(dir); assertNotNull("Test folder created", testFolder); - System.setSecurityManager(new FileChangedManager()); } @RandomlyFails // NB-Core-Build #4386: Background I/O access needs to stop before we finish our task @@ -169,6 +168,7 @@ void doWork() { LOG.log(Level.INFO, "Created {0}", busyFile); for (int i = 0; i < 2000; i ++) { assertTrue("Can be read", busyFile.canRead()); + FileChangedManager.getInstance().checkRead(busyFile.getPath()); LOG.log(Level.INFO, "Touched {0}", i); if (i > 100) { synchronized (this) { diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/TwoFileNamesForASingleFileTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/TwoFileNamesForASingleFileTest.java index db2738700743..24445e50f12d 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/TwoFileNamesForASingleFileTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/TwoFileNamesForASingleFileTest.java @@ -45,7 +45,6 @@ public TwoFileNamesForASingleFileTest(String name) { @Override protected void setUp() throws Exception { clearWorkDir(); - System.setSecurityManager(FileChangedManager.getInstance()); } public void testTwoFileNames() throws Exception { @@ -57,6 +56,7 @@ public void testTwoFileNames() throws Exception { assertEquals("Empty is empty", 0, empty.length); final File n = new File(f, "x.txt"); + FileChangedManager.getInstance().checkWrite(n.getPath()); n.createNewFile(); FileObject fn = FileUtil.toFileObject(f); assertNotNull("File object found", fn); @@ -71,8 +71,10 @@ class R implements Runnable { @Override public void run() { refresh(); + FileChangedManager.getInstance().checkDelete(n.getPath()); n.delete(); none = fo.getChildren(); + FileChangedManager.getInstance().checkWrite(n.getPath()); assertTrue("Directory creation succeeds", n.mkdirs()); refresh(); one = fo.getChildren(); diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObjCacheTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObjCacheTest.java index 57b99d0fc373..f7418a746b48 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObjCacheTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObjCacheTest.java @@ -36,10 +36,6 @@ * @author Radek Matous */ public class FolderObjCacheTest extends NbTestCase { - static { - System.setSecurityManager(FileChangedManager.getInstance()); - } - Logger LOG; public FolderObjCacheTest(String testName) { @@ -92,6 +88,7 @@ private void doWork(boolean gc) throws IOException { assertNull(FileBasedFileSystem.getFileObject(fold)); assertNull(workDirFo.getFileObject(fold.getName())); assertFalse(existsChild(workDirFo, fold.getName())); + FileChangedManager.getInstance().checkWrite(fold.getPath()); fold.mkdir(); assertNotNull((workDirFo.getFileSystem()).findResource(workDirFo.getPath()+"/"+fold.getName())); assertNotNull(workDirFo.getFileObject(fold.getName())); @@ -101,6 +98,7 @@ private void doWork(boolean gc) throws IOException { assertTrue(existsChild(workDirFo, fold.getName())); FileObject gcFo = workDirFo.getFileObject(fold.getName()); assertNotNull("One exists", gcFo); + FileChangedManager.getInstance().checkDelete(fold.getPath()); fold.delete(); assertNull("Immediatelly invalidated thanks to FileChangedManager", workDirFo.getFileObject(fold.getName())); assertFalse(existsChild(workDirFo, fold.getName())); @@ -113,6 +111,7 @@ private void doWork(boolean gc) throws IOException { } LOG.info("Before mkdir: " + fold); + FileChangedManager.getInstance().checkWrite(fold.getPath()); fold.mkdir(); LOG.info("After mkdir: " + fold); final FileObject okFn = workDirFo.getFileObject(fold.getName()); @@ -128,6 +127,7 @@ private void doWork(boolean gc) throws IOException { foldFo.delete(); assertNull(workDirFo.getFileObject(fold.getName())); assertFalse(existsChild(workDirFo, fold.getName())); + FileChangedManager.getInstance().checkWrite(fold.getPath()); fold.mkdir(); //assertNull(((FileBasedFileSystem)workDirFo.getFileSystem()).findFileObject(fold)); //assertNull(MasterFileSystem.getFileObject(fold)); @@ -136,6 +136,7 @@ private void doWork(boolean gc) throws IOException { workDirFo.getFileSystem().refresh(false); assertNotNull(workDirFo.getFileObject(fold.getName())); assertTrue(existsChild(workDirFo, fold.getName())); + FileChangedManager.getInstance().checkDelete(fold.getPath()); fold.delete(); assertNull(workDirFo.getFileObject(fold.getName())); assertFalse(existsChild(workDirFo, fold.getName())); diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/NoLockWhenRefreshIOTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/NoLockWhenRefreshIOTest.java index 9cd126c56ecd..b5383d9c0220 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/NoLockWhenRefreshIOTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/NoLockWhenRefreshIOTest.java @@ -74,7 +74,6 @@ public void testRefreshOfAFolder() throws IOException { FileObject fo = FileUtil.toFileObject(getWorkDir()); FileObject dir = fo.getFileObject("dir"); assertNotNull("dir found", dir); - System.setSecurityManager(new AssertNoLockManager(getWorkDirPath())); List arr = Arrays.asList(dir.getChildren()); dir.refresh(); List arr2 = Arrays.asList(dir.getChildren()); @@ -92,37 +91,7 @@ public void testGetChild() throws IOException { FileObject fo = FileUtil.toFileObject(getWorkDir()); FileObject dir = fo.getFileObject("dir"); assertNotNull("dir found", dir); - System.setSecurityManager(new AssertNoLockManager(getWorkDirPath())); FileObject fileObject = dir.getFileObject("x50.txt"); assertNotNull(fileObject); } - - private static class AssertNoLockManager extends SecurityManager { - final String prefix; - - public AssertNoLockManager(String p) { - prefix = p; - } - - @Override - public void checkRead(String string) { - if (string.startsWith(prefix)) { - assertFalse("No lock", ChildrenSupport.isLock()); - } - } - - @Override - public void checkRead(String string, Object o) { - checkRead(string); - } - - @Override - public void checkPermission(Permission prmsn) { - } - - @Override - public void checkPermission(Permission prmsn, Object o) { - } - } - } diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/StatFilesTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/StatFilesTest.java index e24bd3c4bd14..2494a753e775 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/StatFilesTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/StatFilesTest.java @@ -63,7 +63,6 @@ protected void setUp() throws java.lang.Exception { //init FileUtil.toFileObject(testFile); monitor = new StatFiles(); - System.setSecurityManager(monitor); monitor.reset(); } diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/naming/NamingFactoryTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/naming/NamingFactoryTest.java index 2ad7c8951f3f..39868a66d029 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/naming/NamingFactoryTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/naming/NamingFactoryTest.java @@ -41,7 +41,7 @@ public NamingFactoryTest(String n) { public static Test suite() { NbTestSuite s = new NbTestSuite(); s.addTestSuite(NamingFactoryTest.class); - s.addTest(new NamingFactoryTest("registerSecurityManager")); + s.addTest(new NamingFactoryTest("NamingFactoryTest")); s.addTestSuite(NamingFactoryTest.class); return s; } @@ -55,10 +55,6 @@ protected void setUp() throws Exception { assertTrue("Contains Fixed: " + res.getClass(), res.getClass().getName().contains("Fixed")); } - public void registerSecurityManager() { - System.setSecurityManager(new AssertNoLockManager(NamingFactory.class)); - } - public void testDontForciblyUnregisterFileName() throws Exception { File f = new File(getWorkDir(), "child.txt"); f.createNewFile(); @@ -167,31 +163,5 @@ public void testInvalidatePrevFolder() throws Exception { assertFalse("Oldest file object is no longer valid", dir.isValid()); assertFalse("Middle file object is no longer valid", file.isValid()); assertTrue("Newest is valid", newDir.isValid()); - - } - - private static class AssertNoLockManager extends SecurityManager { - private final Object LOCK; - - public AssertNoLockManager(Object lock) { - LOCK = lock; - } - @Override - public void checkRead(String string) { - assertFalse("No lock", Thread.holdsLock(LOCK)); - } - - @Override - public void checkRead(String string, Object o) { - checkRead(string); - } - - @Override - public void checkPermission(Permission prmsn) { - } - - @Override - public void checkPermission(Permission prmsn, Object o) { - } } } diff --git a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/TestBaseHid.java b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/TestBaseHid.java index 029b9db853db..20ff9b9cef30 100644 --- a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/TestBaseHid.java +++ b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/TestBaseHid.java @@ -31,12 +31,12 @@ */ public abstract class TestBaseHid extends MultiThreadedTestCaseHid { /** Support for events*/ - protected List fileChangedL = new ArrayList (); - protected List fileDCreatedL = new ArrayList (); - protected List fileFCreatedL = new ArrayList (); - protected List fileDeletedL = new ArrayList (); - protected List fileRenamedL = new ArrayList (); - protected List fileAttrChangedL = new ArrayList (); + protected List fileChangedL = new ArrayList<>(); + protected List fileDCreatedL = new ArrayList<>(); + protected List fileFCreatedL = new ArrayList<>(); + protected List fileDeletedL = new ArrayList<>(); + protected List fileRenamedL = new ArrayList<>(); + protected List fileAttrChangedL = new ArrayList<>(); private FileChangeListener defListener; private String resourcePrefix = ""; @@ -57,8 +57,7 @@ public TestBaseHid(String name) { /** array of filesystems that can be used for tests. All filesystems should * satisfy requirements for resources @see getResources () */ protected FileSystem allTestedFS[]; - private static SecurityManager defaultSecurityManager; - /** If not null, file accesses are counted through custom SecurityManager. */ + public static StatFiles accessMonitor; @Override @@ -74,22 +73,10 @@ protected void setUp() throws Exception { allTestedFS = FileSystemFactoryHid.createFileSystem(getName(),resources,this); } if (allTestedFS != null) testedFS = allTestedFS[0]; - // If not null, file accesses are counted through custom SecurityManager. - if(accessMonitor != null) { - if(defaultSecurityManager == null) { - defaultSecurityManager = System.getSecurityManager(); - } - System.setSecurityManager(accessMonitor); - } } @Override protected void tearDown() throws Exception { - // restore SecurityManager if previously changed - if(accessMonitor != null) { - System.setSecurityManager(defaultSecurityManager); - } - if (testedFS instanceof JarFileSystem) { testedFS.removeNotify(); } diff --git a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/test/StatFiles.java b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/test/StatFiles.java index 6fab0f33a51a..786f146d1c46 100644 --- a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/test/StatFiles.java +++ b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/test/StatFiles.java @@ -47,16 +47,9 @@ public StatFiles() { } public void register() { - if (defaultSecurityManager == null) { - defaultSecurityManager = System.getSecurityManager(); - } - System.setSecurityManager(this); } public void unregister() { - if (defaultSecurityManager == null) { - System.setSecurityManager(defaultSecurityManager); - } } public void reset() {