Java Code Examples for org.openide.filesystems.FileUtil#removeRecursiveListener()

The following examples show how to use org.openide.filesystems.FileUtil#removeRecursiveListener() . 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: PhpProject.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void removeSourceDirListener() {
    FileObject sourceDir = sourceDirectoryFileChangeListener.getSourceDir();
    if (sourceDir == null) {
        // not listening
        return;
    }
    synchronized (sourceDirectoryFileChangeListener) {
        try {
            FileUtil.removeRecursiveListener(sourceDirectoryFileChangeListener, FileUtil.toFile(sourceDir));
        } catch (IllegalArgumentException ex) {
            LOGGER.log(Level.INFO, null, ex);
        } finally {
            sourceDirectoryFileChangeListener.setSourceDir(null);
        }
    }
}
 
Example 2
Source File: CopyResourcesOnSave.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public final void closed() {
    nbproject.removePropertyChangeListener(pchl);
    synchronized (resourceUris) {
        for (File fl : resourceUris) {
            FileUtil.removeRecursiveListener(this, fl);
        }
        resourceUris.clear();
    }
}
 
Example 3
Source File: CopyResourcesOnSave.java    From netbeans with Apache License 2.0 5 votes vote down vote up
final void refresh() {
    synchronized (resourceUris) {
        List<Resource> resources = new ArrayList<Resource>();
        resources.addAll(nbproject.getMavenProject().getResources());
        resources.addAll(nbproject.getMavenProject().getTestResources());
        Set<File> old = new HashSet<File>(resourceUris);
        Set<File> added = new HashSet<File>();
        
            for (Resource res : resources) {
                String dir = res.getDirectory();
                if (dir == null) {
                    continue;
                }
                URI uri = FileUtilities.getDirURI(project.getProjectDirectory(), dir);
                File file = Utilities.toFile(uri);
                if (!old.contains(file) && !added.contains(file)) { // if a given file is there multiple times, we get assertion back from FileUtil. there can be only one listener+file tuple
                    FileUtil.addRecursiveListener(this, file);
                }
                added.add(file);
            }
        
        old.removeAll(added);
        for (File oldFile : old) {
            FileUtil.removeRecursiveListener(this, oldFile);
        }
        resourceUris.removeAll(old);
        resourceUris.addAll(added);
    }
}
 
Example 4
Source File: RecursiveListenerOnOffTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testRecursiveListenerIsOn() throws Exception {
    clearWorkDir();
    
    final File rootF = getWorkDir();
    final File dirF = new File(rootF, "dir");
    File fileF = new File(dirF, "file1");
    File subdirF = new File(dirF, "subdir");
    File subfileF = new File(subdirF, "subfile");
    File subsubdirF = new File(subdirF, "subsubdir");
    File subsubfileF = new File(subsubdirF, "subsubfile");
    subsubdirF.mkdirs();

    TestFileChangeListener fcl = new TestFileChangeListener();
    FileUtil.addRecursiveListener(fcl, dirF);
    
    FileObject fo = FileUtil.toFileObject(subsubdirF);
    assertNotNull("Found", fo);
    assertEquals("It is folder", FolderObj.class, fo.getClass());
    FolderObj obj = (FolderObj)fo;
    
    assertTrue("There is a listener around", obj.hasRecursiveListener());
    
    FileUtil.addRecursiveListener(fcl, subdirF);
    
    assertTrue("There is still a listener around", obj.hasRecursiveListener());
    
    FileUtil.removeRecursiveListener(fcl, dirF);

    assertTrue("Listener still remains around", obj.hasRecursiveListener());
    
    FileUtil.removeRecursiveListener(fcl, subdirF);
    assertFalse("No Listener anymore", obj.hasRecursiveListener());

    LOG.info("OK");
}
 
Example 5
Source File: ClientSideProject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private synchronized void removeSiteRootListener() {
    if (siteRootFolder == null) {
        // no listener
        return;
    }
    try {
        FileUtil.removeRecursiveListener(siteRootChangesListener, siteRootFolder);
    } catch (IllegalArgumentException ex) {
        // #216349
        LOGGER.log(Level.INFO, null, ex);
    }
    siteRootFolder = null;
}
 
Example 6
Source File: ChangeLiveSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void destroy() {
    if (sourceChangeRoots.length == 0) {
        FileUtil.removeFileChangeListener(sourceChangeListener);
    } else {
        for (File root : sourceChangeRoots) {
            FileUtil.removeRecursiveListener(sourceChangeListener, root);
        }
    }
}
 
Example 7
Source File: ArtifactCopyOnSaveSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public final void close() {
    synchronized (this) {
        for (Map.Entry<File, ItemDescription> entry : listeningTo.entrySet()) {
            FileUtil.removeRecursiveListener(this, entry.getKey());
        }
        listeningTo.clear();
    }
    antHelper.removeAntProjectListener(this);
    evaluator.removePropertyChangeListener(this);
}
 
Example 8
Source File: RecursiveListenerOnOffTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testRecursiveListenerInsideRenamedFolder() throws Exception {

        final FileObject wd = FileUtil.toFileObject(getWorkDir());
        final FileObject prj = wd.createFolder("prj");          //NOI18N
        final FileObject src = prj.createFolder("src");         //NOI18N
        final FileObject pkg = src.createFolder("pkg");         //NOI18N
        final FileObject file = pkg.createData("Test","java");  //NOI18N

        class FL extends FileChangeAdapter {

            private final Semaphore sem = new Semaphore(0);
            private final Queue<File> waitFor = new ArrayDeque<File>();

            public synchronized void expect(final File... files) {
                waitFor.addAll(Arrays.asList(files));
            }

            public boolean await() throws InterruptedException {
                final int size;
                synchronized (this) {
                    size = waitFor.size();
                }
                return sem.tryAcquire(size, TIMEOUT, TimeUnit.SECONDS);
            }

            @Override
            public void fileChanged(FileEvent fe) {
                final File f = FileUtil.toFile(fe.getFile());
                final boolean remove;
                synchronized (this) {
                    remove = waitFor.remove(f);
                }
                if (remove) {
                    sem.release();
                }
            }

        }

        final FL fl = new FL();
        final File srcDir = FileUtil.toFile(src);
        FileUtil.addRecursiveListener(fl, srcDir);
        FileLock lck = prj.lock();
        try {
            prj.rename(lck, "prj2", null);      //NOI18N
        } finally {
            lck.releaseLock();
        }
        FileUtil.removeRecursiveListener(fl, srcDir);
        final File newSrcDir = FileUtil.toFile(src);
        FileUtil.addRecursiveListener(fl, newSrcDir);
        fl.expect(FileUtil.toFile(file));
        lck = file.lock();
        try {
            final OutputStream out = file.getOutputStream(lck);
            out.write(1);
            out.close();
        } finally {
            lck.releaseLock();
        }
        assertTrue(fl.await());
    }
 
Example 9
Source File: CoverageWatcher.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void stop() {
    FileUtil.removeRecursiveListener(fileChangeListener, coverageDir);
}