This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 168237
Collapse All | Expand All

(-)a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/FileObjectCrawler.java (-4 / +18 lines)
Lines 43-48 Link Here
43
import java.util.Collection;
43
import java.util.Collection;
44
import java.util.Comparator;
44
import java.util.Comparator;
45
import java.util.HashMap;
45
import java.util.HashMap;
46
import java.util.HashSet;
46
import java.util.Map;
47
import java.util.Map;
47
import java.util.Set;
48
import java.util.Set;
48
import java.util.TreeMap;
49
import java.util.TreeMap;
Lines 88-96 Link Here
88
        final Stats stats = LOG.isLoggable(Level.FINE) ? new Stats() : null;
89
        final Stats stats = LOG.isLoggable(Level.FINE) ? new Stats() : null;
89
90
90
        if (files != null) {
91
        if (files != null) {
91
            finished = collect(files, root, resources, allResources, stats, entry);
92
            finished = collect(files, root, resources, allResources, stats, entry, null);
92
        } else {
93
        } else {
93
            finished = collect(root.getChildren(), root, resources, allResources, stats, entry);
94
            Set<FileObject> seenFoldersOrFilesOrEmpty = !FileObjectKeeper.getDefault().isKnown(root) ? new HashSet<FileObject>() : null;
95
            
96
            finished = collect(root.getChildren(), root, resources, allResources, stats, entry, seenFoldersOrFilesOrEmpty);
97
98
            if (seenFoldersOrFilesOrEmpty != null && !isCancelled()) {
99
                FileObjectKeeper.getDefault().record(root, seenFoldersOrFilesOrEmpty);
100
            }
94
        }
101
        }
95
102
96
        final long tm2 = System.currentTimeMillis();
103
        final long tm2 = System.currentTimeMillis();
