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

The following examples show how to use org.openide.filesystems.FileUtil#addFileChangeListener() . 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: OSXNotifierTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: ChangeLiveSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ChangeLiveSupport(V8Debugger dbg) {
    this.dbg = dbg;
    this.sourceChangeListener = new SourceChangeListener();
    this.sourceChangeRoots = dbg.getScriptsHandler().getLocalRoots();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("new ChangeLiveSupport(), sourceChangeRoots = "+Arrays.toString(sourceChangeRoots));
    }
    if (sourceChangeRoots.length == 0) {
        FileUtil.addFileChangeListener(sourceChangeListener);
    } else {
        for (File root : sourceChangeRoots) {
            FileUtil.addRecursiveListener(sourceChangeListener, root);
        }
    }
    dbg.addListener(new V8Debugger.Listener() {
        @Override public void notifySuspended(boolean suspended) {}

        @Override public void notifyCurrentFrame(CallFrame cf) {}

        @Override public void notifyFinished() {
            destroy();
        }
    });
}
 
Example 3
Source File: ProjectEar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void initialize() throws FileStateInvalidException {
    ProjectEar.this.project.evaluator().addPropertyChangeListener(this);

    if (!isCopyOnSaveEnabled()) {
        return;
    }
    
    if (resources != null) {
        FileUtil.removeFileChangeListener(this, resources);
    }
    resources = getResourceDirectory();

    if (resources != null) {
        FileUtil.addFileChangeListener(this, resources);
    }

    // Add deployed resources notification listener
    ProjectEar.this.getConfigSupport().addDeployOnSaveListener(this);

}
 
Example 4
Source File: WLSharedState.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public synchronized void configure(InstanceProperties ip) {
    if (domainListener != null) {
        return;
    }

    File domainConfig = WLPluginProperties.getDomainConfigFile(ip);
    if (domainConfig != null) {
        domainListener = new DomainChangeListener();
        // weak reference
        FileUtil.addFileChangeListener(domainListener, domainConfig);
    }
}
 
Example 5
Source File: MultiModuleUnitTestsCompilerOptionsQueryImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void safeAddFileListener(
        @NonNull final File file,
        @NonNull final FileChangeListener listener) {
    try {
        FileUtil.addFileChangeListener(listener, file);
    } catch (IllegalArgumentException e) {
        LOG.log(
                Level.WARNING,
                "Cannot add listener to: {0}",      //NOI18N
                file);
    }
}
 
Example 6
Source File: WebProject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void initialize() throws FileStateInvalidException {
    WebProject.this.evaluator().addPropertyChangeListener(this);

    if (!isCopyOnSaveEnabled()) {
        return;
    }

    docBase = getWebModule().getDocumentBase();
    docBaseValue = evaluator().getProperty(WebProjectProperties.WEB_DOCBASE_DIR);
    webInf = getWebModule().getWebInf();
    webInfValue = evaluator().getProperty(WebProjectProperties.WEBINF_DIR);
    if (resources != null) {
        FileUtil.removeFileChangeListener(this, resources);
    }
    resources = getWebModule().getResourceDirectory();
    buildWeb = evaluator().getProperty(WebProjectProperties.BUILD_WEB_DIR);
    buildClasses = evaluator().getProperty("build.classes.dir");

    if (docBase != null) {
        docBase.addRecursiveListener(this);
    }

    if (webInf != null && !FileUtil.isParentOf(docBase, webInf)) {
        webInf.addRecursiveListener(this);
    }

    if (resources != null) {
        FileUtil.addFileChangeListener(this, resources);
    }

    // Add deployed resources notification listener
    webModule.getConfigSupport().addDeployOnSaveListener(this);

    LOGGER.log(Level.FINE, "Web directory is {0}", docBaseValue);
    LOGGER.log(Level.FINE, "WEB-INF directory is {0}", webInfValue);
}
 
