Lines 101-106
Link Here
|
101 |
import org.netbeans.modules.parsing.api.UserTask; |
101 |
import org.netbeans.modules.parsing.api.UserTask; |
102 |
import org.netbeans.modules.parsing.impl.SourceAccessor; |
102 |
import org.netbeans.modules.parsing.impl.SourceAccessor; |
103 |
import org.netbeans.modules.parsing.impl.SourceFlags; |
103 |
import org.netbeans.modules.parsing.impl.SourceFlags; |
|
|
104 |
import org.netbeans.modules.parsing.impl.TaskProcessor; |
104 |
import org.netbeans.modules.parsing.impl.Utilities; |
105 |
import org.netbeans.modules.parsing.impl.Utilities; |
105 |
import org.netbeans.modules.parsing.impl.event.EventSupport; |
106 |
import org.netbeans.modules.parsing.impl.event.EventSupport; |
106 |
import org.netbeans.modules.parsing.impl.indexing.IndexerCache.IndexerInfo; |
107 |
import org.netbeans.modules.parsing.impl.indexing.IndexerCache.IndexerInfo; |
Lines 3863-3876
Link Here
|
3863 |
private FileChangeListener binariesListener = null; |
3864 |
private FileChangeListener binariesListener = null; |
3864 |
private final Map<URL, File> sourceRoots = new HashMap<URL, File>(); |
3865 |
private final Map<URL, File> sourceRoots = new HashMap<URL, File>(); |
3865 |
private final Map<URL, Pair<File, Boolean>> binaryRoots = new HashMap<URL, Pair<File, Boolean>>(); |
3866 |
private final Map<URL, Pair<File, Boolean>> binaryRoots = new HashMap<URL, Pair<File, Boolean>>(); |
3866 |
|
3867 |
|
3867 |
public RootsListeners() { |
3868 |
public RootsListeners() { |
3868 |
} |
3869 |
} |
3869 |
|
3870 |
|
3870 |
public void setListener(FileChangeListener sourcesListener, FileChangeListener binariesListener) { |
3871 |
public void setListener(FileChangeListener sourcesListener, FileChangeListener binariesListener) { |
3871 |
assert (sourcesListener != null && binariesListener != null) || (sourcesListener == null && binariesListener == null) : |
3872 |
assert (sourcesListener != null && binariesListener != null) || (sourcesListener == null && binariesListener == null) : |
3872 |
"Both sourcesListener and binariesListener must either be null or non-null"; //NOI18N |
3873 |
"Both sourcesListener and binariesListener must either be null or non-null"; //NOI18N |
3873 |
|
3874 |
//todo: remove removeRecursiveListener from synchronized block |
3874 |
synchronized (this) { |
3875 |
synchronized (this) { |
3875 |
if (sourcesListener != null) { |
3876 |
if (sourcesListener != null) { |
3876 |
assert this.sourcesListener == null : "Already using " + this.sourcesListener + "and " + this.binariesListener //NOI18N |
3877 |
assert this.sourcesListener == null : "Already using " + this.sourcesListener + "and " + this.binariesListener //NOI18N |
Lines 3923-3935
Link Here
|
3923 |
} |
3924 |
} |
3924 |
|
3925 |
|
3925 |
private void interruptibleAddRecursiveListener(URL root, boolean sourceRoot) { |
3926 |
private void interruptibleAddRecursiveListener(URL root, boolean sourceRoot) { |
|
|
3927 |
Pair<File,FileChangeListener> toAdd = null; |
3926 |
synchronized (this) { |
3928 |
synchronized (this) { |
3927 |
if (sourceRoot) { |
3929 |
if (sourceRoot) { |
3928 |
if (sourcesListener != null) { |
3930 |
if (sourcesListener != null) { |
3929 |
if (!sourceRoots.containsKey(root) && root.getProtocol().equals("file")) { //NOI18N |
3931 |
if (!sourceRoots.containsKey(root) && root.getProtocol().equals("file")) { //NOI18N |
3930 |
try { |
3932 |
try { |
3931 |
File f = new File(root.toURI()); |
3933 |
File f = new File(root.toURI()); |
3932 |
FileUtil.addRecursiveListener(sourcesListener, f); |
3934 |
toAdd = Pair.of (f,sourcesListener); |
3933 |
sourceRoots.put(root, f); |
3935 |
sourceRoots.put(root, f); |
3934 |
} catch (URISyntaxException use) { |
3936 |
} catch (URISyntaxException use) { |
3935 |
LOGGER.log(Level.INFO, null, use); |
3937 |
LOGGER.log(Level.INFO, null, use); |
Lines 3953-3959
Link Here
|
3953 |
FileUtil.addFileChangeListener(binariesListener, f); |
3955 |
FileUtil.addFileChangeListener(binariesListener, f); |
3954 |
} else { |
3956 |
} else { |
3955 |
// listening on a folder |
3957 |
// listening on a folder |
3956 |
FileUtil.addRecursiveListener(binariesListener, f); |
3958 |
toAdd = Pair.of(f,binariesListener); |
3957 |
} |
3959 |
} |
3958 |
binaryRoots.put(root, Pair.of(f, archiveUrl != null)); |
3960 |
binaryRoots.put(root, Pair.of(f, archiveUrl != null)); |
3959 |
} |
3961 |
} |
Lines 3961-3990
Link Here
|
3961 |
} |
3963 |
} |
3962 |
} |
3964 |
} |
3963 |
} |
3965 |
} |
3964 |
} |
3966 |
if (toAdd != null) { |
3965 |
|
3967 |
FileUtil.addRecursiveListener(toAdd.second, toAdd.first); |
3966 |
public void remove(URL root, boolean sourceRoot) { |
3968 |
} |
3967 |
synchronized (this) { |
3969 |
} |
3968 |
if (sourceRoot) { |
3970 |
|
3969 |
if (sourcesListener != null) { |
3971 |
public void remove(final URL root, final boolean sourceRoot) { |
3970 |
File f = sourceRoots.remove(root); |
3972 |
final RequestProcessor.Task task = RP.post(new Runnable() { //Serialize requests into single thread |
3971 |
if (f != null) { |
3973 |
public @Override void run() { |
3972 |
safeRemoveRecursiveListener(sourcesListener, f); |
3974 |
synchronized (this) { //Synchronized to ensure visibility |
3973 |
} |
3975 |
if (sourceRoot) { |
3974 |
} |
3976 |
if (sourcesListener != null) { |
3975 |
} else { |
3977 |
File f = sourceRoots.remove(root); |
3976 |
if (binariesListener != null) { |
3978 |
if (f != null) { |
3977 |
Pair<File, Boolean> pair = binaryRoots.remove(root); |
3979 |
safeRemoveRecursiveListener(sourcesListener, f); |
3978 |
if (pair != null) { |
3980 |
} |
3979 |
if (pair.second) { |
3981 |
} |
3980 |
FileUtil.removeFileChangeListener(binariesListener, pair.first); |
3982 |
} else { |
3981 |
} else { |
3983 |
if (binariesListener != null) { |
3982 |
safeRemoveRecursiveListener(binariesListener, pair.first); |
3984 |
Pair<File, Boolean> pair = binaryRoots.remove(root); |
3983 |
} |
3985 |
if (pair != null) { |
3984 |
} |
3986 |
if (pair.second) { |
3985 |
} |
3987 |
FileUtil.removeFileChangeListener(binariesListener, pair.first); |
3986 |
} |
3988 |
} else { |
3987 |
} |
3989 |
safeRemoveRecursiveListener(binariesListener, pair.first); |
|
|
3990 |
} |
3991 |
} |
3992 |
} |
3993 |
} |
3994 |
} |
3995 |
} |
3996 |
}); |
3997 |
task.waitFinished(); |
3988 |
} |
3998 |
} |
3989 |
|
3999 |
|
3990 |
private void safeRemoveRecursiveListener(FileChangeListener listener, File path) { |
4000 |
private void safeRemoveRecursiveListener(FileChangeListener listener, File path) { |