Lines 123-129 Link Here
123
    private boolean collect (FileObject[] fos, FileObject root,
130
    private boolean collect (FileObject[] fos, FileObject root,
124
            final Collection<IndexableImpl> resources,
131
            final Collection<IndexableImpl> resources,
125
            final Collection<IndexableImpl> allResources,
132
            final Collection<IndexableImpl> allResources,
126
            final Stats stats, final ClassPath.Entry entry) {
133
            final Stats stats, final ClassPath.Entry entry,
134
            Set<FileObject> seenFoldersOrFilesOrNull) {
127
        for (FileObject fo : fos) {
135
        for (FileObject fo : fos) {
128
            //keep the same logic like in RepositoryUpdater
136
            //keep the same logic like in RepositoryUpdater
129
            if (isCancelled()) {
137
            if (isCancelled()) {
Lines 136-145 Link Here
136
                continue;
144
                continue;
137
            }
145
            }
138
            if (fo.isFolder()) {
146
            if (fo.isFolder()) {
139
                if (!collect(fo.getChildren(), root, resources, allResources, stats, entry)) {
147
                if (seenFoldersOrFilesOrNull != null && FileObjectKeeper.KEEP_FOLDERS) {
148
                    seenFoldersOrFilesOrNull.add(fo);
149
                }
150
                if (!collect(fo.getChildren(), root, resources, allResources, stats, entry, seenFoldersOrFilesOrNull)) {
140
                    return false;
151
                    return false;
141
                }
152
                }
142
            } else {
153
            } else {
154
                if (seenFoldersOrFilesOrNull != null && FileObjectKeeper.KEEP_FILES) {
155
                    seenFoldersOrFilesOrNull.add(fo);
156
                }
143
                if (stats != null) {
157
                if (stats != null) {
144
                    stats.filesCount++;
158
                    stats.filesCount++;
145
                    Stats.inc(stats.extensions, fo.getExt());
159
                    Stats.inc(stats.extensions, fo.getExt());
(-)a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/FileObjectKeeper.java (+107 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.parsing.impl.indexing;
41
42
import java.net.URL;
43
import java.util.HashMap;
44
import java.util.Map;
45
import java.util.Set;
46
import org.openide.filesystems.FileObject;
47
import org.openide.filesystems.FileStateInvalidException;
48
import org.openide.util.Exceptions;
49
50
/**
51
 *
52
 * @author lahvac
53
 */
54
public class FileObjectKeeper {
55
56
    private static final FileObjectKeeper INSTANCE = new FileObjectKeeper();
57
58
    public static FileObjectKeeper getDefault() {
59
        return INSTANCE;
60
    }
61
62
    private static final String KEEP_KIND = System.getProperty(FileObjectKeeper.class.getName() + ".kind");
63
    public static final boolean KEEP_FOLDERS = "folders".equals(KEEP_KIND) || "all".equals(KEEP_KIND);
64
    public static final boolean KEEP_FILES = "all".equals(KEEP_KIND);
65
66
    private final Map<URL, Set<FileObject>> kept = new HashMap<URL, Set<FileObject>>();
67
68
    public synchronized boolean isKnown(FileObject root) {
69
        try {
70
            return kept.containsKey(root.getURL());
71
        } catch (FileStateInvalidException ex) {
72
            Exceptions.printStackTrace(ex);
73
            return false;
74
        }
75
    }
76
77
    public synchronized void record(FileObject root, Set<FileObject> files) {
78
        try {
79
            kept.put(root.getURL(), files);
80
        } catch (FileStateInvalidException ex) {
81
            Exceptions.printStackTrace(ex);
82
        }
83
    }
84
85
    public synchronized void remove(Iterable<? extends URL> roots) {
86
        for (URL u : roots) {
87
            kept.remove(u);
88
        }
89
    }
90
91
    public synchronized void fileCreated(URL root, FileObject file) {
92
        Set<FileObject> d = kept.get(root);
93
94
        if (d != null) {
95
            d.add(file);
96
        }
97
    }
98
99
    public synchronized void fileDeleted(URL root, FileObject file) {
100
        Set<FileObject> d = kept.get(root);
101
102
        if (d != null) {
103
            d.remove(file);
104
        }
105
    }
106
107
}
(-)a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/RepositoryUpdater.java (-1 / +14 lines)
Lines 366-371 Link Here
366
        if (fo != null && fo.isValid() && !isCacheFile(fo) && VisibilityQuery.getDefault().isVisible(fo)) {
366
        if (fo != null && fo.isValid() && !isCacheFile(fo) && VisibilityQuery.getDefault().isVisible(fo)) {
367
            root = getOwningSourceRoot(fo);
367
            root = getOwningSourceRoot(fo);
368
            if (root != null) {
368
            if (root != null) {
369
                if (FileObjectKeeper.KEEP_FOLDERS)
370
                    FileObjectKeeper.getDefault().fileCreated(root, fo);//TODO: correct place?
369
                boolean sourcForBinaryRoot = sourcesForBinaryRoots.contains(root);
371
                boolean sourcForBinaryRoot = sourcesForBinaryRoots.contains(root);
370
                ClassPath.Entry entry = sourcForBinaryRoot ? null : getClassPathEntry(URLMapper.findFileObject(root));
372
                ClassPath.Entry entry = sourcForBinaryRoot ? null : getClassPathEntry(URLMapper.findFileObject(root));
371
                if (entry == null || entry.includes(fo)) {
373
                if (entry == null || entry.includes(fo)) {
Lines 388-397 Link Here
388
    }
390
    }
389
391
390
    public void fileDataCreated(FileEvent fe) {
392
    public void fileDataCreated(FileEvent fe) {
391
        fileChanged(fe);
393
        fileChanged(fe, true);
392
    }
394
    }
393
395
394
    public void fileChanged(FileEvent fe) {
396
    public void fileChanged(FileEvent fe) {
397
        fileChanged(fe, false);
398
    }
399
400
    private void fileChanged(FileEvent fe, boolean newFile) {
395
        if (!authorize(fe)) {
401
        if (!authorize(fe)) {
396
            return;
402
            return;
397
        }
403
        }
Lines 403-408 Link Here
403
        if (fo != null && fo.isValid() && !isCacheFile(fo) && VisibilityQuery.getDefault().isVisible(fo)) {
409
        if (fo != null && fo.isValid() && !isCacheFile(fo) && VisibilityQuery.getDefault().isVisible(fo)) {
404
            root = getOwningSourceRoot (fo);
410
            root = getOwningSourceRoot (fo);
405
            if (root != null) {
411
            if (root != null) {
412
                if (newFile && FileObjectKeeper.KEEP_FILES)
413
                    FileObjectKeeper.getDefault().fileCreated(root, fo);//TODO: correct place?
406
                boolean sourceForBinaryRoot = sourcesForBinaryRoots.contains(root);
414
                boolean sourceForBinaryRoot = sourcesForBinaryRoots.contains(root);
407
                ClassPath.Entry entry = sourceForBinaryRoot ? null : getClassPathEntry(URLMapper.findFileObject(root));
415
                ClassPath.Entry entry = sourceForBinaryRoot ? null : getClassPathEntry(URLMapper.findFileObject(root));
408
                if (entry == null || entry.includes(fo)) {
416
                if (entry == null || entry.includes(fo)) {
Lines 436-441 Link Here
436
        if (fo != null && !isCacheFile(fo) && VisibilityQuery.getDefault().isVisible(fo)) {
444
        if (fo != null && !isCacheFile(fo) && VisibilityQuery.getDefault().isVisible(fo)) {
437
            root = getOwningSourceRoot (fo);
445
            root = getOwningSourceRoot (fo);
438
            if (root != null) {
446
            if (root != null) {
447
                if (fo.isData() && FileObjectKeeper.KEEP_FILES)
448
                    FileObjectKeeper.getDefault().fileDeleted(root, fo);//TODO: correct place?
449
                if (fo.isFolder() && FileObjectKeeper.KEEP_FOLDERS)
450
                    FileObjectKeeper.getDefault().fileDeleted(root, fo);//TODO: correct place?
439
                if (fo.isData() /*&& FileUtil.getMIMEType(fo, recognizers.getMimeTypes())!=null*/) {
451
                if (fo.isData() /*&& FileUtil.getMIMEType(fo, recognizers.getMimeTypes())!=null*/) {
440
                    String relativePath = FileUtil.getRelativePath(URLMapper.findFileObject(root), fo);
452
                    String relativePath = FileUtil.getRelativePath(URLMapper.findFileObject(root), fo);
441
                    assert relativePath != null : "FileObject not under root: f=" + fo + ", root=" + root; //NOI18N
453
                    assert relativePath != null : "FileObject not under root: f=" + fo + ", root=" + root; //NOI18N
Lines 2431-2436 Link Here
2431
                for (IndexerCache.IndexerInfo<EmbeddingIndexerFactory> embeddingIndexer : embeddingIndexers) {
2443
                for (IndexerCache.IndexerInfo<EmbeddingIndexerFactory> embeddingIndexer : embeddingIndexers) {
2432
                    embeddingIndexer.getIndexerFactory().rootsRemoved(roots);
2444
                    embeddingIndexer.getIndexerFactory().rootsRemoved(roots);
2433
                }
2445
                }
2446
                FileObjectKeeper.getDefault().remove(roots);
2434
            }            
2447
            }            
2435
        }
2448
        }
2436
2449

Return to bug 168237