Example 7
Source File: MultiModuleNodeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Map<String,SourceGroup> getCache() {
    synchronized (this) {
        if (cache != null) {
            return cache;
        }
    }
    final File genSrc = Optional.ofNullable(eval.getProperty(sourceOutputProp))
            .map(helper.getAntProjectHelper()::resolveFile)
            .orElse(null);
    final Map<String,SourceGroup> m = new HashMap<>();
    if (genSrc != null) {
        if (listensOnFs.compareAndSet(false, true)) {
            FileUtil.addFileChangeListener(this, genSrc);
        }
        final FileObject genSrcFo = FileUtil.toFileObject(genSrc);
        if (genSrcFo != null) {
            Arrays.stream(genSrcFo.getChildren())
                    .filter(FileObject::isFolder)
                    .forEach((fo) -> m.put(fo.getNameExt(), new APSourceGroup(genSrcFo, fo)));
        }
    }
    synchronized (this) {
        if (cache == null) {
            cache = m;
            return m;
        } else {
            return cache;
        }
    }
}
 
Example 8
Source File: JavaSourceNodeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void addChangeListener(ChangeListener l) {
    synchronized (changeSupport) {
        final boolean shouldAdd = !changeSupport.hasListeners();
        changeSupport.addChangeListener(l);
        if (shouldAdd) {
            FileUtil.addFileChangeListener(genSrcDirListener, genSrcDir);
        }
    }
}
 
Example 9
Source File: J2SEActionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void safeAddFileChangeListener(@NonNull final File f) {
    try {
        FileUtil.addFileChangeListener(this, f);
    } catch (IllegalArgumentException e) {
        //not important
    }
}
 
Example 10
Source File: RuntimePlatformProblemsProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initListeners() {
    if (listens.compareAndSet(false, true)) {
        final JavaPlatformManager jpm = JavaPlatformManager.getDefault();
        jpm.addPropertyChangeListener(WeakListeners.propertyChange(
            this,
            jpm));
        J2SEProject j2sePrj = project.getLookup().lookup(J2SEProject.class);
        if (j2sePrj != null) {
            j2sePrj.evaluator().addPropertyChangeListener(this);
        } else {
            LOG.log(
               Level.WARNING,
               "No property evaluator provider in project {0}({1})", //NOI18N
               new Object[]{
                   ProjectUtils.getInformation(project).getDisplayName(),
                   FileUtil.getFileDisplayName(project.getProjectDirectory())
               });
        }

        final FileObject projectFolder = project.getProjectDirectory();
        if (projectFolder != null) {
            final File projectDir = FileUtil.toFile(projectFolder);
            if (projectDir != null) {
                final File cfgDir = new File(projectDir, CFG_PATH);   //NOI18N
                FileUtil.addFileChangeListener(this, cfgDir);
            }
        }
    }
}
 
Example 11
Source File: WatchedFile.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private synchronized File getWatchedFile() {
    if (file == null) {
        file = FileUtil.normalizeFile(new File(FileUtil.toFile(directory), filename)); // #254561
        try {
            FileUtil.addFileChangeListener(fileListener, file);
            LOGGER.log(Level.FINE, "Started listening to {0}", file);
        } catch (IllegalArgumentException ex) {
            // ignore, already listening
            LOGGER.log(Level.FINE, "Already listening to {0}", file);
        }
    }
    return file;
}
 
Example 12
Source File: DomainXMLChangeListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Register this listener for Payara instance configuration file
 * <code>domain.xml</code> changes.
 * <p/>
 * @param instance Payara server instance.
 * @return Payara configuration file <code>domain.xml</code> changes
 *         listener created and registered.
 */
public static void registerListener(
        PayaraInstance instance) {
    String domainDirPath = instance.getDomainsFolder();
    String domainName = instance.getDomainName();
    String domainXMLName = org.netbeans.modules.payara.tooling.utils.ServerUtils
            .getDomainConfigFile(domainDirPath, domainName);
    File configPAth = FileUtil.normalizeFile(new File(domainXMLName));
    FileUtil.addFileChangeListener(
            instance.getDomainXMLChangeListener(), configPAth);
}
 
Example 13
Source File: ModuleInfoSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ModuleInfoSupport(NbMavenProjectImpl project, DependencyType type) {
    this.project = project;
    this.type = type;        
    
    Collection<String> roots = getRoots(project.getOriginalMavenProject(), type);
    for (String root : roots) {
        FileUtil.addFileChangeListener(moduleInfoListener, new File(root));
    }        
    moduleInfo = getModuleInfo(roots);
    if(moduleInfo != null) {
        populateDeclaredModules(moduleInfo);
    }
}
 
