Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-02-14 03:45:59 -0500
committerMarkus Schorn2008-02-14 03:45:59 -0500
commitff837afb2e7a4620e685ca0e94f07ad50af56833 (patch)
tree61c0c4abe8219c55c0803ca13620c742d07babba
parent1c9e22a4079b6f4131ddafcdca0b4a073576820d (diff)
downloadorg.eclipse.cdt-ff837afb2e7a4620e685ca0e94f07ad50af56833.tar.gz
org.eclipse.cdt-ff837afb2e7a4620e685ca0e94f07ad50af56833.tar.xz
org.eclipse.cdt-ff837afb2e7a4620e685ca0e94f07ad50af56833.zip
Participants for indexer-setup, bug 218286.
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexManager.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexerSetupParticipant.java43
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/CProjectDescriptionListener.java22
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java109
4 files changed, 154 insertions, 33 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexManager.java
index 3e2531e8d3..6cce732b04 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexManager.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,7 @@
package org.eclipse.cdt.core.index;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
@@ -196,4 +197,14 @@ public interface IIndexManager extends IPDOMManager {
* @since 4.0
*/
public void export(ICProject project, String location, int options, IProgressMonitor monitor) throws CoreException;
+
+ /**
+ * Adds a participant for the indexer-setup
+ */
+ public void addIndexerSetupParticipant(IndexerSetupParticipant participant);
+
+ /**
+ * Removes a participant for the indexer-setup
+ */
+ public void removeIndexerSetupParticipant(IndexerSetupParticipant participant);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexerSetupParticipant.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexerSetupParticipant.java
new file mode 100644
index 0000000000..4979d85d22
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexerSetupParticipant.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Wind River Systems, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.index;
+
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.internal.core.CCoreInternals;
+
+/**
+ * Abstract base class for indexer setup participants. A participant can delay the
+ * setup of the indexer when a project is added to the workspace.
+ */
+public abstract class IndexerSetupParticipant {
+
+ /**
+ * The method will be called before an indexer is set up for a project. If you
+ * return <code>true</code> the setup will be postponed. You need to call
+ * {@link #notifyIndexerSetup(ICProject)} as soon as this participant no longer
+ * needs to block the indexer setup.
+ * <p>
+ * This method may be called multiple times for the same project.
+ * @param project the project for which the indexer is supposed to be initialized.
+ * @return whether or not to proceed with the indexer setup.
+ */
+ public abstract boolean postponeIndexerSetup(ICProject project);
+
+ /**
+ * Informs the index manager that this participant no longer needs to postpone the
+ * indexer setup for the given project. Depending on the state of other participants
+ * this may trigger the indexer setup.
+ * @param project the project for which the setup no longer needs to be postponed
+ */
+ public void notifyIndexerSetup(ICProject project) {
+ CCoreInternals.getPDOMManager().notifyIndexerSetup(this, project);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/CProjectDescriptionListener.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/CProjectDescriptionListener.java
index 70163de9ee..cdf710af19 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/CProjectDescriptionListener.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/CProjectDescriptionListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,20 +11,33 @@
package org.eclipse.cdt.internal.core.pdom;
+import org.eclipse.cdt.core.index.IndexerSetupParticipant;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
+import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
import org.eclipse.core.resources.IProject;
public class CProjectDescriptionListener implements ICProjectDescriptionListener {
private PDOMManager fIndexManager;
+ private IndexerSetupParticipant fIndexerSetupParticipant;
public CProjectDescriptionListener(PDOMManager manager) {
fIndexManager= manager;
+ fIndexerSetupParticipant= createIndexerSetupParticipant();
+ manager.addIndexerSetupParticipant(fIndexerSetupParticipant);
+ }
+
+ private IndexerSetupParticipant createIndexerSetupParticipant() {
+ return new IndexerSetupParticipant() {
+ public boolean postponeIndexerSetup(ICProject project) {
+ return !isProjectCreationComplete(project.getProject());
+ }
+ };
}
public void handleEvent(CProjectDescriptionEvent event) {
@@ -34,7 +47,7 @@ public class CProjectDescriptionListener implements ICProjectDescriptionListener
if (completedProjectCreation(old, act)) {
ICProject project= getProject(event);
if (project != null) {
- fIndexManager.addProject(project);
+ fIndexerSetupParticipant.notifyIndexerSetup(project);
}
}
else if (old != null && changedDefaultSettingConfiguration(old, act)) {
@@ -69,6 +82,11 @@ public class CProjectDescriptionListener implements ICProjectDescriptionListener
return null;
}
+ protected boolean isProjectCreationComplete(IProject project) {
+ ICProjectDescription desc= CProjectDescriptionManager.getInstance().getProjectDescription(project.getProject(), false);
+ return !(desc == null || desc.isCdtProjectCreating());
+ }
+
private boolean completedProjectCreation(ICProjectDescription old, ICProjectDescription act) {
return (old == null || old.isCdtProjectCreating()) && !act.isCdtProjectCreating();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
index 6ce38c6fa0..3f20f05fcd 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 QNX Software Systems and others.
+ * Copyright (c) 2005, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -22,6 +22,7 @@ import java.nio.channels.FileChannel;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -38,6 +39,7 @@ import org.eclipse.cdt.core.index.IIndexChangeListener;
import org.eclipse.cdt.core.index.IIndexLocationConverter;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.index.IIndexerStateListener;
+import org.eclipse.cdt.core.index.IndexerSetupParticipant;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICContainer;
@@ -48,7 +50,6 @@ import org.eclipse.cdt.core.model.ILanguageMappingChangeListener;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
-import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
@@ -67,7 +68,6 @@ import org.eclipse.cdt.internal.core.pdom.indexer.PDOMRebuildTask;
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMUpdateTask;
import org.eclipse.cdt.internal.core.pdom.indexer.TriggerNotificationTask;
import org.eclipse.cdt.internal.core.pdom.indexer.nulli.PDOMNullIndexer;
-import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -163,7 +163,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
private CModelListener fCModelListener= new CModelListener(this);
private ILanguageMappingChangeListener fLanguageChangeListener = new LanguageMappingChangeListener(this);
- private ICProjectDescriptionListener fProjectDescriptionListener= new CProjectDescriptionListener(this);
+ private final ICProjectDescriptionListener fProjectDescriptionListener;
private IndexFactory fIndexFactory= new IndexFactory(this);
private IndexProviderManager fIndexProviderManager = new IndexProviderManager();
@@ -175,7 +175,13 @@ public class PDOMManager implements IWritableIndexManager, IListener {
*/
private HashMap fUpdatePolicies= new HashMap();
private HashMap fPrefListeners= new HashMap();
+ private ArrayList fSetupParticipants= new ArrayList();
+ private HashSet fPostponedProjects= new HashSet();
+ public PDOMManager() {
+ fProjectDescriptionListener= new CProjectDescriptionListener(this);
+ }
+
public Job startup() {
Job postStartupJob= new Job(CCorePlugin.getResourceString("CCorePlugin.startupJob")) { //$NON-NLS-1$
protected IStatus run(IProgressMonitor monitor) {
@@ -627,7 +633,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
Job addProject= new Job(Messages.PDOMManager_StartJob_name) {
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask("", 100); //$NON-NLS-1$
- if (project.isOpen() && isFullyCreated(project)) {
+ if (project.isOpen() && !postponeSetup(cproject)) {
syncronizeProjectSettings(project, new SubProgressMonitor(monitor, 1));
if (getIndexer(cproject) == null) {
createIndexer(cproject, new SubProgressMonitor(monitor, 99));
@@ -668,14 +674,6 @@ public class PDOMManager implements IWritableIndexManager, IListener {
addProject.schedule();
}
- private boolean isFullyCreated(IProject project) {
- ICProjectDescription desc= CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
- if (desc != null && !desc.isCdtProjectCreating()) {
- return true;
- }
- return false;
- }
-
private void registerPreferenceListener(ICProject project) {
IProject prj= project.getProject();
PCL pcl= (PCL) fPrefListeners.get(prj);
@@ -836,24 +834,33 @@ public class PDOMManager implements IWritableIndexManager, IListener {
}
}
- public void reindex(ICProject project) {
- assert !Thread.holdsLock(fProjectToPDOM);
- IPDOMIndexer indexer= null;
- synchronized (fUpdatePolicies) {
- indexer= getIndexer(project);
- }
- // don't attempt to hold lock on indexerMutex while cancelling
- if (indexer != null) {
- cancelIndexerJobs(indexer);
- }
-
- synchronized(fUpdatePolicies) {
- indexer= getIndexer(project);
- if (indexer != null) {
- createPolicy(project).clearTUs();
- enqueue(new PDOMRebuildTask(indexer));
+ public void reindex(final ICProject project) {
+ Job job= new Job(Messages.PDOMManager_notifyJob_label) {
+ protected IStatus run(IProgressMonitor monitor) {
+ IPDOMIndexer indexer= null;
+ synchronized (fUpdatePolicies) {
+ indexer= getIndexer(project);
+ }
+ // don't attempt to hold lock on indexerMutex while cancelling
+ if (indexer != null) {
+ cancelIndexerJobs(indexer);
+ }
+
+ synchronized(fUpdatePolicies) {
+ indexer= getIndexer(project);
+ if (indexer != null) {
+ createPolicy(project).clearTUs();
+ enqueue(new PDOMRebuildTask(indexer));
+ }
+ }
+ return Status.OK_STATUS;
}
- }
+ public boolean belongsTo(Object family) {
+ return family == PDOMManager.this;
+ }
+ };
+ job.setSystem(true);
+ job.schedule();
}
public void addIndexChangeListener(IIndexChangeListener listener) {
@@ -1279,4 +1286,46 @@ public class PDOMManager implements IWritableIndexManager, IListener {
}
}
}
+
+ protected boolean postponeSetup(ICProject cproject) {
+ synchronized(fSetupParticipants) {
+ for (Iterator it = fSetupParticipants.iterator(); it.hasNext();) {
+ IndexerSetupParticipant sp = (IndexerSetupParticipant) it.next();
+ if (sp.postponeIndexerSetup(cproject)) {
+ fPostponedProjects.add(cproject);
+ return true;
+ }
+ }
+ fPostponedProjects.remove(cproject);
+ return false;
+ }
+ }
+
+ /**
+ * @param indexerSetupParticipant
+ * @param project
+ */
+ public void notifyIndexerSetup(IndexerSetupParticipant participant, ICProject project) {
+ synchronized(fSetupParticipants) {
+ if (fPostponedProjects.contains(project)) {
+ addProject(project);
+ }
+ }
+ }
+
+ public void addIndexerSetupParticipant(IndexerSetupParticipant participant) {
+ synchronized (fSetupParticipants) {
+ fSetupParticipants.add(participant);
+ }
+ }
+
+ public void removeIndexerSetupParticipant(IndexerSetupParticipant participant) {
+ synchronized (fSetupParticipants) {
+ fSetupParticipants.remove(participant);
+ for (Iterator it = fPostponedProjects.iterator(); it.hasNext();) {
+ ICProject project = (ICProject) it.next();
+ addProject(project);
+ }
+ }
+ }
}

Back to the top