diff --git a/java.source/src/org/netbeans/modules/java/source/indexing/COSSynchronizingIndexer.java b/java.source/src/org/netbeans/modules/java/source/indexing/COSSynchronizingIndexer.java --- a/java.source/src/org/netbeans/modules/java/source/indexing/COSSynchronizingIndexer.java +++ b/java.source/src/org/netbeans/modules/java/source/indexing/COSSynchronizingIndexer.java @@ -43,6 +43,7 @@ package org.netbeans.modules.java.source.indexing; import java.io.File; +import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.Collections; @@ -51,12 +52,14 @@ import java.util.List; import java.util.Set; import org.netbeans.modules.java.source.usages.BuildArtifactMapperImpl; +import org.netbeans.modules.parsing.impl.indexing.CacheFolder; import org.netbeans.modules.parsing.impl.indexing.IndexerCache; import org.netbeans.modules.parsing.impl.indexing.IndexerCache.IndexerInfo; import org.netbeans.modules.parsing.spi.indexing.Context; import org.netbeans.modules.parsing.spi.indexing.CustomIndexer; import org.netbeans.modules.parsing.spi.indexing.CustomIndexerFactory; import org.netbeans.modules.parsing.spi.indexing.Indexable; +import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; /** @@ -71,7 +74,7 @@ return ; } - Set javaMimeTypes = gatherJavaMimeTypes(); + Set javaMimeTypes = gatherJavaMimeTypes(context.getRootURI()); List updated = new LinkedList(); for (Indexable i : files) { @@ -103,13 +106,19 @@ } } - public static Set gatherJavaMimeTypes() { + public static Set gatherJavaMimeTypes(final URL sourceRoot) { Set mimeTypes = new HashSet(); - for (IndexerInfo i : IndexerCache.getCifCache().getIndexersByName(JavaIndex.NAME)) { - mimeTypes.addAll(i.getMimeTypes()); + try { + final FileObject cacheFolder = CacheFolder.getDataFolder(sourceRoot, true); + if (cacheFolder != null) { + for (IndexerInfo i : IndexerCache.getCifCache().getIndexersByName(cacheFolder.getURL(), JavaIndex.NAME)) { + mimeTypes.addAll(i.getMimeTypes()); + } + } + } catch (IOException ioe) { + Exceptions.printStackTrace(ioe); } - return mimeTypes; } diff --git a/java.source/src/org/netbeans/modules/java/source/usages/BuildArtifactMapperImpl.java b/java.source/src/org/netbeans/modules/java/source/usages/BuildArtifactMapperImpl.java --- a/java.source/src/org/netbeans/modules/java/source/usages/BuildArtifactMapperImpl.java +++ b/java.source/src/org/netbeans/modules/java/source/usages/BuildArtifactMapperImpl.java @@ -280,7 +280,7 @@ copyRecursively(index, targetFolder); if (copyResources) { - Set javaMimeTypes = COSSynchronizingIndexer.gatherJavaMimeTypes(); + Set javaMimeTypes = COSSynchronizingIndexer.gatherJavaMimeTypes(sourceRoot); String[] javaMimeTypesArr = javaMimeTypes.toArray(new String[0]); copyRecursively(sr, targetFolder, javaMimeTypes, javaMimeTypesArr); diff --git a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/IndexerCache.java b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/IndexerCache.java --- a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/IndexerCache.java +++ b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/IndexerCache.java @@ -45,10 +45,17 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Method; +import java.net.URISyntaxException; +import java.net.URL; import java.text.DateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -66,12 +73,11 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.modules.editor.settings.storage.api.EditorSettings; import org.netbeans.modules.parsing.spi.indexing.CustomIndexerFactory; import org.netbeans.modules.parsing.spi.indexing.EmbeddingIndexerFactory; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; import org.openide.filesystems.MIMEResolver; import org.openide.util.Lookup; import org.openide.util.LookupEvent; @@ -119,34 +125,25 @@ return instanceEIF; } - public Collection> getIndexers(Set> changedIndexers) { - final Object [] data = getData(changedIndexers); - @SuppressWarnings("unchecked") - List> infos = (List>) data[2]; - return infos; + public Collection> getIndexers(final URL cacheRoot, final Set> changedIndexers) { + final State data = getData(cacheRoot, changedIndexers); + return data.orderedInfos; } - public Map>> getIndexersMap(Set> changedIndexers) { - final Object [] data = getData(changedIndexers); - @SuppressWarnings("unchecked") - Map>> infosMap = (Map>>) data[1]; - return infosMap; + public Map>> getIndexersMap(final URL cacheRoot, final Set> changedIndexers) { + final State data = getData(cacheRoot, changedIndexers); + return data.infosByMimeType; } - public Collection> getIndexersFor(String mimeType) { - final Object [] data = getData(null); - @SuppressWarnings("unchecked") - Map>> infosMap = (Map>>) data[1]; - Set> infos = infosMap.get(mimeType); + public Collection> getIndexersFor(final URL cacheRoot, final String mimeType) { + final State data = getData(cacheRoot, null); + final Set> infos = data.infosByMimeType.get(mimeType); return infos == null ? Collections.>emptySet() : infos; } - public Collection> getIndexersByName(String indexerName) { - final Object [] data = getData(null); - @SuppressWarnings("unchecked") - Map>> infosMap = (Map>>) data[0]; - Set> info = infosMap.get(indexerName); - return info; + public Collection> getIndexersByName(final URL cacheRoot, final String indexerName) { + final State data = getData(cacheRoot, null); + return data.infosByName.get(indexerName); } @@ -290,11 +287,8 @@ private final String infoFileName; private final Tracker tracker = new Tracker(); private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - - private boolean firstGetData = true; - private Map>> infosByName = null; - private Map>> infosByMimeType = null; - private List> orderedInfos = null; + //@GuardedBy("this") + private final Map> stateMap = new HashMap>(); private IndexerCache(Class type) { this.type = type; @@ -340,15 +334,20 @@ } } - private Object[] getData(Set> changedIndexers) { + private State getData(final URL cacheRoot, Set> changedIndexers) { boolean fire = false; synchronized (this) { - if (infosByName == null) { - Map> lastKnownInfos = readLastKnownIndexers(); + State state = stateMap.get(cacheRoot); + if (state == null) { + state = new State(); + stateMap.put(cacheRoot, state); + } + if (state.infosByName == null) { + Map> lastKnownInfos = readLastKnownIndexers(cacheRoot); Set mimeTypesToCheck = null; - if (firstGetData) { - firstGetData = false; + if (state.firstGetData) { + state.firstGetData = false; if (changedIndexers != null) { mimeTypesToCheck = new HashSet(); for(IndexerInfo ii : lastKnownInfos.values()) { @@ -404,14 +403,14 @@ // the comparator instance must not be cached, because it uses data // from the default lookup Collections.sort(_orderedInfos, new C()); - infosByName = Collections.unmodifiableMap(_infosByName); - infosByMimeType = Collections.unmodifiableMap(_infosByMimeType); - orderedInfos = Collections.unmodifiableList(_orderedInfos); + state.infosByName = Collections.unmodifiableMap(_infosByName); + state.infosByMimeType = Collections.unmodifiableMap(_infosByMimeType); + state.orderedInfos = Collections.unmodifiableList(_orderedInfos); - writeLastKnownIndexers(infosByName); + writeLastKnownIndexers(cacheRoot, state.infosByName); Map>> addedOrChangedInfosMap = new HashMap>>(); - diff(lastKnownInfos, infosByName, addedOrChangedInfosMap); + diff(lastKnownInfos, state.infosByName, addedOrChangedInfosMap); for(Set> addedOrChangedInfos : addedOrChangedInfosMap.values()) { if (changedIndexers == null) { @@ -423,7 +422,7 @@ if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "Ordered indexers of {0}: ", type.getName()); //NOI18N - for (IndexerInfo ii : orderedInfos) { + for (IndexerInfo ii : state.orderedInfos) { LOG.log(Level.FINE, " {0} {1}: {2}", new Object[] { //NOI18N ii.getIndexerFactory(), changedIndexers != null && changedIndexers.contains(ii) ? "(modified)" : "", //NOI18N @@ -435,25 +434,25 @@ RP.post(new Runnable() { public @Override void run() { resetCache(); - getData(null); + getData(cacheRoot,null); } }, 321); } } if (fire && changedIndexers.size() > 0) { - pcs.firePropertyChange(type.getName(), null, changedIndexers); + pcs.firePropertyChange(type.getName(), null, Pair.>>of(cacheRoot,changedIndexers)); } - return new Object [] { infosByName, infosByMimeType, orderedInfos }; + return new State(state); } } private void resetCache() { synchronized (IndexerCache.this) { - IndexerCache.this.infosByName = null; - IndexerCache.this.infosByMimeType = null; - IndexerCache.this.orderedInfos = null; + for (State state : stateMap.values()) { + state.reset(); + } LOG.log(Level.FINE, "{0}: resetting indexer cache", type.getName()); //NOI18N } } @@ -493,15 +492,18 @@ } } - private Map> readLastKnownIndexers() { + private Map> readLastKnownIndexers(final URL cacheRoot) { Map> lki = new HashMap>(); - - FileObject cacheFolder = CacheFolder.getCacheFolder(); - FileObject infoFile = cacheFolder.getFileObject(infoFileName); - if (infoFile != null) { + File infoFile = null; + try { + infoFile = new File(new File(cacheRoot.toURI()),infoFileName); + } catch (URISyntaxException use) { + LOG.log(Level.FINE, "URISyntaxException: " + cacheRoot.toString(), use); //NOI18N + } + if (infoFile != null && infoFile.canRead()) { Properties props = new Properties(); try { - InputStream is = infoFile.getInputStream(); + final InputStream is = new BufferedInputStream(new FileInputStream(infoFile)); try { props.load(is); } finally { @@ -554,7 +556,7 @@ return lki; } - private void writeLastKnownIndexers(Map>> lki) { + private void writeLastKnownIndexers(final URL cacheRoot, Map>> lki) { Properties props = new Properties(); for(String indexerName : lki.keySet()) { Set> iinfos = lki.get(indexerName); @@ -590,18 +592,18 @@ props.put(indexerName, sb.toString()); } - - FileObject cacheFolder = CacheFolder.getCacheFolder(); try { - FileObject infoFile = FileUtil.createData(cacheFolder, infoFileName); - OutputStream os = infoFile.getOutputStream(); + File infoFile = new File (new File(cacheRoot.toURI()), infoFileName); + final OutputStream os = new BufferedOutputStream(new FileOutputStream(infoFile)); try { props.store(os, "Last known indexer " + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date())); //NOI18N } finally { os.close(); } } catch (IOException ioe) { - LOG.log(Level.FINE, "Can't write " + infoFileName + " file in " + cacheFolder.getPath(), ioe); //NOI18N + LOG.log(Level.FINE, "Can't write " + infoFileName + " file in " + cacheRoot, ioe); //NOI18N + } catch (URISyntaxException use) { + LOG.log(Level.FINE, "Can't write " + infoFileName + " file in " + cacheRoot, use); //NOI18N } } @@ -786,4 +788,30 @@ return highest; } } // End of C class + + private static class State { + private boolean firstGetData; + private Map>> infosByName; + private Map>> infosByMimeType; + private List> orderedInfos; + + private State() { + firstGetData = true; + } + + private State(final @NonNull State other) { + this.firstGetData = other.firstGetData; + this.infosByName = other.infosByName; + this.infosByMimeType = other.infosByMimeType; + this.orderedInfos = other.orderedInfos; + } + + + + private void reset() { + infosByName = null; + infosByMimeType = null; + orderedInfos = null; + } + } } 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 @@ -52,7 +52,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -146,6 +145,7 @@ import org.openide.util.Parameters; import org.openide.util.RequestProcessor; import org.openide.util.TopologicalSortException; +import org.openide.util.Union2; import org.openide.util.lookup.ServiceProvider; /** @@ -345,14 +345,9 @@ if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("addIndexingJob: indexerName=" + indexerName); //NOI18N } - - Collection> cifInfos = IndexerCache.getCifCache().getIndexersByName(indexerName); - if (cifInfos == null) { - throw new InvalidParameterException("No CustomIndexerFactory with name: '" + indexerName + "'"); //NOI18N - } else { - Work w = new RefreshCifIndices(cifInfos, scannedRoots2Dependencies, sourcesForBinaryRoots); - scheduleWork(w, false); - } + + Work w = new RefreshCifIndices(indexerName, scannedRoots2Dependencies.keySet(), sourcesForBinaryRoots); + scheduleWork(w, false); } public void refreshAll(boolean fullRescan, boolean wait, boolean logStatistics, Object... filesOrFileObjects) { @@ -688,15 +683,15 @@ if (evt.getPropertyName() != null && evt.getPropertyName().equals(CustomIndexerFactory.class.getName())) { if (!ignoreIndexerCacheEvents) { @SuppressWarnings("unchecked") - Set> changedIndexers = (Set>) evt.getNewValue(); - scheduleWork(new RefreshCifIndices(changedIndexers, scannedRoots2Dependencies, sourcesForBinaryRoots), false); + Pair>> changedIndexers = (Pair>>) evt.getNewValue(); + scheduleWork(new RefreshCifIndices(changedIndexers.second, Collections.singleton(changedIndexers.first), sourcesForBinaryRoots), false); } return; } else if (evt.getPropertyName() != null && evt.getPropertyName().equals(EmbeddingIndexerFactory.class.getName())) { if (!ignoreIndexerCacheEvents) { @SuppressWarnings("unchecked") - Set> changedIndexers = (Set>) evt.getNewValue(); - scheduleWork(new RefreshEifIndices(changedIndexers, scannedRoots2Dependencies, sourcesForBinaryRoots), false); + Pair>> changedIndexers = (Pair>>) evt.getNewValue(); + scheduleWork(new RefreshEifIndices(changedIndexers.second, Collections.singleton(changedIndexers.first), sourcesForBinaryRoots), false); } return; } @@ -973,29 +968,34 @@ Collection dirty = Collections.singleton(SPIAccessor.getInstance().create(new FileObjectIndexable(root.second, docFile))); String mimeType = DocumentUtilities.getMimeType(document); - - Collection> cifInfos = IndexerCache.getCifCache().getIndexersFor(mimeType); - for(IndexerCache.IndexerInfo info : cifInfos) { - try { - CustomIndexerFactory factory = info.getIndexerFactory(); - Context ctx = SPIAccessor.getInstance().createContext(CacheFolder.getDataFolder(root.first), root.first, - factory.getIndexerName(), factory.getIndexVersion(), null, false, true, false, null); - factory.filesDirty(dirty, ctx); - } catch (IOException ex) { - LOGGER.log(Level.WARNING, null, ex); + try { + final FileObject cacheFolder = CacheFolder.getDataFolder(root.first); + final URL cacheFolderURL = cacheFolder.getURL(); + Collection> cifInfos = IndexerCache.getCifCache().getIndexersFor(cacheFolderURL, mimeType); + for(IndexerCache.IndexerInfo info : cifInfos) { + try { + CustomIndexerFactory factory = info.getIndexerFactory(); + Context ctx = SPIAccessor.getInstance().createContext(cacheFolder, root.first, + factory.getIndexerName(), factory.getIndexVersion(), null, false, true, false, null); + factory.filesDirty(dirty, ctx); + } catch (IOException ex) { + LOGGER.log(Level.WARNING, null, ex); + } } - } - - Collection> eifInfos = IndexerCache.getEifCache().getIndexersFor(mimeType); - for(IndexerCache.IndexerInfo info : eifInfos) { - try { - EmbeddingIndexerFactory factory = info.getIndexerFactory(); - Context ctx = SPIAccessor.getInstance().createContext(CacheFolder.getDataFolder(root.first), root.first, - factory.getIndexerName(), factory.getIndexVersion(), null, false, true, false, null); - factory.filesDirty(dirty, ctx); - } catch (IOException ex) { - LOGGER.log(Level.WARNING, null, ex); + + Collection> eifInfos = IndexerCache.getEifCache().getIndexersFor(cacheFolderURL, mimeType); + for(IndexerCache.IndexerInfo info : eifInfos) { + try { + EmbeddingIndexerFactory factory = info.getIndexerFactory(); + Context ctx = SPIAccessor.getInstance().createContext(cacheFolder, root.first, + factory.getIndexerName(), factory.getIndexVersion(), null, false, true, false, null); + factory.filesDirty(dirty, ctx); + } catch (IOException ex) { + LOGGER.log(Level.WARNING, null, ex); + } } + } catch (IOException ioe) { + LOGGER.log(Level.WARNING, null, ioe); } } } else { @@ -1703,7 +1703,7 @@ try { FileObject cacheRoot = CacheFolder.getDataFolder(root); - Collection> cifInfos = IndexerCache.getCifCache().getIndexers(null); + Collection> cifInfos = IndexerCache.getCifCache().getIndexers(cacheRoot.getURL(), null); for(IndexerCache.IndexerInfo cifInfo : cifInfos) { CustomIndexerFactory factory = cifInfo.getIndexerFactory(); Context ctx = SPIAccessor.getInstance().createContext(cacheRoot, root, factory.getIndexerName(), factory.getIndexVersion(), null, followUpJob, checkEditor, false, null); @@ -1711,7 +1711,7 @@ factory.filesDeleted(ci.getIndexablesFor(null), ctx); } - Collection> eifInfos = IndexerCache.getEifCache().getIndexers(null); + Collection> eifInfos = IndexerCache.getEifCache().getIndexers(cacheRoot.getURL(), null); for(IndexerCache.IndexerInfo eifInfo : eifInfos) { EmbeddingIndexerFactory factory = eifInfo.getIndexerFactory(); Context ctx = SPIAccessor.getInstance().createContext(cacheRoot, root, factory.getIndexerName(), factory.getIndexVersion(), null, followUpJob, checkEditor, false, null); @@ -2102,7 +2102,7 @@ if (crawler.isFinished()) { final Map invalidatedMap = new IdentityHashMap(); final Map,Pair> ctxToFinish = new HashMap,Pair>(); - final SourceIndexers indexers = SourceIndexers.load(false); + final SourceIndexers indexers = SourceIndexers.load(root, false); invalidateSources(resources); scanStarted (root, sourceForBinaryRoot, indexers, invalidatedMap, ctxToFinish); delete(crawler.getDeletedResources(), root); @@ -2442,20 +2442,27 @@ private static class RefreshCifIndices extends Work { - private final Collection> cifInfos; - private final Map> scannedRoots2Dependencies; + private final Union2>> cifUnion; + private final Set rootsToRefresh; private final Set sourcesForBinaryRoots; - public RefreshCifIndices(Collection> cifInfos, Map> scannedRoots2Depencencies, Set sourcesForBinaryRoots) { + public RefreshCifIndices(Collection> cifInfos, Set rootsToRefresh, Set sourcesForBinaryRoots) { super(false, false, NbBundle.getMessage(RepositoryUpdater.class, "MSG_RefreshingIndices"),true); //NOI18N - this.cifInfos = cifInfos; - this.scannedRoots2Dependencies = scannedRoots2Depencencies; + this.cifUnion = Union2.>>createSecond(cifInfos); + this.rootsToRefresh = rootsToRefresh; this.sourcesForBinaryRoots = sourcesForBinaryRoots; } + public RefreshCifIndices(String indexerName, Set rootsToRefresh, Set sourcesForBinaryRoots) { + super(false, false, NbBundle.getMessage(RepositoryUpdater.class, "MSG_RefreshingIndices"),true); //NOI18N + this.cifUnion = Union2.>>createFirst(indexerName); + this.rootsToRefresh = rootsToRefresh; + this.sourcesForBinaryRoots = sourcesForBinaryRoots; + } + protected @Override boolean getDone() { - switchProgressToDeterminate(scannedRoots2Dependencies.size()); - for(URL root : scannedRoots2Dependencies.keySet()) { + switchProgressToDeterminate(rootsToRefresh.size()); + for(URL root : rootsToRefresh) { if (getShuttdownRequest().isRaised()) { // XXX: this only happens when the IDE is shutting down return true; @@ -2480,6 +2487,9 @@ final LinkedList> allIndexblesSentToIndexers = new LinkedList>(); try { ClusteredIndexables ci = new ClusteredIndexables(resources); + final FileObject cacheRoot = CacheFolder.getDataFolder(root); + Collection> cifInfos = + cifUnion.hasSecond() ? cifUnion.second() : IndexerCache.getCifCache().getIndexersByName(cacheRoot.getURL(), cifUnion.first()); for(IndexerCache.IndexerInfo cifInfo : cifInfos) { List> indexerIndexablesList = new LinkedList>(); for(String mimeType : cifInfo.getMimeTypes()) { @@ -2493,7 +2503,7 @@ } final CustomIndexerFactory factory = cifInfo.getIndexerFactory(); - final FileObject cacheRoot = CacheFolder.getDataFolder(root); + final Context ctx = SPIAccessor.getInstance().createContext(cacheRoot, root, factory.getIndexerName(), factory.getIndexVersion(), null, false, false, sourceForBinaryRoot, getShuttdownRequest()); SPIAccessor.getInstance().setAllFilesJob(ctx, true); transactionContexts.add(ctx); @@ -2534,15 +2544,19 @@ public @Override String toString() { StringBuilder sb = new StringBuilder(); - for(Iterator> it = cifInfos.iterator(); it.hasNext(); ) { - IndexerCache.IndexerInfo cifInfo = it.next(); - sb.append(" indexer=").append(cifInfo.getIndexerName()).append('/').append(cifInfo.getIndexerVersion()); //NOI18N - sb.append(" ("); //NOI18N - printMimeTypes(cifInfo.getMimeTypes(), sb); - sb.append(')'); //NOI18N - if (it.hasNext()) { - sb.append(','); //NOI18N + if (cifUnion.hasSecond()) { + for(Iterator> it = cifUnion.second().iterator(); it.hasNext(); ) { + IndexerCache.IndexerInfo cifInfo = it.next(); + sb.append(" indexer=").append(cifInfo.getIndexerName()).append('/').append(cifInfo.getIndexerVersion()); //NOI18N + sb.append(" ("); //NOI18N + printMimeTypes(cifInfo.getMimeTypes(), sb); + sb.append(')'); //NOI18N + if (it.hasNext()) { + sb.append(','); //NOI18N + } } + } else { + sb.append("indexerName=").append(cifUnion.first()); //NOI18N } return super.toString() + sb.toString(); } @@ -2551,19 +2565,19 @@ private static class RefreshEifIndices extends Work { private final Collection> eifInfos; - private final Map> scannedRoots2Dependencies; + private final Set toRefresh; private final Set sourcesForBinaryRoots; - public RefreshEifIndices(Collection> eifInfos, Map> scannedRoots2Depencencies, Set sourcesForBinaryRoots) { + public RefreshEifIndices(Collection> eifInfos, Set toRefresh, Set sourcesForBinaryRoots) { super(false, false, NbBundle.getMessage(RepositoryUpdater.class, "MSG_RefreshingIndices"),true); //NOI18N this.eifInfos = eifInfos; - this.scannedRoots2Dependencies = scannedRoots2Depencencies; + this.toRefresh = toRefresh; this.sourcesForBinaryRoots = sourcesForBinaryRoots; } protected @Override boolean getDone() { - switchProgressToDeterminate(scannedRoots2Dependencies.size()); - for(URL root : scannedRoots2Dependencies.keySet()) { + switchProgressToDeterminate(toRefresh.size()); + for(URL root : toRefresh) { if (getShuttdownRequest().isRaised()) { // XXX: this only happens when the IDE is shutting down return true; @@ -2859,7 +2873,7 @@ boolean finished = scanBinaries(depCtx); if (finished) { - finished = scanSources(depCtx, null,null); + finished = scanSources(depCtx, false, null); if (finished) { finished = scanRootFiles(fullRescanFiles); if (finished) { @@ -2936,7 +2950,6 @@ private boolean useInitialState; private DependenciesContext depCtx; - protected SourceIndexers indexers = null; // is only ever filled by InitialRootsWork public RootsWork( Map> scannedRoots2Depencencies, @@ -3076,7 +3089,7 @@ switchProgressToDeterminate(depCtx.newBinariesToScan.size() + depCtx.newRootsToScan.size()); boolean finished = scanBinaries(depCtx); if (finished) { - finished = scanSources(depCtx, indexers, scannedRoots2Dependencies); + finished = scanSources(depCtx, true, scannedRoots2Dependencies); } final List missingRoots = new LinkedList(); @@ -3172,15 +3185,37 @@ } if (!sources.isEmpty()) { - final Iterable roots = Collections.unmodifiableSet(sources); - final Collection> customIndexers = IndexerCache.getCifCache().getIndexers(null); - for (IndexerCache.IndexerInfo customIndexer : customIndexers) { - customIndexer.getIndexerFactory().rootsRemoved(roots); + final IndexerCache cifCache = IndexerCache.getCifCache(); + final IndexerCache eifCache = IndexerCache.getEifCache(); + Map,Collection> rootsByFactories = new HashMap, Collection>(); + for (URL source : sources) { + try { + final FileObject cacheFolder = CacheFolder.getDataFolder(source, true); + final URL cacheFolderURL = cacheFolder.getURL(); + final Collection> cinfos = cifCache.getIndexers(cacheFolderURL, null); + for (IndexerCache.IndexerInfo info : cinfos) { + Collection rootsSet = rootsByFactories.get(info); + if (rootsSet == null) { + rootsSet = new HashSet(); + rootsByFactories.put(info, rootsSet); + } + rootsSet.add(source); + } + final Collection> einfos = eifCache.getIndexers(cacheFolderURL, null); + for (IndexerCache.IndexerInfo info : einfos) { + Collection rootsSet = rootsByFactories.get(info); + if (rootsSet == null) { + rootsSet = new HashSet(); + rootsByFactories.put(info, rootsSet); + } + rootsSet.add(source); + } + } catch (IOException ioe) { + LOGGER.log(Level.WARNING, null, ioe); + } } - - final Collection> embeddingIndexers = IndexerCache.getEifCache().getIndexers(null); - for (IndexerCache.IndexerInfo embeddingIndexer : embeddingIndexers) { - embeddingIndexer.getIndexerFactory().rootsRemoved(roots); + for (Map.Entry,Collection> e : rootsByFactories.entrySet()) { + e.getKey().getIndexerFactory().rootsRemoved(Collections.unmodifiableCollection(e.getValue())); } RepositoryUpdater.getDefault().rootsListeners.remove(sources, true); } @@ -3301,7 +3336,7 @@ return false; } - protected final boolean scanSources(DependenciesContext ctx, SourceIndexers indexers, Map> preregisterIn) { + protected final boolean scanSources(DependenciesContext ctx, boolean detectIndexerChanges, Map> preregisterIn) { assert ctx != null; long scannedRootsCnt = 0; long completeTime = 0; @@ -3309,11 +3344,7 @@ int totalDeletedFiles = 0; long totalRecursiveListenersTime = 0; boolean finished = true; - - if (indexers == null) { - indexers = SourceIndexers.load(false); - } - + for (URL source : ctx.newRootsToScan) { if (isCancelled()) { finished = false; @@ -3333,6 +3364,7 @@ preregistered = true; } try { + final SourceIndexers indexers = SourceIndexers.load(source, detectIndexerChanges); if (scanSource (source, ctx.fullRescanSourceRoots.contains(source), ctx.sourcesForBinaryRoots.contains(source), indexers, outOfDateFiles, deletedFiles, recursiveListenersTime)) { ctx.scannedRoots.add(source); success = true; @@ -3488,10 +3520,6 @@ public @Override boolean getDone() { try { - if (indexers == null) { - indexers = SourceIndexers.load(true); - } - if (waitForProjects) { boolean retry = true; while (retry) { @@ -3958,8 +3986,8 @@ private static final class SourceIndexers { - public static SourceIndexers load(boolean detectChanges) { - return new SourceIndexers(detectChanges); + public static SourceIndexers load(final URL sourceRoot, final boolean detectChanges) throws IOException { + return new SourceIndexers(sourceRoot, detectChanges); } public final Set> changedCifs; @@ -3967,7 +3995,7 @@ public final Set> changedEifs; public final Map>> eifInfosMap; - private SourceIndexers(boolean detectChanges) { + private SourceIndexers(final URL sourceRoot, final boolean detectChanges) throws IOException { final long start = System.currentTimeMillis(); if (detectChanges) { changedCifs = new HashSet>(); @@ -3976,8 +4004,9 @@ changedCifs = null; changedEifs = null; } - cifInfos = IndexerCache.getCifCache().getIndexers(changedCifs); - eifInfosMap = IndexerCache.getEifCache().getIndexersMap(changedEifs); + final URL cacheRootURL = CacheFolder.getDataFolder(sourceRoot).getURL(); + cifInfos = IndexerCache.getCifCache().getIndexers(cacheRootURL, changedCifs); + eifInfosMap = IndexerCache.getEifCache().getIndexersMap(cacheRootURL, changedEifs); final long delta = System.currentTimeMillis() - start; LOGGER.log(Level.FINE, "Loading indexers took {0} ms.", delta); // NOI18N