[hg] main-silver: #223341:Use VisibilityQueryChangeEvent to prev...

  • From: Tomas Zezula < >
  • To:
  • Subject: [hg] main-silver: #223341:Use VisibilityQueryChangeEvent to prev...
  • Date: Thu, 06 Dec 2012 11:30:22 -0800

changeset e03e4ec416cb in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/e03e4ec416cb
description:
        #223341:Use VisibilityQueryChangeEvent to prevent rescan of all 
sources

diffstat:

 
parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java
              |   32 +-
 parsing.api/src/org/netbeans/modules/parsing/impl/indexing/TimeStamps.java   
                  |   49 ++
 
parsing.api/src/org/netbeans/modules/parsing/impl/indexing/VisibilitySupport.java
              |  164 +++++++-
 
parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/VisibilityChangeTest.java
 |  197 ++++++++-
 4 files changed, 399 insertions(+), 43 deletions(-)

diffs (651 lines):

diff --git 
a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java
 
b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java
--- 
a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java
+++ 
b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java
@@ -335,6 +335,28 @@
         }
     }
     
+    void addDeleteJob(
+        @NonNull final URL root,
+        @NonNull final Set<String> relativePaths,
+        @NonNull final LogContext logCtx) {
+        final Work wrk = new DeleteWork(
+            root,
+            relativePaths,
+            suspendSupport.getSuspendStatus(),
+            logCtx);
+        scheduleWork(wrk, false);
+    }
+
+    void addBinaryJob(
+        @NonNull final URL root,
+        @NonNull final LogContext logCtx) {
+        final Work wrk = new BinaryWork(
+            root,
+            suspendSupport.getSuspendStatus(),
+            logCtx);
+        scheduleWork(wrk, false);
+    }
+    
     public void enforcedFileListUpdate(
             @NonNull final URL rootUrl,
             @NonNull final Collection<? extends URL> fileUrls) {        
@@ -1558,7 +1580,7 @@
         }
     }
 
