org.openide.filesystems.FileChangeAdapter Java Examples
The following examples show how to use
org.openide.filesystems.FileChangeAdapter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LinuxNotifier235632Test.java From netbeans with Apache License 2.0 | 6 votes |
/** * Test of nextEvent method, of class LinuxNotifier. * * @throws java.lang.Exception */ public void testNextEvent() throws Exception { prepareFiles(); final AtomicBoolean folder2refreshed = new AtomicBoolean(false); Logger log = Logger.getLogger(FolderObj.class.getName()); Handler h = createHandler(folder2refreshed); log.addHandler(h); try { FileChangeListener l = new FileChangeAdapter(); FileUtil.addFileChangeListener(l, folder1text1Txt); // This causes an IN_IGNORED native event. FileUtil.removeFileChangeListener(l, folder1text1Txt); // Native listeners may need some time. Thread.sleep(2000); } finally { log.removeHandler(h); } assertFalse("Folder folder2 should not be refreshed.", folder2refreshed.get()); }
Example #2
Source File: WatcherTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testRemoveListenerFromAFileObj() throws Exception { File f = new File(new File(getWorkDir(), "dir"), "X.txt"); final File pf = f.getParentFile(); pf.mkdirs(); f.createNewFile(); FileObject fo = FileUtil.toFileObject(f); assertTrue("Is data", fo.isData()); f.delete(); pf.delete(); FileObject parent = FileUtil.toFileObject(getWorkDir()).createData("dir"); assertTrue("Also data", parent.isData()); fo.removeFileChangeListener(new FileChangeAdapter()); }
Example #3
Source File: OSXNotifierTest.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected void setUp() throws Exception { Log.enable(FolderObj.class.getName(), Level.FINEST); clearWorkDir(); folder1 = new File(getWorkDir(), "folder1"); folder1.mkdir(); folder1text1Txt = new File(folder1, "text1.txt"); folder1text1Txt.createNewFile(); File folder2 = new File(getWorkDir(), "folder2"); folder2.mkdir(); folder2FO = FileUtil.toFileObject(folder2); folder2text2TxtFO = folder2FO.createData("text2.txt"); folder2text2TxtFO.addFileChangeListener(new FileChangeAdapter()); folder2FO.refresh(); }
Example #4
Source File: OSXNotifierTest.java From netbeans with Apache License 2.0 | 6 votes |
@Test public void testNextEvent() throws Exception { final AtomicBoolean folder2refreshed = new AtomicBoolean(false); Logger log = Logger.getLogger(FolderObj.class.getName()); Handler h = createHandler(folder2refreshed); log.addHandler(h); try { FileChangeListener l = new FileChangeAdapter(); FileUtil.addFileChangeListener(l, folder1text1Txt); FileUtil.removeFileChangeListener(l, folder1text1Txt); Thread.sleep(2000); } finally { log.removeHandler(h); } assertFalse("Folder folder2 should not be refreshed.", folder2refreshed.get()); }
Example #5
Source File: WatcherDeadlockTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testDeadlockWhileRefesh() throws IOException { clearWorkDir(); MockServices.setServices(Watcher.class, AnnotationProviderImpl.class); final File root = new File(getWorkDir(), "root"); File f = new File(new File(new File(root, "x"), "y"), "z"); f.mkdirs(); final FileObject r = FileUtil.toFileObject(root); r.refresh(true); Set<FileObject> all = new HashSet<FileObject>(); Enumeration<? extends FileObject> en = r.getChildren(true); while (en.hasMoreElements()) { FileObject fileObject = en.nextElement(); all.add(fileObject); } assertEquals("Some files: " + all, 3, all.size()); FileChangeListener l = new FileChangeAdapter(); FileUtil.addRecursiveListener(l, root); FileChangeListener l2 = new FileChangeAdapter(); FileUtil.addRecursiveListener(l2, root); }
Example #6
Source File: NbEditorToolBar.java From netbeans with Apache License 2.0 | 6 votes |
/** See issue #57773 for details. Toolbar should be updated with possible changes after module install/uninstall */ private void installModulesInstallationListener(){ moduleRegListener = new FileChangeAdapter() { public @Override void fileChanged(FileEvent fe) { //some module installed/uninstalled. Refresh toolbar content Runnable r = new Runnable() { public void run() { if (isToolbarVisible()) { checkPresentersRemoved(); checkPresentersAdded(); } } }; Utilities.runInEventDispatchThread(r); } }; FileObject moduleRegistry = FileUtil.getConfigFile("Modules"); //NOI18N if (moduleRegistry !=null){ moduleRegistry.addFileChangeListener( FileUtil.weakFileChangeListener(moduleRegListener, moduleRegistry)); } }
Example #7
Source File: AnnotationTypesFolder.java From netbeans with Apache License 2.0 | 6 votes |
/** Creates new AnnotationTypesFolder */ private AnnotationTypesFolder(FileObject fo, DataFolder fld) { super(fld); recreate(); instanceFinished(); // add listener on changes in annotation types folder fo.addFileChangeListener(new FileChangeAdapter() { public void fileDeleted(FileEvent fe) { AnnotationType type; for (Iterator it = AnnotationTypes.getTypes().getAnnotationTypeNames(); it.hasNext(); ) { type = AnnotationTypes.getTypes().getType((String)it.next()); if ( type != null && ((FileObject)type.getProp(AnnotationType.PROP_FILE)).equals(fe.getFile()) ) { AnnotationTypes.getTypes().removeType(type.getName()); break; } } } }); }
Example #8
Source File: TimesCollectorPeer.java From netbeans with Apache License 2.0 | 6 votes |
private synchronized Map<String, Description> getKey2Desc(final Object fo) { Map<String, Description> result = fo2Key2Desc.get(fo); if (result == null) { files.add(new CleanableWeakReference<Object>(fo)); fo2Key2Desc.put(fo, result = Collections.synchronizedMap(new LinkedHashMap<String, Description>())); pcs.firePropertyChange("fos", null, fo); if (fo instanceof FileObject) { ((FileObject)fo).addFileChangeListener(new FileChangeAdapter() { @Override public void fileDeleted(FileEvent ev) { fileDeletedSync(ev, (FileObject)fo); } }); } } return result; }
Example #9
Source File: ProjectWebModule.java From netbeans with Apache License 2.0 | 6 votes |
public synchronized MetadataModel<WebAppMetadata> getMetadataModel() { if (webAppMetadataModel == null) { FileObject ddFO = getDeploymentDescriptor(); final FileObject webInf = getWebInf(true); if (ddFO == null && webInf != null) { webInf.addFileChangeListener(new FileChangeAdapter() { @Override public void fileDataCreated(FileEvent fe) { if (FILE_DD.equals(fe.getFile().getNameExt())) { webInf.removeFileChangeListener(this); resetMetadataModel(); } } }); } File ddFile = ddFO != null ? FileUtil.toFile(ddFO) : null; MetadataUnit metadataUnit = MetadataUnit.create( cpProvider.getProjectSourcesClassPath(ClassPath.BOOT), cpProvider.getProjectSourcesClassPath(ClassPath.COMPILE), cpProvider.getProjectSourcesClassPath(ClassPath.SOURCE), ddFile); webAppMetadataModel = WebAppMetadataModelFactory.createMetadataModel(metadataUnit, true); } return webAppMetadataModel; }
Example #10
Source File: WsitPojectOpenedHook.java From netbeans with Apache License 2.0 | 6 votes |
private void addDescriptorsCleaner( FileObject fileObject , final String fqn , final String endpointName ) { fileObject.addFileChangeListener( new FileChangeAdapter(){ /* (non-Javadoc) * @see org.openide.filesystems.FileChangeAdapter#fileDeleted(org.openide.filesystems.FileEvent) */ @Override public void fileDeleted( FileEvent fe ) { try { JAXWSSupport support = JAXWSSupport.getJAXWSSupport( project.getProjectDirectory()); support.removeNonJsr109Entries(Util.MEX_NAME); support.removeNonJsr109Entries(fqn); support.removeNonJsr109Entries(endpointName); } catch(IOException e ){ LOG.log(Level.WARNING , null , e); } } }); }
Example #11
Source File: FolderObjTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testRefresh69744() throws Exception { File thisTest = new File(getWorkDir(),"thisTest"); thisTest.createNewFile(); FileObject testf = FileBasedFileSystem.getFileObject(thisTest); assertNotNull(testf); assertGC("",new WeakReference<FileObject>(testf.getParent())); modifyFileObject(testf, "abc"); FileSystem fs = testf.getFileSystem(); final List<FileEvent> l = new ArrayList<FileEvent>(); FileChangeListener fcl = new FileChangeAdapter() { @Override public void fileChanged(FileEvent fe) { l.add(fe); } }; Thread.sleep(1500); fs.addFileChangeListener(fcl); try { modifyFileObject(testf, "def"); assertFalse(l.isEmpty()); } finally { fs.removeFileChangeListener(fcl); } }
Example #12
Source File: VCSInterceptorTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testRefreshRecursively() throws IOException { File f = new File(dataRootDir, "workdir/root-test-versioned"); f.mkdirs(); FileObject fo = FileUtil.toFileObject(f); fo = fo.createFolder("folder"); fo.addRecursiveListener(new FileChangeAdapter()); assertTrue(inteceptor.getRefreshRecursivelyFiles().contains(FileUtil.toFile(fo))); }
Example #13
Source File: DataShadowTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testCreateTheShadow () throws Exception { DataShadow shade = original.createShadow (folder); Node node = shade.createNodeDelegate(); final AtomicBoolean modified = new AtomicBoolean(); shade.getPrimaryFile().addFileChangeListener(new FileChangeAdapter() { @Override public void fileChanged (FileEvent fe) { modified.set(true); } }); String originName = node.getName(); PropertySet[] props = node.getPropertySets(); Node.Property p = null; for (PropertySet propSet : props) { for (Node.Property prop : propSet.getProperties()) { if ("OriginalName".equals(prop.getName())) { p = prop; break; } } } assertNotNull(p); // set name to the same value p.setValue(originName); // nothing should happen assertFalse(modified.get()); assertEquals(originName, original.getName()); // set name to the same value p.setValue(originName + ".txt"); // link should be changed assertTrue(modified.get()); assertEquals(originName + ".txt", original.getName()); }
Example #14
Source File: LocalizedBundleInfo.java From netbeans with Apache License 2.0 | 5 votes |
/** Use factory method instead. */ private LocalizedBundleInfo(FileObject[] bundleFOs) throws IOException { if (bundleFOs == null || bundleFOs.length == 0) { throw new IllegalArgumentException(); } props = new EditableProperties[bundleFOs.length]; paths = new File[bundleFOs.length]; for (int i = 0; i < bundleFOs.length; i++) { InputStream bundleIS = bundleFOs[i].getInputStream(); try { props[i] = new EditableProperties(true); props[i].load(bundleIS); } finally { bundleIS.close(); } paths[i] = FileUtil.toFile(bundleFOs[i]); bundleFOs[i].addFileChangeListener(new FileChangeAdapter() { public void fileChanged(FileEvent fe) { try { LocalizedBundleInfo.this.reload(); } catch (IOException e) { Util.err.log(ErrorManager.WARNING, "Cannot reload localized bundle info " + // NOI18N FileUtil.getFileDisplayName(fe.getFile())); } } }); } }
Example #15
Source File: WebModuleImpl.java From netbeans with Apache License 2.0 | 5 votes |
@Override public synchronized MetadataModel<WebAppMetadata> getMetadataModel() { if (webAppMetadataModel == null) { final FileObject ddFO = getDeploymentDescriptor(); final FileObject webInf = getOrCreateWebInf(); if (ddFO == null && webInf != null) { webInf.addFileChangeListener(new FileChangeAdapter() { @Override public void fileDataCreated(FileEvent fe) { if ("web.xml".equals(fe.getFile().getNameExt())) { // NOI18N webInf.removeFileChangeListener(this); resetMetadataModel(); } } }); } GradleWebProject wp = GradleWebProject.get(project); ProjectSourcesClassPathProvider gcp = project.getLookup().lookup(ProjectSourcesClassPathProvider.class); File ddFile = ddFO != null ? FileUtil.toFile(ddFO) : null; MetadataUnit mu = MetadataUnit.create( gcp.getProjectSourcesClassPath(ClassPath.BOOT), gcp.getProjectSourcesClassPath(ClassPath.COMPILE), gcp.getProjectSourcesClassPath(ClassPath.SOURCE), ddFile); webAppMetadataModel = WebAppMetadataModelFactory.createMetadataModel(mu, true); } return webAppMetadataModel; }
Example #16
Source File: WebModuleImpl.java From netbeans with Apache License 2.0 | 5 votes |
@Override public synchronized MetadataModel<WebAppMetadata> getMetadataModel() { if (webAppMetadataModel == null) { final FileObject ddFO = getDeploymentDescriptor(); final FileObject webInf = getOrCreateWebInf(); if (ddFO == null && webInf != null) { webInf.addFileChangeListener(new FileChangeAdapter() { @Override public void fileDataCreated(FileEvent fe) { if ("web.xml".equals(fe.getFile().getNameExt())) { // NOI18N webInf.removeFileChangeListener(this); resetMetadataModel(); } } }); } File ddFile = ddFO != null ? FileUtil.toFile(ddFO) : null; ProjectSourcesClassPathProvider cpProvider = project.getLookup().lookup(ProjectSourcesClassPathProvider.class); MetadataUnit metadataUnit = MetadataUnit.create( cpProvider.getProjectSourcesClassPath(ClassPath.BOOT), cpProvider.getProjectSourcesClassPath(ClassPath.COMPILE), cpProvider.getProjectSourcesClassPath(ClassPath.SOURCE), ddFile); webAppMetadataModel = WebAppMetadataModelFactory.createMetadataModel(metadataUnit, true); } return webAppMetadataModel; }
Example #17
Source File: TplDataObject.java From netbeans with Apache License 2.0 | 5 votes |
private Charset cache(final Charset encoding) { if (!listeningOnContentChange.getAndSet(true)) { final FileObject primaryFile = getPrimaryFile(); primaryFile.addFileChangeListener(FileUtil.weakFileChangeListener(new FileChangeAdapter() { @Override public void fileChanged(FileEvent fe) { cachedEncoding = null; } }, primaryFile)); } cachedEncoding = encoding; LOG.log(Level.FINEST, "TplDataObject.getFileEncoding noncached {0}", new Object[] {encoding}); //NOI18N return encoding; }
Example #18
Source File: ExternalChangesTest.java From netbeans with Apache License 2.0 | 5 votes |
@RandomlyFails public void testLogExtCmd () throws Exception { waitForInitialScan(); FileChangeAdapter fca = new FileChangeAdapter(); workdirFO.addRecursiveListener(fca); FileUtil.refreshFor(repositoryLocation); Thread.sleep(11000); // some time for initial scans to finish and event logger to settle down File gitFolder = new File(repositoryLocation, ".git"); final File lockFile = new File(gitFolder, "index.lock"); Logger GESTURES_LOG = Logger.getLogger("org.netbeans.ui.vcs"); ExternalCommandUsageHandler h = new ExternalCommandUsageHandler(); GESTURES_LOG.addHandler(h); lockFile.createNewFile(); FileUtil.refreshFor(repositoryLocation); pause(); lockFile.delete(); FileUtil.refreshFor(repositoryLocation); h.waitForEvent(); assertNotNull(h.event); assertEquals(1, h.numberOfEvents); assertTrue(h.event.time > 0); assertEquals("GIT", h.event.vcs); assertEquals("UNKNOWN", h.event.command); assertTrue(h.event.external); assertEquals(Long.valueOf(0), h.event.modifications); GESTURES_LOG.removeHandler(h); workdirFO.removeRecursiveListener(fca); }
Example #19
Source File: HtmlDataObject.java From netbeans with Apache License 2.0 | 5 votes |
private Charset cache (final Charset encoding) { if (!listeningOnContentChange.getAndSet(true)) { final FileObject primaryFile = getPrimaryFile(); primaryFile.addFileChangeListener(FileUtil.weakFileChangeListener(new FileChangeAdapter(){ @Override public void fileChanged(FileEvent fe) { cachedEncoding = null; } },primaryFile)); } cachedEncoding = encoding; LOG.log(Level.FINEST, "HtmlDataObject.getFileEncoding noncached {0}", new Object[] {encoding}); //NOI18N return encoding; }
Example #20
Source File: VCSInterceptorTestCase.java From netbeans with Apache License 2.0 | 5 votes |
public void testRefreshRecursively() throws IOException { FileObject fo = getVersionedFolder(); fo = fo.createFolder("folder"); VCSFileProxy proxy = VCSFileProxy.createFileProxy(fo); logHandler.clear(); fo.addRecursiveListener(new FileChangeAdapter()); assertTrue(inteceptor.getRefreshRecursivelyFiles().contains(VCSFileProxy.createFileProxy(fo))); // XXX listFiles called twice on adding the listener. is this realy necessary assertInterceptedCalls( 1, 2, f(listFilesFormat, proxy) ); }
Example #21
Source File: AfterDeleteAfterMoveEndsTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testExternalyMoved() throws IOException { FileObject fo = getVersionedFolder(); FileObject fromFile = fo.createData("move.txt"); FileObject toFolder = fo.createFolder("toFolder"); fo.addFileChangeListener(new FileChangeAdapter()); inteceptor.startAcceptingEvents = true; FileObject toFile = fromFile.move(fromFile.lock(), toFolder, fromFile.getName(), fromFile.getExt()); VCSFileProxy fromProxy = VCSFileProxy.createFileProxy(fromFile); VCSFileProxy toProxy = VCSFileProxy.createFileProxy(toFile); assertEquals(ExternalyMovedInterceptor.DO_MOVE + " from " + fromProxy + " " + toProxy, inteceptor.events.get(0)); assertEquals(ExternalyMovedInterceptor.TIMEDOUT + " from " + fromProxy + " " + toProxy, inteceptor.events.get(1)); }
Example #22
Source File: RefreshWorkTest.java From netbeans with Apache License 2.0 | 5 votes |
protected @Override void setUp() throws IOException { this.clearWorkDir(); final File _wd = this.getWorkDir(); final FileObject wd = FileUtil.toFileObject(_wd); final FileObject cache = wd.createFolder("cache"); CacheFolder.setCacheFolder(cache); outerFolder1 = new File(getWorkDir(), "OuterFolder-1"); outerFolder1.mkdirs(); outerFolder2 = new File(getWorkDir(), "OuterFolder-2"); outerFolder2.mkdirs(); File rootAFile = new File(outerFolder1, "rootA"); rootAFile.mkdirs(); rootAUrl = Utilities.toURI(rootAFile).toURL(); scannedRoots2Dependencies.put(rootAUrl, Collections.<URL>emptyList()); File rootBFile = new File(outerFolder1, "rootB"); rootBFile.mkdirs(); rootBUrl = Utilities.toURI(rootBFile).toURL(); scannedRoots2Dependencies.put(rootBUrl, Collections.<URL>emptyList()); File rootCFile = new File(outerFolder2, "rootC"); rootCFile.mkdirs(); populateFolderStructure(rootCFile, "org/pckg1/file1.txt", "org/pckg1/pckg2/file1.txt", "org/pckg1/pckg2/file2.txt", "org/pckg2/" ); rootCUrl = Utilities.toURI(rootCFile).toURL(); scannedRoots2Dependencies.put(rootCUrl, Collections.<URL>emptyList()); RepositoryUpdater.getDefault().rootsListeners.setListener(new FileChangeAdapter(), new FileChangeAdapter()); }
Example #23
Source File: ExternalChangesTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testExternalCommandLoggedNoChanges () throws Exception { Mercurial.getInstance().getMercurialInterceptor().pingRepositoryRootFor(workdir); FileChangeAdapter fca = new FileChangeAdapter(); workdirFO.addRecursiveListener(fca); FileUtil.refreshFor(workdir); Thread.sleep(11000); // some time for initial scans to finish and event logger to settle down File hgFolder = new File(workdir, ".hg"); final File lockFile = new File(hgFolder, "wlock"); Logger GESTURES_LOG = Logger.getLogger("org.netbeans.ui.vcs"); ExternalCommandUsageHandler h = new ExternalCommandUsageHandler(); GESTURES_LOG.addHandler(h); lockFile.createNewFile(); FileUtil.refreshFor(workdir); pause(); lockFile.delete(); FileUtil.refreshFor(workdir); h.waitForEvent(); assertNotNull(h.event); assertEquals(1, h.numberOfEvents); assertTrue(h.event.time > 0); assertEquals("HG", h.event.vcs); assertEquals("UNKNOWN", h.event.command); assertTrue(h.event.external); assertEquals(Long.valueOf(0), h.event.modifications); GESTURES_LOG.removeHandler(h); workdirFO.removeRecursiveListener(fca); }
Example #24
Source File: ExternalChangesTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testExternalCommandLoggedChanges () throws Exception { Mercurial.getInstance().getMercurialInterceptor().pingRepositoryRootFor(workdir); FileChangeAdapter fca = new FileChangeAdapter(); workdirFO.addRecursiveListener(fca); File toAdd = new File(modifiedFile.getParentFile(), "toAdd"); File toDelete = new File(modifiedFile.getParentFile(), "toDelete"); toDelete.createNewFile(); FileUtil.refreshFor(workdir); Thread.sleep(11000); // some time for initial scans to finish and event logger to settle down File hgFolder = new File(workdir, ".hg"); final File lockFile = new File(hgFolder, "wlock"); Logger GESTURES_LOG = Logger.getLogger("org.netbeans.ui.vcs"); ExternalCommandUsageHandler h = new ExternalCommandUsageHandler(); GESTURES_LOG.addHandler(h); createLockFile(lockFile); FileUtil.refreshFor(workdir); // modification write(modifiedFile, "testExternalCommandLoggedChanges"); // delete toDelete.delete(); // create toAdd.createNewFile(); FileUtil.refreshFor(workdir); pause(); lockFile.delete(); FileUtil.refreshFor(workdir); h.waitForEvent(); assertNotNull(h.event); assertEquals(1, h.numberOfEvents); assertTrue(h.event.time > 0); assertEquals("HG", h.event.vcs); assertEquals("UNKNOWN", h.event.command); assertTrue(h.event.external); assertEquals(Long.valueOf(3), h.event.modifications); GESTURES_LOG.removeHandler(h); workdirFO.removeRecursiveListener(fca); }
Example #25
Source File: PlatformConvertor.java From netbeans with Apache License 2.0 | 5 votes |
private PlatformConvertor(@NonNull final XMLDataObject object) { Parameters.notNull("object", object); this.holder = object; this.holder.getPrimaryFile().addFileChangeListener( new FileChangeAdapter () { @Override public void fileDeleted (final FileEvent fe) { if (!defaultPlatform) { try { ProjectManager.mutex().writeAccess( new Mutex.ExceptionAction<Void> () { @Override public Void run () throws IOException { String systemName = fe.getFile().getName(); String propPrefix = "platforms." + systemName + "."; //NOI18N boolean changed = false; EditableProperties props = PropertyUtils.getGlobalProperties(); for (Iterator<String> it = props.keySet().iterator(); it.hasNext(); ) { String key = it.next (); if (key.startsWith(propPrefix)) { it.remove(); changed =true; } } if (changed) { PropertyUtils.putGlobalProperties(props); } return null; } }); } catch (MutexException e) { Exceptions.printStackTrace(e); } } } }); cookies = new InstanceContent(); cookies.add(this); lookup = new AbstractLookup(cookies); cookies.add(Node.class, this); }
Example #26
Source File: BaseFileObjectTestHid.java From netbeans with Apache License 2.0 | 5 votes |
public void testRefresh109490() throws Exception { final File wDir = new File(getWorkDir(), getName()); wDir.mkdir(); final FileObject wDirFo = FileUtil.toFileObject(wDir); final List<FileEvent> fileEvents = new ArrayList<FileEvent>(); FileSystem fs = wDirFo.getFileSystem(); FileChangeListener fListener = new FileChangeAdapter(){ @Override public void fileDataCreated(FileEvent fe) { super.fileDataCreated(fe); fileEvents.add(fe); } }; try { fs.refresh(true); // catch and skip changes made in VCS metadata, they are not part of this test fs.addFileChangeListener(fListener); File file = new File(wDir, "testao.f"); File file2 = new File(wDir, "testc1.f"); assertEquals(file.hashCode(), file2.hashCode()); wDirFo.getChildren(); assertTrue(file.createNewFile()); assertTrue(file2.createNewFile()); assertEquals(0, fileEvents.size()); fs.refresh(true); assertEquals(2, fileEvents.size()); assertEquals(Arrays.asList(wDirFo.getChildren()).toString(), 2,wDirFo.getChildren().length); assertTrue(Arrays.asList(wDirFo.getChildren()).toString().indexOf(file.getName()) != -1); assertTrue(Arrays.asList(wDirFo.getChildren()).toString().indexOf(file2.getName()) != -1); } finally { fs.removeFileChangeListener(fListener); } }
Example #27
Source File: BaseFileObjectTestHid.java From netbeans with Apache License 2.0 | 5 votes |
public void testCaseSensitiveRenameEventForMasterFS() throws Exception { FileObject parent = root.getFileObject("testdir").createFolder("parent"); FileObject file = parent.createData("origi.nal"); file.addFileChangeListener(new FileChangeAdapter() { @Override public void fileRenamed(FileRenameEvent fe) { assertEquals("origi", fe.getName()); assertEquals("nal", fe.getExt()); } }); FileLock lock = file.lock(); file.rename(lock, "Origi", "nal"); lock.releaseLock(); }
Example #28
Source File: FolderObjTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testRefresh43231() throws Exception { File thisTest = new File(getWorkDir(),getName()); thisTest.createNewFile(); FileObject testf = FileBasedFileSystem.getFileObject(thisTest); final List<FileEvent> l = new ArrayList<FileEvent>(); testf.addFileChangeListener(new FileChangeAdapter(){ @Override public void fileChanged(FileEvent fe) { if (l.isEmpty()) { fail(); } l.clear(); } }); //first refresh after initialization compares //lastModified with oldLastModified this way: //if (lastModified > oldLastModified) the fileChange assertTrue(thisTest.setLastModified(thisTest.lastModified() - 1000000)); testf.refresh(); assertTrue(l.isEmpty()); //every next refresh compares //lastModified with oldLastModified this way: //if (lastModified != oldLastModified) the fileChange l.add(new FileEvent(testf)); // make not empty assertTrue(thisTest.setLastModified(thisTest.lastModified()-10000)); testf.refresh(); assertTrue(l.isEmpty()); }
Example #29
Source File: FolderObjTest.java From netbeans with Apache License 2.0 | 5 votes |
/** * Test of delete method, of class org.netbeans.modules.masterfs.filebasedfs.fileobjects.FolderObj. */ public void testDelete() throws IOException { File f = testFile; FileObject testFo = FileBasedFileSystem.getFileObject(testFile); assertNotNull(testFo); final List<FileEvent> l = new ArrayList<FileEvent>(); FileChangeListener fcl = new FileChangeAdapter () { @Override public void fileDeleted(FileEvent fe) { l.add(fe); } }; FileObject fo = FileUtil.createData(testFo, "delete/the/whole/structure/in/depth/todelete.txt"); fo.addFileChangeListener(fcl); FileObject toDelete = testFo.getFileObject("delete"); assertNotNull(toDelete); toDelete.addFileChangeListener(fcl); FileObject toGC = testFo.getFileObject("delete/the/whole/structure"); assertNotNull(toGC); Reference<FileObject> toGCRef = new WeakReference<FileObject>(toGC); toGC.addFileChangeListener(fcl); toGC = null; assertGC("", toGCRef); toDelete.delete(); assertEquals(0,testFo.getChildren().length); toDelete = testFo.getFileObject("delete"); assertNull(toDelete); assertEquals(2, l.size()); }
Example #30
Source File: RemotePlatformProvider.java From netbeans with Apache License 2.0 | 5 votes |
private RemotePlatformProvider(@NonNull final XMLDataObject store) { Parameters.notNull("store", store); //NOI18N this.store = store; this.store.getPrimaryFile().addFileChangeListener(new FileChangeAdapter(){ @Override public void fileDeleted(@NonNull final FileEvent fe) { final String systemName = fe.getFile().getName(); try { ProjectManager.mutex().writeAccess( new Mutex.ExceptionAction<Void> () { @Override public Void run () throws IOException { final String propPrefix = String.format("platforms.%s.", systemName); //NOI18N boolean changed = false; final EditableProperties props = PropertyUtils.getGlobalProperties(); for (Iterator<String> it = props.keySet().iterator(); it.hasNext(); ) { final String key = it.next (); if (key.startsWith(propPrefix)) { it.remove(); changed =true; } } if (changed) { PropertyUtils.putGlobalProperties(props); } return null; } }); } catch (MutexException e) { Exceptions.printStackTrace(e); } ConnectionMethod.Authentification.clear(systemName); } }); final InstanceContent c = new InstanceContent(); c.add(Node.class, this); c.add(this); this.lkp = new AbstractLookup(c); task = RP.create(this); }