Java Code Examples for org.openide.filesystems.FileObject#addRecursiveListener()

The following examples show how to use org.openide.filesystems.FileObject#addRecursiveListener() . 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: SourceMapsScanner.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void init(Project p) {
    Sources sources = ProjectUtils.getSources(p);
    sources.addChangeListener(this);
    SourceGroup[] groups = sources.getSourceGroups(Sources.TYPE_GENERIC);
    roots = new FileObject[groups.length];
    for (int i = 0; i < groups.length; i++) {
        SourceGroup group = groups[i];
        FileObject rootFolder = group.getRootFolder();
        roots[i] = rootFolder;
        rootFolder.addRecursiveListener(this);
        //scan(rootFolder);
        rootsToScan.add(rootFolder);
    }
    scanningTask = RP.post(this);
    DependencyProjectProvider prov = p.getLookup().lookup(DependencyProjectProvider.class);
    if (prov != null) {
        projectDependencyManager = new ProjectDependencyManager(prov);
    }
}
 
Example 2
Source File: FileUtilAddRecursiveListenerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testProvideExtensionsRefreshRecursively() throws Exception {
    File root = new File(getWorkDir(), "root");
    final File sub = new File(root, "sub");
    final File subsub = new File(sub, "subsub");
    File subsubdir = new File(subsub, "dir");
    subsubdir.mkdirs();
    File subfile = new File(sub, "file");
    subfile.createNewFile();
    File deepfile = new File(subsubdir, "deep");
    deepfile.createNewFile();

    ProvidedExtensionsTest.ProvidedExtensionsImpl.nextRefreshCall(
        sub,
        Long.MAX_VALUE - 10,
        subfile
    );


    TestFileChangeListener fcl = new TestFileChangeListener();
    FileObject rf = FileUtil.toFileObject(root);
    rf.addRecursiveListener(fcl);

    BaseFileObj noFO = FileObjectFactory.getInstance(root).getCachedOnly(subsubdir);
    assertNull("subsub directory has been skipped", noFO);

    assertEquals("No events", 0, fcl.checkAll());
    LOG.log(Level.INFO, "Touching subfile: {0}", deepfile);
    TestFileUtils.touch(deepfile, null);
    LOG.log(Level.INFO, "Will do refresh, lastModified: {0}", deepfile.lastModified());
    FileUtil.refreshFor(root);
    LOG.info("Refresh done");
    fcl.check(EventType.ATTRIBUTE_CHANGED); // ignore if any

    fcl.printAll(LOG);
    assertEquals("No other events", 0, fcl.checkAll());
}
 
Example 3
Source File: VCSInterceptorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 4
Source File: VCSInterceptorTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 5
Source File: AndroidResValuesProvider.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private void init() {
    for (File srcDir : androidProject.getDefaultConfig().getSourceProvider().getResDirectories()) {
        if (!srcDir.exists() || srcDir.isFile()) {
            continue;
        }
        FileObject fo = FileUtil.toFileObject(srcDir).getFileObject("values");
        if (fo != null && fo.isValid() && fo.isFolder()) {
            parseFolder(fo);
            fo.addRecursiveListener(WeakListeners.create(FileChangeListener.class, this, fo));
        }
    }
}
 
Example 6
Source File: ListenerAttacher.java    From editorconfig-netbeans with MIT License 5 votes vote down vote up
/**
 * Recursively attach listeners to folders containing a .editorconfig file.
 *
 * @param file file or folder to attach listener
 * @param project the project the file is related to
 */
public static void attachListeners(FileObject file, Project project) {
  if (project.getProjectDirectory().equals(file)) {
    ProjectChangeListener projectChangeListener = new ProjectChangeListener(project);
    LISTENER_REGISTRY.put(file, projectChangeListener);
    file.addRecursiveListener(projectChangeListener);
  }

  if (file.isFolder()) {
    if (SmartSkip.skipDirectory(file)) {
      LOG.log(Level.INFO, "\u00ac Skipped directory: {0}", file.getPath());
    } else {
      for (FileObject child : file.getChildren()) {
        attachListeners(child, project);
      }
    }
  } else {
    if (file.getExt().equals(EXTENSION) || file.getName().equals(DEFAULT_FILE_NAME)) {
      EditorConfigChangeListener editorConfigChangeListener = new EditorConfigChangeListener(project, file);
      LISTENER_REGISTRY.put(file, editorConfigChangeListener);
      file.addFileChangeListener(editorConfigChangeListener);
      LOG.log(Level.INFO, "\u00ac Found EditorConfig: {0}", file.getPath());
    } else {
      LOG.log(Level.FINE, "\u00ac No EditorConfig Found: {0}", file.getPath());
    }
  }
}