mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Move LanguageSettingsScannerInfoProvider from ScannerInfoProviderProxy
to CCorePlugin.getScannerInfoProvider()
This commit is contained in:
parent
666d9577c6
commit
eba8c57096
3 changed files with 105 additions and 28 deletions
|
@ -12,14 +12,19 @@
|
|||
package org.eclipse.cdt.internal.core.language.settings.providers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsChangeEvent;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsChangeListener;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
|
@ -35,6 +40,7 @@ import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
|||
import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
@ -49,11 +55,13 @@ import org.eclipse.osgi.util.NLS;
|
|||
* @see IScannerInfo#getIncludePaths()
|
||||
*
|
||||
*/
|
||||
public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider {
|
||||
public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider, ILanguageSettingsChangeListener {
|
||||
private static final String FRAMEWORK_PRIVATE_HEADERS_INCLUDE = "/__framework__.framework/PrivateHeaders/__header__"; //$NON-NLS-1$
|
||||
private static final String FRAMEWORK_HEADERS_INCLUDE = "/__framework__.framework/Headers/__header__"; //$NON-NLS-1$
|
||||
private static final ExtendedScannerInfo DUMMY_SCANNER_INFO = new ExtendedScannerInfo();
|
||||
|
||||
private Map<IResource, List<IScannerInfoChangeListener>> listenersMap = null;
|
||||
|
||||
@Override
|
||||
public ExtendedScannerInfo getScannerInformation(IResource rc) {
|
||||
// AG FIXME - temporary log to remove before CDT Juno release
|
||||
|
@ -262,12 +270,70 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider
|
|||
|
||||
@Override
|
||||
public void subscribe(IResource resource, IScannerInfoChangeListener listener) {
|
||||
// Handled by ScannerInfoProviderProxy for the moment
|
||||
if (resource == null || listener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (listenersMap == null) {
|
||||
listenersMap = Collections.synchronizedMap(new HashMap<IResource, List<IScannerInfoChangeListener>>());
|
||||
}
|
||||
|
||||
IProject project = resource.getProject();
|
||||
List<IScannerInfoChangeListener> list = listenersMap.get(project);
|
||||
if (list == null) {
|
||||
list = new Vector<IScannerInfoChangeListener>();
|
||||
listenersMap.put(project, list);
|
||||
}
|
||||
if (!list.contains(listener)) {
|
||||
list.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe(IResource resource, IScannerInfoChangeListener listener) {
|
||||
// Handled by ScannerInfoProviderProxy for the moment
|
||||
if (resource == null || listener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
IProject project = resource.getProject();
|
||||
if (listenersMap != null) {
|
||||
List<IScannerInfoChangeListener> list = listenersMap.get(project);
|
||||
if (list != null) {
|
||||
list.remove(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEvent(ILanguageSettingsChangeEvent event) {
|
||||
if (listenersMap == null || listenersMap.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(event.getProjectName());
|
||||
if (project != null) {
|
||||
ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project);
|
||||
if (prjDescription != null) {
|
||||
ICConfigurationDescription indexedCfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
String indexedCfgId = indexedCfgDescription.getId();
|
||||
|
||||
for (String cfgId : event.getConfigurationDescriptionIds()) {
|
||||
if (cfgId.equals(indexedCfgId)) {
|
||||
for (Entry<IResource, List<IScannerInfoChangeListener>> entry : listenersMap.entrySet()) {
|
||||
IResource rc = entry.getKey();
|
||||
List<IScannerInfoChangeListener> listeners = listenersMap.get(rc);
|
||||
if (listeners != null && !listeners.isEmpty()) {
|
||||
IScannerInfo info = getScannerInformation(rc);
|
||||
for (IScannerInfoChangeListener listener : listeners) {
|
||||
listener.changeNotification(rc, info);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,12 +16,10 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsScannerInfoProvider;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
|
@ -36,11 +34,6 @@ public class ScannerInfoProviderProxy extends AbstractCExtensionProxy implements
|
|||
|
||||
@Override
|
||||
public IScannerInfo getScannerInformation(IResource resource) {
|
||||
if (ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(getProject())) {
|
||||
LanguageSettingsScannerInfoProvider lsProvider = new LanguageSettingsScannerInfoProvider();
|
||||
return lsProvider.getScannerInformation(resource);
|
||||
}
|
||||
// Legacy logic
|
||||
providerRequested();
|
||||
return fProvider.getScannerInformation(resource);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.eclipse.cdt.core.cdtvariables.IUserVarSupplier;
|
|||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
|
||||
import org.eclipse.cdt.core.index.IIndexManager;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
|
@ -50,6 +51,7 @@ import org.eclipse.cdt.internal.core.PositionTrackerManager;
|
|||
import org.eclipse.cdt.internal.core.cdtvariables.CdtVariableManager;
|
||||
import org.eclipse.cdt.internal.core.cdtvariables.UserVarSupplier;
|
||||
import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsScannerInfoProvider;
|
||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||
import org.eclipse.cdt.internal.core.model.Util;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
|
||||
|
@ -1027,28 +1029,17 @@ public class CCorePlugin extends Plugin {
|
|||
return provider;
|
||||
|
||||
// Next search the extension registry to see if a provider is registered with a build command
|
||||
IExtensionRegistry registry = Platform.getExtensionRegistry();
|
||||
IExtensionPoint point = registry.getExtensionPoint(SCANNER_INFO_PROVIDER2);
|
||||
if (point != null) {
|
||||
IExtension[] exts = point.getExtensions();
|
||||
for (IExtension ext : exts) {
|
||||
IConfigurationElement[] elems = ext.getConfigurationElements();
|
||||
for (IConfigurationElement elem : elems) {
|
||||
String builder = elem.getAttribute("builder"); //$NON-NLS-1$
|
||||
if (builder != null) {
|
||||
IProjectDescription desc = project.getDescription();
|
||||
ICommand[] commands = desc.getBuildSpec();
|
||||
for (ICommand command : commands)
|
||||
if (builder.equals(command.getBuilderName()))
|
||||
provider = (IScannerInfoProvider)elem.createExecutableExtension("class"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
provider = getExtensionScannerInfoProvider2(project);
|
||||
|
||||
// Regular usage is where Language Settings Providers are employed
|
||||
if (provider == null && ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(project)) {
|
||||
provider = new LanguageSettingsScannerInfoProvider();
|
||||
}
|
||||
|
||||
// Default to the proxy
|
||||
// Fall back to the MBS legacy
|
||||
if (provider == null)
|
||||
provider = fNewCProjectDescriptionManager.getScannerInfoProviderProxy(project);
|
||||
|
||||
project.setSessionProperty(scannerInfoProviderName, provider);
|
||||
} catch (CoreException e) {
|
||||
// Bug 313725: When project is being closed, don't report an error.
|
||||
|
@ -1061,6 +1052,33 @@ public class CCorePlugin extends Plugin {
|
|||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find {@link IScannerInfoProvider} registered as extension via extension point
|
||||
* org.eclipse.cdt.core.ScannerInfoProvider2.
|
||||
*/
|
||||
private IScannerInfoProvider getExtensionScannerInfoProvider2(IProject project) throws CoreException {
|
||||
IScannerInfoProvider provider = null;
|
||||
IExtensionRegistry registry = Platform.getExtensionRegistry();
|
||||
IExtensionPoint point = registry.getExtensionPoint(SCANNER_INFO_PROVIDER2);
|
||||
if (point != null) {
|
||||
IExtension[] exts = point.getExtensions();
|
||||
for (IExtension ext : exts) {
|
||||
IConfigurationElement[] elems = ext.getConfigurationElements();
|
||||
for (IConfigurationElement elem : elems) {
|
||||
String builder = elem.getAttribute("builder"); //$NON-NLS-1$
|
||||
if (builder != null) {
|
||||
IProjectDescription desc = project.getDescription();
|
||||
ICommand[] commands = desc.getBuildSpec();
|
||||
for (ICommand command : commands)
|
||||
if (builder.equals(command.getBuilderName()))
|
||||
provider = (IScannerInfoProvider)elem.createExecutableExtension("class"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function, returning the content type for a filename
|
||||
* Same as: <pre>
|
||||
|
|
Loading…
Add table
Reference in a new issue