diff --git a/build/org.eclipse.cdt.make.core/plugin.xml b/build/org.eclipse.cdt.make.core/plugin.xml index bee6f6a1a97..69c21ff16e9 100644 --- a/build/org.eclipse.cdt.make.core/plugin.xml +++ b/build/org.eclipse.cdt.make.core/plugin.xml @@ -129,7 +129,9 @@ id="GCCStandardMakePerProjectProfile" name="%extensionGCCPerProjectProfile.name" point="org.eclipse.cdt.make.core.ScannerConfigurationDiscoveryProfile"> - + @@ -146,7 +148,9 @@ id="GCCStandardMakePerFileProfile" name="%extensionGCCPerFileProfile.name" point="org.eclipse.cdt.make.core.ScannerConfigurationDiscoveryProfile"> - + diff --git a/build/org.eclipse.cdt.make.core/schema/ScannerConfigurationDiscoveryProfile.exsd b/build/org.eclipse.cdt.make.core/schema/ScannerConfigurationDiscoveryProfile.exsd index 24c96f200c4..e0604e8ec12 100644 --- a/build/org.eclipse.cdt.make.core/schema/ScannerConfigurationDiscoveryProfile.exsd +++ b/build/org.eclipse.cdt.make.core/schema/ScannerConfigurationDiscoveryProfile.exsd @@ -65,6 +65,21 @@ + + + + + + + + + + + + + + + diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/IDiscoveredPathManager.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/IDiscoveredPathManager.java index 4e3a341a69c..60471eba6be 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/IDiscoveredPathManager.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/IDiscoveredPathManager.java @@ -11,9 +11,11 @@ package org.eclipse.cdt.make.core.scannerconfig; import java.util.LinkedHashMap; import java.util.Map; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.w3c.dom.Element; public interface IDiscoveredPathManager { @@ -21,25 +23,75 @@ public interface IDiscoveredPathManager { IProject getProject(); - IPath[] getIncludePaths(); + /** + * Get include paths for the whole project + * @return + */ + IPath[] getIncludePaths(); + /** + * Get defined symbols for the whole project + * @return + */ Map getSymbols(); - void setIncludeMap(LinkedHashMap map); + /** + * Get include paths for the specific path (file) + * @return + */ + IPath[] getIncludePaths(IPath path); + /** + * Get defined symbols for the specific path (file) + * @return + */ + Map getSymbols(IPath path); + + IDiscoveredScannerInfoSerializable getSerializable(); + ScannerConfigScope getScope(); + + void setIncludeMap(LinkedHashMap map); void setSymbolMap(LinkedHashMap map); LinkedHashMap getIncludeMap(); LinkedHashMap getSymbolMap(); } - interface IDiscoveredInfoListener { + interface IDiscoveredScannerInfoSerializable { + /** + * Serialize discovered scanner info to an XML element + * + * @param root + */ + public void serialize(Element root); + + /** + * Deserialize discovered scanner info from an XML element + * + * @param root + */ + public void deserialize(Element root); + + /** + * @return an id of the collector + */ + public String getCollectorId(); + } + + interface IDiscoveredInfoListener { void infoChanged(IDiscoveredPathInfo info); - void infoRemoved(IProject project); + void infoRemoved(IDiscoveredPathInfo info); } IDiscoveredPathInfo getDiscoveredInfo(IProject project) throws CoreException; void removeDiscoveredInfo(IProject project); void updateDiscoveredInfo(IDiscoveredPathInfo info) throws CoreException; + /** + * @param project + * @param profileScope + * @throws CModelException + * @throws CoreException + */ + void changeDiscoveredContainer(IProject project, ScannerConfigScope profileScope); void addDiscoveredInfoListener(IDiscoveredInfoListener listener); void removeDiscoveredInfoListener(IDiscoveredInfoListener listener); diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/IScannerInfoCollector2.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/IScannerInfoCollector2.java index 116c54b7425..005384bf4a0 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/IScannerInfoCollector2.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/IScannerInfoCollector2.java @@ -10,6 +10,7 @@ ***********************************************************************/ package org.eclipse.cdt.make.core.scannerconfig; +import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -31,6 +32,15 @@ public interface IScannerInfoCollector2 extends IScannerInfoCollector { * @throws CoreException */ public void updateScannerConfiguration(IProgressMonitor monitor) throws CoreException; + + /** + * Create and return new IDiscoveredPathInfo that can hopefully serialize + * discovered scanner config to a file + * + * @return pathInfo + * @throws CoreException + */ + public IDiscoveredPathInfo createPathInfoObject(); // /** // * Answers a map of collected defines that the the compiler uses by default. diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigScope.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigScope.java new file mode 100644 index 00000000000..a8c4b8743f0 --- /dev/null +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigScope.java @@ -0,0 +1,35 @@ +package org.eclipse.cdt.make.core.scannerconfig; + +/** + * Profile scope enum + * + * @author vhirsl + */ +public class ScannerConfigScope { + public static final ScannerConfigScope PROJECT_SCOPE = new ScannerConfigScope("project"); //$NON-NLS-1$ + public static final ScannerConfigScope FILE_SCOPE = new ScannerConfigScope("file"); //$NON-NLS-1$ + + public String toString() { + return scope; + } + + private String scope; + private ScannerConfigScope(String scope) { + this.scope = scope; + } + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object arg0) { + if (arg0 == null) return false; + if (arg0 == this) return true; + if (arg0 instanceof ScannerConfigScope) return scope.equals(((ScannerConfigScope)arg0).scope); + return false; + } + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return scope.hashCode(); + } +} \ No newline at end of file diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeMessages.properties b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeMessages.properties index c2ed9295cbe..888ca278dea 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeMessages.properties +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeMessages.properties @@ -49,4 +49,5 @@ ConsoleParser.Ambiguous_Filepath_Error_Message=CDT Path Discovery is unable to r ConsoleParser.Working_Directory_Error_Message=CDT Path Discovery is unable to determine working directory of the build command ConsoleParser.Nonexistent_Include_Path_Error_Message=CDT Path Discovery has discovered and will ignore a non-existent include path: -DiscoveredContainer.description=Discovered Paths \ No newline at end of file +DiscoveredContainer.description=Discovered Paths +DiscoveredContainer.ScopeErrorMessage=Invalid scanner configuration discovery profile scope diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/AbstractDiscoveredPathContainer.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/AbstractDiscoveredPathContainer.java new file mode 100644 index 00000000000..ab9adcd8652 --- /dev/null +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/AbstractDiscoveredPathContainer.java @@ -0,0 +1,85 @@ +/*********************************************************************** + * Copyright (c) 2004 IBM Corporation 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: + * IBM - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.make.internal.core.scannerconfig; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.core.model.IPathEntryContainer; +import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo; +import org.eclipse.cdt.make.internal.core.MakeMessages; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +public abstract class AbstractDiscoveredPathContainer implements IPathEntryContainer { + public static final IPath CONTAINER_ID = new Path("org.eclipse.cdt.make.core.DISCOVERED_SCANNER_INFO"); //$NON-NLS-1$ + + protected final IProject fProject; + + public AbstractDiscoveredPathContainer(IProject project) { + fProject = project; + } + + public IPathEntry[] getPathEntries() { + IPathEntry[] fPathEntries; + try { + fPathEntries = getPathEntries(getPathEntryMap(), fProject); + } catch (CoreException e) { + MakeCorePlugin.log(e); + return new IPathEntry[0]; + } + return fPathEntries; + } + + abstract protected Map getPathEntryMap(); + + public String getDescription() { + return MakeMessages.getString("DiscoveredContainer.description"); //$NON-NLS-1$ + } + + public IPath getPath() { + return CONTAINER_ID; + } + + public static IPathEntry[] getPathEntries(Map pathEntryMap, IProject project) throws CoreException { + IPathEntry[] entries = (IPathEntry[])pathEntryMap.get(project); + if (entries == null) { + entries = computeNewPathEntries(project); + pathEntryMap.put(project, entries); + } + return entries; + } + + private static IPathEntry[] computeNewPathEntries(IProject project) throws CoreException { + IDiscoveredPathInfo info = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(project); + IPath[] includes = info.getIncludePaths(); + Map syms = info.getSymbols(); + List entries = new ArrayList(includes.length + syms.size()); + for (int i = 0; i < includes.length; i++) { + entries.add(CoreModel.newIncludeEntry(Path.EMPTY, Path.EMPTY, includes[i])); //$NON-NLS-1$ //$NON-NLS-2$ + } + Iterator iter = syms.entrySet().iterator(); + while (iter.hasNext()) { + Entry entry = (Entry)iter.next(); + entries.add(CoreModel.newMacroEntry(Path.EMPTY, (String)entry.getKey(), (String)entry.getValue())); //$NON-NLS-1$ + } + return (IPathEntry[])entries.toArray(new IPathEntry[entries.size()]); + } + +} diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathContainer.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathContainer.java index effcd0ee59e..0d1f37626f6 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathContainer.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathContainer.java @@ -8,92 +8,53 @@ ******************************************************************************/ package org.eclipse.cdt.make.internal.core.scannerconfig; -import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; -import java.util.List; import java.util.Map; -import java.util.Map.Entry; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.IPathEntry; -import org.eclipse.cdt.core.model.IPathEntryContainer; import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigScope; import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredInfoListener; import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo; -import org.eclipse.cdt.make.internal.core.MakeMessages; import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -public class DiscoveredPathContainer implements IPathEntryContainer { - - public static IPath CONTAINER_ID = new Path("org.eclipse.cdt.make.core.DISCOVERED_SCANNER_INFO"); //$NON-NLS-1$ - - private final IProject fProject; +public class DiscoveredPathContainer extends AbstractDiscoveredPathContainer { static Map fgPathEntries; public DiscoveredPathContainer(IProject project) { - fProject = project; - } + super(project); + initialize(); + } - public static IPathEntry[] getPathEntries(IProject project) throws CoreException { - if (fgPathEntries == null) { - fgPathEntries = new HashMap(10); - IDiscoveredInfoListener listener = new IDiscoveredInfoListener() { + private static void initialize() { + if (fgPathEntries == null) { + fgPathEntries = new HashMap(10); - public void infoRemoved(IProject project) { - fgPathEntries.remove(project); - } + IDiscoveredInfoListener listener = new IDiscoveredInfoListener() { - public void infoChanged(IDiscoveredPathInfo info) { - fgPathEntries.remove(info.getProject()); - } - }; - MakeCorePlugin.getDefault().getDiscoveryManager().addDiscoveredInfoListener(listener); - } - IPathEntry[] entries = (IPathEntry[])fgPathEntries.get(project); - if (entries == null) { - entries = computeNewPathEntries(project); - fgPathEntries.put(project, entries); - } - return entries; - } + public void infoRemoved(IDiscoveredPathInfo info) { + if (info != null && + ScannerConfigScope.PROJECT_SCOPE.equals(info.getScope())) { + fgPathEntries.remove(info.getProject()); + } + } - private static IPathEntry[] computeNewPathEntries(IProject project) throws CoreException { - IDiscoveredPathInfo info = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(project); - IPath[] includes = info.getIncludePaths(); - Map syms = info.getSymbols(); - List entries = new ArrayList(includes.length + syms.size()); - for (int i = 0; i < includes.length; i++) { - entries.add(CoreModel.newIncludeEntry(Path.EMPTY, Path.EMPTY, includes[i])); //$NON-NLS-1$ //$NON-NLS-2$ - } - Iterator iter = syms.entrySet().iterator(); - while (iter.hasNext()) { - Entry entry = (Entry)iter.next(); - entries.add(CoreModel.newMacroEntry(Path.EMPTY, (String)entry.getKey(), (String)entry.getValue())); //$NON-NLS-1$ - } - return (IPathEntry[])entries.toArray(new IPathEntry[entries.size()]); - } + public void infoChanged(IDiscoveredPathInfo info) { + if (info != null && + ScannerConfigScope.PROJECT_SCOPE.equals(info.getScope())) { + fgPathEntries.remove(info.getProject()); + } + } - public IPathEntry[] getPathEntries() { - IPathEntry[] fPathEntries; - try { - fPathEntries = getPathEntries(fProject); - } catch (CoreException e) { - MakeCorePlugin.log(e); - return new IPathEntry[0]; - } - return fPathEntries; - } + }; + MakeCorePlugin.getDefault().getDiscoveryManager().addDiscoveredInfoListener(listener); + } + } - public String getDescription() { - return MakeMessages.getString("DiscoveredContainer.description"); //$NON-NLS-1$ - } - - public IPath getPath() { - return CONTAINER_ID; - } + /* (non-Javadoc) + * @see org.eclipse.cdt.make.internal.core.scannerconfig.AbstractDiscoveredPathContainer#getPathEntryMap() + */ + protected Map getPathEntryMap() { + return fgPathEntries; + } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathInfo.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathInfo.java index 4984c139f8e..a8986729922 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathInfo.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathInfo.java @@ -15,8 +15,9 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigScope; import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo; -import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore.IDiscoveredScannerInfoSerializable; +import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredScannerInfoSerializable; import org.eclipse.cdt.make.internal.core.scannerconfig.util.SymbolEntry; import org.eclipse.cdt.make.internal.core.scannerconfig2.PerProjectSICollector; import org.eclipse.core.resources.IProject; @@ -196,5 +197,39 @@ public class DiscoveredPathInfo implements IDiscoveredPathInfo, IDiscoveredScann public String getCollectorId() { return PerProjectSICollector.COLLECTOR_ID; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getIncludePaths(org.eclipse.core.runtime.IPath) + */ + public IPath[] getIncludePaths(IPath path) { + if (project.getFile(path) != null) { + return getIncludePaths(); + } + return new IPath[0]; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getSymbols(org.eclipse.core.runtime.IPath) + */ + public Map getSymbols(IPath path) { + if (project.getFile(path) != null) { + return getSymbols(); + } + return new HashMap(0); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getSerializable() + */ + public IDiscoveredScannerInfoSerializable getSerializable() { + return this; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getScope() + */ + public ScannerConfigScope getScope() { + return ScannerConfigScope.PROJECT_SCOPE; + } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathInitializer.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathInitializer.java index cc07436708f..50bc65e0699 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathInitializer.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathInitializer.java @@ -11,14 +11,35 @@ package org.eclipse.cdt.make.internal.core.scannerconfig; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.PathEntryContainerInitializer; +import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2; +import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigScope; +import org.eclipse.cdt.make.internal.core.MakeMessages; +import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfileManager; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; public class DiscoveredPathInitializer extends PathEntryContainerInitializer { - public void initialize(IPath containerPath, ICProject project) throws CoreException { - CoreModel.setPathEntryContainer(new ICProject[]{project}, new DiscoveredPathContainer(project.getProject()), null); + public void initialize(IPath containerPath, ICProject cProject) throws CoreException { + IProject project = cProject.getProject(); + IScannerConfigBuilderInfo2 buildInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(project); + ScannerConfigScope profileScope = ScannerConfigProfileManager.getInstance(). + getSCProfileConfiguration(buildInfo.getSelectedProfileId()).getProfileScope(); + if (ScannerConfigScope.PROJECT_SCOPE.equals(profileScope)) { + CoreModel.setPathEntryContainer(new ICProject[]{cProject}, new DiscoveredPathContainer(project), null); + } + else if (ScannerConfigScope.FILE_SCOPE.equals(profileScope)) { + CoreModel.setPathEntryContainer(new ICProject[]{cProject}, new PerFileDiscoveredPathContainer(project), null); + } + else { + throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), 1, + MakeMessages.getString("DiscoveredContainer.ScopeErrorMessage"), null)); //$NON-NLS-1$ + } } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathManager.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathManager.java index 5ca497c751e..f2e805ef21a 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathManager.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathManager.java @@ -15,12 +15,18 @@ import java.util.List; import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager; +import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2; +import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector; +import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2; +import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigScope; import org.eclipse.cdt.make.internal.core.MakeMessages; -import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore.IDiscoveredScannerInfoSerializable; +import org.eclipse.cdt.make.internal.core.scannerconfig2.SCProfileInstance; +import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfileManager; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceChangeEvent; @@ -33,6 +39,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; + public class DiscoveredPathManager implements IDiscoveredPathManager, IResourceChangeListener { private Map fDiscoveredMap = new HashMap(); @@ -62,7 +69,7 @@ public class DiscoveredPathManager implements IDiscoveredPathManager, IResourceC switch (event.getType()) { case IResourceChangeEvent.POST_CHANGE : - ScannerConfigUtil.updateScannerConfigStore(event.getDelta()); + DiscoveredScannerInfoStore.getInstance().updateScannerConfigStore(event.getDelta()); break; case IResourceChangeEvent.PRE_DELETE : case IResourceChangeEvent.PRE_CLOSE : @@ -75,7 +82,7 @@ public class DiscoveredPathManager implements IDiscoveredPathManager, IResourceC } public IDiscoveredPathInfo getDiscoveredInfo(IProject project) throws CoreException { - DiscoveredPathInfo info = (DiscoveredPathInfo)fDiscoveredMap.get(project); + IDiscoveredPathInfo info = (IDiscoveredPathInfo)fDiscoveredMap.get(project); if (info == null) { info = loadPathInfo(project); fDiscoveredMap.put(project, info); @@ -83,15 +90,27 @@ public class DiscoveredPathManager implements IDiscoveredPathManager, IResourceC return info; } - private DiscoveredPathInfo loadPathInfo(IProject project) throws CoreException { - DiscoveredPathInfo info = new DiscoveredPathInfo(project); - DiscoveredScannerInfoStore.getInstance().loadDiscoveredScannerInfoFromState(project, info); - return info; + private IDiscoveredPathInfo loadPathInfo(IProject project) throws CoreException { + IDiscoveredPathInfo pathInfo = null; + + IScannerConfigBuilderInfo2 buildInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(project); + String profileId = buildInfo.getSelectedProfileId(); + SCProfileInstance profileInstance = ScannerConfigProfileManager.getInstance(). + getSCProfileInstance(project, profileId); + IScannerInfoCollector collector = profileInstance.getScannerInfoCollector(); + + if (collector instanceof IScannerInfoCollector2) { + IScannerInfoCollector2 collector2 = (IScannerInfoCollector2) collector; + pathInfo = collector2.createPathInfoObject(); + } + else { + pathInfo = new DiscoveredPathInfo(project); + } + return pathInfo; } public void removeDiscoveredInfo(IProject project) { - ScannerConfigUtil.getDiscoveredScannerConfigStore(project, true); - DiscoveredPathInfo info = (DiscoveredPathInfo)fDiscoveredMap.remove(project); + IDiscoveredPathInfo info = (IDiscoveredPathInfo)fDiscoveredMap.remove(project); if (info != null) { fireUpdate(INFO_REMOVED, info); } @@ -99,15 +118,22 @@ public class DiscoveredPathManager implements IDiscoveredPathManager, IResourceC public void updateDiscoveredInfo(IDiscoveredPathInfo info) throws CoreException { if (fDiscoveredMap.get(info.getProject()) != null) { - if (info instanceof IDiscoveredScannerInfoSerializable) { - IDiscoveredScannerInfoSerializable serializable = (IDiscoveredScannerInfoSerializable) info; - DiscoveredScannerInfoStore.getInstance().saveDiscoveredScannerInfoToState(info.getProject(), serializable); + IDiscoveredScannerInfoSerializable serializable = info.getSerializable(); + if (serializable != null) { + IProject project = info.getProject(); + DiscoveredScannerInfoStore.getInstance().saveDiscoveredScannerInfoToState(project, serializable); fireUpdate(INFO_CHANGED, info); - ICProject cProject = CoreModel.getDefault().create(info.getProject()); - if (cProject != null) { - CoreModel.setPathEntryContainer(new ICProject[]{cProject}, - new DiscoveredPathContainer(info.getProject()), null); - } + +// ICProject cProject = CoreModel.getDefault().create(info.getProject()); +// if (cProject != null) { +// CoreModel.setPathEntryContainer(new ICProject[]{cProject}, +// new DiscoveredPathContainer(info.getProject()), null); +// } + IScannerConfigBuilderInfo2 buildInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(project); + String profileId = buildInfo.getSelectedProfileId(); + ScannerConfigScope profileScope = ScannerConfigProfileManager.getInstance(). + getSCProfileConfiguration(profileId).getProfileScope(); + changeDiscoveredContainer(project, profileScope); } else { throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, @@ -116,6 +142,40 @@ public class DiscoveredPathManager implements IDiscoveredPathManager, IResourceC } } + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager#changeDiscoveredContainer(org.eclipse.core.resources.IProject, java.lang.String) + */ + public void changeDiscoveredContainer(IProject project, ScannerConfigScope profileScope) { + // order here is of essence + // 1. clear DiscoveredPathManager's path info cache + IDiscoveredPathInfo oldInfo = (IDiscoveredPathInfo) fDiscoveredMap.remove(project); + + // 2. switch the containers + ICProject cProject = CoreModel.getDefault().create(project); + try { + if (ScannerConfigScope.PROJECT_SCOPE.equals(profileScope)) { + CoreModel.setPathEntryContainer(new ICProject[]{cProject}, + new DiscoveredPathContainer(project), null); + } + else if (ScannerConfigScope.FILE_SCOPE.equals(profileScope)) { + CoreModel.setPathEntryContainer(new ICProject[]{cProject}, + new PerFileDiscoveredPathContainer(project), null); + } + else { + MakeCorePlugin.log(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), 1, + MakeMessages.getString("DiscoveredContainer.ScopeErrorMessage"), null)); //$NON-NLS-1$ + } + } + catch (CModelException e) { + MakeCorePlugin.log(e); + } + + // 3. clear the container's path entry cache + if (oldInfo != null) { + fireUpdate(INFO_REMOVED, oldInfo); + } + } + private void fireUpdate(final int type, final IDiscoveredPathInfo info) { Object[] list = listeners.toArray(); for (int i = 0; i < list.length; i++) { @@ -135,7 +195,7 @@ public class DiscoveredPathManager implements IDiscoveredPathManager, IResourceC listener.infoChanged(info); break; case INFO_REMOVED : - listener.infoRemoved(info.getProject()); + listener.infoRemoved(info); break; } } @@ -152,5 +212,4 @@ public class DiscoveredPathManager implements IDiscoveredPathManager, IResourceC listeners.remove(listener); } - } \ No newline at end of file diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredScannerInfoStore.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredScannerInfoStore.java index e32652e19bd..c61acc54aa5 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredScannerInfoStore.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredScannerInfoStore.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.make.internal.core.scannerconfig; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -28,12 +29,17 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredScannerInfoSerializable; import org.eclipse.cdt.make.internal.core.MakeMessages; import org.eclipse.cdt.make.internal.core.scannerconfig2.PerProjectSICollector; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.IResourceDeltaVisitor; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.Status; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -48,28 +54,8 @@ import org.xml.sax.SAXException; * @author vhirsl */ public class DiscoveredScannerInfoStore { - public interface IDiscoveredScannerInfoSerializable { - /** - * Serialize discovered scanner info to an XML element - * - * @param root - */ - public void serialize(Element root); - - /** - * Deserialize discovered scanner info from an XML element - * - * @param root - */ - public void deserialize(Element root); - - /** - * @return an id of the collector - */ - public String getCollectorId(); - } - - + private static final QualifiedName dscFileNameProperty = new + QualifiedName(MakeCorePlugin.getUniqueIdentifier(), "discoveredScannerConfigFileName"); //$NON-NLS-1$ private static final String CDESCRIPTOR_ID = MakeCorePlugin.getUniqueIdentifier() + ".discoveredScannerInfo"; //$NON-NLS-1$ public static final String SCD_STORE_VERSION = "scdStore"; //$NON-NLS-1$ public static final String SI_ELEM = "scannerInfo"; //$NON-NLS-1$ @@ -124,7 +110,7 @@ public class DiscoveredScannerInfoStore { if (document == null) { try { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - IPath path = ScannerConfigUtil.getDiscoveredScannerConfigStore(project, false); + IPath path = getDiscoveredScannerConfigStore(project); if (path.toFile().exists()) { // read form file FileInputStream file = new FileInputStream(path.toFile()); @@ -241,7 +227,7 @@ public class DiscoveredScannerInfoStore { // Save the document try { - IPath path = ScannerConfigUtil.getDiscoveredScannerConfigStore(project, false); + IPath path = getDiscoveredScannerConfigStore(project); FileOutputStream file = new FileOutputStream(path.toFile()); file.write(stream.toByteArray()); file.close(); @@ -263,4 +249,105 @@ public class DiscoveredScannerInfoStore { } } + public IPath getDiscoveredScannerConfigStore(IProject project) { + String fileName = project.getName() + ".sc"; //$NON-NLS-1$ + String storedFileName = null; + try { + storedFileName = project.getPersistentProperty(dscFileNameProperty); + } catch (CoreException e) { + MakeCorePlugin.log(e.getStatus()); + } + if (storedFileName != null && !storedFileName.equals(fileName)) { + // try to move 2.x file name format to 3.x file name format + movePluginStateFile(storedFileName, fileName); + } + try { + project.setPersistentProperty(dscFileNameProperty, fileName); + } catch (CoreException e) { + MakeCorePlugin.log(e.getStatus()); + } + + return MakeCorePlugin.getWorkingDirectory().append(fileName); + } + + /** + * @param delta + */ + public void updateScannerConfigStore(IResourceDelta delta) { + try { + delta.accept(new IResourceDeltaVisitor() { + + public boolean visit(IResourceDelta delta) throws CoreException { + IResource resource = delta.getResource(); + if (resource instanceof IProject) { + IProject project = (IProject) resource; + int kind = delta.getKind(); + switch (kind) { + case IResourceDelta.REMOVED: + if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) { + // project renamed + IPath newPath = delta.getMovedToPath(); + IProject newProject = delta.getResource().getWorkspace(). + getRoot().getProject(newPath.toString()); + scProjectRenamed(project, newProject); + } + else { + // project deleted + scProjectDeleted(project); + } + } + return false; + } + return true; + } + + }); + } + catch (CoreException e) { + MakeCorePlugin.log(e); + } + } + + private void scProjectDeleted(IProject project) { + String scFileName = project.getName() + ".sc"; //$NON-NLS-1$ + deletePluginStateFile(scFileName); + } + + /** + * @param scFileName + */ + private void deletePluginStateFile(String scFileName) { + IPath path = MakeCorePlugin.getWorkingDirectory().append(scFileName); + File file = path.toFile(); + if (file.exists()) { + file.delete(); + } + } + + private void scProjectRenamed(IProject project, IProject newProject) { + String scOldFileName = project.getName() + ".sc"; //$NON-NLS-1$ + String scNewFileName = newProject.getName() + ".sc"; //$NON-NLS-1$ + movePluginStateFile(scOldFileName, scNewFileName); + try { + newProject.setPersistentProperty(dscFileNameProperty, scNewFileName); + } + catch (CoreException e) { + MakeCorePlugin.log(e); + } + } + + /** + * @param oldFileName + * @param newFileName + */ + private void movePluginStateFile(String oldFileName, String newFileName) { + IPath oldPath = MakeCorePlugin.getWorkingDirectory().append(oldFileName); + IPath newPath = MakeCorePlugin.getWorkingDirectory().append(newFileName); + File oldFile = oldPath.toFile(); + File newFile = newPath.toFile(); + if (oldFile.exists()) { + oldFile.renameTo(newFile); + } + } + } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/PerFileDiscoveredPathContainer.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/PerFileDiscoveredPathContainer.java new file mode 100644 index 00000000000..3c543f6644e --- /dev/null +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/PerFileDiscoveredPathContainer.java @@ -0,0 +1,116 @@ +/*********************************************************************** + * Copyright (c) 2004 IBM Corporation 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: + * IBM - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.make.internal.core.scannerconfig; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.IIncludeEntry; +import org.eclipse.cdt.core.model.IMacroEntry; +import org.eclipse.cdt.core.model.IPathEntryContainerExtension; +import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigScope; +import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredInfoListener; +import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +public class PerFileDiscoveredPathContainer extends AbstractDiscoveredPathContainer + implements IPathEntryContainerExtension { + private static final IIncludeEntry[] NO_INCLUDENTRIES = new IIncludeEntry[0]; + private static final IMacroEntry[] NO_SYMBOLENTRIES = new IMacroEntry[0]; + + static Map fgPathEntries; + + public PerFileDiscoveredPathContainer(IProject project) { + super(project); + initialize(); + } + + private static void initialize() { + if (fgPathEntries == null) { + fgPathEntries = new HashMap(10); + + IDiscoveredInfoListener listener = new IDiscoveredInfoListener() { + + public void infoRemoved(IDiscoveredPathInfo info) { + if (info != null && + ScannerConfigScope.FILE_SCOPE.equals(info.getScope())) { + fgPathEntries.remove(info.getProject()); + } + } + + public void infoChanged(IDiscoveredPathInfo info) { + if (info != null && + ScannerConfigScope.FILE_SCOPE.equals(info.getScope())) { + fgPathEntries.remove(info.getProject()); + } + } + + }; + MakeCorePlugin.getDefault().getDiscoveryManager().addDiscoveredInfoListener(listener); + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.model.IPathEntryContainerExtension#getIncludeEntries(org.eclipse.core.runtime.IPath) + */ + public IIncludeEntry[] getIncludeEntries(IPath path) { + IDiscoveredPathInfo info; + try { + info = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(fProject); + IPath[] includes = info.getIncludePaths(path); + List entries = new ArrayList(includes.length); + for (int i = 0; i < includes.length; i++) { + entries.add(CoreModel.newIncludeEntry(path, Path.EMPTY, includes[i])); //$NON-NLS-1$ //$NON-NLS-2$ + } + return (IIncludeEntry[])entries.toArray(new IIncludeEntry[entries.size()]); + } + catch (CoreException e) { + return NO_INCLUDENTRIES; + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.model.IPathEntryContainerExtension#getMacroEntries(org.eclipse.core.runtime.IPath) + */ + public IMacroEntry[] getMacroEntries(IPath path) { + IDiscoveredPathInfo info; + try { + info = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(fProject); + Map syms = info.getSymbols(path); + List entries = new ArrayList(syms.size()); + for (Iterator iter = syms.entrySet().iterator(); iter.hasNext(); ) { + Entry entry = (Entry)iter.next(); + entries.add(CoreModel.newMacroEntry(path, (String)entry.getKey(), (String)entry.getValue())); //$NON-NLS-1$ + } + return (IMacroEntry[])entries.toArray(new IMacroEntry[entries.size()]); + } + catch (CoreException e) { + return NO_SYMBOLENTRIES; + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.internal.core.scannerconfig.AbstractDiscoveredPathContainer#getPathEntryMap() + */ + protected Map getPathEntryMap() { + return fgPathEntries; + } + +} diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerConfigUtil.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerConfigUtil.java index 76e4d688f65..86805738d1b 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerConfigUtil.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerConfigUtil.java @@ -10,7 +10,6 @@ **********************************************************************/ package org.eclipse.cdt.make.internal.core.scannerconfig; -import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -19,15 +18,8 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.internal.core.scannerconfig.util.SymbolEntry; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.QualifiedName; /** * Utility class that handles some Scanner Config specifig collection conversions @@ -35,9 +27,6 @@ import org.eclipse.core.runtime.QualifiedName; * @author vhirsl */ public final class ScannerConfigUtil { - private static final QualifiedName dscFileNameProperty = new - QualifiedName(MakeCorePlugin.getUniqueIdentifier(), "discoveredScannerConfigFileName"); //$NON-NLS-1$ - /** * Adds all new discovered symbols/values to the existing ones. * @@ -298,108 +287,4 @@ public final class ScannerConfigUtil { return rv; } - public static IPath getDiscoveredScannerConfigStore(IProject project, boolean delete) { - String fileName = project.getName() + ".sc"; //$NON-NLS-1$ - String storedFileName = null; - try { - storedFileName = project.getPersistentProperty(dscFileNameProperty); - } catch (CoreException e) { - MakeCorePlugin.log(e.getStatus()); - } - if (storedFileName != null && !storedFileName.equals(fileName)) { - // try to move 2.x file name format to 3.x file name format - movePluginStateFile(storedFileName, fileName); - } - try { - project.setPersistentProperty(dscFileNameProperty, fileName); - } catch (CoreException e) { - MakeCorePlugin.log(e.getStatus()); - } - - if (delete) { - deletePluginStateFile(fileName); - } - return MakeCorePlugin.getWorkingDirectory().append(fileName); - } - - /** - * @param delta - */ - public static void updateScannerConfigStore(IResourceDelta delta) { - try { - delta.accept(new IResourceDeltaVisitor() { - - public boolean visit(IResourceDelta delta) throws CoreException { - IResource resource = delta.getResource(); - if (resource instanceof IProject) { - IProject project = (IProject) resource; - int kind = delta.getKind(); - switch (kind) { - case IResourceDelta.REMOVED: - if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) { - // project renamed - IPath newPath = delta.getMovedToPath(); - IProject newProject = delta.getResource().getWorkspace(). - getRoot().getProject(newPath.toString()); - scProjectRenamed(project, newProject); - } - else { - // project deleted - scProjectDeleted(project); - } - } - return false; - } - return true; - } - - }); - } - catch (CoreException e) { - MakeCorePlugin.log(e); - } - } - - private static void scProjectDeleted(IProject project) { - String scFileName = project.getName() + ".sc"; //$NON-NLS-1$ - deletePluginStateFile(scFileName); - } - - /** - * @param scFileName - */ - private static void deletePluginStateFile(String scFileName) { - IPath path = MakeCorePlugin.getWorkingDirectory().append(scFileName); - File file = path.toFile(); - if (file.exists()) { - file.delete(); - } - } - - private static void scProjectRenamed(IProject project, IProject newProject) { - String scOldFileName = project.getName() + ".sc"; //$NON-NLS-1$ - String scNewFileName = newProject.getName() + ".sc"; //$NON-NLS-1$ - movePluginStateFile(scOldFileName, scNewFileName); - try { - newProject.setPersistentProperty(dscFileNameProperty, scNewFileName); - } - catch (CoreException e) { - MakeCorePlugin.log(e); - } - } - - /** - * @param oldFileName - * @param newFileName - */ - private static void movePluginStateFile(String oldFileName, String newFileName) { - IPath oldPath = MakeCorePlugin.getWorkingDirectory().append(oldFileName); - IPath newPath = MakeCorePlugin.getWorkingDirectory().append(newFileName); - File oldFile = oldPath.toFile(); - File newFile = newPath.toFile(); - if (oldFile.exists()) { - oldFile.renameTo(newFile); - } - } - } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCPerFileBOPConsoleParserUtility.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCPerFileBOPConsoleParserUtility.java index 6442203142e..7a264b33a27 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCPerFileBOPConsoleParserUtility.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCPerFileBOPConsoleParserUtility.java @@ -18,7 +18,7 @@ import java.util.Map; import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.make.internal.core.scannerconfig.util.CCommandDSC; -import org.eclipse.cdt.make.internal.core.scannerconfig.util.KVPair; +import org.eclipse.cdt.make.internal.core.scannerconfig.util.KVStringPair; import org.eclipse.cdt.make.internal.core.scannerconfig.util.SCDOptionsEnum; import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil; import org.eclipse.core.resources.IProject; @@ -93,10 +93,10 @@ public class GCCPerFileBOPConsoleParserUtility extends AbstractGCCBOPConsolePars * */ void generateReport() { - TraceUtil.metricsTrace("Stats for directory ", - "Generic command: '", "' applicable for:", + TraceUtil.metricsTrace("Stats for directory ", //$NON-NLS-1$ + "Generic command: '", "' applicable for:", //$NON-NLS-1$ //$NON-NLS-2$ directoryCommandListMap); - TraceUtil.summaryTrace("Discovery summary", workingDirsN, commandsN, filesN); + TraceUtil.summaryTrace("Discovery summary", workingDirsN, commandsN, filesN); //$NON-NLS-1$ } /** @@ -130,8 +130,8 @@ public class GCCPerFileBOPConsoleParserUtility extends AbstractGCCBOPConsolePars */ public CCommandDSC getNewCCommandDSC(String genericLine, boolean cppFileType) { CCommandDSC command = new CCommandDSC(cppFileType); - String[] tokens = genericLine.split("\\s+"); - command.addSCOption(new KVPair(SCDOptionsEnum.COMMAND, tokens[0])); + String[] tokens = genericLine.split("\\s+"); //$NON-NLS-1$ + command.addSCOption(new KVStringPair(SCDOptionsEnum.COMMAND.toString(), tokens[0])); for (int i = 1; i < tokens.length; ++i) { for (int j = SCDOptionsEnum.MIN; j <= SCDOptionsEnum.MAX; ++j) { if (tokens[i].startsWith(SCDOptionsEnum.getSCDOptionsEnum(j).toString())) { @@ -144,7 +144,7 @@ public class GCCPerFileBOPConsoleParserUtility extends AbstractGCCBOPConsolePars // ex. -I /dir // take a next token ++i; - if (i < tokens.length && !tokens[i].startsWith("-")) { + if (i < tokens.length && !tokens[i].startsWith("-")) { //$NON-NLS-1$ option = tokens[i]; } else break; @@ -157,7 +157,7 @@ public class GCCPerFileBOPConsoleParserUtility extends AbstractGCCBOPConsolePars option = (getAbsolutePath(option)).toString(); } // add the pair - command.addSCOption(new KVPair(SCDOptionsEnum.getSCDOptionsEnum(j), option)); + command.addSCOption(new KVStringPair(SCDOptionsEnum.getSCDOptionsEnum(j).toString(), option)); break; } } @@ -171,8 +171,8 @@ public class GCCPerFileBOPConsoleParserUtility extends AbstractGCCBOPConsolePars */ IPath getAbsolutePath(String filePath) { IPath pFilePath; - if (filePath.startsWith("/") || filePath.startsWith("\\") || - (!filePath.startsWith(".") && + if (filePath.startsWith("/") || filePath.startsWith("\\") || //$NON-NLS-1$ //$NON-NLS-2$ + (!filePath.startsWith(".") && //$NON-NLS-1$ filePath.length() > 2 && filePath.charAt(1) == ':' && (filePath.charAt(2) == '\\' || filePath.charAt(2) == '/'))) { // absolute path diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CCommandDSC.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CCommandDSC.java index 5e39343d6c0..c6a697ff6c2 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CCommandDSC.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CCommandDSC.java @@ -25,9 +25,16 @@ import org.w3c.dom.NodeList; */ public class CCommandDSC { private final static String SINGLE_SPACE = " "; //$NON-NLS-1$ + private final static String CMD_DESCRIPTION_ELEM = "commandDescription"; //$NON-NLS-1$ + private final static String CMD_SI_ELEM = "commandScannerInfo"; //$NON-NLS-1$ + private final static String OPTION_ELEM = "option"; //$NON-NLS-1$ + private final static String SI_ITEM_ELEM = "siItem"; //$NON-NLS-1$ + private final static String KEY_ATTR = "key"; //$NON-NLS-1$ + private final static String VALUE_ATTR = "value"; //$NON-NLS-1$ + private final static String KIND_ATTR = "kind"; //$NON-NLS-1$ private int commandId; - private List compilerCommand; // members are KVPair objects + private List compilerCommand; // members are KVStringPair objects private boolean discovered; private boolean cppFileType; // C or C++ file type @@ -40,7 +47,6 @@ public class CCommandDSC { public CCommandDSC(boolean cppFileType) { compilerCommand = new ArrayList(); discovered = false; -// files = null; this.cppFileType = cppFileType; symbols = new ArrayList(); @@ -51,7 +57,7 @@ public class CCommandDSC { return cppFileType; } - public void addSCOption(KVPair option) { + public void addSCOption(KVStringPair option) { compilerCommand.add(option); } @@ -74,28 +80,11 @@ public class CCommandDSC { this.commandId = commandId; } -// public void addFile(String fileName) { -// if (files == null) { -// files = new ArrayList(); -// } -// if (!files.contains(fileName)) { -// files.add(fileName); -// if (!cppFileType && !fileName.endsWith(".c")) { //$NON-NLS-1$ -// cppFileType = true; -// } -// } -// } - -// public int getNumberOfFiles() { -// if (files == null) return 0; -// return files.size(); -// } - public String toString() { String commandAsString = new String(); for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) { - KVPair optionPair = (KVPair)i.next(); - commandAsString += optionPair.getKey().toString() + SINGLE_SPACE + + KVStringPair optionPair = (KVStringPair)i.next(); + commandAsString += optionPair.getKey() + SINGLE_SPACE + optionPair.getValue() + SINGLE_SPACE; } return commandAsString.trim(); @@ -112,15 +101,15 @@ public class CCommandDSC { public String getSCDRunnableCommand() { String commandAsString = new String(); for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) { - KVPair optionPair = (KVPair)i.next(); - if (optionPair.getKey().equals(SCDOptionsEnum.COMMAND)) { + KVStringPair optionPair = (KVStringPair)i.next(); + if (optionPair.getKey().equals(SCDOptionsEnum.COMMAND.toString())) { commandAsString += optionPair.getValue() + SINGLE_SPACE; } else { -// if (optionPair.getKey().equals(SCDOptionsEnum.IMACROS_FILE) || -// optionPair.getKey().equals(SCDOptionsEnum.INCLUDE_FILE)) +// if (optionPair.getKey().equals(SCDOptionsEnum.IMACROS_FILE.toString()) || +// optionPair.getKey().equals(SCDOptionsEnum.INCLUDE_FILE.toString())) // continue; - commandAsString += optionPair.getKey().toString() + SINGLE_SPACE + + commandAsString += optionPair.getKey() + SINGLE_SPACE + optionPair.getValue() + SINGLE_SPACE; } } @@ -130,8 +119,8 @@ public class CCommandDSC { public String[] getImacrosFile() { List imacrosFiles = new ArrayList(); for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) { - KVPair optionPair = (KVPair)i.next(); - if (optionPair.getKey().equals(SCDOptionsEnum.IMACROS_FILE)) { + KVStringPair optionPair = (KVStringPair)i.next(); + if (optionPair.getKey().equals(SCDOptionsEnum.IMACROS_FILE.toString())) { imacrosFiles.add(optionPair.getValue()); } } @@ -141,8 +130,8 @@ public class CCommandDSC { public String[] getIncludeFile() { List includeFiles = new ArrayList(); for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) { - KVPair optionPair = (KVPair)i.next(); - if (optionPair.getKey().equals(SCDOptionsEnum.INCLUDE_FILE)) { + KVStringPair optionPair = (KVStringPair)i.next(); + if (optionPair.getKey().equals(SCDOptionsEnum.INCLUDE_FILE.toString())) { includeFiles.add(optionPair.getValue()); } } @@ -214,27 +203,27 @@ public class CCommandDSC { public void serialize(Element cmdElem) { Document doc = cmdElem.getOwnerDocument(); // serialize the command - Element cmdDescElem = doc.createElement("commandDescription"); //$NON-NLS-1$ + Element cmdDescElem = doc.createElement(CMD_DESCRIPTION_ELEM); for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) { - Element optionElem = doc.createElement("option"); //$NON-NLS-1$ - KVPair option = (KVPair) i.next(); - optionElem.setAttribute("key", option.getKey().toString()); //$NON-NLS-1$ - optionElem.setAttribute("value", option.getValue()); //$NON-NLS-1$ + Element optionElem = doc.createElement(OPTION_ELEM); + KVStringPair option = (KVStringPair) i.next(); + optionElem.setAttribute(KEY_ATTR, option.getKey()); + optionElem.setAttribute(VALUE_ATTR, option.getValue()); cmdDescElem.appendChild(optionElem); } cmdElem.appendChild(cmdDescElem); // serialize includes and symbols - Element siElem = doc.createElement("commandScannerInfo"); //$NON-NLS-1$ + Element siElem = doc.createElement(CMD_SI_ELEM); for (Iterator j = includes.iterator(); j.hasNext(); ) { - Element siItem = doc.createElement("siItem"); //$NON-NLS-1$ - siItem.setAttribute("kind", "INCLUDE_PATH"); //$NON-NLS-1$ //$NON-NLS-2$ - siItem.setAttribute("value", (String) j.next()); //$NON-NLS-1$ + Element siItem = doc.createElement(SI_ITEM_ELEM); + siItem.setAttribute(KIND_ATTR, "INCLUDE_PATH"); //$NON-NLS-1$ + siItem.setAttribute(VALUE_ATTR, (String) j.next()); siElem.appendChild(siItem); } for (Iterator j = symbols.iterator(); j.hasNext(); ) { - Element siItem = doc.createElement("siItem"); //$NON-NLS-1$ - siItem.setAttribute("kind", "SYMBOL_DEFINITION"); //$NON-NLS-1$ //$NON-NLS-2$ - siItem.setAttribute("value", (String) j.next()); //$NON-NLS-1$ + Element siItem = doc.createElement(SI_ITEM_ELEM); + siItem.setAttribute(KIND_ATTR, "SYMBOL_DEFINITION"); //$NON-NLS-1$ + siItem.setAttribute(VALUE_ATTR, (String) j.next()); siElem.appendChild(siItem); } cmdElem.appendChild(siElem); @@ -245,32 +234,31 @@ public class CCommandDSC { */ public void deserialize(Element cmdElem) { // read command options - NodeList descList = cmdElem.getElementsByTagName("commandDescription"); + NodeList descList = cmdElem.getElementsByTagName(CMD_DESCRIPTION_ELEM); if (descList.getLength() > 0) { Element descElem = (Element) descList.item(0); - NodeList optionList = descElem.getElementsByTagName("option"); + NodeList optionList = descElem.getElementsByTagName(OPTION_ELEM); for (int i = 0; i < optionList.getLength(); ++i) { Element optionElem = (Element) optionList.item(i); - String key = optionElem.getAttribute("key"); - SCDOptionsEnum eKey = SCDOptionsEnum.getSCDOptionsEnum(key); - String value = optionElem.getAttribute("value"); - KVPair option = new KVPair(eKey, value); + String key = optionElem.getAttribute(KEY_ATTR); + String value = optionElem.getAttribute(VALUE_ATTR); + KVStringPair option = new KVStringPair(key, value); addSCOption(option); } } // read associated scanner info - NodeList siList = cmdElem.getElementsByTagName("commandScannerInfo"); + NodeList siList = cmdElem.getElementsByTagName(CMD_SI_ELEM); if (siList.getLength() > 0) { Element siElem = (Element) siList.item(0); - NodeList siItemList = siElem.getElementsByTagName("siItem"); + NodeList siItemList = siElem.getElementsByTagName(SI_ITEM_ELEM); for (int i = 0; i < siItemList.getLength(); ++i) { Element siItemElem = (Element) siItemList.item(i); - String kind = siItemElem.getAttribute("kind"); - String value = siItemElem.getAttribute("value"); - if (kind.equals("INCLUDE_PATH")) { + String kind = siItemElem.getAttribute(KIND_ATTR); + String value = siItemElem.getAttribute(VALUE_ATTR); + if (kind.equals("INCLUDE_PATH")) { //$NON-NLS-1$ includes.add(value); } - else if (kind.equals("SYMBOL_DEFINITION")) { + else if (kind.equals("SYMBOL_DEFINITION")) { //$NON-NLS-1$ symbols.add(value); } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CygpathTranslator.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CygpathTranslator.java index 27c9a56e8c8..9cc14451ff5 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CygpathTranslator.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CygpathTranslator.java @@ -15,11 +15,12 @@ import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Enumeration; +import java.util.Iterator; +import java.util.List; import java.util.Properties; import org.eclipse.cdt.core.CommandLauncher; import org.eclipse.cdt.make.core.MakeCorePlugin; -import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.Path; @@ -31,15 +32,29 @@ import org.eclipse.core.runtime.Platform; * @author vhirsl */ public class CygpathTranslator { - IProject project; - String orgPath; - String transPath; + private IPath cwd; + private String orgPath; + private String transPath; + private boolean status; + - public CygpathTranslator(IProject project, String path) { - this.project = project; + public CygpathTranslator(String path) { + this(MakeCorePlugin.getDefault().getStateLocation(), path); + } + + public CygpathTranslator(IPath cwd, String path) { + this.cwd = cwd; orgPath = path; + status = false; } + /** + * @return Returns the status. + */ + public boolean isStatus() { + return status; + } + public String run() { ISafeRunnable runnable = new ISafeRunnable() { public void run() throws Exception { @@ -71,7 +86,7 @@ public class CygpathTranslator { new Path("cygpath"), //$NON-NLS-1$ new String[] {"-m", orgPath}, //$NON-NLS-1$ new String[0],//setEnvironment(launcher, "c:/"),//$NON-NLS-1$ - project.getLocation()); //$NON-NLS-1$ + cwd); //$NON-NLS-1$ if (p != null) { try { // Close the input of the Process explicitely. @@ -82,8 +97,10 @@ public class CygpathTranslator { } if (launcher.waitAndRead(output, output) != CommandLauncher.OK) { //String errMsg = launcher.getErrorMessage(); + status = false; } else + status = true; return output.toString().trim(); } return orgPath; @@ -111,4 +128,52 @@ public class CygpathTranslator { } return env; } + + /** + * @param sumIncludes + * @return + */ + public static List translateIncludePaths(List sumIncludes) { + CygpathTranslator test = new CygpathTranslator("/"); //$NON-NLS-1$ + test.run(); + if (!test.isStatus()) return sumIncludes; + + List translatedIncludePaths = new ArrayList(); + for (Iterator i = sumIncludes.iterator(); i.hasNext(); ) { + String includePath = (String) i.next(); + IPath realPath = new Path(includePath); + if (!realPath.toFile().exists()) { + String translatedPath = includePath; + if (Platform.getOS().equals(Platform.OS_WIN32)) { + translatedPath = (new CygpathTranslator(includePath)).run(); + } + if (translatedPath != null) { + if (!translatedPath.equals(includePath)) { + // Check if the translated path exists + IPath transPath = new Path(translatedPath); + if (transPath.toFile().exists()) { + translatedIncludePaths.add(translatedPath); + } + else { + // TODO VMIR for now add even if it does not exist + translatedIncludePaths.add(translatedPath); + } + } + else { + // TODO VMIR for now add even if it does not exist + translatedIncludePaths.add(translatedPath); + } + } + else { + TraceUtil.outputError("CygpathTranslator unable to translate path: ",//$NON-NLS-1$ + includePath); + } + } + else { + translatedIncludePaths.add(includePath); + } + } + return translatedIncludePaths; + } + } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/KVPair.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/KVStringPair.java similarity index 83% rename from build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/KVPair.java rename to build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/KVStringPair.java index a57d9af68ee..1cc00ae9e3a 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/KVPair.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/KVStringPair.java @@ -11,23 +11,23 @@ package org.eclipse.cdt.make.internal.core.scannerconfig.util; /** - * Key - Value Pair + * Key - Value String Pair * * @author vhirsl */ -public class KVPair { - private SCDOptionsEnum key; +public class KVStringPair { + private String key; private String value; /** * */ - public KVPair(SCDOptionsEnum key, String value) { + public KVStringPair(String key, String value) { this.key = key; this.value = value; } - public SCDOptionsEnum getKey() { + public String getKey() { return key; } @@ -39,7 +39,7 @@ public class KVPair { */ public boolean equals(Object arg0) { if (arg0 != null && arg0.getClass().equals(this.getClass())) { - KVPair arg = (KVPair) arg0; + KVStringPair arg = (KVStringPair) arg0; return (key.equals(arg.getKey()) && value.equals(arg.getValue())); } return false; @@ -54,6 +54,6 @@ public class KVPair { * @see java.lang.Object#toString() */ public String toString() { - return key + " -> " + value; + return key + " -> " + value; //$NON-NLS-1$ } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java index 89667ea7fd9..6ae0fd6d651 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java @@ -21,16 +21,20 @@ import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import java.util.Map.Entry; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2; import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollectorCleaner; +import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigScope; import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes; import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo; +import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredScannerInfoSerializable; import org.eclipse.cdt.make.internal.core.MakeMessages; import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore; -import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore.IDiscoveredScannerInfoSerializable; +import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerConfigUtil; import org.eclipse.cdt.make.internal.core.scannerconfig.util.CCommandDSC; +import org.eclipse.cdt.make.internal.core.scannerconfig.util.CygpathTranslator; import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -39,6 +43,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -49,9 +54,90 @@ import org.w3c.dom.NodeList; * * @author vhirsl */ -public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoCollectorCleaner, - IDiscoveredScannerInfoSerializable { - public static final String COLLECTOR_ID = MakeCorePlugin.getUniqueIdentifier() + ".PerFileSICollector"; //$NON-NLS-1$ +public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoCollectorCleaner { + public class ScannerInfoData implements IDiscoveredScannerInfoSerializable { + private Map commandIdToFilesMap; // command id and set of files it applies to + private Map fileToCommandIdMap; // maps each file to the corresponding command id + private Map commandIdCommandMap; // map of all commands + + public ScannerInfoData() { + commandIdCommandMap = new LinkedHashMap(); // [commandId, command] + fileToCommandIdMap = new HashMap(); // [file, commandId] + commandIdToFilesMap = new HashMap(); // [commandId, set of files] + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore.IDiscoveredScannerInfoSerializable#serialize(org.w3c.dom.Element) + */ + public void serialize(Element collectorElem) { + Document doc = collectorElem.getOwnerDocument(); + + List commandIds = new ArrayList(commandIdCommandMap.keySet()); + Collections.sort(commandIds); + for (Iterator i = commandIds.iterator(); i.hasNext(); ) { + Integer commandId = (Integer) i.next(); + CCommandDSC command = (CCommandDSC) commandIdCommandMap.get(commandId); + + Element cmdElem = doc.createElement(CC_ELEM); //$NON-NLS-1$ + collectorElem.appendChild(cmdElem); + cmdElem.setAttribute(ID_ATTR, commandId.toString()); //$NON-NLS-1$ + cmdElem.setAttribute(FILE_TYPE_ATTR, command.appliesToCPPFileType() ? "c++" : "c"); //$NON-NLS-1$ //$NON-NLS-2$ + // write command and scanner info + command.serialize(cmdElem); + // write files command applies to + Element filesElem = doc.createElement(APPLIES_TO_ATTR); //$NON-NLS-1$ + cmdElem.appendChild(filesElem); + Set files = (Set) commandIdToFilesMap.get(commandId); + if (files != null) { + for (Iterator j = files.iterator(); j.hasNext(); ) { + Element fileElem = doc.createElement(FILE_ELEM); //$NON-NLS-1$ + IFile file = (IFile) j.next(); + IPath path = file.getProjectRelativePath(); + fileElem.setAttribute(PATH_ATTR, path.toString()); //$NON-NLS-1$ + filesElem.appendChild(fileElem); + } + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore.IDiscoveredScannerInfoSerializable#deserialize(org.w3c.dom.Element) + */ + public void deserialize(Element collectorElem) { + for (Node child = collectorElem.getFirstChild(); child != null; child = child.getNextSibling()) { + if (child.getNodeName().equals(CC_ELEM)) { //$NON-NLS-1$ + Element cmdElem = (Element) child; + boolean cppFileType = cmdElem.getAttribute(FILE_TYPE_ATTR).equals("c++"); //$NON-NLS-1$ + CCommandDSC command = new CCommandDSC(cppFileType); + command.setCommandId(Integer.parseInt(cmdElem.getAttribute(ID_ATTR))); + // deserialize command + command.deserialize(cmdElem); + // get set of files the command applies to + NodeList appliesList = cmdElem.getElementsByTagName(APPLIES_TO_ATTR); + if (appliesList.getLength() > 0) { + Element appliesElem = (Element) appliesList.item(0); + NodeList fileList = appliesElem.getElementsByTagName(FILE_ELEM); + for (int i = 0; i < fileList.getLength(); ++i) { + Element fileElem = (Element) fileList.item(i); + String fileName = fileElem.getAttribute(PATH_ATTR); + IFile file = project.getFile(fileName); + addCompilerCommand(file, command); + } + } + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore.IDiscoveredScannerInfoSerializable#getCollectorId() + */ + public String getCollectorId() { + return COLLECTOR_ID; + } + + }; + + public static final String COLLECTOR_ID = MakeCorePlugin.getUniqueIdentifier() + ".PerFileSICollector"; //$NON-NLS-1$ private static final String CC_ELEM = "compilerCommand"; //$NON-NLS-1$ private static final String ID_ATTR = "id"; //$NON-NLS-1$ private static final String FILE_TYPE_ATTR = "fileType"; //$NON-NLS-1$ @@ -59,23 +145,29 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC private static final String FILE_ELEM = "file"; //$NON-NLS-1$ private static final String PATH_ATTR = "path"; //$NON-NLS-1$ - private IProject project; - - private Map commandIdToFilesMap; // command id and set of files it applies to - private Map fileToCommandIdMap; // maps each file to the corresponding command id - private Map commandIdCommandMap; // map of all commands + private static final LinkedHashMap EMPTY_LHM = new LinkedHashMap(0); + private IProject project; + + private ScannerInfoData sid; // scanner info data + + private List siChangedForFileList; // list of files for which scanner info has changed + private SortedSet freeCommandIdPool; // sorted set of free command ids private int commandIdCounter = 0; + + private boolean siAvailable; // is there any scanner info discovered + /** * */ public PerFileSICollector() { - commandIdCommandMap = new LinkedHashMap(); // [commandId, command] - fileToCommandIdMap = new HashMap(); // [file, commandId] - commandIdToFilesMap = new HashMap(); // [commandId, set of files] - + sid = new ScannerInfoData(); + + siChangedForFileList = new ArrayList(); + freeCommandIdPool = new TreeSet(); + siAvailable = false; } /* (non-Javadoc) @@ -85,10 +177,12 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC this.project = project; try { - IDiscoveredPathInfo pathInfo = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(project); + // deserialize from SI store + DiscoveredScannerInfoStore.getInstance().loadDiscoveredScannerInfoFromState(project, sid); } catch (CoreException e) { MakeCorePlugin.log(e); + siAvailable = false; } } @@ -139,12 +233,12 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC * @param scannerInfo */ private void addScannerInfo(Integer commandId, Map scannerInfo) { - CCommandDSC cmd = (CCommandDSC) commandIdCommandMap.get(commandId); + CCommandDSC cmd = (CCommandDSC) sid.commandIdCommandMap.get(commandId); if (cmd != null) { List symbols = (List) scannerInfo.get(ScannerInfoTypes.SYMBOL_DEFINITIONS); List includes = (List) scannerInfo.get(ScannerInfoTypes.INCLUDE_PATHS); cmd.setSymbols(symbols); - cmd.setIncludes(includes); + cmd.setIncludes(CygpathTranslator.translateIncludePaths(includes)); cmd.setDiscovered(true); } } @@ -154,7 +248,7 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC * @param object */ private void addCompilerCommand(IFile file, CCommandDSC cmd) { - List existingCommands = new ArrayList(commandIdCommandMap.values()); + List existingCommands = new ArrayList(sid.commandIdCommandMap.values()); int index = existingCommands.indexOf(cmd); if (index != -1) { cmd = (CCommandDSC) existingCommands.get(index); @@ -170,35 +264,64 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC commandId = ++commandIdCounter; } cmd.setCommandId(commandId); - commandIdCommandMap.put(cmd.getCommandIdAsInteger(), cmd); + sid.commandIdCommandMap.put(cmd.getCommandIdAsInteger(), cmd); } Integer commandId = cmd.getCommandIdAsInteger(); - // update commandIdToFilesMap - Set fileSet = (Set) commandIdToFilesMap.get(commandId); + // update sid.commandIdToFilesMap + Set fileSet = (Set) sid.commandIdToFilesMap.get(commandId); if (fileSet == null) { fileSet = new HashSet(); - commandIdToFilesMap.put(commandId, fileSet); + sid.commandIdToFilesMap.put(commandId, fileSet); } - fileSet.add(file); - // update fileToCommandIdsMap - boolean change = true; - Integer oldCommandId = (Integer) fileToCommandIdMap.get(file); - if (oldCommandId != null) { - if (oldCommandId.equals(commandId)) { - change = false; + if (fileSet.add(file)) { + // update fileToCommandIdsMap + boolean change = true; + Integer oldCommandId = (Integer) sid.fileToCommandIdMap.get(file); + if (oldCommandId != null) { + if (oldCommandId.equals(commandId)) { + change = false; + } + else { + Set oldFileSet = (Set) sid.commandIdToFilesMap.get(oldCommandId); + oldFileSet.remove(file); + } } - else { - commandIdToFilesMap.remove(file); - if (((Set)(commandIdToFilesMap.get(oldCommandId))).isEmpty()) { - // old command does not apply to any files any more; remove - commandIdCommandMap.remove(oldCommandId); - freeCommandIdPool.add(oldCommandId); + if (change) { + sid.fileToCommandIdMap.put(file, commandId); + // TODO generate change event for this resource + if (!siChangedForFileList.contains(file)) { + siChangedForFileList.add(file); } } } - fileToCommandIdMap.put(file, commandId); } + private void removeUnusedCommands() { + for (Iterator i = sid.commandIdToFilesMap.entrySet().iterator(); i.hasNext(); ) { + Entry entry = (Entry) i.next(); + Integer cmdId = (Integer) entry.getKey(); + Set fileSet = (Set) entry.getValue(); + if (fileSet.isEmpty()) { + // return cmdId to the free command id pool + freeCommandIdPool.add(cmdId); + } + } + for (Iterator i = freeCommandIdPool.iterator(); i.hasNext(); ) { + Integer cmdId = (Integer) i.next(); + // the command does not have any files associated; remove + sid.commandIdCommandMap.remove(cmdId); + sid.commandIdToFilesMap.remove(cmdId); + } + while (!freeCommandIdPool.isEmpty()) { + Integer last = (Integer) freeCommandIdPool.last(); + if (last.intValue() == commandIdCounter) { + freeCommandIdPool.remove(last); + --commandIdCounter; + } + else break; + } + } + /** * @param type * @param object @@ -216,13 +339,16 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC monitor = new NullProgressMonitor(); } monitor.beginTask(MakeMessages.getString("ScannerInfoCollector.Processing"), 100); //$NON-NLS-1$ + removeUnusedCommands(); monitor.subTask(MakeMessages.getString("ScannerInfoCollector.Processing")); //$NON-NLS-1$ - DiscoveredScannerInfoStore.getInstance().loadDiscoveredScannerInfoFromState(project, this); + MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(project); +// DiscoveredScannerInfoStore.getInstance().loadDiscoveredScannerInfoFromState(project, this); monitor.worked(50); monitor.subTask(MakeMessages.getString("ScannerInfoCollector.Updating") + project.getName()); //$NON-NLS-1$ try { // update scanner configuration - DiscoveredScannerInfoStore.getInstance().saveDiscoveredScannerInfoToState(project, this); + MakeCorePlugin.getDefault().getDiscoveryManager().updateDiscoveredInfo(createPathInfoObject()); +// DiscoveredScannerInfoStore.getInstance().saveDiscoveredScannerInfoToState(project, this); monitor.worked(50); } catch (CoreException e) { MakeCorePlugin.log(e); @@ -230,6 +356,13 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC monitor.done(); } + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2#createPathInfoObject() + */ + public IDiscoveredPathInfo createPathInfoObject() { + return new PerFileDiscoveredPathInfo(); + } + /* (non-Javadoc) * @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector#getCollectedScannerInfo(java.lang.Object, org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes) */ @@ -255,81 +388,19 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC } else if (project.equals(((IResource)resource).getProject())) { if (type.equals(ScannerInfoTypes.COMPILER_COMMAND)) { - rv = new ArrayList(commandIdCommandMap.values()); - } - } - return rv; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore.IDiscoveredScannerInfoSerializable#serialize(org.w3c.dom.Element) - */ - public void serialize(Element collectorElem) { - Document doc = collectorElem.getOwnerDocument(); - - List commandIds = new ArrayList(commandIdCommandMap.keySet()); - Collections.sort(commandIds); - for (Iterator i = commandIds.iterator(); i.hasNext(); ) { - Integer commandId = (Integer) i.next(); - CCommandDSC command = (CCommandDSC) commandIdCommandMap.get(commandId); - - Element cmdElem = doc.createElement(CC_ELEM); //$NON-NLS-1$ - collectorElem.appendChild(cmdElem); - cmdElem.setAttribute(ID_ATTR, commandId.toString()); //$NON-NLS-1$ - cmdElem.setAttribute(FILE_TYPE_ATTR, command.appliesToCPPFileType() ? "c++" : "c"); - // write command and scanner info - command.serialize(cmdElem); - // write files command applies to - Element filesElem = doc.createElement(APPLIES_TO_ATTR); //$NON-NLS-1$ - cmdElem.appendChild(filesElem); - Set files = (Set) commandIdToFilesMap.get(commandId); - if (files != null) { - for (Iterator j = files.iterator(); j.hasNext(); ) { - Element fileElem = doc.createElement(FILE_ELEM); //$NON-NLS-1$ - IFile file = (IFile) j.next(); - IPath path = file.getProjectRelativePath(); - fileElem.setAttribute(PATH_ATTR, path.toString()); //$NON-NLS-1$ - filesElem.appendChild(fileElem); - } - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore.IDiscoveredScannerInfoSerializable#deserialize(org.w3c.dom.Element) - */ - public void deserialize(Element collectorElem) { - for (Node child = collectorElem.getFirstChild(); child != null; child = child.getNextSibling()) { - if (child.getNodeName().equals(CC_ELEM)) { //$NON-NLS-1$ - Element cmdElem = (Element) child; - boolean cppFileType = cmdElem.getAttribute(FILE_TYPE_ATTR).equals("c++"); - CCommandDSC command = new CCommandDSC(cppFileType); - command.setCommandId(Integer.parseInt(cmdElem.getAttribute(ID_ATTR))); - // deserialize command - command.deserialize(cmdElem); - // get set of files the command applies to - NodeList appliesList = cmdElem.getElementsByTagName(APPLIES_TO_ATTR); - if (appliesList.getLength() > 0) { - Element appliesElem = (Element) appliesList.item(0); - NodeList fileList = appliesElem.getElementsByTagName(FILE_ELEM); - for (int i = 0; i < fileList.getLength(); ++i) { - Element fileElem = (Element) fileList.item(i); - String fileName = fileElem.getAttribute(PATH_ATTR); - IFile file = project.getFile(fileName); - addCompilerCommand(file, command); + rv = new ArrayList(); + for (Iterator i = sid.commandIdCommandMap.keySet().iterator(); i.hasNext(); ) { + Integer cmdId = (Integer) i.next(); + Set fileSet = (Set) sid.commandIdToFilesMap.get(cmdId); + if (!fileSet.isEmpty()) { + rv.add(sid.commandIdCommandMap.get(cmdId)); } } } } + return rv; } - /* (non-Javadoc) - * @see org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore.IDiscoveredScannerInfoSerializable#getCollectorId() - */ - public String getCollectorId() { - return COLLECTOR_ID; - } - /* (non-Javadoc) * @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollectorUtil#deleteAllPaths(org.eclipse.core.resources.IResource) */ @@ -362,4 +433,176 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC } + /** + * Per file DPI object + * + * @author vhirsl + */ + public class PerFileDiscoveredPathInfo implements IDiscoveredPathInfo { + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getProject() + */ + public IProject getProject() { + return project; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getIncludePaths() + */ + public IPath[] getIncludePaths() { +// return new IPath[0]; + List includes = getAllIncludePaths(); + List finalIncludePaths = new ArrayList(includes.size()); + for (Iterator i = includes.iterator(); i.hasNext(); ) { + finalIncludePaths.add(new Path((String) i.next())); + } + return (IPath[])finalIncludePaths.toArray(new IPath[finalIncludePaths.size()]); + } + + /** + * @return list of IPath(s). + */ + private List getAllIncludePaths() { + List allIncludes = new ArrayList(); + for (Iterator i = sid.commandIdCommandMap.keySet().iterator(); i.hasNext(); ) { + Integer cmdId = (Integer) i.next(); + CCommandDSC cmd = (CCommandDSC) sid.commandIdCommandMap.get(cmdId); + if (cmd.isDiscovered()) { + List discovered = cmd.getIncludes(); + for (Iterator j = discovered.iterator(); j.hasNext(); ) { + String include = (String) j.next(); + if (!allIncludes.contains(include)) { + allIncludes.add(include); + } + } + } + } + return allIncludes; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getSymbols() + */ + public Map getSymbols() { +// return new HashMap(); + return getAllSymbols(); + } + + /** + * @return + */ + private Map getAllSymbols() { + Map symbols = new HashMap(); + for (Iterator i = sid.commandIdCommandMap.keySet().iterator(); i.hasNext(); ) { + Integer cmdId = (Integer) i.next(); + CCommandDSC cmd = (CCommandDSC) sid.commandIdCommandMap.get(cmdId); + if (cmd.isDiscovered()) { + List discovered = cmd.getSymbols(); + for (Iterator j = discovered.iterator(); j.hasNext(); ) { + String symbol = (String) j.next(); + String key = ScannerConfigUtil.getSymbolKey(symbol); + String value = ScannerConfigUtil.getSymbolValue(symbol); + symbols.put(key, value); + } + } + } + + return symbols; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#setIncludeMap(java.util.LinkedHashMap) + */ + public void setIncludeMap(LinkedHashMap map) { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#setSymbolMap(java.util.LinkedHashMap) + */ + public void setSymbolMap(LinkedHashMap map) { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getIncludeMap() + */ + public LinkedHashMap getIncludeMap() { + return EMPTY_LHM; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getSymbolMap() + */ + public LinkedHashMap getSymbolMap() { + return EMPTY_LHM; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getIncludePaths(org.eclipse.core.runtime.IPath) + */ + public IPath[] getIncludePaths(IPath path) { + IFile file = project.getWorkspace().getRoot().getFile(path); + if (file != null) { + Integer cmdId = (Integer) sid.fileToCommandIdMap.get(file); + if (cmdId != null) { + // get the command + CCommandDSC cmd = (CCommandDSC) sid.commandIdCommandMap.get(cmdId); + if (cmd != null && cmd.isDiscovered()) { + List includes = cmd.getIncludes(); + List includePaths = new ArrayList(includes.size()); + for (Iterator i = includes.iterator(); i.hasNext(); ) { + includePaths.add(new Path((String) i.next())); + } + return (IPath[])includePaths.toArray(new IPath[includePaths.size()]); + } + } + } + return new IPath[0]; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getSymbols(org.eclipse.core.runtime.IPath) + */ + public Map getSymbols(IPath path) { + IFile file = project.getFile(path); + if (file != null) { + Integer cmdId = (Integer) sid.fileToCommandIdMap.get(file); + if (cmdId != null) { + // get the command + CCommandDSC cmd = (CCommandDSC) sid.commandIdCommandMap.get(cmdId); + if (cmd != null && cmd.isDiscovered()) { + List symbols = cmd.getSymbols(); + Map definedSymbols = new HashMap(symbols.size()); + for (Iterator i = symbols.iterator(); i.hasNext(); ) { + String symbol = (String) i.next(); + String key = ScannerConfigUtil.getSymbolKey(symbol); + String value = ScannerConfigUtil.getSymbolValue(symbol); + definedSymbols.put(key, value); + } + return definedSymbols; + } + } + } + return new HashMap(0); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getSerializable() + */ + public IDiscoveredScannerInfoSerializable getSerializable() { + return sid; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getScope() + */ + public ScannerConfigScope getScope() { + return ScannerConfigScope.FILE_SCOPE; + } + + } + } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerProjectSICollector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerProjectSICollector.java index e7c8ed731ab..b96ac2242ec 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerProjectSICollector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerProjectSICollector.java @@ -26,17 +26,17 @@ import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollectorCleaner; import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes; import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo; import org.eclipse.cdt.make.internal.core.MakeMessages; +import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredPathInfo; +import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore; import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerConfigUtil; import org.eclipse.cdt.make.internal.core.scannerconfig.util.CygpathTranslator; import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil; 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.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; import org.w3c.dom.Element; /** @@ -233,7 +233,7 @@ public class PerProjectSICollector implements IScannerInfoCollector2, IScannerIn addedIncludes = addItemsWithOrder(sumDiscoveredIncludes, discoveredIncludes, true); // try to translate cygpaths to absolute paths - List finalSumIncludes = translateIncludePaths(sumDiscoveredIncludes); + List finalSumIncludes = CygpathTranslator.translateIncludePaths(sumDiscoveredIncludes); // Step 2. Get project's scanner config LinkedHashMap persistedIncludes = discPathInfo.getIncludeMap(); @@ -298,49 +298,6 @@ public class PerProjectSICollector implements IScannerInfoCollector2, IScannerIn return addedSymbols; } - /** - * @param sumIncludes - * @return - */ - private List translateIncludePaths(List sumIncludes) { - List translatedIncludePaths = new ArrayList(); - for (Iterator i = sumIncludes.iterator(); i.hasNext(); ) { - String includePath = (String) i.next(); - IPath realPath = new Path(includePath); - if (!realPath.toFile().exists()) { - String translatedPath = includePath; - if (Platform.getOS().equals(Platform.OS_WIN32)) { - translatedPath = new CygpathTranslator(project, includePath).run(); - } - if (translatedPath != null) { - if (!translatedPath.equals(includePath)) { - // Check if the translated path exists - IPath transPath = new Path(translatedPath); - if (transPath.toFile().exists()) { - translatedIncludePaths.add(translatedPath); - } - else { - // TODO VMIR for now add even if it does not exist - translatedIncludePaths.add(translatedPath); - } - } - else { - // TODO VMIR for now add even if it does not exist - translatedIncludePaths.add(translatedPath); - } - } - else { - TraceUtil.outputError("CygpathTranslator unable to translate path: ",//$NON-NLS-1$ - includePath); - } - } - else { - translatedIncludePaths.add(includePath); - } - } - return translatedIncludePaths; - } - /* (non-Javadoc) * @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector#getCollectedScannerInfo(java.lang.Object, org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes) */ @@ -440,4 +397,18 @@ public class PerProjectSICollector implements IScannerInfoCollector2, IScannerIn } } + /* (non-Javadoc) + * @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2#createPathInfoObject() + */ + public IDiscoveredPathInfo createPathInfoObject() { + DiscoveredPathInfo pathInfo = new DiscoveredPathInfo(project); + try { + DiscoveredScannerInfoStore.getInstance().loadDiscoveredScannerInfoFromState(project, pathInfo); + } + catch (CoreException e) { + MakeCorePlugin.log(e); + } + return pathInfo; + } + } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/ScannerConfigInfoFactory2.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/ScannerConfigInfoFactory2.java index ed239cb5359..994e3e094ba 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/ScannerConfigInfoFactory2.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/ScannerConfigInfoFactory2.java @@ -454,10 +454,10 @@ public class ScannerConfigInfoFactory2 { ((Element)sc).getAttribute(PROBLEM_REPORTING_ENABLED)).booleanValue(); } else if (sc.getNodeName().equals(PROFILE)) { - //if (selectedProfile.equals(((Element)sc).getAttribute(ID))) { + if (profileIds.contains(((Element)sc).getAttribute(ID))) { load(sc); loadedProfiles.add(((Element)sc).getAttribute(ID)); - //} + } } } if (loadedProfiles.size() < 1) { diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/ScannerConfigProfile.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/ScannerConfigProfile.java index 4fc17d3be2b..6d68d349761 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/ScannerConfigProfile.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/ScannerConfigProfile.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map; import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigScope; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; @@ -29,7 +30,7 @@ import org.eclipse.core.runtime.Platform; * @author vhirsl */ public class ScannerConfigProfile { - /** + /** * scannerInfoCollector element * * @author vhirsl @@ -48,6 +49,9 @@ public class ScannerConfigProfile { return null; } } + public String getScope() { + return configElem.getAttribute("scope"); //$NON-NLS-1$ + } } /** * scannerInfoConsoleParser element @@ -296,6 +300,20 @@ public class ScannerConfigProfile { public ScannerInfoCollector getScannerInfoCollectorElement() { return scannerInfoCollector; } + + public ScannerConfigScope getProfileScope() { + ScannerConfigScope scope = null; + if (scannerInfoCollector != null) { + if (scannerInfoCollector.getScope().equals(ScannerConfigScope.PROJECT_SCOPE.toString())) { + scope = ScannerConfigScope.PROJECT_SCOPE; + } + else if (scannerInfoCollector.getScope().equals(ScannerConfigScope.FILE_SCOPE.toString())) { + scope = ScannerConfigScope.FILE_SCOPE; + } + } + return scope; + } + /** * @return Returns the scannerInfoProviders. */ diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeResources.properties b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeResources.properties index 10b5761d98e..5f7b7c7f504 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeResources.properties +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeResources.properties @@ -234,6 +234,14 @@ ScannerConfigOptionsDialog.siProvider.browse.runCommandDialog='gcc' command: ScannerConfigOptionsDialog.siProvider.command.errorMessage=Must enter compiler invocation command ScannerConfigOptionsDialog.apply.progressMessage=Setting scanner configuration discovery options... +ScannerConfigOptionsDialog.unsavedchanges.title=Setting C/C++ Make Project Discovery Options +ScannerConfigOptionsDialog.unsavedchanges.message=The C/C++ Make Project Discovery Options property page contains unsaved modifications. Do you want to save changes so that other discovery related settings can be updated? +ScannerConfigOptionsDialog.unsavedchanges.button.save=Apply +ScannerConfigOptionsDialog.unsavedchanges.button.cancel=Cancel + +ScannerConfigOptionsDialog.error.title=Error Setting Project Discovery options +ScannerConfigOptionsDialog.error.message=An error occurred while setting the project discovery options + # --- DiscoveredScannerConfigurationContainerPage --- DiscoveredScannerConfigurationContainerPage.title=Edit container DiscoveredScannerConfigurationContainerPage.description=Manage discovered scanner configuration diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/AbstractDiscoveryOptionsBlock.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/AbstractDiscoveryOptionsBlock.java index 892a5ff52f7..1c04c481f3b 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/AbstractDiscoveryOptionsBlock.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/AbstractDiscoveryOptionsBlock.java @@ -10,12 +10,15 @@ ***********************************************************************/ package org.eclipse.cdt.make.ui.dialogs; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import org.eclipse.cdt.internal.ui.dialogs.cpaths.CPathEntryMessages; +import org.eclipse.cdt.internal.ui.util.ExceptionHandler; import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2; import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfileManager; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; @@ -26,8 +29,12 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Preferences; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.widgets.Composite; @@ -37,10 +44,21 @@ import org.eclipse.swt.widgets.Composite; * @author vhirsl */ public abstract class AbstractDiscoveryOptionsBlock extends AbstractCOptionPage { + protected static final String PREFIX = "ScannerConfigOptionsDialog"; //$NON-NLS-1$ + private static final String UNSAVEDCHANGES_TITLE = PREFIX + ".unsavedchanges.title"; //$NON-NLS-1$ + private static final String UNSAVEDCHANGES_MESSAGE = PREFIX + ".unsavedchanges.message"; //$NON-NLS-1$ + private static final String UNSAVEDCHANGES_BSAVE = PREFIX + ".unsavedchanges.button.save"; //$NON-NLS-1$ + private static final String UNSAVEDCHANGES_BCANCEL = PREFIX + ".unsavedchanges.button.cancel"; //$NON-NLS-1$ + private static final String ERROR_TITLE = PREFIX + ".error.title"; //$NON-NLS-1$ + private static final String ERROR_MESSAGE = PREFIX + ".error.message"; //$NON-NLS-1$ + private static final String PROFILE_PAGE = "profilePage"; //$NON-NLS-1$ + private static final String PROFILE_ID = "profileId"; //$NON-NLS-1$ + private Preferences fPrefs; private IScannerConfigBuilderInfo2 fBuildInfo; private boolean fInitialized = false; - + private String fPersistedProfileId = null; + private Map fProfilePageMap = null; // Composite parent provided by the block. @@ -77,6 +95,41 @@ public abstract class AbstractDiscoveryOptionsBlock extends AbstractCOptionPage protected void setInitialized(boolean initialized) { fInitialized = initialized; } + + /** + * @return true - OK to continue + */ + public boolean checkDialogForChanges() { + boolean rc = true; + if (isProfileDifferentThenPersisted()) { + String title = MakeUIPlugin.getResourceString(UNSAVEDCHANGES_TITLE); + String message = MakeUIPlugin.getResourceString(UNSAVEDCHANGES_MESSAGE); + String[] buttonLabels = new String[]{ + MakeUIPlugin.getResourceString(UNSAVEDCHANGES_BSAVE), + MakeUIPlugin.getResourceString(UNSAVEDCHANGES_BCANCEL), + }; + MessageDialog dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.QUESTION, + buttonLabels, 0); + int res = dialog.open(); + if (res == 0) { // OK + callPerformApply(); + rc = true; + } else if (res == 1) { // CANCEL + rc = false; + } + } + return rc; + } + + public boolean isProfileDifferentThenPersisted() { + return (fPersistedProfileId != null && + !fPersistedProfileId.equals(getBuildInfo().getSelectedProfileId())); + } + + public void updatePersistedProfile() { + fPersistedProfileId = getBuildInfo().getSelectedProfileId(); + } + /** * Create a profile page only on request * @@ -128,8 +181,8 @@ public abstract class AbstractDiscoveryOptionsBlock extends AbstractCOptionPage IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(MakeUIPlugin.getPluginId(), "DiscoveryProfilePage"); //$NON-NLS-1$ IConfigurationElement[] infos = extensionPoint.getConfigurationElements(); for (int i = 0; i < infos.length; i++) { - if (infos[i].getName().equals("profilePage")) { //$NON-NLS-1$ - String id = infos[i].getAttribute("profileId"); //$NON-NLS-1$ + if (infos[i].getName().equals(PROFILE_PAGE)) { //$NON-NLS-1$ + String id = infos[i].getAttribute(PROFILE_ID); //$NON-NLS-1$ fProfilePageMap.put(id, new DiscoveryProfilePageConfiguration(infos[i])); } } @@ -156,6 +209,9 @@ public abstract class AbstractDiscoveryOptionsBlock extends AbstractCOptionPage } else { fBuildInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(fPrefs, false); } + if (fBuildInfo != null) { + fPersistedProfileId = fBuildInfo.getSelectedProfileId(); + } } protected void updateContainer() { @@ -215,7 +271,7 @@ public abstract class AbstractDiscoveryOptionsBlock extends AbstractCOptionPage } /** - * Notification that the user changed the selection of the Binary Parser. + * Notification that the user changed the selection of the SCD profile. */ protected void handleDiscoveryProfileChanged() { if (getCompositeParent() == null) { @@ -297,5 +353,31 @@ public abstract class AbstractDiscoveryOptionsBlock extends AbstractCOptionPage } protected abstract String getCurrentProfileId(); + + /** + * + */ + public void callPerformApply() { + try { + new ProgressMonitorDialog(getShell()).run(false, false, new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + performApply(monitor); + } + catch (CoreException e) { + throw new InvocationTargetException(e); + } + } + + }); + } catch (InvocationTargetException e) { + String title = CPathEntryMessages.getString(ERROR_TITLE); //$NON-NLS-1$ + String message = CPathEntryMessages.getString(ERROR_MESSAGE); //$NON-NLS-1$ + ExceptionHandler.handle(e, getShell(), title, message); + } catch (InterruptedException e) { + // cancelled + } + } + } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/AbstractDiscoveryPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/AbstractDiscoveryPage.java index 92a233772c1..6620412b52a 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/AbstractDiscoveryPage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/AbstractDiscoveryPage.java @@ -15,15 +15,15 @@ import org.eclipse.jface.dialogs.DialogPage; import org.eclipse.jface.resource.ImageDescriptor; /** - * TODO Provide description + * Abstract SCD profile page * * @author vhirsl */ public abstract class AbstractDiscoveryPage extends DialogPage { protected static final String PREFIX = "ScannerConfigOptionsDialog"; //$NON-NLS-1$ protected static final String PROFILE_GROUP_LABEL = PREFIX + ".profile.group.label"; //$NON-NLS-1$ - - protected AbstractDiscoveryOptionsBlock fContainer; + + protected AbstractDiscoveryOptionsBlock fContainer; // parent /** * @return Returns the fContainer. diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/DiscoveryOptionsBlock.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/DiscoveryOptionsBlock.java index f3aa19d07ce..c38e481db2c 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/DiscoveryOptionsBlock.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/DiscoveryOptionsBlock.java @@ -22,8 +22,10 @@ import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.core.MakeProjectNature; import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2; +import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigScope; import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature; import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredPathContainer; +import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfileManager; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.cdt.make.internal.ui.preferences.TabFolderLayout; import org.eclipse.cdt.make.ui.IMakeHelpContextIds; @@ -55,7 +57,6 @@ import org.eclipse.ui.help.WorkbenchHelp; public class DiscoveryOptionsBlock extends AbstractDiscoveryOptionsBlock { private static final String MISSING_BUILDER_MSG = "ScannerConfigOptionsDialog.label.missingBuilderInformation"; //$NON-NLS-1$ - private static final String PREFIX = "ScannerConfigOptionsDialog"; //$NON-NLS-1$ private static final String DIALOG_TITLE = PREFIX + ".title"; //$NON-NLS-1$ private static final String DIALOG_DESCRIPTION = PREFIX + ".description"; //$NON-NLS-1$ private static final String SC_GROUP_LABEL = PREFIX + ".scGroup.label"; //$NON-NLS-1$ @@ -73,6 +74,7 @@ public class DiscoveryOptionsBlock extends AbstractDiscoveryOptionsBlock { private boolean needsSCNature = false; private boolean fCreatePathContainer = false; private boolean isValid = true; + private boolean persistedProfileChanged = false; // new persisted selected profile different than the old one /** * @@ -227,6 +229,16 @@ public class DiscoveryOptionsBlock extends AbstractDiscoveryOptionsBlock { * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean) */ public void setVisible(boolean visible) { + if (!visible) { + if (!checkDialogForChanges()) { + createBuildInfo(); + restoreFromBuildinfo(getBuildInfo()); + enableAllControls(); + handleDiscoveryProfileChanged(); + + getCurrentPage().performDefaults(); + } + } super.setVisible(visible); enableAllControls(); } @@ -267,6 +279,10 @@ public class DiscoveryOptionsBlock extends AbstractDiscoveryOptionsBlock { configureProject(project, monitor); } getBuildInfo().save(); + if (isProfileDifferentThenPersisted()) { + changeDiscoveryContainer(project); + updatePersistedProfile(); + } } monitor.done(); } @@ -308,17 +324,21 @@ public class DiscoveryOptionsBlock extends AbstractDiscoveryOptionsBlock { MakeCorePlugin.getDefault().getDiscoveryManager().removeDiscoveredInfo(project); } + /** + * @param project + */ + private void changeDiscoveryContainer(IProject project) { + String profileId = getBuildInfo().getSelectedProfileId(); + ScannerConfigScope profileScope = ScannerConfigProfileManager.getInstance(). + getSCProfileConfiguration(profileId).getProfileScope(); + MakeCorePlugin.getDefault().getDiscoveryManager().changeDiscoveredContainer(project, profileScope); + } + private void populateBuildInfo(IScannerConfigBuilderInfo2 buildInfo) { if (buildInfo != null) { buildInfo.setAutoDiscoveryEnabled(scEnabledButton.getSelection()); String profileName = profileComboBox.getItem(profileComboBox.getSelectionIndex()); - String oldProfileId = buildInfo.getSelectedProfileId(); buildInfo.setSelectedProfileId(getDiscoveryProfileId(profileName)); - String newProfileId = buildInfo.getSelectedProfileId(); - if (!oldProfileId.equals(newProfileId) && getProject() != null) { - // invalidate scanner config store and reload -// MakeCorePlugin.getDefault().getDiscoveryManager().removeDiscoveredInfo(getProject()); - } buildInfo.setProblemReportingEnabled(scProblemReportingEnabledButton.getSelection()); } } @@ -345,7 +365,7 @@ public class DiscoveryOptionsBlock extends AbstractDiscoveryOptionsBlock { private void restoreFromBuildinfo(IScannerConfigBuilderInfo2 buildInfo) { if (buildInfo != null) { scEnabledButton.setSelection(buildInfo.isAutoDiscoveryEnabled()); - String profileId = buildInfo.getSelectedProfileId(); + String profileId = buildInfo.getSelectedProfileId(); profileComboBox.setText(getDiscoveryProfileName(profileId)); scProblemReportingEnabledButton.setSelection(buildInfo.isProblemReportingEnabled()); } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/GCCPerFileSCDProfilePage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/GCCPerFileSCDProfilePage.java index 9b2bc09ceb6..7eec7c3869b 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/GCCPerFileSCDProfilePage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/GCCPerFileSCDProfilePage.java @@ -216,6 +216,7 @@ public class GCCPerFileSCDProfilePage extends AbstractDiscoveryPage { } private void handleBOPLoadFileButtonSelected() { + if (!getContainer().checkDialogForChanges()) return; loadButtonInitialEnabled = false; bopLoadButton.setEnabled(false); diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/GCCPerProjectSCDProfilePage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/GCCPerProjectSCDProfilePage.java index cd917c05f7e..780e683734e 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/GCCPerProjectSCDProfilePage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/GCCPerProjectSCDProfilePage.java @@ -294,6 +294,7 @@ public class GCCPerProjectSCDProfilePage extends AbstractDiscoveryPage { } private void handleBOPLoadFileButtonSelected() { + if (!getContainer().checkDialogForChanges()) return; loadButtonInitialEnabled = false; bopLoadButton.setEnabled(false); diff --git a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml index ca4bdf4737e..7a7a29b5e70 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml @@ -88,7 +88,9 @@ id="GCCManagedMakePerProjectProfile" name="GNU C/C++ managed make per project SCD profile" point="org.eclipse.cdt.make.core.ScannerConfigurationDiscoveryProfile"> - + - + 0) {