Java Code Examples for org.openide.filesystems.FileChangeAdapter

The following examples show how to use org.openide.filesystems.FileChangeAdapter. These examples are extracted from open source projects. 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 Project: netbeans   Source File: OSXNotifierTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 2
Source Project: netbeans   Source File: OSXNotifierTest.java    License: 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 3
Source Project: netbeans   Source File: WatcherDeadlockTest.java    License: Apache License 2.0 6 votes vote down vote up
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 4
Source Project: netbeans   Source File: FolderObjTest.java    License: Apache License 2.0 6 votes vote down vote up
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 5
Source Project: netbeans   Source File: WatcherTest.java    License: Apache License 2.0 6 votes vote down vote up
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 6
Source Project: netbeans   Source File: LinuxNotifier235632Test.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 7
Source Project: netbeans   Source File: TimesCollectorPeer.java    License: Apache License 2.0 6 votes vote down vote up
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 8
Source Project: netbeans   Source File: ProjectWebModule.java    License: Apache License 2.0 6 votes vote down vote up
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 9
Source Project: netbeans   Source File: WsitPojectOpenedHook.java    License: Apache License 2.0 6 votes vote down vote up
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 10
Source Project: netbeans   Source File: AnnotationTypesFolder.java    License: Apache License 2.0 6 votes vote down vote up
/** 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 11
Source Project: netbeans   Source File: NbEditorToolBar.java    License: Apache License 2.0 6 votes vote down vote up
/** 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 12
Source Project: netbeans   Source File: PlatformConvertor.java    License: Apache License 2.0 5 votes vote down vote up
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 13
Source Project: netbeans   Source File: RemotePlatformProvider.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 14
Source Project: netbeans   Source File: ExternalTouchTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testNewChildNoticed() throws Exception {
    FileObject fileObject1 = testFolder.createData("fileObject1");
    FileObject[] arr = testFolder.getChildren();
    assertEquals("One child", 1, arr.length);
    assertEquals("Right child", fileObject1, arr[0]);

    File file = FileUtil.toFile(fileObject1);
    assertNotNull("File found", file);
    arr = null;
    fileObject1 = null;
    Reference<FileObject> ref = new WeakReference<FileObject>(fileObject1);
    assertGC("File Object can disappear", ref);

    Thread.sleep(100);

    class L extends FileChangeAdapter {
        int cnt;
        FileEvent event;

        @Override
        public void fileDataCreated(FileEvent fe) {
            cnt++;
            event = fe;
        }

    }
    L listener = new L();
    testFolder.addRecursiveListener(listener);

    File nfile = new File(file.getParentFile(), "new.txt");
    nfile.createNewFile();

    testFolder.refresh();

    assertEquals("Change notified", 1, listener.cnt);
    assertEquals("Right file", nfile, FileUtil.toFile(listener.event.getFile()));
}
 
Example 15
Source Project: netbeans   Source File: ExternalTouchTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testDeleteOfAChildNoticed() throws Exception {
    FileObject fileObject1 = testFolder.createData("fileObject1");
    FileObject[] arr = testFolder.getChildren();
    assertEquals("One child", 1, arr.length);
    assertEquals("Right child", fileObject1, arr[0]);

    File file = FileUtil.toFile(fileObject1);
    assertNotNull("File found", file);
    arr = null;
    fileObject1 = null;
    Reference<FileObject> ref = new WeakReference<FileObject>(fileObject1);
    assertGC("File Object can disappear", ref);

    Thread.sleep(100);

    class L extends FileChangeAdapter {
        int cnt;
        FileEvent event;

        @Override
        public void fileDeleted(FileEvent fe) {
            cnt++;
            event = fe;
        }

    }
    L listener = new L();
    testFolder.addRecursiveListener(listener);

    file.delete();

    testFolder.refresh();

    assertEquals("Change notified", 1, listener.cnt);
    assertEquals("Right file", file, FileUtil.toFile(listener.event.getFile()));
}
 
Example 16
Source Project: netbeans   Source File: FolderObjTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testAsyncCall() throws Exception {
    final FileObject workDirFo = FileBasedFileSystem.getFileObject(getWorkDir());
    File f = new File(getWorkDir(), "a");
    assertNull(workDirFo.getFileObject("a"));
    assertTrue(f.createNewFile());
    final Thread t = Thread.currentThread();
    class FileChange extends FileChangeAdapter {
        private boolean called = false;
        @Override
        public void fileDataCreated(FileEvent fe) {
            assertNotSame(t, Thread.currentThread());
            called = true;
            synchronized (workDirFo) {
                workDirFo.notifyAll();
            }
        }
        public boolean isCalled() {
            return called;
        }            
    } 
    FileChange fcl = new FileChange();
    workDirFo.addFileChangeListener(fcl);
    try {
        assertNotNull(FileUtil.toFileObject(f));
        synchronized(workDirFo) {
            workDirFo.wait();
        }
        assertNotNull(workDirFo.getFileObject("a"));                
        assertTrue(fcl.isCalled());
    } finally {
        workDirFo.removeFileChangeListener(fcl);
    }
}
 
Example 17
Source Project: netbeans   Source File: FolderObjTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testRefresh109490() throws Exception {
    final File wDir = getWorkDir();
    final FileObject wDirFo = FileBasedFileSystem.getFileObject(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.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 18
Source Project: netbeans   Source File: FolderObjTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 19
Source Project: netbeans   Source File: FolderObjTest.java    License: Apache License 2.0 5 votes vote down vote up
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 20
Source Project: netbeans   Source File: BaseFileObjectTestHid.java    License: Apache License 2.0 5 votes vote down vote up
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 21
Source Project: netbeans   Source File: BaseFileObjectTestHid.java    License: Apache License 2.0 5 votes vote down vote up
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 22
Source Project: netbeans   Source File: LinuxNotifier235632Test.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Prepare folders and files for testing.
 *
 * <pre>
 * - folder1          (only java.io.File)
 *    - text1.txt     (only java.io.File)
 * - folder2          (FileObject)
 *    - text2.txt     (FileObject, with registered listener)
 * </pre>
 *
 * @throws IOException
 */
private void prepareFiles() throws IOException {
    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");
    // Causes the path to be registered in the notifier.
    folder2text2TxtFO.addFileChangeListener(new FileChangeAdapter());
    folder2FO.refresh();
}
 
Example 23
Source Project: netbeans   Source File: DataShadowTest.java    License: Apache License 2.0 5 votes vote down vote up
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 24
Source Project: netbeans   Source File: LocalizedBundleInfo.java    License: Apache License 2.0 5 votes vote down vote up
/** 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 25
Source Project: netbeans   Source File: WebModuleImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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 26
Source Project: netbeans   Source File: WebModuleImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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 27
Source Project: netbeans   Source File: TplDataObject.java    License: Apache License 2.0 5 votes vote down vote up
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 28
Source Project: netbeans   Source File: ExternalChangesTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 29
Source Project: netbeans   Source File: VCSInterceptorTest.java    License: 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 30
Source Project: netbeans   Source File: VCSInterceptorTestCase.java    License: 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)
    );            
}