Example 14
Source File: ClassPath.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void safeAddFileChangeListener(@NonNull final File file) {
    try {
        FileUtil.addFileChangeListener(this, file);
    } catch (IllegalArgumentException iae) {
        LOG.log(Level.FINE, iae.getMessage());
    }
}
 
Example 15
Source File: CacheFolderArchive.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public CacheFolderArchive(
        @NonNull File cache) {
    Parameters.notNull("cache", cache); //NOI18N
    this.cache = cache;
    if (cache.isDirectory()) {
        delegate = new FolderArchive(cache);
    } else {
        FileUtil.addFileChangeListener(this, cache);
        delegate = Archive.EMPTY;
    }
}
 
Example 16
Source File: ProjectClassPathImplementation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void updateListener(FileChangeListener listener, File oldDir, File newDir) {
    if (oldDir == null || !oldDir.equals(newDir)) {
        if (oldDir != null) {
            FileUtil.removeFileChangeListener(listener, oldDir);
        }
        if (newDir != null) {
            FileUtil.addFileChangeListener(listener, newDir);
        }
    }
}
 
Example 17
Source File: ModuleNames.java    From netbeans with Apache License 2.0 5 votes vote down vote up
FileCacheLine(
        @NonNull final URL artefact,
        @NullAllowed final String modName,
        @NonNull final File path) {
    super(artefact, modName);
    this.path = path;
    FileUtil.addFileChangeListener(this, path);
}
 
Example 18
Source File: RepositoryForBinaryQueryImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
JavadocResult(@NullAllowed String groupId, @NullAllowed String artifactId, @NullAllowed String version, @NullAllowed String classifier, @NonNull URL binary, @NullAllowed File javadocJar, @NonNull Function<File, List<Coordinates>> coorProvider) {
    javadocJarFile = javadocJar;
    this.groupId = groupId;
    this.artifactId = artifactId;
    this.version = version;
    this.binary = binary;
    this.classifier = classifier;
    this.gav = MavenFileOwnerQueryImpl.cacheKey(groupId, artifactId, version);
    this.coorProvider = coorProvider;

    support = new ChangeSupport(this);
    mfoListener = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            //external root in local repository changed..
            checkChanges();
        }
    };
    projectListener = new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (NbMavenProject.PROP_PROJECT.equals(event.getPropertyName())) {
                checkChanges();
            }
        }
    };
    javadocJarChangeListener = new FileChangeAdapter() {
        @Override
        public void fileDataCreated(FileEvent fe) {
            //source jar was created..
            checkChanges();
        }

    };
    MavenFileOwnerQueryImpl.getInstance().addChangeListener(
            WeakListeners.create(ChangeListener.class, mfoListener, MavenFileOwnerQueryImpl.getInstance()));
    if (javadocJarFile != null) {
        FileUtil.addFileChangeListener(javadocJarChangeListener, javadocJarFile);
        if (classifier != null) {
            // listen for regular javadoc because attached javadoc for classifier might be missing
            String regularJavadoc = artifactId + "-" + version + "-javadoc.jar"; //NOI18N
            if (!javadocJarFile.getName().equals(regularJavadoc)) {
                fallbackJavadocJarFile = new File(javadocJarFile.getParentFile(), regularJavadoc);
                FileUtil.addFileChangeListener(javadocJarChangeListener, fallbackJavadocJarFile);
                return;
            }
        }
    }
    fallbackJavadocJarFile = null;
}
 
Example 19
Source File: SiteDocsNodeFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void addNotify() {
    NbMavenProject.addPropertyChangeListener(project, this);
    FileUtil.addFileChangeListener(this, Utilities.toFile(project.getSiteDirectory()));
}
 
Example 20
Source File: AntProjectHelper.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void lazyAttachFileListener() {
    if (fileListenerSet.compareAndSet(false, true)) {
        FileUtil.addFileChangeListener(fileListener, resolveFile(PROJECT_XML_PATH));
        FileUtil.addFileChangeListener(fileListener, resolveFile(PRIVATE_XML_PATH));
    }
}