-    private Pair<URL, FileObject> getOwningBinaryRoot(final FileObject fo) {
+    Pair<URL, FileObject> getOwningBinaryRoot(final FileObject fo) {
         if (fo == null) {
             return null;
         }
@@ -3433,11 +3455,17 @@
                 final 
Map<Pair<String,Integer>,Pair<SourceIndexerFactory,Context>> contexts = new 
HashMap<Pair<String,Integer>,Pair<SourceIndexerFactory,Context>>();
                 final UsedIndexables usedIterables = new UsedIndexables();
                 final SourceIndexers indexers = SourceIndexers.load(false);
+                final TimeStamps ts = TimeStamps.forRoot(root, false);
                 try {
                     scanStarted(root, false, indexers, votes, contexts);
                     delete(indexables, contexts, usedIterables);
+                    ts.remove(relativePaths);
                 } finally {
-                    scanFinished(contexts.values(), usedIterables, 
!getCancelRequest().isRaised());
+                    final boolean finished = !getCancelRequest().isRaised();
+                    if (finished) {
+                        ts.store();
+                        scanFinished(contexts.values(), usedIterables, 
finished);
+                    }
                 }
                 TEST_LOGGER.log(Level.FINEST, "delete"); //NOI18N
             } catch (IOException ioe) {
diff --git 
a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/TimeStamps.java 
b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/TimeStamps.java
--- 
a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/TimeStamps.java
+++ 
b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/TimeStamps.java
@@ -53,6 +53,7 @@
 import java.io.OutputStreamWriter;
 import java.net.URL;
 import java.text.MessageFormat;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Map;
@@ -64,6 +65,7 @@
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
 import org.openide.filesystems.URLMapper;
+import org.openide.util.Parameters;
 
 /**
  *
@@ -102,6 +104,21 @@
         impl.reset(now);
     }
 
+    void remove(@NonNull final Iterable<? extends String> relativePaths) {
+        Parameters.notNull("relativePaths", relativePaths); //NOI18N
+        impl.remove(relativePaths);
+    }
+
+    @NonNull
+    Collection<? extends String> getEnclosedFiles(@NonNull String folder) {
+        Parameters.notNull("folder", folder);           //NOI18N
+        if (folder.charAt(folder.length()-1) != '/') {  //NOI18N
+            folder = folder + '/';                      //NOI18N
+        }
+        Collection<? extends String> res = impl.getEnclosedFiles(folder);
+        return res;
+    }
+
     public static TimeStamps forRoot(
             @NonNull final URL root,
             final boolean detectDeletedFiles) throws IOException {
@@ -127,6 +144,9 @@
         boolean checkAndStoreTimestamp(FileObject root, String relativePath);
         Set<String> getUnseenFiles();
         void reset(long time);
+        void remove(@NonNull Iterable<? extends String> relativePaths);
+        @NonNull
+        Collection<? extends String> getEnclosedFiles(@NonNull String 
relativePath);
         void store() throws IOException;
     }
     
@@ -195,6 +215,25 @@
         }
 
         @Override
+        public void remove(@NonNull final Iterable<? extends String> 
relativePaths) {
+            for (String relPath : relativePaths) {
+                timestamps.remove(relPath);
+            }
+        }
+
+        @NonNull
+        @Override
+        public Collection<? extends String> getEnclosedFiles(@NonNull final 
String relativePath) {
+            final Set<String> res = new HashSet<String>();
+            for (String filePath : timestamps.keySet()) {
+                if (filePath.startsWith(relativePath)) {
+                    res.add(filePath);
+                }
+            }
+            return res;
+        }
+
+        @Override
         public void store() throws IOException {
             final File cacheDir = 
FileUtil.toFile(CacheFolder.getDataFolder(root));
             final File f = new File(cacheDir, TIME_STAMPS_FILE);
@@ -337,6 +376,16 @@
         }
 
         @Override
+        public void remove(@NonNull final Iterable<? extends String> 
relativePaths) {
+        }
+
+        @NonNull
+        @Override
+        public Collection<? extends String> getEnclosedFiles(@NonNull final 
String relativePath) {
+            return Collections.<String>emptySet();
+        }
+
+        @Override
         public void store() throws IOException {
         }
     }
diff --git 
a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/VisibilitySupport.java
 
b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/VisibilitySupport.java
--- 
a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/VisibilitySupport.java
+++ 
b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/VisibilitySupport.java
@@ -41,10 +41,21 @@
  */
 package org.netbeans.modules.parsing.impl.indexing;
 
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Deque;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 import java.util.WeakHashMap;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.logging.Level;
@@ -54,7 +65,10 @@
 import org.netbeans.api.annotations.common.NonNull;
 import org.netbeans.api.annotations.common.NullAllowed;
 import org.netbeans.api.queries.VisibilityQuery;
+import org.netbeans.spi.queries.VisibilityQueryChangeEvent;
 import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
 import org.openide.util.Parameters;
 import org.openide.util.RequestProcessor;
 
@@ -64,18 +78,19 @@
  */
 class VisibilitySupport implements ChangeListener {
 
-    private static final int VISIBILITY_CHANGE_WINDOW = 500;
+    private static final int VISIBILITY_CHANGE_WINDOW = 1000;
     private static final Logger LOGGER = 
Logger.getLogger(VisibilitySupport.class.getName());
     
     //@GuardedBy("visibilityCache")
     private final Map<FileObject,Boolean> visibilityCache = 
Collections.synchronizedMap(new WeakHashMap<FileObject, Boolean>());    
-    private final AtomicReference<LogContext> visibilityLogCtx = new 
AtomicReference<LogContext>();
+    private final SlidingTask visibilityTask;
     private final RequestProcessor.Task visibilityChanged;
     
     private VisibilitySupport(
             @NonNull final RepositoryUpdater ru,
             @NonNull final RequestProcessor worker) {
-        this.visibilityChanged = worker.create(new SlidingTask(ru));
+        this.visibilityTask = new SlidingTask(ru);
+        this.visibilityChanged = worker.create(this.visibilityTask);
     }
 
     void start() {
@@ -139,25 +154,158 @@
     public void stateChanged(ChangeEvent e) {
         visibilityCache.clear();
         if (Crawler.listenOnVisibility()) {
-            if (visibilityLogCtx.get()==null) {
-                visibilityLogCtx.compareAndSet(null, 
LogContext.create(LogContext.EventType.FILE, null));
+            if (e instanceof VisibilityQueryChangeEvent) {
+                final FileObject[] affectedFiles = 
((VisibilityQueryChangeEvent)e).getFileObjects();
+                visibilityTask.localChange(affectedFiles);
+            } else {
+                visibilityTask.globalChange();
             }
             visibilityChanged.schedule(VISIBILITY_CHANGE_WINDOW);
         }
     }
 
-    private class SlidingTask implements Runnable {
+    private static class SlidingTask implements Runnable {
 
         private final RepositoryUpdater ru;
 
+        //@GuardedBy("this")
+        private boolean globalChange;
+        private final Set</*@GuardedBy("this")*/FileObject> localChanges = 
new HashSet<FileObject>();
+        //@GuardedBy("this")
+        private  LogContext visibilityLogCtx;
+
         SlidingTask(@NonNull final RepositoryUpdater ru) {
             this.ru = ru;
         }
 
+        synchronized void globalChange() {
+            globalChange = true;
+
+            if (visibilityLogCtx == null) {
+                visibilityLogCtx = 
LogContext.create(LogContext.EventType.FILE, null);
+            }
+        }
+
+        synchronized void localChange(final FileObject... onFiles) {
+            localChanges.addAll(Arrays.asList(onFiles));
+            if (visibilityLogCtx == null) {
+                visibilityLogCtx = 
LogContext.create(LogContext.EventType.FILE, null);
+            }
+        }
+
         @Override
         public void run() {
-            LOGGER.fine ("VisibilityQuery changed, reindexing");    //NOI18N
-            ru.refreshAll(false, false, true, 
visibilityLogCtx.getAndSet(null));
+            final boolean global;
+            final Collection<FileObject> changedFiles;
+            final LogContext logCtx;
+            synchronized (this) {
+                logCtx = visibilityLogCtx;
+                visibilityLogCtx = null;
+                global = globalChange;
+                globalChange = false;
+                changedFiles = new ArrayList<FileObject>(localChanges);
+                localChanges.clear();
+            }
+            if (global) {
+                LOGGER.fine ("VisibilityQuery global changed, reindexing");  
  //NOI18N
+                ru.refreshAll(false, false, true, logCtx);
+            } else {
+                if (LOGGER.isLoggable(Level.FINE)) {
+                    LOGGER.log (
+                      Level.FINE,
+                      "VisibilityQuery changed for {0}, reindexing these 
files.",    //NOI18N
+                      Arrays.asList(changedFiles));
+                }
+                final Map<URI, Collection<URL>> srcShownPerRoot =
+                        new HashMap<URI, Collection<URL>>();
+                final Map<URI, Set<String>> srcHiddenPerRoot =
+                        new HashMap<URI, Set<String>>();
+                final Set<URI> binChangedRoot =
+                        new HashSet<URI>();
+                final Map<URI,TimeStamps> tsPerRoot = new HashMap<URI, 
TimeStamps>();
+                final VisibilityQuery vq = VisibilityQuery.getDefault();
+                for (FileObject chf : changedFiles) {
+                    Pair<URL,FileObject> owner = ru.getOwningSourceRoot(chf);
+                    if (owner != null) {
+                        final boolean visible = vq.isVisible(chf);
+                        try {
+                            final URI ownerURI = owner.first.toURI();
+                            if (visible) {
+                                Collection<URL> files = 
srcShownPerRoot.get(ownerURI);
+                                if (files == null) {
+                                    files = new ArrayList<URL>();
+                                    srcShownPerRoot.put(ownerURI, files);
+                                }
+                                files.add(chf.toURL());
+                            } else if (owner.second != null) {
+                                Set<String> files = 
srcHiddenPerRoot.get(ownerURI);
+                                if (files == null) {
+                                    files = new HashSet<String>();
+                                    srcHiddenPerRoot.put(ownerURI, files);
+                                }
+                                if (chf.isFolder()) {
+                                    TimeStamps ts = tsPerRoot.get(ownerURI);
+                                    if (ts == null) {
+                                        ts = TimeStamps.forRoot(owner.first, 
false);
+                                        tsPerRoot.put(ownerURI, ts);
+                                    }
+                                    
files.addAll(ts.getEnclosedFiles(FileUtil.getRelativePath(owner.second, 
chf)));
+                                } else {
+                                    
files.add(FileUtil.getRelativePath(owner.second, chf));
+                                }
+                            }
+                        } catch (URISyntaxException e) {
+                            Exceptions.printStackTrace(e);
+                        } catch (IOException e) {
+                            Exceptions.printStackTrace(e);
+                        }
+                        continue;
+                    }
+                    owner = ru.getOwningBinaryRoot(chf);
+                    if (owner != null) {
+                        try {
+                            final URI ownerURI = owner.first.toURI();
+                            binChangedRoot.add(ownerURI);
+                        } catch (URISyntaxException e) {
+                            Exceptions.printStackTrace(e);
+                        }
+                    }
+                }
+                for (Map.Entry<URI,Collection<URL>> e : 
srcShownPerRoot.entrySet()) {
+                    try {
+                        ru.addIndexingJob(
+                            e.getKey().toURL(),
+                            e.getValue(),
+                            false,
+                            false,
+                            false,
+                            false,
+                            true,
+                            logCtx);
+                    } catch (MalformedURLException ex) {
+                        Exceptions.printStackTrace(ex);
+                    }
+                }
+                for (Map.Entry<URI,Set<String>> e : 
srcHiddenPerRoot.entrySet()) {
+                    try {
+                        ru.addDeleteJob(
+                            e.getKey().toURL(),
+                            e.getValue(),
+                            logCtx);
+                    } catch (MalformedURLException ex) {
+                        Exceptions.printStackTrace(ex);
+                    }
+                }
+                for (URI e : binChangedRoot) {
+                    try {
+                        ru.addBinaryJob(
+                            e.toURL(),
+                            logCtx);
+                    } catch (MalformedURLException ex) {
+                        Exceptions.printStackTrace(ex);
+                    }
+                }
+            }
         }
     }
 
diff --git 
a/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/VisibilityChangeTest.java
 
b/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/VisibilityChangeTest.java
--- 
a/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/VisibilityChangeTest.java
+++ 
b/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/VisibilityChangeTest.java
@@ -95,6 +95,7 @@
     private FileObject src2;
     private FileObject src3;
     private FileObject src4;
+    private FileObject src2fld;
     private FileObject outside;
     private FileObject src1file1;
     private FileObject src1file2;
@@ -133,9 +134,11 @@
         assertNotNull(src1file1);
         src1file2 = src1.createData("test2", FOO_EXT);  //NOI18N
         assertNotNull(src1file2);
-        src2file1 = src2.createData("test", FOO_EXT);   //NOI18N
+        src2fld = src2.createFolder("folder"); //NOI18N
+        assertNotNull(src2fld);
+        src2file1 = src2fld.createData("test", FOO_EXT);   //NOI18N
         assertNotNull(src2file1);
-        src2file2 = src2.createData("test2", FOO_EXT);  //NOI18N
+        src2file2 = src2fld.createData("test2", FOO_EXT);  //NOI18N
         assertNotNull(src2file2);
         src3file1 = src3.createData("test", FOO_EXT);   //NOI18N
         assertNotNull(src3file1);
@@ -184,7 +187,7 @@
         final Logger logger = 
Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); //NOI18N
         logger.setLevel (Level.FINEST);
         logger.addHandler(handler);
-
+        try {
         globalPathRegistry_register(FOO_SOURCES,new ClassPath[]{cp1});
         assertTrue (handler.await());
         assertEquals(0, handler.getBinaries().size());
@@ -215,12 +218,14 @@
         assertEquals(
             new URI[0],
             
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearRemovedFiles());
        
+        } finally {
+            logger.removeHandler(handler);
+        }
     }
 
     /**
      * Tests specific VisibilityChange but outside of the source roots.
-     * Change to file (folder) outside of source roots -> be defensive and 
refresh everything,
-     * may be parent of some root or metadata.
+     * Change to file (folder) outside of source roots -> no scan.
      */
     public void testVisibilityChangeOutsideOfRoot() throws 
InterruptedException, IOException {
 
@@ -229,7 +234,7 @@
         final Logger logger = 
Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); //NOI18N
         logger.setLevel (Level.FINEST);
         logger.addHandler(handler);
-
+        try {
         globalPathRegistry_register(FOO_SOURCES,new ClassPath[]{cp1});
         assertTrue (handler.await());
         assertEquals(0, handler.getBinaries().size());
@@ -250,17 +255,13 @@
             new URI[0],
             
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearRemovedFiles());
         handler.reset();
-        
Lookup.getDefault().lookup(MockVisibilityQuery.class).change(outside);
-        assertTrue (handler.await());
-        assertEquals(0, handler.getBinaries().size());
-        assertEquals(4, handler.getSources().size());
-        assertEquals(
-            new URI[0],
-            
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearIndexedFiles());
-        assertEquals(
-            new URI[0],
-            
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearRemovedFiles());
-
+            
Lookup.getDefault().lookup(MockVisibilityQuery.class).hide(outside);
+            assertFalse(handler.await(RepositoryUpdaterTest.NEGATIVE_TIME));
+            assertNull(handler.getBinaries());
+            assertNull(handler.getSources());
+        } finally {
+            logger.removeHandler(handler);
+        }
     }
 
     public void testVisibilityChangeInSingleRoot() throws 
InterruptedException, IOException {
@@ -270,7 +271,7 @@
         final Logger logger = 
Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); //NOI18N
         logger.setLevel (Level.FINEST);
         logger.addHandler(handler);
-
+        try {
         globalPathRegistry_register(FOO_SOURCES,new ClassPath[]{cp1});
         assertTrue (handler.await());
         assertEquals(0, handler.getBinaries().size());
@@ -290,19 +291,143 @@
         assertEquals(
             new URI[0],
             
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearRemovedFiles());
-        handler.reset();
-//        
Lookup.getDefault().lookup(MockVisibilityQuery.class).change(src1file1);
-//        assertTrue (handler.await());
-//        assertEquals(0, handler.getBinaries().size());
-//        assertEquals(1, handler.getSources().size());
-//        assertEquals(
-//            new URI[0],
-//            
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearIndexedFiles());
-//        assertEquals(
-//            new URI[]{
-//                src1file1.toURI()
-//            },
-//            
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearRemovedFiles());
+            handler.reset(RepositoryUpdaterTest.TestHandler.Type.DELETE);
+            
Lookup.getDefault().lookup(MockVisibilityQuery.class).hide(src1file1);
+            assertTrue (handler.await());
+            assertEquals(
+                new URI[0],
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearIndexedFiles());
+            assertEquals(
+                new URI[]{
+                    src1file1.toURI()
+                },
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearRemovedFiles());
+            handler.reset(RepositoryUpdaterTest.TestHandler.Type.FILELIST);
+            
Lookup.getDefault().lookup(MockVisibilityQuery.class).show(src1file1);
+            assertTrue (handler.await());
+            assertEquals(
+                new URI[]{
+                    src1file1.toURI()
+                },
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearIndexedFiles());
+            assertEquals(
+                new URI[0],
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearRemovedFiles());
+        } finally {
+            logger.removeHandler(handler);
+        }
+    }
+
+    public void testMultipleVisibilityChangesInSingleRoot() throws 
InterruptedException, IOException {
+
+        
assertTrue(GlobalPathRegistry.getDefault().getPaths(FOO_SOURCES).isEmpty());
+        final RepositoryUpdaterTest.TestHandler handler = new 
RepositoryUpdaterTest.TestHandler();
+        final Logger logger = 
Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); //NOI18N
+        logger.setLevel (Level.FINEST);
+        logger.addHandler(handler);
+        try {
+            globalPathRegistry_register(FOO_SOURCES,new ClassPath[]{cp1});
+            assertTrue (handler.await());
+            assertEquals(0, handler.getBinaries().size());
+            assertEquals(4, handler.getSources().size());
+            assertEquals(
+                new URI[] {
+                    src1file1.toURI(),
+                    src1file2.toURI(),
+                    src2file1.toURI(),
+                    src2file2.toURI(),
+                    src3file1.toURI(),
+                    src3file2.toURI(),
+                    src4file1.toURI(),
+                    src4file2.toURI()
+                },
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearIndexedFiles());
+            assertEquals(
+                new URI[0],
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearRemovedFiles());
+            handler.reset(RepositoryUpdaterTest.TestHandler.Type.DELETE);
+            
Lookup.getDefault().lookup(MockVisibilityQuery.class).hide(src1file1, 
src1file2);
+            assertTrue (handler.await());
+            assertEquals(
+                new URI[0],
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearIndexedFiles());
+            assertEquals(
+                new URI[]{
+                    src1file1.toURI(),
+                    src1file2.toURI()
+                },
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearRemovedFiles());
+            handler.reset(RepositoryUpdaterTest.TestHandler.Type.FILELIST);
+            
Lookup.getDefault().lookup(MockVisibilityQuery.class).show(src1file1, 
src1file2);
+            assertTrue (handler.await());
+            assertEquals(
+                new URI[]{
+                    src1file1.toURI(),
+                    src1file2.toURI()
+                },
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearIndexedFiles());
+            assertEquals(
+                new URI[0],
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearRemovedFiles());
+        } finally {
+            logger.removeHandler(handler);
+        }
+    }
+
+    public void testFolderVisibilityChangeInSingleRoot() throws 
InterruptedException, IOException {
+
+        
assertTrue(GlobalPathRegistry.getDefault().getPaths(FOO_SOURCES).isEmpty());
+        final RepositoryUpdaterTest.TestHandler handler = new 
RepositoryUpdaterTest.TestHandler();
+        final Logger logger = 
Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); //NOI18N
+        logger.setLevel (Level.FINEST);
+        logger.addHandler(handler);
+        try {
+            globalPathRegistry_register(FOO_SOURCES,new ClassPath[]{cp1});
+            assertTrue (handler.await());
+            assertEquals(0, handler.getBinaries().size());
+            assertEquals(4, handler.getSources().size());
+            assertEquals(
+                new URI[] {
+                    src1file1.toURI(),
+                    src1file2.toURI(),
+                    src2file1.toURI(),
+                    src2file2.toURI(),
+                    src3file1.toURI(),
+                    src3file2.toURI(),
+                    src4file1.toURI(),
+                    src4file2.toURI()
+                },
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearIndexedFiles());
+            assertEquals(
+                new URI[0],
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearRemovedFiles());
+            handler.reset(RepositoryUpdaterTest.TestHandler.Type.DELETE);
+            
Lookup.getDefault().lookup(MockVisibilityQuery.class).hide(src2fld);
+            assertTrue (handler.await());
+            assertEquals(
+                new URI[0],
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearIndexedFiles());
+            assertEquals(
+                new URI[]{
+                    src2file1.toURI(),
+                    src2file2.toURI()
+                },
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearRemovedFiles());
+            handler.reset(RepositoryUpdaterTest.TestHandler.Type.FILELIST);
+            
Lookup.getDefault().lookup(MockVisibilityQuery.class).show(src2fld);
+            assertTrue (handler.await());
+            assertEquals(
+                new URI[]{
+                    src2file1.toURI(),
+                    src2file2.toURI()
+                },
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearIndexedFiles());
+            assertEquals(
+                new URI[0],
+                
MimeLookup.getLookup(MimePath.get(FOO_MIME)).lookup(FooIndexerFactory.class).clearRemovedFiles());
+        } finally {
+            logger.removeHandler(handler);
+        }
     }
     
     private void assertEquals(URI[] expected, URI[] result) {
@@ -430,14 +555,20 @@
         private final Set<FileObject> invisibles = 
Collections.synchronizedSet(new HashSet<FileObject>());
         private final List<ChangeListener> listeners = new 
CopyOnWriteArrayList<ChangeListener>();
 
-        void change(FileObject... fos) {
+        void hide(FileObject... fos) {
             synchronized (invisibles) {
-                invisibles.clear();
                 invisibles.addAll(Arrays.asList(fos));
             }
             fire(new VisibilityQueryChangeEvent(this, fos));
         }
 
+        void show(FileObject... fos) {
+            synchronized (invisibles) {
+                invisibles.removeAll(Arrays.asList(fos));
+            }
+            fire(new VisibilityQueryChangeEvent(this, fos));
+        }
+
         void globalChange() {
             invisibles.clear();
             fire(new ChangeEvent(this));

[hg] main-silver: #223341:Use VisibilityQueryChangeEvent to prev...

Tomas Zezula 12/06/2012

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close