1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 08:46:02 +02:00

bug 401961: Regression: pathEntryContainers entries are no longer honored when importing a project into cdt-8.1.2, due to LSP's being enabled

This commit is contained in:
Andrew Gvozdev 2013-03-30 07:17:37 -04:00
parent f123a05068
commit 4a20097fd3
5 changed files with 282 additions and 78 deletions

View file

@ -22,88 +22,86 @@ import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo;
import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IPerFileDiscoveredPathInfo;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
public class PerFileDiscoveredPathContainer extends DiscoveredPathContainer
implements IPathEntryContainerExtension {
public class PerFileDiscoveredPathContainer extends DiscoveredPathContainer implements IPathEntryContainerExtension {
public PerFileDiscoveredPathContainer(IProject project) {
super(project);
}
public PerFileDiscoveredPathContainer(IProject project) {
super(project);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.IPathEntryContainerExtension#getPathEntries(org.eclipse.core.runtime.IPath, int)
*/
@Override
@Override
public IPathEntry[] getPathEntries(IPath path, int mask) {
ArrayList<IPathEntry> entries = new ArrayList<IPathEntry>();
try {
IDiscoveredPathInfo info = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(fProject);
if (info instanceof IPerFileDiscoveredPathInfo) {
IPerFileDiscoveredPathInfo filePathInfo = (IPerFileDiscoveredPathInfo) info;
try {
IDiscoveredPathInfo info = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(fProject);
if (info instanceof IPerFileDiscoveredPathInfo) {
IResource rc = fProject.getWorkspace().getRoot().findMember(path);
if (rc.getType() == IResource.FOLDER || rc.getType() == IResource.PROJECT) {
return new IPathEntry[0];
}
if ((mask & IPathEntry.CDT_INCLUDE) != 0) {
IPath[] includes = filePathInfo.getIncludePaths(path);
for (int i = 0; i < includes.length; i++) {
// add as a system include path
entries.add(CoreModel.newIncludeEntry(path, Path.EMPTY, includes[i], true));
}
includes = filePathInfo.getQuoteIncludePaths(path);
for (int i = 0; i < includes.length; i++) {
// add as a local include path
entries.add(CoreModel.newIncludeEntry(path, Path.EMPTY, includes[i], false));
}
}
if ((mask & IPathEntry.CDT_MACRO) != 0) {
Map<String, String> syms = filePathInfo.getSymbols(path);
Set<Entry<String, String>> entrySet = syms.entrySet();
for (Entry<String, String> entry : entrySet) {
entries.add(CoreModel.newMacroEntry(path, entry.getKey(), entry.getValue()));
}
}
// compare the resource with include and macros files
IPath fullResPath = fProject.getWorkspace().getRoot().getFile(path).getLocation();
if (fullResPath == null) {
fullResPath = path;
}
if ((mask & IPathEntry.CDT_INCLUDE_FILE) != 0) {
IPath[] includeFiles = filePathInfo.getIncludeFiles(path);
for (int i = 0; i < includeFiles.length; i++) {
if (!includeFiles[i].equals(fullResPath)) {
entries.add(CoreModel.newIncludeFileEntry(path, includeFiles[i]));
}
}
}
if ((mask & IPathEntry.CDT_MACRO_FILE) != 0) {
IPath[] imacrosFiles = filePathInfo.getMacroFiles(path);
for (int i = 0; i < imacrosFiles.length; i++) {
if (!imacrosFiles[i].equals(fullResPath)) {
entries.add(CoreModel.newMacroFileEntry(path, imacrosFiles[i]));
}
}
}
}
}
catch (CoreException e) {
//
}
IPerFileDiscoveredPathInfo filePathInfo = (IPerFileDiscoveredPathInfo) info;
if ((mask & IPathEntry.CDT_INCLUDE) != 0) {
IPath[] includes = filePathInfo.getIncludePaths(path);
for (int i = 0; i < includes.length; i++) {
// add as a system include path
entries.add(CoreModel.newIncludeEntry(path, Path.EMPTY, includes[i], true));
}
includes = filePathInfo.getQuoteIncludePaths(path);
for (int i = 0; i < includes.length; i++) {
// add as a local include path
entries.add(CoreModel.newIncludeEntry(path, Path.EMPTY, includes[i], false));
}
}
if ((mask & IPathEntry.CDT_MACRO) != 0) {
Map<String, String> syms = filePathInfo.getSymbols(path);
Set<Entry<String, String>> entrySet = syms.entrySet();
for (Entry<String, String> entry : entrySet) {
entries.add(CoreModel.newMacroEntry(path, entry.getKey(), entry.getValue()));
}
}
// compare the resource with include and macros files
IPath fullResPath = fProject.getWorkspace().getRoot().getFile(path).getLocation();
if (fullResPath == null) {
fullResPath = path;
}
if ((mask & IPathEntry.CDT_INCLUDE_FILE) != 0) {
IPath[] includeFiles = filePathInfo.getIncludeFiles(path);
for (int i = 0; i < includeFiles.length; i++) {
if (!includeFiles[i].equals(fullResPath)) {
entries.add(CoreModel.newIncludeFileEntry(path, includeFiles[i]));
}
}
}
if ((mask & IPathEntry.CDT_MACRO_FILE) != 0) {
IPath[] imacrosFiles = filePathInfo.getMacroFiles(path);
for (int i = 0; i < imacrosFiles.length; i++) {
if (!imacrosFiles[i].equals(fullResPath)) {
entries.add(CoreModel.newMacroFileEntry(path, imacrosFiles[i]));
}
}
}
}
}
catch (CoreException e) {
//
}
return entries.toArray(new IPathEntry[entries.size()]);
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.IPathEntryContainerExtension#isEmpty(org.eclipse.core.runtime.IPath)
*/
@Override
public boolean isEmpty(IPath path) {
IDiscoveredPathInfo info;
IDiscoveredPathInfo info;
try {
info = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(fProject);
if (info instanceof IPerFileDiscoveredPathInfo) {
IPerFileDiscoveredPathInfo filePathInfo = (IPerFileDiscoveredPathInfo) info;
return filePathInfo.isEmpty(path);
}
if (info instanceof IPerFileDiscoveredPathInfo) {
IPerFileDiscoveredPathInfo filePathInfo = (IPerFileDiscoveredPathInfo) info;
return filePathInfo.isEmpty(path);
}
} catch (CoreException e) {
}
return false;

View file

@ -24,6 +24,7 @@ import org.eclipse.cdt.internal.core.LocalProjectScope;
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager;
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
import org.eclipse.cdt.internal.core.language.settings.providers.ScannerInfoExtensionLanguageSettingsProvider;
import org.eclipse.cdt.internal.core.model.PathEntryManager;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.preferences.InstanceScope;
@ -44,8 +45,18 @@ public class ScannerDiscoveryLegacySupport {
public static final String USER_LANGUAGE_SETTINGS_PROVIDER_ID = "org.eclipse.cdt.ui.UserLanguageSettingsProvider"; //$NON-NLS-1$
/** ID of MBS language settings provider (from org.eclipse.cdt.managedbuilder.core) */
public static final String MBS_LANGUAGE_SETTINGS_PROVIDER_ID = "org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider"; //$NON-NLS-1$
/** ID of ScannerInfo language settings provider wrapping ScannerInfoProvider defined by org.eclipse.cdt.core.ScannerInfoProvider extension point */
private static final String SI_LANGUAGE_SETTINGS_PROVIDER_ID = "org.eclipse.cdt.core.LegacyScannerInfoLanguageSettingsProvider"; //$NON-NLS-1$
/**
* ID of ScannerInfo language settings provider wrapping ScannerInfoProvider defined by org.eclipse.cdt.core.ScannerInfoProvider extension point
* @since 5.5
*/
public static final String SI_LANGUAGE_SETTINGS_PROVIDER_ID = "org.eclipse.cdt.core.LegacyScannerInfoLanguageSettingsProvider"; //$NON-NLS-1$
/**
* ID of language settings provider wrapping {@link org.eclipse.cdt.core.resources.ScannerProvider} of {@link PathEntryManager} for 3.X projects
* @since 5.5
*/
public static final String PATH_ENTRY_MANAGER_LANGUAGE_SETTINGS_PROVIDER_ID = "org.eclipse.cdt.core.PathEntryScannerInfoLanguageSettingsProvider"; //$NON-NLS-1$
private static String DISABLE_LSP_PREFERENCE = "language.settings.providers.disabled"; //$NON-NLS-1$
// the default for project needs to be "disabled" - for legacy projects to be open with old SD enabled for MBS provider
@ -131,6 +142,24 @@ public class ScannerDiscoveryLegacySupport {
return false;
}
/**
* Check if legacy Scanner Discovery should be active.
* @noreference This is internal helper method to support compatibility with previous versions
* which is not intended to be referenced by clients.
*/
public static boolean isLegacyProviderOn(ICConfigurationDescription cfgDescription) {
if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) {
List<ILanguageSettingsProvider> lsProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
for (ILanguageSettingsProvider lsp : lsProviders) {
String id = lsp.getId();
if (MBS_LANGUAGE_SETTINGS_PROVIDER_ID.equals(id) || SI_LANGUAGE_SETTINGS_PROVIDER_ID.equals(id) || PATH_ENTRY_MANAGER_LANGUAGE_SETTINGS_PROVIDER_ID.equals(id)) {
return true;
}
}
}
return false;
}
/**
* @noreference This is internal helper method to support compatibility with previous versions
* which is not intended to be referenced by clients.
@ -143,7 +172,7 @@ public class ScannerDiscoveryLegacySupport {
project = prjDescription.getProject();
}
}
return !isLanguageSettingsProvidersFunctionalityEnabled(project) || isMbsLanguageSettingsProviderOn(cfgDescription);
return !isLanguageSettingsProvidersFunctionalityEnabled(project) || isLegacyProviderOn(cfgDescription);
}
/**
@ -156,7 +185,7 @@ public class ScannerDiscoveryLegacySupport {
if (prjDescription != null) {
cfgDescription = prjDescription.getActiveConfiguration();
}
return !isLanguageSettingsProvidersFunctionalityEnabled(project) || isMbsLanguageSettingsProviderOn(cfgDescription);
return !isLanguageSettingsProvidersFunctionalityEnabled(project) || isLegacyProviderOn(cfgDescription);
}
/**
@ -168,14 +197,16 @@ public class ScannerDiscoveryLegacySupport {
*/
public static String[] getDefaultProviderIdsLegacy(ICConfigurationDescription cfgDescription) {
boolean useScannerInfoProviderExtension = new ScannerInfoExtensionLanguageSettingsProvider().getScannerInfoProvider(cfgDescription) != null;
String legacyProviderId;
if (useScannerInfoProviderExtension) {
return new String[] {USER_LANGUAGE_SETTINGS_PROVIDER_ID, SI_LANGUAGE_SETTINGS_PROVIDER_ID};
legacyProviderId = SI_LANGUAGE_SETTINGS_PROVIDER_ID;
} else if (CProjectDescriptionManager.getInstance().isNewStyleCfg(cfgDescription)) {
legacyProviderId = MBS_LANGUAGE_SETTINGS_PROVIDER_ID;
} else {
legacyProviderId = PATH_ENTRY_MANAGER_LANGUAGE_SETTINGS_PROVIDER_ID;
}
if (CProjectDescriptionManager.getInstance().isNewStyleCfg(cfgDescription)) {
return new String[] {USER_LANGUAGE_SETTINGS_PROVIDER_ID, MBS_LANGUAGE_SETTINGS_PROVIDER_ID};
}
return null;
return new String[] {USER_LANGUAGE_SETTINGS_PROVIDER_ID, legacyProviderId};
}
/**
@ -192,10 +223,14 @@ public class ScannerDiscoveryLegacySupport {
return useScannerInfoProviderExtension;
}
boolean isNewStyleCfg = CProjectDescriptionManager.getInstance().isNewStyleCfg(cfgDescription);
if (MBS_LANGUAGE_SETTINGS_PROVIDER_ID.equals(providerId)) {
boolean isNewStyleCfg = CProjectDescriptionManager.getInstance().isNewStyleCfg(cfgDescription);
return !useScannerInfoProviderExtension && isNewStyleCfg;
}
if (PATH_ENTRY_MANAGER_LANGUAGE_SETTINGS_PROVIDER_ID.equals(providerId)) {
return !useScannerInfoProviderExtension && !isNewStyleCfg;
}
}
return true;

View file

@ -0,0 +1,165 @@
/*******************************************************************************
* Copyright (c) 2013, 2013 Andrew Gvozdev 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:
* Andrew Gvozdev - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.language.settings.providers;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IContainerEntry;
import org.eclipse.cdt.core.model.IIncludeEntry;
import org.eclipse.cdt.core.model.IIncludeFileEntry;
import org.eclipse.cdt.core.model.ILibraryEntry;
import org.eclipse.cdt.core.model.IMacroEntry;
import org.eclipse.cdt.core.model.IMacroFileEntry;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.IPathEntryContainer;
import org.eclipse.cdt.core.model.IPathEntryContainerExtension;
import org.eclipse.cdt.core.resources.IPathEntryStore;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.model.DefaultPathEntryStore;
import org.eclipse.cdt.internal.core.model.PathEntryManager;
import org.eclipse.cdt.internal.core.model.PathEntryUtil;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
/**
* Wrapper class intended to provide backward compatibility with ScannerInfo supplied by {@link PathEntryManager}.
*/
public class PathEntryScannerInfoLanguageSettingsProvider extends LanguageSettingsBaseProvider {
@Override
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
if (cfgDescription == null) {
return null;
}
ICProjectDescription prjDescription = cfgDescription.getProjectDescription();
if (prjDescription == null) {
return null;
}
IProject project = prjDescription.getProject();
ICProject cproject = CModelManager.getDefault().getCModel().getCProject(project);
IPath projectPath = cproject.getPath();
// using map of sets to support specific ordering of entries
LinkedHashMap<Integer, Set<IPathEntry>> pathEntriesMap = new LinkedHashMap<Integer, Set<IPathEntry>>();
pathEntriesMap.put(IPathEntry.CDT_INCLUDE, new LinkedHashSet<IPathEntry>());
// keep macros sorted
pathEntriesMap.put(IPathEntry.CDT_MACRO, new TreeSet<IPathEntry>(new Comparator<IPathEntry>() {
@Override
public int compare(IPathEntry macro1, IPathEntry macro2) {
if (macro1 instanceof IMacroEntry && macro2 instanceof IMacroEntry) {
return ((IMacroEntry)macro1).getMacroName().compareTo(((IMacroEntry)macro2).getMacroName());
}
return 0;
}
}));
pathEntriesMap.put(IPathEntry.CDT_INCLUDE_FILE, new LinkedHashSet<IPathEntry>());
pathEntriesMap.put(IPathEntry.CDT_MACRO_FILE, new LinkedHashSet<IPathEntry>());
pathEntriesMap.put(IPathEntry.CDT_LIBRARY, new LinkedHashSet<IPathEntry>());
IPathEntryStore pathEntryStore = new DefaultPathEntryStore(project);
int typesMask = IPathEntry.CDT_INCLUDE | IPathEntry.CDT_MACRO | IPathEntry.CDT_INCLUDE_FILE | IPathEntry.CDT_MACRO_FILE | IPathEntry.CDT_LIBRARY;
try {
IPathEntry[] storePathEntries = pathEntryStore.getRawPathEntries();
for (IPathEntry storePathEntry : storePathEntries) {
if (storePathEntry instanceof IContainerEntry) {
try {
IPathEntryContainer container = PathEntryManager.getDefault().getPathEntryContainer((IContainerEntry) storePathEntry, cproject);
if (container != null) {
IPathEntry[] pathEntries = null;
if (container instanceof IPathEntryContainerExtension) {
pathEntries = ((IPathEntryContainerExtension)container).getPathEntries(rc.getFullPath(), typesMask);
} else {
pathEntries = container.getPathEntries();
}
if (pathEntries != null) {
for (IPathEntry pathEntry : pathEntries) {
collectPathEntry(pathEntriesMap, projectPath, pathEntry);
}
}
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
} else {
collectPathEntry(pathEntriesMap, projectPath, storePathEntry);
}
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
Set<ICLanguageSettingEntry> lsEntries = new LinkedHashSet<ICLanguageSettingEntry>();
for (Entry<Integer, Set<IPathEntry>> entrySet : pathEntriesMap.entrySet()) {
Set<IPathEntry> pathEntries = entrySet.getValue();
for (IPathEntry pathEntry : pathEntries) {
ICLanguageSettingEntry lsEntry = toLanguageSettingsEntry(pathEntry);
if (lsEntry != null) {
lsEntries.add(lsEntry);
}
}
}
return LanguageSettingsSerializableStorage.getPooledList(new ArrayList<ICLanguageSettingEntry>(lsEntries));
}
private void collectPathEntry(LinkedHashMap<Integer, Set<IPathEntry>> pathEntriesMap, IPath projectPath, IPathEntry pathEntry) {
switch (pathEntry.getEntryKind()) {
case IPathEntry.CDT_INCLUDE:
case IPathEntry.CDT_MACRO:
case IPathEntry.CDT_INCLUDE_FILE:
case IPathEntry.CDT_MACRO_FILE:
case IPathEntry.CDT_LIBRARY:
IPathEntry resolvedPathEntry = PathEntryUtil.cloneEntryAndExpand(projectPath, pathEntry);
Set<IPathEntry> set = pathEntriesMap.get(resolvedPathEntry.getEntryKind());
if (set != null) {
set.add(resolvedPathEntry);
}
}
}
private ICLanguageSettingEntry toLanguageSettingsEntry(IPathEntry pathEntry) {
switch (pathEntry.getEntryKind()) {
case IPathEntry.CDT_INCLUDE:
IIncludeEntry includeEntry = (IIncludeEntry)pathEntry;
return CDataUtil.createCIncludePathEntry(includeEntry.getFullIncludePath().toOSString(), includeEntry.isSystemInclude() ? 0 : ICSettingEntry.LOCAL);
case IPathEntry.CDT_MACRO:
IMacroEntry macroEntry = (IMacroEntry) pathEntry;
return CDataUtil.createCMacroEntry(macroEntry.getMacroName(), macroEntry.getMacroValue(), 0);
case IPathEntry.CDT_INCLUDE_FILE:
IIncludeFileEntry includeFileEntry = (IIncludeFileEntry) pathEntry;
return CDataUtil.createCIncludeFileEntry(includeFileEntry.getFullIncludeFilePath().toOSString(), 0);
case IPathEntry.CDT_MACRO_FILE:
IMacroFileEntry macroFileEntry = (IMacroFileEntry) pathEntry;
return CDataUtil.createCMacroFileEntry(macroFileEntry.getFullMacroFilePath().toOSString(), 0);
case IPathEntry.CDT_LIBRARY:
ILibraryEntry libraryEntry = (ILibraryEntry) pathEntry;
return CDataUtil.createCLibraryFileEntry(libraryEntry.getFullLibraryPath().toOSString(), 0);
}
return null;
}
}

View file

@ -135,3 +135,4 @@ efsExtensionProvider.name = EFSExtensionProvider
refreshExclusionFactory.name = Refresh Exclusion Factory
uncPathConverter.name = UNC Path Converter
ScannerInfoExtensionLanguageSettingsProvider.name=Contributed ScannerInfo Entries
PathEntryScannerInfoLanguageSettingsProvider.name=Contributed PathEntry Containers

View file

@ -814,6 +814,11 @@
id="org.eclipse.cdt.core.LegacyScannerInfoLanguageSettingsProvider"
name="%ScannerInfoExtensionLanguageSettingsProvider.name">
</provider>
<provider
class="org.eclipse.cdt.internal.core.language.settings.providers.PathEntryScannerInfoLanguageSettingsProvider"
id="org.eclipse.cdt.core.PathEntryScannerInfoLanguageSettingsProvider"
name="%PathEntryScannerInfoLanguageSettingsProvider.name">
</provider>
</extension>
</plugin>