diff options
author | David Inglis | 2004-04-15 19:02:00 +0000 |
---|---|---|
committer | David Inglis | 2004-04-15 19:02:00 +0000 |
commit | e75bafa4a4e6c14b60634418bc08cee3200fcd49 (patch) | |
tree | 430c5ea0387c1a850e4dbd81f84dba3352cab902 | |
parent | ce4bd0a14125930a0dc9d2a03f9ecff48b58e253 (diff) | |
download | org.eclipse.cdt-e75bafa4a4e6c14b60634418bc08cee3200fcd49.tar.gz org.eclipse.cdt-e75bafa4a4e6c14b60634418bc08cee3200fcd49.tar.xz org.eclipse.cdt-e75bafa4a4e6c14b60634418bc08cee3200fcd49.zip |
patch from vhirsl@ca.ibm.com for scanner discovery machanism
31 files changed, 3123 insertions, 1287 deletions
diff --git a/build/org.eclipse.cdt.make.core/plugin.xml b/build/org.eclipse.cdt.make.core/plugin.xml index 14dddcd1ef2..46367f91b3f 100644 --- a/build/org.eclipse.cdt.make.core/plugin.xml +++ b/build/org.eclipse.cdt.make.core/plugin.xml @@ -142,5 +142,14 @@ class="org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCSpecsConsoleParser"> </scannerInfoConsoleParser> </extension> + <extension + id="DiscoveredScannerInfoProvider" + point="org.eclipse.cdt.core.ScannerInfoProvider"> + <cextension> + <run + class="org.eclipse.cdt.make.core.scannerconfig.DiscoveredScannerInfoProvider"> + </run> + </cextension> + </extension> </plugin> diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeScannerInfo.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeScannerInfo.java index 0c6c3b92845..9dc04c204ba 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeScannerInfo.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeScannerInfo.java @@ -27,7 +27,7 @@ public class MakeScannerInfo implements IScannerInfo { private ArrayList pathList; boolean hasChanged = false; - MakeScannerInfo(IProject project) { + public MakeScannerInfo(IProject project) { this.project = project; } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeScannerProvider.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeScannerProvider.java index e7bb6992cb9..3a510c2972a 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeScannerProvider.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeScannerProvider.java @@ -123,7 +123,7 @@ public class MakeScannerProvider extends AbstractCExtension implements IScannerI * information is then associated with the resource for the duration of the * session. */ - private MakeScannerInfo loadScannerInfo(IProject project) throws CoreException { + public MakeScannerInfo loadScannerInfo(IProject project) throws CoreException { ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project); Node child = descriptor.getProjectData(CDESCRIPTOR_ID).getFirstChild(); ArrayList includes = new ArrayList(); @@ -169,7 +169,7 @@ public class MakeScannerProvider extends AbstractCExtension implements IScannerI * * @param project */ - static void updateScannerInfo(MakeScannerInfo scannerInfo) throws CoreException { + public static void updateScannerInfo(MakeScannerInfo scannerInfo) throws CoreException { IProject project = scannerInfo.getProject(); // See if there's already one associated with the resource for this diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/PluginResources.properties b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/PluginResources.properties index e17efd09391..0d023072e39 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/PluginResources.properties +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/PluginResources.properties @@ -16,8 +16,11 @@ MakeTargetManager.error_writing_file=Error writing target file ProjectTargets.error_reading_project_targets=Error reading project targets. ScannerConfigBuilder.Invoking_Builder=Invoking scanner config builder on project +ScannerConfigNature.Missing_Project=Missing or closed project -ExternalScannerInfoProvider.Provider_Error=Error launching compiler scanner info generator ({0}) +ScannerConfigInfoFactory.Missing_Builder=Missing Builder: + +ExternalScannerInfoProvider.Provider_Error=Error launching external scanner info generator ({0}) ExternalScannerInfoProvider.Reading_Specs=Reading specs ... ExternalScannerInfoProvider.Invoking_Command=Invoking Command: ExternalScannerInfoProvider.Parsing_Output=Parsing output ... diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/DiscoveredScannerInfo.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/DiscoveredScannerInfo.java new file mode 100644 index 00000000000..0bf398da93c --- /dev/null +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/DiscoveredScannerInfo.java @@ -0,0 +1,216 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.make.core.scannerconfig; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.cdt.core.parser.IScannerInfo; +import org.eclipse.cdt.make.core.MakeScannerInfo; +import org.eclipse.cdt.make.internal.core.scannerconfig.util.ScannerConfigUtil; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; + +/** + * Discovered portion of scanner configuration + * + * @author vhirsl + */ +public class DiscoveredScannerInfo implements IScannerInfo { + private IProject project; + private LinkedHashMap discoveredPaths; + private LinkedHashMap discoveredSymbols; + + private ArrayList activePaths; + private ArrayList removedPaths; + + private ArrayList activeSymbols; + private ArrayList removedSymbols; + + private MakeScannerInfo userInfo; + + /** + * @param project + */ + public DiscoveredScannerInfo(IProject project) { + this.project = project; + } + + public IProject getProject() { + return project; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.IScannerInfo#getDefinedSymbols() + */ + public synchronized Map getDefinedSymbols() { + Map dSymbols = ScannerConfigUtil.scSymbolEntryMap2Map(discoveredSymbols); + dSymbols.putAll(userInfo.getDefinedSymbols()); + return dSymbols; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.IScannerInfo#getIncludePaths() + */ + public synchronized String[] getIncludePaths() { + String[] iPaths = new String[getUserIncludePaths().length + getActiveIncludePaths().length]; + System.arraycopy(getUserIncludePaths(), 0, iPaths, 0, getUserIncludePaths().length); + System.arraycopy(getActiveIncludePaths(), 0, iPaths, getUserIncludePaths().length, getActiveIncludePaths().length); + return iPaths; + } + + public MakeScannerInfo getUserScannerInfo() { + return userInfo; + } + public synchronized void setUserScannerInfo(MakeScannerInfo info) { + userInfo = info; + } + + public LinkedHashMap getDiscoveredIncludePaths() { + if (discoveredPaths == null) { + return new LinkedHashMap(); + } + return new LinkedHashMap(discoveredPaths); + } + public synchronized void setDiscoveredIncludePaths(LinkedHashMap paths) { + discoveredPaths = new LinkedHashMap(paths); + createPathLists(); + } + + /** + * Populates active and removed include path lists + */ + private void createPathLists() { + List aPaths = getActivePathList(); + aPaths.clear(); + List rPaths = getRemovedPathList(); + rPaths.clear(); + + for (Iterator i = discoveredPaths.keySet().iterator(); i.hasNext(); ) { + String path = (String) i.next(); + Boolean removed = (Boolean) discoveredPaths.get(path); + if (removed == null || removed.booleanValue() == false) { + aPaths.add(path); + } + else { + rPaths.add(path); + } + } + } + + public LinkedHashMap getDiscoveredSymbolDefinitions() { + if (discoveredSymbols == null) { + return new LinkedHashMap(); + } + return new LinkedHashMap(discoveredSymbols); + } + public synchronized void setDiscoveredSymbolDefinitions(LinkedHashMap symbols) { + discoveredSymbols = new LinkedHashMap(symbols); + createSymbolsLists(); + } + + /** + * Populates active and removed defined symbols sets + */ + private void createSymbolsLists() { + List aSymbols = getActiveSymbolsList(); + aSymbols.clear(); + List rSymbols = getRemovedSymbolsList(); + rSymbols.clear(); + + aSymbols.addAll(ScannerConfigUtil.scSymbolsSymbolEntryMap2List(discoveredSymbols, true)); + rSymbols.addAll(ScannerConfigUtil.scSymbolsSymbolEntryMap2List(discoveredSymbols, false)); + } + + public String[] getUserIncludePaths() { + if (userInfo == null) { + return new String[0]; + } + return userInfo.getIncludePaths(); + } + public String[] getActiveIncludePaths() { + return (String[]) getActivePathList().toArray(new String[getActivePathList().size()]); + } + public String[] getRemovedIncludePaths() { + return (String[])getRemovedPathList().toArray(new String[getRemovedPathList().size()]); + } + + public String[] getUserSymbolDefinitions() { + if (userInfo == null) { + return new String[0]; + } + return userInfo.getPreprocessorSymbols(); + } + public String[] getActiveSymbolDefinitions() { + return (String[]) getActiveSymbolsList().toArray(new String[getActiveSymbolsList().size()]); + } + public String[] getRemovedSymbolDefinitions() { + return (String[]) getRemovedSymbolsList().toArray(new String[getRemovedSymbolsList().size()]); + } + public String[] getPreprocessorSymbols() { + // user specified + active + String[] userSymbols = getUserSymbolDefinitions(); + String[] discActiveSymbols = getActiveSymbolDefinitions(); + String[] rv = new String[userSymbols.length + discActiveSymbols.length]; + System.arraycopy(userSymbols, 0, rv, 0, userSymbols.length); + System.arraycopy(discActiveSymbols, 0, rv, userSymbols.length, discActiveSymbols.length); + return rv; + } + + private List getActivePathList() { + if (activePaths == null) { + activePaths = new ArrayList(); + } + return activePaths; + } + + private List getRemovedPathList() { + if (removedPaths == null) { + removedPaths = new ArrayList(); + } + return removedPaths; + } + + private List getActiveSymbolsList() { + if (activeSymbols == null) { + activeSymbols = new ArrayList(); + } + return activeSymbols; + } + + private List getRemovedSymbolsList() { + if (removedSymbols == null) { + removedSymbols = new ArrayList(); + } + return removedSymbols; + } + + public void update() throws CoreException { + DiscoveredScannerInfoProvider.updateScannerInfo(this); + } + + /** + * @param userPaths + */ + public void setUserIncludePaths(List userPaths) { + userInfo.setIncludePaths((String[]) userPaths.toArray(new String[userPaths.size()])); + } + + /** + * @param userSymbols + */ + public void setUserDefinedSymbols(List userSymbols) { + userInfo.setPreprocessorSymbols((String[]) userSymbols.toArray(new String[userSymbols.size()])); + } + +} diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/DiscoveredScannerInfoProvider.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/DiscoveredScannerInfoProvider.java new file mode 100644 index 00000000000..44da128e778 --- /dev/null +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/DiscoveredScannerInfoProvider.java @@ -0,0 +1,262 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.make.core.scannerconfig; + +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.eclipse.cdt.core.AbstractCExtension; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.ICDescriptor; +import org.eclipse.cdt.core.parser.IScannerInfo; +import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; +import org.eclipse.cdt.core.parser.IScannerInfoProvider; +import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.MakeScannerInfo; +import org.eclipse.cdt.make.core.MakeScannerProvider; +import org.eclipse.cdt.make.internal.core.scannerconfig.util.ScannerConfigUtil; +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.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * Provider of both user specified and discovered scanner info + * + * @author vhirsl + */ +public class DiscoveredScannerInfoProvider extends AbstractCExtension implements IScannerInfoProvider { + + // This is the id of the IScannerInfoProvider extension point entry + public static final String INTERFACE_IDENTITY = MakeCorePlugin.getUniqueIdentifier() + ".DiscoveredScannerInfoProvider"; //$NON-NLS-1$ + + // Name we will use to store build property with the project + private static final QualifiedName scannerInfoProperty = new QualifiedName(MakeCorePlugin.getUniqueIdentifier(), "discoveredMakeBuildInfo"); //$NON-NLS-1$ + private static final String CDESCRIPTOR_ID = MakeCorePlugin.getUniqueIdentifier() + ".discoveredScannerInfo"; //$NON-NLS-1$ + + public static final String INCLUDE_PATH = "includePath"; //$NON-NLS-1$ + public static final String PATH = "path"; //$NON-NLS-1$ + public static final String DEFINED_SYMBOL = "definedSymbol"; //$NON-NLS-1$ + public static final String SYMBOL = "symbol"; //$NON-NLS-1$ + public static final String REMOVED = "removed"; //$NON-NLS-1$ + + private static final String ROOT_ELEM_NAME = "DiscoveredScannerInfo"; //$NON-NLS-1$ + + // Singleton + private static DiscoveredScannerInfoProvider instance; + public static DiscoveredScannerInfoProvider getDefault() { + if (instance == null) { + instance = new DiscoveredScannerInfoProvider(); + } + return instance; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#getScannerInformation(org.eclipse.core.resources.IResource) + */ + public IScannerInfo getScannerInformation(IResource resource) { + IScannerInfo info = null; + try { + info = getDiscoveredScannerInfo(resource.getProject(), true); + } catch (CoreException e) { + } + return info; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#subscribe(org.eclipse.core.resources.IResource, org.eclipse.cdt.core.parser.IScannerInfoChangeListener) + */ + public void subscribe(IResource resource, IScannerInfoChangeListener listener) { + MakeScannerProvider.getDefault().subscribe(resource, listener); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#unsubscribe(org.eclipse.core.resources.IResource, org.eclipse.cdt.core.parser.IScannerInfoChangeListener) + */ + public void unsubscribe(IResource resource, IScannerInfoChangeListener listener) { + MakeScannerProvider.getDefault().unsubscribe(resource, listener); + } + + public DiscoveredScannerInfo getDiscoveredScannerInfo(IProject project, boolean cacheInfo) throws CoreException { + DiscoveredScannerInfo scannerInfo = null; + // See if there's already one associated with the resource for this + // session + scannerInfo = (DiscoveredScannerInfo)project.getSessionProperty(scannerInfoProperty); + + // Try to load one for the project + if (scannerInfo == null) { + scannerInfo = loadScannerInfo(project); + } + else { + // TODO VMIR temporary + // get the separately stored MakeScannerInfo in case someone accessed it + // not through DiscoveredScannerInfoProvider + MakeScannerInfo makeScannerInfo = MakeScannerProvider.getDefault().getMakeScannerInfo(project, cacheInfo); + scannerInfo.setUserScannerInfo(makeScannerInfo); + } + + // There is nothing persisted for the session, or saved in a file so + // create a build info object + if (scannerInfo != null && cacheInfo == true) { + project.setSessionProperty(scannerInfoProperty, scannerInfo); + } + return scannerInfo; + } + + /* + * Loads the build file and parses the nodes for build information. The + * information is then associated with the resource for the duration of the + * session. + */ + private DiscoveredScannerInfo loadScannerInfo(IProject project) throws CoreException { + LinkedHashMap includes = new LinkedHashMap(); + LinkedHashMap symbols = new LinkedHashMap(); + loadDiscoveredScannerInfoFromCDescriptor(project, includes, symbols); + MakeScannerInfo userInfo = MakeScannerProvider.getDefault().loadScannerInfo(project); + DiscoveredScannerInfo info = new DiscoveredScannerInfo(project); + info.setUserScannerInfo(userInfo); + info.setDiscoveredIncludePaths(includes); + info.setDiscoveredSymbolDefinitions(symbols); + return info; + } + + /** + * Loads discovered scanner configuration from .cdtproject file + * @param project + * @param includes + * @param symbols + * @throws CoreException + */ + private void loadDiscoveredScannerInfoFromCDescriptor(IProject project, LinkedHashMap includes, LinkedHashMap symbols) throws CoreException { + ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project); + Node child = descriptor.getProjectData(CDESCRIPTOR_ID).getFirstChild(); + while (child != null) { + if (child.getNodeName().equals(INCLUDE_PATH)) { + // Add the path to the property list + includes.put(((Element)child).getAttribute(PATH), + Boolean.valueOf(((Element)child).getAttribute(REMOVED))); + } else if (child.getNodeName().equals(DEFINED_SYMBOL)) { + // Add the symbol to the symbol list + String symbol = ((Element)child).getAttribute(SYMBOL); + String removed = ((Element)child).getAttribute(REMOVED); + boolean bRemoved = (removed != null && removed == "true"); //$NON-NLS-1$ + ScannerConfigUtil.scAddSymbolString2SymbolEntryMap(symbols, symbol, !bRemoved); + } + child = child.getNextSibling(); + } + } + + /** + * The build model manager for standard builds only caches the build + * information for a resource on a per-session basis. This method allows + * clients of the build model manager to programmatically remove the + * association between the resource and the information while the reource + * is still open or in the workspace. The Eclipse core will take care of + * removing it if a resource is closed or deleted. + * + * @param resource + */ + public static void removeScannerInfo(IResource resource) { + try { + resource.getProject().setSessionProperty(scannerInfoProperty, null); + } catch (CoreException e) { + } + } + + /** + * Persists build-specific information in the build file. Build information + * for standard make projects consists of preprocessor symbols and includes + * paths. Other project-related information is stored in the persistent + * properties of the project. + * + * @param scannerInfo + */ + static void updateScannerInfo(DiscoveredScannerInfo scannerInfo) throws CoreException { + IProject project = scannerInfo.getProject(); + + // See if there's already one associated with the resource for this + // session + if (project.getSessionProperty(scannerInfoProperty) != null) { + project.setSessionProperty(scannerInfoProperty, scannerInfo); + } + + saveDiscoveredScannerInfoToCDescriptor(scannerInfo, project); + + MakeScannerProvider.updateScannerInfo(scannerInfo.getUserScannerInfo()); +// listeners are notified by MakeScannerProvider.updateScannerInfo +// notifyInfoListeners(project, scannerInfo); + } + + /** + * Save discovered scanner configuration to .cdtproject file + * @param scannerInfo + * @param project + * @throws CoreException + */ + private static void saveDiscoveredScannerInfoToCDescriptor(DiscoveredScannerInfo scannerInfo, IProject project) throws CoreException { + ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project); + + Element rootElement = descriptor.getProjectData(CDESCRIPTOR_ID); + + // Clear out all current children + // Note: Probably would be a better idea to merge in the data + Node child = rootElement.getFirstChild(); + while (child != null) { + rootElement.removeChild(child); + child = rootElement.getFirstChild(); + } + + // Save the build info + if (scannerInfo != null) { + // Serialize the include paths + Document doc = rootElement.getOwnerDocument(); + Map discoveredIncludes = scannerInfo.getDiscoveredIncludePaths(); + Iterator iter = discoveredIncludes.keySet().iterator(); + while (iter.hasNext()) { + Element pathElement = doc.createElement(INCLUDE_PATH); + String include = (String) iter.next(); + pathElement.setAttribute(PATH, include); + Boolean removed = (Boolean) discoveredIncludes.get(include); + if (removed != null && removed.booleanValue() == true) { + pathElement.setAttribute(REMOVED, "true"); //$NON-NLS-1$ + } + rootElement.appendChild(pathElement); + } + // Now do the same for the symbols + Map discoveredSymbols = scannerInfo.getDiscoveredSymbolDefinitions(); + iter = discoveredSymbols.keySet().iterator(); + while (iter.hasNext()) { + String symbol = (String) iter.next(); + SymbolEntry se = (SymbolEntry) discoveredSymbols.get(symbol); + for (Iterator i = se.getActiveRaw().iterator(); i.hasNext(); ) { + String value = (String) i.next(); + Element symbolElement = doc.createElement(DEFINED_SYMBOL); + symbolElement.setAttribute(SYMBOL, value); + rootElement.appendChild(symbolElement); + } + for (Iterator i = se.getRemovedRaw().iterator(); i.hasNext(); ) { + String value = (String) i.next(); + Element symbolElement = doc.createElement(DEFINED_SYMBOL); + symbolElement.setAttribute(SYMBOL, value); + symbolElement.setAttribute(REMOVED, "true"); //$NON-NLS-1$ + rootElement.appendChild(symbolElement); + } + } +// descriptor is saved by MakeScannerProvider.updateScannerInfo +// descriptor.saveProjectData(); + } + } +}
\ No newline at end of file diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigNature.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigNature.java index aab6fa15c30..62616bed04f 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigNature.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigNature.java @@ -10,7 +10,10 @@ **********************************************************************/ package org.eclipse.cdt.make.core.scannerconfig; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.MakeScannerProvider; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IProject; @@ -25,9 +28,6 @@ public class ScannerConfigNature implements IProjectNature { public final static String NATURE_ID = MakeCorePlugin.getUniqueIdentifier() + ".ScannerConfigNature"; //$NON-NLS-1$ private IProject fProject; - public ScannerConfigNature() { - } - /** * @see IProjectNature#configure */ @@ -46,6 +46,8 @@ public class ScannerConfigNature implements IProjectNature { newCommands[commands.length] = command; description.setBuildSpec(newCommands); getProject().setDescription(description, null); + + // set default project scanner config settings } /** @@ -81,20 +83,24 @@ public class ScannerConfigNature implements IProjectNature { } public static void addScannerConfigNature(IProject project) throws CoreException { - if (project.hasNature(NATURE_ID)) - return; - IProjectDescription description = project.getDescription(); + if (description.hasNature(NATURE_ID)) + return; String[] ids = description.getNatureIds(); String[] newIds = new String[ids.length + 1]; System.arraycopy(ids, 0, newIds, 0, ids.length); newIds[ids.length] = NATURE_ID; description.setNatureIds(newIds); project.setDescription(description, null); + + // set DiscoveredScannerInfoProvider as a default one for the project + updateProjectsScannerInfoProvider(project, true); } public static void removeScannerConfigNature(IProject project) throws CoreException { IProjectDescription description = project.getDescription(); + if (!description.hasNature(NATURE_ID)) + return; String[] ids = description.getNatureIds(); for (int i = 0; i < ids.length; ++i) { if (ids[i].equals(NATURE_ID)) { @@ -105,6 +111,9 @@ public class ScannerConfigNature implements IProjectNature { project.setDescription(description, null); } } + + // fall back to MakeScannerProvider + updateProjectsScannerInfoProvider(project, false); } /** @@ -125,4 +134,20 @@ public class ScannerConfigNature implements IProjectNature { } return null; } + + /** + * @param project + * @param b + */ + private static void updateProjectsScannerInfoProvider(IProject project, boolean discovered) { + try { + ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(project); + desc.remove(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID); + desc.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, (discovered)? + DiscoveredScannerInfoProvider.INTERFACE_IDENTITY: + MakeScannerProvider.INTERFACE_IDENTITY); + } catch (CoreException e) { + MakeCorePlugin.log(e.getStatus()); + } + } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeProject.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeProject.java index 6085b53d7ea..2727d8c669f 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeProject.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeProject.java @@ -15,7 +15,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICOwner; import org.eclipse.cdt.make.core.MakeCorePlugin; -import org.eclipse.cdt.make.core.MakeScannerProvider; +import org.eclipse.cdt.make.core.scannerconfig.DiscoveredScannerInfoProvider; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Preferences; @@ -24,13 +24,13 @@ public class MakeProject implements ICOwner { public void configure(ICDescriptor cDescriptor) throws CoreException { cDescriptor.remove(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID); cDescriptor.remove(CCorePlugin.BUILDER_MODEL_ID); - cDescriptor.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, MakeScannerProvider.INTERFACE_IDENTITY); + cDescriptor.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, DiscoveredScannerInfoProvider.INTERFACE_IDENTITY); updateBinaryParsers(cDescriptor); } public void update(ICDescriptor cDescriptor, String extensionID) throws CoreException { if (extensionID.equals(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID)) { - cDescriptor.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, MakeScannerProvider.INTERFACE_IDENTITY); + cDescriptor.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, DiscoveredScannerInfoProvider.INTERFACE_IDENTITY); } if (extensionID.equals(CCorePlugin.BINARY_PARSER_UNIQ_ID)) { updateBinaryParsers(cDescriptor); @@ -48,6 +48,7 @@ public class MakeProject implements ICOwner { } } } + private String[] parseStringToArray(String syms) { if (syms != null && syms.length() > 0) { diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DefaultExternalScannerInfoProvider.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DefaultExternalScannerInfoProvider.java index 2816383ac41..7aa290c7842 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DefaultExternalScannerInfoProvider.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DefaultExternalScannerInfoProvider.java @@ -43,7 +43,7 @@ import org.eclipse.core.runtime.SubProgressMonitor; */ public class DefaultExternalScannerInfoProvider implements IExternalScannerInfoProvider, IMarkerGenerator { - private static final String EXTERNAL_SI_PROVIDER_ERROR = "DefaultExternalScannerInfoProvider.Provider_Error"; //$NON-NLS-1$ + private static final String EXTERNAL_SI_PROVIDER_ERROR = "ExternalScannerInfoProvider.Provider_Error"; //$NON-NLS-1$ private static final String EXTERNAL_SI_PROVIDER_CONSOLE_ID = MakeCorePlugin.getUniqueIdentifier() + ".ExternalScannerInfoProviderConsole"; //$NON-NLS-1$ private IPath fWorkingDirectory; @@ -106,7 +106,7 @@ public class DefaultExternalScannerInfoProvider implements IExternalScannerInfoP if (errMsg != null) { String errorDesc = MakeCorePlugin.getFormattedString(EXTERNAL_SI_PROVIDER_ERROR, fCompileCommand.toString() + ca); - addMarker(currentProject, -1, errorDesc, IMarkerGenerator.SEVERITY_ERROR_BUILD, null); + addMarker(currentProject, -1, errorDesc, IMarkerGenerator.SEVERITY_WARNING, null); } monitor.subTask(MakeCorePlugin.getResourceString("ExternalScannerInfoProvider.Creating_Markers")); //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/IScannerInfoConsoleParserUtility.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/IScannerInfoConsoleParserUtility.java index c4355b99572..37bb430c6e1 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/IScannerInfoConsoleParserUtility.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/IScannerInfoConsoleParserUtility.java @@ -28,4 +28,5 @@ public interface IScannerInfoConsoleParserUtility { public void changeMakeDirectory(String dir, int dirLevel, boolean enterDir); public IFile findFile(String fileName); public List translateRelativePaths(IFile file, String fileName, List includes); + public String normalizePath(String path); } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoCollector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoCollector.java index 3e2fa6deba8..79323c71636 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoCollector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoCollector.java @@ -11,13 +11,11 @@ package org.eclipse.cdt.make.internal.core.scannerconfig; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Set; import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCorePlugin; @@ -33,10 +31,10 @@ import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.cdt.make.core.MakeScannerInfo; import org.eclipse.cdt.make.core.MakeProjectNature; import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.scannerconfig.DiscoveredScannerInfo; import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo; import org.eclipse.cdt.make.core.scannerconfig.IExternalScannerInfoProvider; import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigBuilder; @@ -143,18 +141,16 @@ public class ScannerInfoCollector { if (provider != null) { IScannerInfo scanInfo = provider.getScannerInformation(project); if (scanInfo != null) { - if (scanInfo instanceof MakeScannerInfo) { - MakeScannerInfo makeScanInfo = (MakeScannerInfo)scanInfo; + if (scanInfo instanceof DiscoveredScannerInfo) { + DiscoveredScannerInfo discScanInfo = (DiscoveredScannerInfo)scanInfo; String projectName = project.getName(); - monitor.subTask(MakeCorePlugin.getResourceString("ScannerInfoCollector.Processing")); //$NON-NLS-1$ - if (scannerConfigNeedsUpdate(makeScanInfo, projectName)) { + if (scannerConfigNeedsUpdate(discScanInfo, projectName)) { monitor.worked(50); monitor.subTask(MakeCorePlugin.getResourceString("ScannerInfoCollector.Updating") + projectName); //$NON-NLS-1$ - try { // update scanner configuration - makeScanInfo.update(); + discScanInfo.update(); monitor.worked(50); } catch (CoreException e) { // TODO : VMIR create a marker? @@ -173,13 +169,11 @@ public class ScannerInfoCollector { * @param projectName * @return */ - private boolean scannerConfigNeedsUpdate(MakeScannerInfo makeScanInfo, String projectName) { - // TODO : VMIR to implement other variants + private boolean scannerConfigNeedsUpdate(DiscoveredScannerInfo discScanInfo, String projectName) { List includes = (List) discoveredIncludes.get(projectName); - List dSymbols = (List) discoveredSymbols.get(projectName); - if (includes == null && dSymbols == null) + List symbols = (List) discoveredSymbols.get(projectName); + if (includes == null && symbols == null) return false; - Set symbols = new HashSet(dSymbols); // Step 1. Add discovered scanner config to the existing discovered scanner config // add the includes from the latest discovery @@ -205,32 +199,30 @@ public class ScannerInfoCollector { boolean addedSymbols = false; Map sumSymbols = (Map) sumDiscoveredSymbols.get(projectName); if (sumSymbols == null) { - sumSymbols = new HashMap(); + sumSymbols = new LinkedHashMap(); sumDiscoveredSymbols.put(projectName, sumSymbols); } - addedSymbols = ScannerConfigUtil.scAddSymbolsSet2SymbolEntryMap(sumSymbols, symbols, false); + addedSymbols = ScannerConfigUtil.scAddSymbolsList2SymbolEntryMap(sumSymbols, symbols, false); // Step 2. Get project's scanner config - String[] persistedIncludes = makeScanInfo.getIncludePaths(); - Map persistedSymbols = makeScanInfo.getDefinedSymbols(); + LinkedHashMap persistedIncludes = discScanInfo.getDiscoveredIncludePaths(); + LinkedHashMap persistedSymbols = discScanInfo.getDiscoveredSymbolDefinitions(); - // TODO VMIR this is likely to change when new UI is introduced // Step 3. Merge scanner config from steps 1 and 2 - List candidateIncludes = new ArrayList(Arrays.asList(persistedIncludes)); for (Iterator i = finalSumIncludes.iterator(); i.hasNext(); ) { String include = (String) i.next(); - if (!candidateIncludes.contains(include)) { - addedIncludes |= candidateIncludes.add(include); + if (!persistedIncludes.containsKey(include)) { + persistedIncludes.put(include, + ((new Path(include)).toFile().exists()) ? Boolean.FALSE : Boolean.TRUE); + addedIncludes |= true; } } - Map candidateSymbols = new HashMap(sumSymbols); - Set persistedSymbolsSet = ScannerConfigUtil.scSymbolsMap2Set(persistedSymbols); - addedSymbols |= ScannerConfigUtil.scAddSymbolsSet2SymbolEntryMap(candidateSymbols, persistedSymbolsSet, true); + LinkedHashMap candidateSymbols = new LinkedHashMap(persistedSymbols); + addedSymbols |= ScannerConfigUtil.scAddSymbolEntryMap2SymbolEntryMap(candidateSymbols, sumSymbols); // Step 4. Set resulting scanner config - makeScanInfo.setIncludePaths((String[])candidateIncludes.toArray(new String[candidateIncludes.size()])); - makeScanInfo.setPreprocessorSymbols((String[])ScannerConfigUtil. - scSymbolsSymbolEntryMap2Set(candidateSymbols).toArray(new String[candidateSymbols.size()])); + discScanInfo.setDiscoveredIncludePaths(persistedIncludes); + discScanInfo.setDiscoveredSymbolDefinitions(candidateSymbols); // invalidate discovered include paths and symbol definitions discoveredIncludes.put(projectName, null); @@ -291,7 +283,6 @@ public class ScannerInfoCollector { project, ScannerConfigBuilder.BUILDER_ID); } catch (CoreException e) { - MakeCorePlugin.log(e); info = MakeCorePlugin.createScannerConfigBuildInfo( MakeCorePlugin.getDefault().getPluginPreferences(), ScannerConfigBuilder.BUILDER_ID, false); @@ -340,4 +331,27 @@ public class ScannerInfoCollector { discoveredTSO.put(projectName, null); } + /** + * Delete all discovered paths for the project + * + * @param project + */ + public void deleteAllPaths(IProject project) { + if (project != null) { + sumDiscoveredIncludes.put(project.getName(), null); + } + // TODO VMIR define error message + } + + /** + * Delete all discovered symbols for the project + * + * @param project + */ + public void deleteAllSymbols(IProject project) { + if (project != null) { + sumDiscoveredSymbols.put(project.getName(), null); + } + // TODO VMIR define error message + } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoConsoleParserFactory.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoConsoleParserFactory.java index eb04a0499af..6916dfb64f6 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoConsoleParserFactory.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerInfoConsoleParserFactory.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo; import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser; import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigBuilder; +import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature; import org.eclipse.cdt.make.internal.core.scannerconfig.util.ScannerInfoConsoleParserUtility; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; @@ -73,18 +74,20 @@ public class ScannerInfoConsoleParserFactory { IMarkerGenerator markerGenerator) { try { // get the SC builder settings - IScannerConfigBuilderInfo scBuildInfo = MakeCorePlugin. - createScannerConfigBuildInfo(currentProject, ScannerConfigBuilder.BUILDER_ID); - if (scBuildInfo.isMakeBuilderConsoleParserEnabled()) { - // get the make builder console parser - IScannerInfoConsoleParser clParser = MakeCorePlugin.getDefault(). - getScannerInfoConsoleParser(scBuildInfo.getMakeBuilderConsoleParserId()); - // initialize it with the utility - clParser.startup(currentProject, new ScannerInfoConsoleParserUtility( - currentProject, workingDirectory, markerGenerator)); - // create an output stream sniffer - return new ConsoleOutputStreamSniffer(outputStream, new - IScannerInfoConsoleParser[] {clParser}); + if (currentProject.hasNature(ScannerConfigNature.NATURE_ID)) { + IScannerConfigBuilderInfo scBuildInfo = MakeCorePlugin. + createScannerConfigBuildInfo(currentProject, ScannerConfigBuilder.BUILDER_ID); + if (scBuildInfo != null && scBuildInfo.isMakeBuilderConsoleParserEnabled()) { + // get the make builder console parser + IScannerInfoConsoleParser clParser = MakeCorePlugin.getDefault(). + getScannerInfoConsoleParser(scBuildInfo.getMakeBuilderConsoleParserId()); + // initialize it with the utility + clParser.startup(currentProject, new ScannerInfoConsoleParserUtility( + currentProject, workingDirectory, markerGenerator)); + // create an output stream sniffer + return new ConsoleOutputStreamSniffer(outputStream, new + IScannerInfoConsoleParser[] {clParser}); + } } } catch (CoreException e) { diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCScannerConfigUtil.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCScannerConfigUtil.java index e207339b595..c9ed1d8d6d6 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCScannerConfigUtil.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCScannerConfigUtil.java @@ -49,7 +49,7 @@ public class GCCScannerConfigUtil { file.close(); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, - MakeCorePlugin.getDefault().getDescriptor().getUniqueIdentifier(), -1, + MakeCorePlugin.getUniqueIdentifier(), -1, MakeCorePlugin.getResourceString("GCCScannerConfigUtil.Error_Message"), e)); //$NON-NLS-1$ } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCScannerInfoConsoleParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCScannerInfoConsoleParser.java index 571603feb90..5013ee2f01f 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCScannerInfoConsoleParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCScannerInfoConsoleParser.java @@ -76,7 +76,8 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser { boolean rc = false; // make\[[0-9]*\]: error_desc int firstColon= line.indexOf(':'); - if (firstColon != -1 && line.startsWith("make")) { //$NON-NLS-1$ + String make = line.substring(0, firstColon + 1); + if (firstColon != -1 && make.indexOf("make") != -1) { //$NON-NLS-1$ boolean enter = false; String msg = line.substring(firstColon + 1).trim(); if ((enter = msg.startsWith("Entering directory")) || //$NON-NLS-1$ @@ -95,8 +96,8 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser { StringTokenizer scanner = new StringTokenizer(line); if (scanner.countTokens() <= 1) return false; - String token = scanner.nextToken(); - if (token.equalsIgnoreCase("gcc") || token.equalsIgnoreCase("g++")) {//$NON-NLS-1$ //$NON-NLS-2$ + String token = scanner.nextToken().toLowerCase(); + if (token.endsWith("gcc") || token.endsWith("g++")) {//$NON-NLS-1$ //$NON-NLS-2$ // Recognized gcc or g++ compiler invocation List includes = new ArrayList(); List symbols = new ArrayList(); @@ -114,8 +115,9 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser { } else if (token.startsWith("-I")) {//$NON-NLS-1$ String iPath = token.substring(2); - if (!includes.contains(iPath)) - includes.add(iPath); + String nPath = fUtil.normalizePath(iPath); + if (!includes.contains(nPath)) + includes.add(nPath); } else if (token.equals("-mwin32") || //$NON-NLS-1$ token.equals("-mno-win32") || //$NON-NLS-1$ @@ -132,7 +134,6 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser { if (possibleFileName.startsWith("..") || //$NON-NLS-1$ possibleFileName.startsWith(".") || //$NON-NLS-1$ possibleFileName.startsWith("/") || //$NON-NLS-1$ - possibleFileName.startsWith("$(") || //$NON-NLS-1$ possibleFileName.endsWith(".c") || //$NON-NLS-1$ possibleFileName.endsWith(".cpp") || //$NON-NLS-1$ possibleFileName.endsWith(".cc") || //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/ScannerConfigUtil.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/ScannerConfigUtil.java index 8b3f6e7ed83..8e3bff7a7ff 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/ScannerConfigUtil.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/ScannerConfigUtil.java @@ -10,8 +10,10 @@ **********************************************************************/ package org.eclipse.cdt.make.internal.core.scannerconfig.util; -import java.util.HashSet; +import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; @@ -22,37 +24,13 @@ import java.util.Set; */ public final class ScannerConfigUtil { /** - * Converts a map of symbols to a set - * - * @param symbolsMap - * @return - */ - public static Set scSymbolsMap2Set(Map symbolsMap) { - Set retSymbols = new HashSet(); - Set keys = symbolsMap.keySet(); - for (Iterator i = keys.iterator(); i.hasNext(); ) { - String symbol; - String key = (String) i.next(); - String value = (String) symbolsMap.get(key); - if (value == null || value.length() == 0) { - symbol = key; - } - else { - symbol = key + "=" + value; //$NON-NLS-1$ - } - retSymbols.add(symbol); - } - return retSymbols; - } - - /** * Adds all new discovered symbols/values to the existing ones. * - * @param sumSymbols - a map of [String, Set] where Set is a SymbolEntry + * @param sumSymbols - a map of [String, Map] where Map is a SymbolEntry * @param symbols * @return boolean */ - public static boolean scAddSymbolsSet2SymbolEntryMap(Map sumSymbols, Set symbols, boolean preferred) { + public static boolean scAddSymbolsList2SymbolEntryMap(Map sumSymbols, List symbols, boolean active) { boolean rc = false; for (Iterator i = symbols.iterator(); i.hasNext(); ) { String symbol = (String) i.next(); @@ -67,11 +45,12 @@ public final class ScannerConfigUtil { } SymbolEntry sEntry = (SymbolEntry) sumSymbols.get(key); if (sEntry == null) { + // make only the first one to be active sEntry = new SymbolEntry(key, value, true); rc = true; } else { - rc |= sEntry.add(value, preferred); + rc |= sEntry.add(value, active); } sumSymbols.put(key, sEntry); } @@ -79,17 +58,115 @@ public final class ScannerConfigUtil { } /** - * Gets all discovered symbols with preferred values + * Gets all discovered symbols with either active or removed values * @param sumSymbols + * @param active - false = removed * @return */ - public static Set scSymbolsSymbolEntryMap2Set(Map sumSymbols) { - Set symbols = (Set) sumSymbols.entrySet(); - Set rv = new HashSet(symbols.size()); + public static List scSymbolsSymbolEntryMap2List(Map sumSymbols, boolean active) { + Set symbols = sumSymbols.entrySet(); + List rv = new ArrayList(symbols.size()); for (Iterator i = symbols.iterator(); i.hasNext(); ) { SymbolEntry sEntry = (SymbolEntry) ((Map.Entry) i.next()).getValue(); - rv.add(sEntry.getPreferedRaw()); + if (active) { + rv.addAll(sEntry.getActiveRaw()); + } + else { + rv.addAll(sEntry.getRemovedRaw()); + } } return rv; } + + /** + * MapsSymbolEntryMap to a plain Map + * + * @param sumSymbols (in) - discovered symbols in SymbolEntryMap + * @return - active symbols as a plain Map + */ + public static Map scSymbolEntryMap2Map(Map sumSymbols) { + Map rv = new HashMap(); + for (Iterator i = sumSymbols.keySet().iterator(); i.hasNext(); ) { + String key = (String) i.next(); + SymbolEntry values = (SymbolEntry) sumSymbols.get(key); + for (Iterator j = values.getValuesOnly(true).iterator(); j.hasNext(); ) { + String value = (String) j.next(); + rv.put(key, value); // multiple active values will be condensed to one !!! + } + } + return rv; + } + + /** + * Adds a single symbol definition string ("DEBUG_LEVEL=4") to the SymbolEntryMap + * + * @param symbols + * @param symbol + * @param active + */ + public static boolean scAddSymbolString2SymbolEntryMap(Map symbols, String symbol, boolean active) { + boolean rc = false; + String key; + String value = null; + int index = symbol.indexOf("="); //$NON-NLS-1$ + if (index != -1) { + key = symbol.substring(0, index).trim(); + value = symbol.substring(index + 1).trim(); + } else { + key = symbol.trim(); + } + SymbolEntry sEntry = (SymbolEntry) symbols.get(key); + if (sEntry == null) { + // make only the first one to be active + sEntry = new SymbolEntry(key, value, active); + rc = true; + } + else { + rc |= sEntry.add(value, active); + } + symbols.put(key, sEntry); + return rc; + } + + /** + * @param result (out) + * @param addend (in) + * @return + */ + public static boolean scAddSymbolEntryMap2SymbolEntryMap(Map result, Map addend) { + boolean rc = false; + for (Iterator i = addend.keySet().iterator(); i.hasNext(); ) { + String key = (String) i.next(); + if (result.keySet().contains(key)) { + SymbolEntry rSE = (SymbolEntry) result.get(key); + SymbolEntry aSE = (SymbolEntry) addend.get(key); + List activeValues = rSE.getActiveRaw(); + for (Iterator j = aSE.getActiveRaw().iterator(); j.hasNext(); ) { + String aValue = (String) j.next(); + if (!activeValues.contains(aValue)) { + // result does not contain addend's value; add it + rSE.add(aValue, true); + rc |= true; + } + } + List removedValues = rSE.getRemovedRaw(); + for (Iterator j = aSE.getRemovedRaw().iterator(); j.hasNext(); ) { + String aValue = (String) j.next(); + if (!removedValues.contains(aValue)) { + // result does not contain addend's value; add it + rSE.add(aValue, false); + rc |= true; + } + } + } + else { + // result does not contain the symbol; add it + // shallow copy + SymbolEntry aSymbolEntry = (SymbolEntry) addend.get(key); + result.put(key, aSymbolEntry); + rc |= true; + } + } + return rc; + } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/ScannerInfoConsoleParserUtility.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/ScannerInfoConsoleParserUtility.java index cfef7a4d07a..cdd75c93b01 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/ScannerInfoConsoleParserUtility.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/ScannerInfoConsoleParserUtility.java @@ -168,7 +168,7 @@ public class ScannerInfoConsoleParserUtility implements IScannerInfoConsoleParse path = fp; } } else { - path = (IPath) getWorkingDirectory().append(filePath); + path = getWorkingDirectory().append(filePath); } IFile file = null; @@ -312,24 +312,46 @@ public class ScannerInfoConsoleParserUtility implements IScannerInfoConsoleParse // check if it is a relative path if (include.startsWith("..") || include.startsWith(".")) { //$NON-NLS-1$ //$NON-NLS-2$ // First try the current working directory - IPath pwd = getWorkingDirectory(); - if (!pwd.isAbsolute()) { - pwd = fProject.getLocation().append(pwd); + IPath cwd = getWorkingDirectory(); + if (!cwd.isAbsolute()) { + cwd = fProject.getLocation().append(cwd); } - IPath candidatePath = pwd.append(includePath); - File dir = candidatePath.makeAbsolute().toFile(); + // check if the cwd is the right one + // appending fileName to cwd should yield file path + IPath filePath = cwd.append(fileName); + if (!filePath.equals(file.getLocation())) { + // must be the cwd is wrong + // check if file name starts with ".." + if (fileName.startsWith("..")) { //$NON-NLS-1$ + // probably multiple choices for cwd, hopeless + generateMarker(file, -1, "Unable to determine working directory", + IMarkerGenerator.SEVERITY_WARNING, fileName); + break; + } + else { + // remove common segments at the end + IPath tPath = new Path(fileName); + if (fileName.startsWith(".")) { //$NON-NLS-1$ + tPath = tPath.removeFirstSegments(1); + } + // get the file path from the file + filePath = file.getLocation(); + IPath lastFileSegment = filePath.removeFirstSegments(filePath.segmentCount() - tPath.segmentCount()); + if (lastFileSegment.matchingFirstSegments(tPath) == tPath.segmentCount()) { + cwd = filePath.removeLastSegments(tPath.segmentCount()); + } + } + } + + IPath candidatePath = cwd.append(includePath); + File dir = candidatePath.toFile(); if (dir.exists()) { translatedIncludes.add(candidatePath.toString()); - break; + continue; } else { - // try to deduce a current path from the fileName format - if (file != null && fileName != null) { - // TODO VMIR implement heuristics to translate relative path when the working directory is invalid - // For now create a marker to identify prospective cases - generateMarker(file.getProject(), -1, "Ambiguous include path: "+include, //$NON-NLS-1$ - IMarkerGenerator.SEVERITY_WARNING, fileName); - } + generateMarker(file, -1, "Nonexistent include path: "+include, + IMarkerGenerator.SEVERITY_WARNING, fileName); } } } @@ -339,4 +361,47 @@ public class ScannerInfoConsoleParserUtility implements IScannerInfoConsoleParse return translatedIncludes; } + /* (non-Javadoc) + * @see org.eclipse.cdt.make.internal.core.scannerconfig.IScannerInfoConsoleParserUtility#normalizePath(java.lang.String) + */ + public String normalizePath(String path) { + if (path.indexOf('.') == -1 || path.equals(".")) { //$NON-NLS-1$ + return path; + } + // lose "./" segments since they confuse the Path normalization + StringBuffer buf = new StringBuffer(path); + int len = buf.length(); + StringBuffer newBuf = new StringBuffer(buf.length()); + int i = 0; + int sp = 0; + int sdot; + while (sp < len && (sdot = buf.indexOf(".", sp)) != -1) { //$NON-NLS-1$ + int ddot = buf.indexOf("..", sp);//$NON-NLS-1$ + if (sdot < ddot || ddot == -1) { + newBuf.append(buf.substring(i, sdot)); + i = sdot + 1; + if (i < len) { + char nextChar = buf.charAt(i); + if (nextChar == '/') { + ++i; + } + else if (nextChar == '\\') { + ++i; + if (i < len - 1 && buf.charAt(i) == '\\') { + ++i; + } + } + } + sp = i; + } + else if (sdot == ddot) { + sp = sdot + 2; + } + } + newBuf.append(buf.substring(i, len)); + + IPath orgPath = new Path(newBuf.toString()); + return orgPath.toString(); + } + } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/SymbolEntry.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/SymbolEntry.java index 116a541ebd3..fe079d9a653 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/SymbolEntry.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/SymbolEntry.java @@ -11,9 +11,11 @@ package org.eclipse.cdt.make.internal.core.scannerconfig.util; -import java.util.HashSet; +import java.util.ArrayList; import java.util.Iterator; -import java.util.Set; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; /** @@ -27,101 +29,114 @@ import java.util.Set; public class SymbolEntry { private static final String UNSPECIFIED_VALUE = "1"; //$NON-NLS-1$ private String name; - private Set values; - private String preferredValue; // the first added value unless otherwise specified + private Map values; // Values can be either in the active (selected) group or in the removed group - public SymbolEntry(String name) { - this.name = name; - } +// public SymbolEntry(String name) { +// this.name = name; +// } + public SymbolEntry(String name, String value) { - this(name); + this(name, value, true); + } + public SymbolEntry(String name, String value, boolean active) { + this.name = name; if (values == null) { - values = new HashSet(); + values = new LinkedHashMap(); } - values.add(value); + values.put(value, Boolean.valueOf(active)); } - public SymbolEntry(String name, String value, boolean preferred) { - this(name, value); - if (preferred) { - preferredValue = value; + public SymbolEntry(SymbolEntry se) { + name = se.name; + // deep copy + values = new LinkedHashMap(se.values.size()); + for (Iterator i = se.values.keySet().iterator(); i.hasNext(); ) { + String key = (String) i.next(); + Boolean value = (Boolean) se.values.get(key); + values.put(key, Boolean.valueOf(value.booleanValue())); } } public boolean add(String value) { - if (values == null) { - values = new HashSet(); - } - if (preferredValue == null) { - preferredValue = value; - } - return values.add(value); + return add(value, true); } - public boolean add(String value, boolean preferred) { - boolean rc = add(value); - if (preferred) { - preferredValue = value; + public boolean add(String value, boolean active) { + boolean rc = false; + if (!values.containsKey(value)) { + values.put(value, Boolean.valueOf(active)); + rc = true; } return rc; } - public boolean addAll(SymbolEntry se) { - return values.addAll(se.values); + public void replace(String value, boolean active) { + values.put(value, Boolean.valueOf(active)); + } + private void addAll(SymbolEntry se) { + values.putAll(se.values); } + public void remove(String value) { + values.remove(value); + } public void removeAll() { values = null; - preferredValue = null; } - public String getPrefered() { - return name+ "=" + (preferredValue == null ? UNSPECIFIED_VALUE : preferredValue);//$NON-NLS-1$ + public List getActive() { + return get(true, true, true); } - public String getPreferedRaw() { - return name + (preferredValue == null ? "" : "=" + preferredValue);//$NON-NLS-1$ //$NON-NLS-2$ + public List getActiveRaw() { + return get(false, true, true); } - public Set getAllButPreferred() { - if (values == null) - return null; - Set rv = new HashSet(values.size()); - for (Iterator i = values.iterator(); i.hasNext(); ) { - String val = (String) i.next(); - if (val.equals(preferredValue)) - continue; - rv.add(name + "=" + (val == null ? UNSPECIFIED_VALUE : val));//$NON-NLS-1$ - } - return rv; + public List getRemoved() { + return get(true, true, false); } - public Set getAllButPreferredRaw() { - if (values == null) - return null; - Set rv = new HashSet(values.size()); - for (Iterator i = values.iterator(); i.hasNext(); ) { - String val = (String) i.next(); - if (val.equals(preferredValue)) - continue; - rv.add(name + (val == null ? "" : "=" + val));//$NON-NLS-1$ //$NON-NLS-2$ - } - return rv; + public List getRemovedRaw() { + return get(false, true, false); } - public Set getAll() { - if (values == null) - return null; - Set rv = new HashSet(values.size()); - for (Iterator i = values.iterator(); i.hasNext(); ) { + + public List getAll() { + return get(true, false, true /*don't care*/); + } + public List getAllRaw() { + return get(false, false, true /*don't care*/); + } + + /** + * Utility function to retrieve values as a set. + * + * @param format - false = raw + * @param subset - false = all + * @param active - false = removed + * @return List + */ + private List get(boolean format, boolean subset, boolean active) { + List rv = new ArrayList(values.size()); + for (Iterator i = values.keySet().iterator(); i.hasNext(); ) { String val = (String) i.next(); - rv.add(name + "=" + (val == null ? UNSPECIFIED_VALUE : val));//$NON-NLS-1$ + if (subset && ((Boolean) values.get(val)).booleanValue() != active) + continue; + if (format) { + rv.add(name + "=" + (val == null ? UNSPECIFIED_VALUE : val));//$NON-NLS-1$ + } + else { + rv.add(name + (val == null ? "" : "=" + val));//$NON-NLS-1$ //$NON-NLS-2$ + } } return rv; } - public Set getAllRaw() { - if (values == null) - return null; - Set rv = new HashSet(values.size()); - for (Iterator i = values.iterator(); i.hasNext(); ) { + /** + * Returns only value part of all active entries + * @return List + */ + public List getValuesOnly(boolean active) { + List rv = new ArrayList(values.size()); + for (Iterator i = values.keySet().iterator(); i.hasNext(); ) { String val = (String) i.next(); - rv.add(name + (val == null ? "" : "=" + val));//$NON-NLS-1$ //$NON-NLS-2$ + if (((Boolean) values.get(val)).booleanValue() == active) { + rv.add(val == null ? UNSPECIFIED_VALUE : val); + } } return rv; } - -}
\ No newline at end of file +} diff --git a/build/org.eclipse.cdt.make.ui/plugin.properties b/build/org.eclipse.cdt.make.ui/plugin.properties index 50331a4ce30..81e1cbce176 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.properties +++ b/build/org.eclipse.cdt.make.ui/plugin.properties @@ -23,10 +23,8 @@ CommandTargetCreate.description=Create a new make build target for the selected PreferenceMakeProject.name=New Make Projects PreferenceMakeTargets.name=Make Targets -PreferenceScannerConfig.name=Scanner Configuration Discovery PropertyMakeProject.name= C/C++ Make Project -PropertyScannerConfig.name=Scanner Configuration Discovery ViewCatagoryMake.name=Make ViewMake.name=Make Targets @@ -45,4 +43,3 @@ ActionDefinition.uncomment.name= Uncomment ActionDefinition.uncomment.description= Uncomment the selected # style comment lines MakefileEditor.name=Makefile Editor - diff --git a/build/org.eclipse.cdt.make.ui/plugin.xml b/build/org.eclipse.cdt.make.ui/plugin.xml index 256663ae375..3b3896fef08 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.xml +++ b/build/org.eclipse.cdt.make.ui/plugin.xml @@ -26,6 +26,7 @@ <import plugin="org.eclipse.core.runtime.compatibility"/> </requires> + <extension point="org.eclipse.ui.newWizards"> <wizard @@ -277,12 +278,6 @@ id="org.eclipse.cdt.make.ui.preferences.MakePreferencePage"> </page> <page - name="%PreferenceScannerConfig.name" - category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage" - class="org.eclipse.cdt.make.internal.ui.preferences.ScannerConfigPreferencePage" - id="org.eclipse.cdt.make.ui.preferences.ScannerConfigPreferencePage"> - </page> - <page name="%PreferenceMakeTargets.name" category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage" class="org.eclipse.cdt.make.internal.ui.preferences.MakeTargetsPreferencePage" @@ -302,18 +297,6 @@ value="org.eclipse.cdt.make.core.makeNature"> </filter> </page> - <page - adaptable="true" - objectClass="org.eclipse.core.resources.IProject" - name="%PropertyScannerConfig.name" - class="org.eclipse.cdt.make.internal.ui.properties.ScannerConfigPropertyPage" - id="org.eclipse.cdt.make.ui.properties.ScannerConfigPropertyPage"> - <filter - name="nature" - value="org.eclipse.cdt.make.core.makeNature"> - </filter> - </page> - </extension> <extension point="org.eclipse.ui.views"> @@ -345,13 +328,13 @@ <and> <not> <objectState - name="projectNature" - value="org.eclipse.cdt.make.core.makeNature"> + value="org.eclipse.cdt.make.core.makeNature" + name="projectNature"> </objectState> </not> <objectState - name="projectNature" - value="org.eclipse.cdt.core.cnature"> + value="org.eclipse.cdt.core.cnature" + name="projectNature"> </objectState> </and> </enablement> @@ -404,7 +387,6 @@ </action> </actionSet> </extension> - <extension id="org.eclipse.cdt.make.editor" name="MakefileEditor" @@ -418,7 +400,6 @@ id="org.eclipse.cdt.make.editor"> </editor> </extension> - <extension point="org.eclipse.ui.startup"> <startup @@ -443,4 +424,5 @@ </actionSet> </perspectiveExtension> </extension> + </plugin> 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 ba25cbff428..491b2d24bb1 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 @@ -63,6 +63,9 @@ BuildPathInfoBlock.browse.path.label=Path: BuildPathInfoBlock.browse.symbol=New Defined Symbol BuildPathInfoBlock.browse.symbol.edit=Edit Defined Symbol BuildPathInfoBlock.browse.symbol.label=Symbol: +BuildPathInfoBlock.scGroup.label=Automated discovery of paths and symbols +BuildPathInfoBlock.scGroup.enabled.label=Automate discovery of paths and symbols +BuildPathInfoBlock.scGroup.options.label=Options... BuildPropertyCommon.label.title=Enter Value BuildPropertyCommon.label.new=New... @@ -75,6 +78,7 @@ BuildPropertyCommon.label.addVar=Add BuildPropertyCommon.label.message=Value: BuildPropertyCommon.label.browse=Browse... BuildPropertyCommon.label.configs=Defined configurations: +BuildPropertyCommon.label.manage=Manage... MakeTargetsPreferencePage.buildTargetInBackground.label=Build make targets in background. @@ -195,18 +199,32 @@ LexicalSortingAction.tooltip=Sort LexicalSortingAction.tooltip.on=Do Not Sort LexicalSortingAction.tooltip.off=Sort -# --- ScannerConfigPage --- -ScannerConfigPage.label=Scanner Config -ScannerConfigPage.desc=Scanner configuration discovery settings -ScannerConfigPage.activate=Automate scanner configuration discovery - -ScannerConfigPage.siBuilder.parser.group_label=Build output parser options -ScannerConfigPage.siBuilder.parser.enable.label=Enable build output parser -ScannerConfigPage.siBuilder.parser.label=Make build output parser: -ScannerConfigPage.siProvider.cmd.group_label=Generate scanner info command options -ScannerConfigPage.siProvider.cmd.enable.label=Enable generate scanner info command -ScannerConfigPage.siProvider.cmd.use_default=Use default -ScannerConfigPage.siProvider.cmd.label=Generate scanner info command: -ScannerConfigPage.siProvider.parser.label=Command output parser: - -ScannerConfigPage.siProvider.cmd.error_message=Must enter a 'generate scanner info' command +# --- ManageIncludePathsDialog dialog --- +ManageIncludePathsDialog.title=Manage include paths +ManageIncludePathsDialog.userGroup.title=User specified include paths +ManageIncludePathsDialog.discoveredGroup.title=Discovered include paths + +ManageScannerConfigDialogCommon.discoveredGroup.selected.label=Selected: +ManageScannerConfigDialogCommon.discoveredGroup.removed.label=Removed: +ManageScannerConfigDialogCommon.discoveredGroup.buttons.remove.label=Remove +ManageScannerConfigDialogCommon.discoveredGroup.buttons.restore.label=Restore +ManageScannerConfigDialogCommon.discoveredGroup.buttons.delete.label=Delete +ManageScannerConfigDialogCommon.discoveredGroup.buttons.deleteAll.label=Delete all + +# --- ManageDefinedSymbolsDialog dialog --- +ManageDefinedSymbolsDialog.title=Manage defined symbols +ManageDefinedSymbolsDialog.userGroup.title=User specified symbol definitions +ManageDefinedSymbolsDialog.discoveredGroup.title=Discovered symbol definitions + +# --- ScannerConfigOptionsDialog --- +ScannerConfigOptionsDialog.title=Scanner configuration discovery options +ScannerConfigOptionsDialog.siBuilder.parser.group_label=Build output parser options +ScannerConfigOptionsDialog.siBuilder.parser.enable.label=Enable build output parser +ScannerConfigOptionsDialog.siBuilder.parser.label=Make build output parser: +ScannerConfigOptionsDialog.label.missingBuilderInformation=Missing builder information on project. +ScannerConfigOptionsDialog.siProvider.cmd.group_label=Generate scanner info command options +ScannerConfigOptionsDialog.siProvider.cmd.enable.label=Enable generate scanner info command +ScannerConfigOptionsDialog.siProvider.cmd.use_default=Use default +ScannerConfigOptionsDialog.siProvider.cmd.label=Generate scanner info command: +ScannerConfigOptionsDialog.siProvider.parser.label=Command output parser: +ScannerConfigOptionsDialog.siProvider.cmd.error_message=Must enter a 'generate scanner info' command diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIPlugin.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIPlugin.java index cc5a62a91ef..d5abbccfe5d 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIPlugin.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIPlugin.java @@ -210,7 +210,7 @@ public class MakeUIPlugin extends AbstractUIPlugin { ErrorDialog.openError(shell, title, message, status); } - protected Shell getShell() { + public Shell getShell() { if (getActiveWorkbenchShell() != null) { return getActiveWorkbenchShell(); } else { diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/ScannerConfigPreferencePage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/ScannerConfigPreferencePage.java deleted file mode 100644 index d13cf2a83a5..00000000000 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/ScannerConfigPreferencePage.java +++ /dev/null @@ -1,100 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - **********************************************************************/ -package org.eclipse.cdt.make.internal.ui.preferences; - -import org.eclipse.ui.IWorkbench; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.cdt.ui.dialogs.ICOptionContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.cdt.make.core.MakeCorePlugin; -import org.eclipse.cdt.make.ui.dialogs.ScannerConfigPage; - -/** - * Scanner config preference page - * @author vhirsl - */ -public class ScannerConfigPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, ICOptionContainer { - - private ScannerConfigPage fScannerConfigPage; - - public ScannerConfigPreferencePage() { - super(); - } - - /** - * @see PreferencePage#init - */ - public void init(IWorkbench workbench) { - } - - /** - * @see PreferencePage#createContents - */ - protected Control createContents(Composite parent) { - fScannerConfigPage = new ScannerConfigPage(true); // add title - // must set container before call to createControl - fScannerConfigPage.setContainer(this); - - fScannerConfigPage.createControl(parent); - return fScannerConfigPage.getControl(); - } - - protected void performDefaults() { - fScannerConfigPage.performDefaults(); - super.performDefaults(); - } - - public boolean performOk() { - try { - fScannerConfigPage.performApply(null); - MakeCorePlugin.getDefault().savePluginPreferences(); - return true; - } - catch (CoreException e) { - return false; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.dialogs.ICOptionContainer#updateContainer() - */ - public void updateContainer() { - setValid(fScannerConfigPage.isValid()); - setErrorMessage(fScannerConfigPage.getErrorMessage()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.dialogs.ICOptionContainer#getProject() - */ - public IProject getProject() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.dialogs.ICOptionContainer#getPreferences() - */ - public Preferences getPreferences() { - return MakeCorePlugin.getDefault().getPluginPreferences(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.IPreferencePage#isValid() - */ - public boolean isValid() { - updateContainer(); - return super.isValid(); - } -} diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/properties/ScannerConfigPropertyPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/properties/ScannerConfigPropertyPage.java deleted file mode 100644 index 7775ed0469c..00000000000 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/properties/ScannerConfigPropertyPage.java +++ /dev/null @@ -1,91 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - **********************************************************************/ -package org.eclipse.cdt.make.internal.ui.properties; - -import org.eclipse.cdt.ui.dialogs.ICOptionContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.dialogs.PropertyPage; -import org.eclipse.cdt.make.core.MakeCorePlugin; -import org.eclipse.cdt.make.ui.dialogs.ScannerConfigPage; - -/** - * Scanner config property page - * @author vhirsl - */ -public class ScannerConfigPropertyPage extends PropertyPage implements ICOptionContainer { - - private ScannerConfigPage fScannerConfigPage; - - public ScannerConfigPropertyPage() { - super(); - } - - /** - * @see PreferencePage#createContents(Composite) - */ - protected Control createContents(Composite parent) { - fScannerConfigPage = new ScannerConfigPage(true); // add title - // must set container before call to createControl - fScannerConfigPage.setContainer(this); - - fScannerConfigPage.createControl(parent); - return fScannerConfigPage.getControl(); - } - - protected void performDefaults() { - fScannerConfigPage.performDefaults(); - super.performDefaults(); - } - - public boolean performOk() { - try { - fScannerConfigPage.performApply(null); - return true; - } - catch (CoreException e) { - return false; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.dialogs.ICOptionContainer#updateContainer() - */ - public void updateContainer() { - setValid(fScannerConfigPage.isValid()); - setErrorMessage(fScannerConfigPage.getErrorMessage()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.dialogs.ICOptionContainer#getProject() - */ - public IProject getProject() { - return (IProject) getElement(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.dialogs.ICOptionContainer#getPreferences() - */ - public Preferences getPreferences() { - return MakeCorePlugin.getDefault().getPluginPreferences(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.IPreferencePage#isValid() - */ - public boolean isValid() { - updateContainer(); - return super.isValid(); - } -} diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/BuildPathInfoBlock.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/BuildPathInfoBlock.java index c84333f0e2d..4b560e75cb3 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/BuildPathInfoBlock.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/BuildPathInfoBlock.java @@ -14,14 +14,19 @@ package org.eclipse.cdt.make.ui.dialogs; import java.util.ArrayList; import java.util.StringTokenizer; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.internal.ui.util.SWTUtil; import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.MakeProjectNature; import org.eclipse.cdt.make.core.MakeScannerInfo; -import org.eclipse.cdt.make.core.MakeScannerProvider; +import org.eclipse.cdt.make.core.scannerconfig.DiscoveredScannerInfo; +import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.cdt.make.ui.IMakeHelpContextIds; import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage; import org.eclipse.cdt.utils.ui.controls.ControlFactory; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; @@ -30,24 +35,24 @@ import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.help.WorkbenchHelp; public class BuildPathInfoBlock extends AbstractCOptionPage { - private static final int PROJECT_LIST_MULTIPLIER = 10; + private static final int PROJECT_LIST_MULTIPLIER = 15; private static final String PREF_SYMBOLS = "ScannerSymbols"; //$NON-NLS-1$ private static final String PREF_INCLUDES = "ScannerIncludes"; //$NON-NLS-1$ @@ -55,39 +60,31 @@ public class BuildPathInfoBlock extends AbstractCOptionPage { private static final String LABEL = PREFIX + ".label"; //$NON-NLS-1$ private static final String PATHS = PREFIX + ".paths"; //$NON-NLS-1$ private static final String SYMBOLS = PREFIX + ".symbols"; //$NON-NLS-1$ - private static final String BROWSE = PREFIX + ".browse"; //$NON-NLS-1$ - private static final String PATH_TITLE = BROWSE + ".path"; //$NON-NLS-1$ - private static final String EDIT_PATH_TITLE = BROWSE + ".path.edit"; //$NON-NLS-1$ - private static final String PATH_LABEL = BROWSE + ".path.label"; //$NON-NLS-1$ - private static final String SYMBOL_TITLE = BROWSE + ".symbol"; //$NON-NLS-1$ - private static final String EDIT_SYMBOL_TITLE = BROWSE + ".symbol.edit"; //$NON-NLS-1$ - private static final String SYMBOL_LABEL = BROWSE + ".symbol.label"; //$NON-NLS-1$ - private static final String NEW = "BuildPropertyCommon.label.new"; //$NON-NLS-1$ - private static final String EDIT = "BuildPropertyCommon.label.edit"; //$NON-NLS-1$ - private static final String REMOVE = "BuildPropertyCommon.label.remove"; //$NON-NLS-1$ - private static final String UP = "BuildPropertyCommon.label.up"; //$NON-NLS-1$ - private static final String DOWN = "BuildPropertyCommon.label.down"; //$NON-NLS-1$ - + private static final String MANAGE = "BuildPropertyCommon.label.manage"; //$NON-NLS-1$ + private static final String SC_GROUP_LABEL = PREFIX + ".scGroup.label"; //$NON-NLS-1$ + private static final String SC_ENABLED_LABEL = PREFIX + ".scGroup.enabled.label"; //$NON-NLS-1$ + private static final String SC_OPTIONS_LABEL = PREFIX + ".scGroup.options.label"; //$NON-NLS-1$ + private static final String MISSING_BUILDER_MSG = "ScannerConfigOptionsDialog.label.missingBuilderInformation"; //$NON-NLS-1$ + + private Button scEnabledButton; + private Button scOptionsButton; private List pathList; private List symbolList; private Composite pathButtonComp; - private Button addPath; - private Button editPath; - private Button removePath; - private Button pathUp; - private Button pathDown; + private Button managePathsButton; private Composite symbolButtonComp; - private Button addSymbol; - private Button editSymbol; - private Button removeSymbol; - private Button symbolUp; - private Button symbolDown; - private Shell shell; + private Button manageSymbolsButton; + + private ScannerConfigOptionsDialog scOptionsDialog; + private ManageIncludePathsDialog manageIncludesDialog; + private ManageDefinedSymbolsDialog manageSymbolsDialog; + + private boolean needsSCNature = false; /** * This class add a "browse" button to the selection to be used for the path */ - class SelectPathInputDialog extends InputDialog { + static class SelectPathInputDialog extends InputDialog { public SelectPathInputDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, IInputValidator validator) { super(parentShell, dialogTitle, dialogMessage, initialValue, validator); } @@ -118,78 +115,39 @@ public class BuildPathInfoBlock extends AbstractCOptionPage { } private void createPathListButtons(Composite parent) { + // Create a ManageIncludePathsDialog + if (manageIncludesDialog == null) { + manageIncludesDialog = new ManageIncludePathsDialog(getShell(), getContainer()); + } + // Create a composite for the buttons pathButtonComp = ControlFactory.createComposite(parent, 1); + ((GridData) pathButtonComp.getLayoutData()).verticalAlignment = GridData.BEGINNING; + ((GridData) pathButtonComp.getLayoutData()).grabExcessHorizontalSpace = false; pathButtonComp.setFont(parent.getFont()); // Add the buttons - addPath = ControlFactory.createPushButton(pathButtonComp, MakeUIPlugin.getResourceString(NEW)); - addPath.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - handleAddPath(); - } - }); - addPath.setEnabled(true); - addPath.setFont(parent.getFont()); - addPath.setLayoutData(new GridData()); - SWTUtil.setButtonDimensionHint(addPath); - - editPath = ControlFactory.createPushButton(pathButtonComp, MakeUIPlugin.getResourceString(EDIT)); - editPath.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - editPathListItem(); - } - }); - editPath.setEnabled(true); - editPath.setFont(parent.getFont()); - editPath.setLayoutData(new GridData()); - SWTUtil.setButtonDimensionHint(editPath); - - removePath = ControlFactory.createPushButton(pathButtonComp, MakeUIPlugin.getResourceString(REMOVE)); - removePath.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - handleRemovePath(); - } - }); - removePath.setFont(parent.getFont()); - removePath.setLayoutData(new GridData()); - SWTUtil.setButtonDimensionHint(removePath); - - pathUp = ControlFactory.createPushButton(pathButtonComp, MakeUIPlugin.getResourceString(UP)); - pathUp.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - handlePathUp(); - } - }); - pathUp.setFont(parent.getFont()); - pathUp.setLayoutData(new GridData()); - SWTUtil.setButtonDimensionHint(pathUp); - - pathDown = ControlFactory.createPushButton(pathButtonComp, MakeUIPlugin.getResourceString(DOWN)); - pathDown.addSelectionListener(new SelectionAdapter() { + managePathsButton = ControlFactory.createPushButton(pathButtonComp, MakeUIPlugin.getResourceString(MANAGE)); + managePathsButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - handlePathDown(); + handleManagePaths(); } }); - pathDown.setFont(parent.getFont()); - pathDown.setLayoutData(new GridData()); - SWTUtil.setButtonDimensionHint(pathDown); + managePathsButton.setFont(parent.getFont()); + managePathsButton.setLayoutData(new GridData()); + SWTUtil.setButtonDimensionHint(managePathsButton); + return; + } + protected void handleManagePaths() { + if (manageIncludesDialog.open() == Window.OK) { + pathList.setItems(manageIncludesDialog.getManagedIncludes()); + } } private void createPathListControl(Composite parent, int numColumns) { // Create the list pathList = new List(parent, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); - pathList.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - enablePathButtons(); - } - }); - pathList.addMouseListener(new MouseAdapter() { - public void mouseDoubleClick(MouseEvent e) { - editPathListItem(); - } - }); // Make it occupy the first 2 columns GridData gd = new GridData(GridData.FILL_BOTH); @@ -198,7 +156,6 @@ public class BuildPathInfoBlock extends AbstractCOptionPage { gd.heightHint = getDefaultFontHeight(pathList, PROJECT_LIST_MULTIPLIER); pathList.setLayoutData(gd); pathList.setFont(parent.getFont()); - } /** @@ -218,77 +175,39 @@ public class BuildPathInfoBlock extends AbstractCOptionPage { } private void createSymbolListButtons(Composite parent) { + // Create a ManageDefinedSymbolsDialog + if (manageSymbolsDialog == null) { + manageSymbolsDialog = new ManageDefinedSymbolsDialog(getShell(), getContainer()); + } + // Create a composite for the buttons symbolButtonComp = ControlFactory.createComposite(parent, 1); + ((GridData) symbolButtonComp.getLayoutData()).verticalAlignment = GridData.BEGINNING; + ((GridData) symbolButtonComp.getLayoutData()).grabExcessHorizontalSpace = false; symbolButtonComp.setFont(parent.getFont()); - // Add the buttons - addSymbol = ControlFactory.createPushButton(symbolButtonComp, MakeUIPlugin.getResourceString(NEW)); - addSymbol.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - handleAddSymbol(); - } - }); - addSymbol.setEnabled(true); - addSymbol.setFont(parent.getFont()); - addSymbol.setLayoutData(new GridData()); - SWTUtil.setButtonDimensionHint(addSymbol); - - editSymbol = ControlFactory.createPushButton(symbolButtonComp, MakeUIPlugin.getResourceString(EDIT)); - editSymbol.addSelectionListener(new SelectionAdapter() { + // Add the Manage button + manageSymbolsButton = ControlFactory.createPushButton(symbolButtonComp, MakeUIPlugin.getResourceString(MANAGE)); + manageSymbolsButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - editSymbolListItem(); + handleManageSymbols(); } }); - editSymbol.setEnabled(true); - editSymbol.setFont(parent.getFont()); - editSymbol.setLayoutData(new GridData()); - SWTUtil.setButtonDimensionHint(editSymbol); - - removeSymbol = ControlFactory.createPushButton(symbolButtonComp, MakeUIPlugin.getResourceString(REMOVE)); - removeSymbol.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - handleRemoveSymbol(); - } - }); - removeSymbol.setFont(parent.getFont()); - removeSymbol.setLayoutData(new GridData()); - SWTUtil.setButtonDimensionHint(removeSymbol); - - symbolUp = ControlFactory.createPushButton(symbolButtonComp, MakeUIPlugin.getResourceString(UP)); - symbolUp.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - handleSymbolUp(); - } - }); - symbolUp.setFont(parent.getFont()); - symbolUp.setLayoutData(new GridData()); - SWTUtil.setButtonDimensionHint(symbolUp); + manageSymbolsButton.setFont(parent.getFont()); + manageSymbolsButton.setLayoutData(new GridData()); + SWTUtil.setButtonDimensionHint(manageSymbolsButton); + return; + } - symbolDown = ControlFactory.createPushButton(symbolButtonComp, MakeUIPlugin.getResourceString(DOWN)); - symbolDown.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - handleSymbolDown(); - } - }); - symbolDown.setFont(parent.getFont()); - symbolDown.setLayoutData(new GridData()); - SWTUtil.setButtonDimensionHint(symbolDown); + protected void handleManageSymbols() { + if (manageSymbolsDialog.open() == Window.OK) { + symbolList.setItems(manageSymbolsDialog.getManagedSymbols()); + } } private void createSymbolListControl(Composite parent, int numColumns) { // Create the list symbolList = new List(parent, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); - symbolList.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - enableSymbolButtons(); - } - }); - symbolList.addMouseListener(new MouseAdapter() { - public void mouseDoubleClick(MouseEvent e) { - editSymbolListItem(); - } - }); // Make it occupy the first n-1 columns GridData gd = new GridData(GridData.FILL_BOTH); @@ -307,16 +226,34 @@ public class BuildPathInfoBlock extends AbstractCOptionPage { if (monitor == null) { monitor = new NullProgressMonitor(); } - if (getContainer().getProject() != null) { + // First store scanner config options + if (scOptionsDialog.isInitialized()) { + scOptionsDialog.performApply(monitor); + } + + IProject project = getContainer().getProject(); + if (project != null) { // Store the paths and symbols monitor.beginTask(MakeUIPlugin.getResourceString("BuildPathInfoBlock.monitor.settingScannerInfo"), 3); //$NON-NLS-1$ - MakeScannerInfo info = MakeScannerProvider.getDefault().getMakeScannerInfo(getContainer().getProject(), false); - info.setIncludePaths(getPathListContents()); - monitor.worked(1); - info.setPreprocessorSymbols(getSymbolListContents()); - monitor.worked(1); - info.update(); - monitor.done(); + IScannerInfo info = CCorePlugin.getDefault().getScannerInfoProvider(project).getScannerInformation(project); + if (info instanceof MakeScannerInfo) { + MakeScannerInfo mInfo = (MakeScannerInfo) info; + mInfo.setIncludePaths(getPathListContents()); + monitor.worked(1); + mInfo.setPreprocessorSymbols(getSymbolListContents()); + monitor.worked(1); + mInfo.update(); + monitor.done(); + } + else if (info instanceof DiscoveredScannerInfo) { + DiscoveredScannerInfo dInfo = (DiscoveredScannerInfo) info; + manageIncludesDialog.saveTo(dInfo); + monitor.worked(1); + manageSymbolsDialog.saveTo(dInfo); + monitor.worked(1); + dInfo.update(); + monitor.done(); + } } else { setIncludes(MakeCorePlugin.getDefault().getPluginPreferences()); setSymbols(MakeCorePlugin.getDefault().getPluginPreferences()); @@ -324,12 +261,19 @@ public class BuildPathInfoBlock extends AbstractCOptionPage { } public void performDefaults() { + // First restore scanner config options + scOptionsDialog.performDefaults(); + scEnabledButton.setSelection(scOptionsDialog.isScannerConfigDiscoveryEnabled()); + handleScannerConfigEnable(); + pathList.removeAll(); symbolList.removeAll(); if (getContainer().getProject() != null) { pathList.setItems(getIncludes(MakeCorePlugin.getDefault().getPluginPreferences())); symbolList.setItems(getSymbols(MakeCorePlugin.getDefault().getPluginPreferences())); } + manageIncludesDialog.restore(); + manageSymbolsDialog.restore(); getContainer().updateContainer(); } @@ -349,17 +293,17 @@ public class BuildPathInfoBlock extends AbstractCOptionPage { return buf.toString(); } - private String[] getSymbols(Preferences prefs) { + static String[] getSymbols(Preferences prefs) { String syms = prefs.getString(PREF_SYMBOLS); return parseStringToList(syms); } - private String[] getIncludes(Preferences prefs) { + static String[] getIncludes(Preferences prefs) { String syms = prefs.getString(PREF_INCLUDES); return parseStringToList(syms); } - private String[] parseStringToList(String syms) { + private static String[] parseStringToList(String syms) { if (syms != null && syms.length() > 0) { StringTokenizer tok = new StringTokenizer(syms, ";"); //$NON-NLS-1$ ArrayList list = new ArrayList(tok.countTokens()); @@ -371,99 +315,6 @@ public class BuildPathInfoBlock extends AbstractCOptionPage { return new String[0]; } - /* - * Double-click handler to allow edit of path information - */ - protected void editPathListItem() { - // Edit the selection index - int index = pathList.getSelectionIndex(); - if (index != -1) { - String selItem = pathList.getItem(index); - if (selItem != null) { - InputDialog dialog = - new SelectPathInputDialog( - shell, - MakeUIPlugin.getResourceString(EDIT_PATH_TITLE), - MakeUIPlugin.getResourceString(PATH_LABEL), - selItem, - null); - String newItem = null; - if (dialog.open() == Window.OK) { - newItem = dialog.getValue(); - if (newItem != null && !newItem.equals(selItem)) { - pathList.setItem(index, newItem); - } - } - } - } - } - - /* - * Double-click handler to allow edit of symbol information - */ - protected void editSymbolListItem() { - // Edit the selection index - int index = symbolList.getSelectionIndex(); - if (index != -1) { - String selItem = symbolList.getItem(index); - if (selItem != null) { - InputDialog dialog = - new InputDialog( - shell, - MakeUIPlugin.getResourceString(EDIT_SYMBOL_TITLE), - MakeUIPlugin.getResourceString(SYMBOL_LABEL), - selItem, - null); - String newItem = null; - if (dialog.open() == Window.OK) { - newItem = dialog.getValue(); - if (newItem != null && !newItem.equals(selItem)) { - symbolList.setItem(index, newItem); - } - } - } - } - } - - /* - * Enables the buttons on the path control if the right conditions are met - */ - void enablePathButtons() { - // Enable the remove button if there is at least 1 item in the list - int items = pathList.getItemCount(); - if (items > 0) { - editPath.setEnabled(true); - removePath.setEnabled(true); - // Enable the up/down buttons depending on what item is selected - int index = pathList.getSelectionIndex(); - pathUp.setEnabled(items > 1 && index > 0); - pathDown.setEnabled(items > 1 && index < (items - 1)); - } else { - editPath.setEnabled(false); - removePath.setEnabled(false); - pathUp.setEnabled(false); - pathDown.setEnabled(false); - } - } - - void enableSymbolButtons() { - // Enable the remove button if there is at least 1 item in the list - int items = symbolList.getItemCount(); - if (items > 0) { - editSymbol.setEnabled(true); - removeSymbol.setEnabled(true); - // Enable the up/down buttons depending on what item is selected - int index = symbolList.getSelectionIndex(); - symbolUp.setEnabled(items > 1 && index > 0); - symbolDown.setEnabled(items > 1 && index < (items - 1)); - } else { - editSymbol.setEnabled(false); - removeSymbol.setEnabled(false); - symbolUp.setEnabled(false); - symbolDown.setEnabled(false); - } - } - /* (non-Javadoc) * @see org.eclipse.cdt.ui.wizards.IWizardTab#getControl(org.eclipse.swt.widgets.Composite) */ @@ -472,181 +323,137 @@ public class BuildPathInfoBlock extends AbstractCOptionPage { int tabColumns = 3; Font font = parent.getFont(); Composite composite = ControlFactory.createComposite(parent, tabColumns); + ((GridLayout) composite.getLayout()).makeColumnsEqualWidth = false; composite.setFont(font); GridData gd; setControl(composite); WorkbenchHelp.setHelp(getControl(), IMakeHelpContextIds.MAKE_PATH_SYMBOL_SETTINGS); + // Create a group for scanner config discovery + createScannerConfigControls(composite, tabColumns); + // Create a label for the include paths control Label paths = ControlFactory.createLabel(composite, MakeUIPlugin.getResourceString(PATHS)); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = tabColumns; + gd.grabExcessHorizontalSpace = false; paths.setLayoutData(gd); paths.setFont(font); //Create the list and button controls createPathListControl(composite, tabColumns); createPathListButtons(composite); - enablePathButtons(); // Create a label for the symbols control Label symbols = ControlFactory.createLabel(composite, MakeUIPlugin.getResourceString(SYMBOLS)); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = tabColumns; + gd.grabExcessHorizontalSpace = false; symbols.setLayoutData(gd); symbols.setFont(font); // Create list and button controls for symbols createSymbolListControl(composite, tabColumns); createSymbolListButtons(composite); - enableSymbolButtons(); setListContents(); - pathList.select(0); - enablePathButtons(); - symbolList.select(0); - enableSymbolButtons(); - } - - private String[] getPathListContents() { - return pathList.getItems(); - } - - private String[] getSymbolListContents() { - return symbolList.getItems(); - } - - protected void handleAddPath() { - // Popup an entry dialog - InputDialog dialog = new SelectPathInputDialog(shell, MakeUIPlugin.getResourceString(PATH_TITLE), MakeUIPlugin.getResourceString(PATH_LABEL), "", null); //$NON-NLS-1$ - String path = null; - if (dialog.open() == Window.OK) { - path = dialog.getValue(); - } - if (path != null && path.length() > 0) { - pathList.add(path); - pathList.select(pathList.getItemCount() - 1); - enablePathButtons(); - } - } - - protected void handleAddSymbol() { - // Popup an entry dialog - InputDialog dialog = new InputDialog(shell, MakeUIPlugin.getResourceString(SYMBOL_TITLE), MakeUIPlugin.getResourceString(SYMBOL_LABEL), "", null); //$NON-NLS-1$ - String symbol = null; - if (dialog.open() == Window.OK) { - symbol = dialog.getValue(); - } - if (symbol != null && symbol.length() > 0) { - symbolList.add(symbol); - symbolList.select(symbolList.getItemCount() - 1); - enableSymbolButtons(); - } } - protected void handlePathDown() { - // Get the selection index - int index = pathList.getSelectionIndex(); - int items = pathList.getItemCount(); - if (index == -1 || index == items - 1) { - return; - } - // Swap the items in the list - String selItem = pathList.getItem(index); - pathList.remove(index); - if (index + 1 == items) { - pathList.add(selItem); - } else { - pathList.add(selItem, ++index); + /** + * @param composite + */ + private void createScannerConfigControls(Composite parent, int numColumns) { + // Check if it is an old project + IProject project = getContainer().getProject(); + boolean showMissingBuilder = false; + try { + if (project != null && + project.hasNature(MakeProjectNature.NATURE_ID) && + !project.hasNature(ScannerConfigNature.NATURE_ID)) { + needsSCNature = true; // an old project + } + } + catch (CoreException e) { + showMissingBuilder = true; } - - // Keep the swapped item selected - pathList.select(index); - enablePathButtons(); - } - - protected void handlePathUp() { - // Get the selection index - int index = pathList.getSelectionIndex(); - if (index == -1 || index == 0) { - return; + + // Create a ScannerConfigOptionsDialog + if (scOptionsDialog == null) { + if (needsSCNature) { + // create a temporary dialog + scOptionsDialog = new ScannerConfigOptionsDialog(getContainer()); + } + else { + scOptionsDialog = new ScannerConfigOptionsDialog(getShell(), getContainer()); + } } - // Swap the items in the list - String selItem = pathList.getItem(index); - pathList.remove(index); - pathList.add(selItem, --index); - - // Keep the index selected - pathList.select(index); - enablePathButtons(); - } - - protected void handleRemovePath() { - // Get the selection index - int index = pathList.getSelectionIndex(); - if (index == -1) { + + Group scGroup = ControlFactory.createGroup(parent, MakeUIPlugin.getResourceString(SC_GROUP_LABEL), numColumns); + scGroup.setFont(parent.getFont()); + ((GridData) scGroup.getLayoutData()).grabExcessHorizontalSpace = false; + ((GridData) scGroup.getLayoutData()).horizontalSpan = numColumns; + ((GridData) scGroup.getLayoutData()).horizontalAlignment = GridData.FILL; + ((GridLayout) scGroup.getLayout()).marginWidth = 7; + + if ((!needsSCNature && !scOptionsDialog.isInitialized())) { + ControlFactory.createLabel(scGroup, MakeUIPlugin.getResourceString(MISSING_BUILDER_MSG)); return; } - - // Remove the element at that index - pathList.remove(index); - index = index - 1 < 0 ? 0 : index - 1; - pathList.select(index); - - // Check if the buttons should still be enabled - enablePathButtons(); + + // Add checkbox + scEnabledButton = ControlFactory.createCheckBox(scGroup, MakeUIPlugin.getResourceString(SC_ENABLED_LABEL)); + scEnabledButton.setFont(parent.getFont()); + ((GridData) scEnabledButton.getLayoutData()).horizontalSpan = 2; + ((GridData) scEnabledButton.getLayoutData()).grabExcessHorizontalSpace = true; + // VMIR* old projects will have discovery disabled by default + scEnabledButton.setSelection(needsSCNature ? false : scOptionsDialog.isScannerConfigDiscoveryEnabled()); + scEnabledButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleScannerConfigEnable(); + } + }); + // Add Options... button + scOptionsButton = ControlFactory.createPushButton(scGroup, MakeUIPlugin.getResourceString(SC_OPTIONS_LABEL)); + scOptionsButton.setFont(parent.getFont()); + ((GridData) scOptionsButton.getLayoutData()).grabExcessHorizontalSpace = false; + SWTUtil.setButtonDimensionHint(scOptionsButton); + scOptionsButton.setEnabled(scEnabledButton.getSelection()); + scOptionsButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + scOptionsDialog.open(); + } + }); +// handleScannerConfigEnable(); Only if true in VMIR* } - protected void handleRemoveSymbol() { - // Get the selection index - int index = symbolList.getSelectionIndex(); - if (index == -1) { - return; + /** + * Handles scanner configuration discovery selection change + */ + protected void handleScannerConfigEnable() { + boolean enable = scEnabledButton.getSelection(); + scOptionsButton.setEnabled(enable); + if (enable && needsSCNature) { + // first install the SC nature + try { + ScannerConfigNature.addScannerConfigNature(getContainer().getProject()); + // create the real dialog + scOptionsDialog = new ScannerConfigOptionsDialog(getShell(), getContainer()); + needsSCNature = false; + } + catch (CoreException e) { + MakeCorePlugin.log(e.getStatus()); + } } - // Remove the item at that index - symbolList.remove(index); - index = index - 1 < 0 ? 0 : index - 1; - symbolList.select(index); - // Check if the button state should be toggled - enableSymbolButtons(); + scOptionsDialog.setScannerConfigDiscoveryEnabled(enable); } - protected void handleSymbolDown() { - // Get the selection index - int index = symbolList.getSelectionIndex(); - int items = symbolList.getItemCount(); - if (index == -1 || index == items - 1) { - return; - } - // Swap the items in the list - String selItem = symbolList.getItem(index); - symbolList.remove(index); - if (index + 1 == items) { - symbolList.add(selItem); - } else { - symbolList.add(selItem, ++index); - } - - // Keep the swapped item selected - symbolList.select(index); - enableSymbolButtons(); + private String[] getPathListContents() { + return pathList.getItems(); } - protected void handleSymbolUp() { - // Get the selection index - int index = symbolList.getSelectionIndex(); - if (index == -1 || index == 0) { - return; - } - // Swap the items in the list - String selItem = symbolList.getItem(index); - symbolList.remove(index); - symbolList.add(selItem, --index); - - // Keep the index selected - symbolList.select(index); - enableSymbolButtons(); + private String[] getSymbolListContents() { + return symbolList.getItems(); } /* (non-Javadoc) @@ -658,13 +465,18 @@ public class BuildPathInfoBlock extends AbstractCOptionPage { } private void setListContents() { - if (getContainer().getProject() != null) { - MakeScannerInfo info; - try { - info = MakeScannerProvider.getDefault().getMakeScannerInfo(getContainer().getProject(), false); - pathList.setItems(info.getIncludePaths()); - symbolList.setItems(info.getPreprocessorSymbols()); - } catch (CoreException e) { + IProject project = getContainer().getProject(); + if (project != null) { + IScannerInfo info = CCorePlugin.getDefault().getScannerInfoProvider(project).getScannerInformation(project); + if (info instanceof MakeScannerInfo) { + MakeScannerInfo mInfo = (MakeScannerInfo) info; + pathList.setItems(mInfo.getIncludePaths()); + symbolList.setItems(mInfo.getPreprocessorSymbols()); + } + else if (info instanceof DiscoveredScannerInfo) { + DiscoveredScannerInfo dInfo = (DiscoveredScannerInfo) info; + pathList.setItems(dInfo.getIncludePaths()); + symbolList.setItems(dInfo.getPreprocessorSymbols()); } } else { pathList.setItems(getIncludes(MakeCorePlugin.getDefault().getPluginPreferences())); diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/ManageDefinedSymbolsDialog.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/ManageDefinedSymbolsDialog.java new file mode 100644 index 00000000000..6adbb651c49 --- /dev/null +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/ManageDefinedSymbolsDialog.java @@ -0,0 +1,711 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.make.ui.dialogs; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.StringTokenizer; + +import org.eclipse.cdt.internal.ui.util.SWTUtil; +import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.MakeScannerInfo; +import org.eclipse.cdt.make.core.scannerconfig.DiscoveredScannerInfo; +import org.eclipse.cdt.make.core.scannerconfig.DiscoveredScannerInfoProvider; +import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerInfoCollector; +import org.eclipse.cdt.make.internal.core.scannerconfig.util.SymbolEntry; +import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; +import org.eclipse.cdt.make.internal.ui.MessageLine; +import org.eclipse.cdt.ui.dialogs.ICOptionContainer; +import org.eclipse.cdt.utils.ui.controls.ControlFactory; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.Preferences; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Shell; + +/** + * Manage defined symbols dialog + * + * @author vhirsl + */ +public class ManageDefinedSymbolsDialog extends Dialog { + private static final String PREF_SYMBOLS = "ScannerSymbols"; //$NON-NLS-1$ + + private static final String PREFIX = "ManageDefinedSymbolsDialog"; //$NON-NLS-1$ + private static final String DIALOG_TITLE = PREFIX + ".title"; //$NON-NLS-1$ + private static final String USER_GROUP = PREFIX + ".userGroup.title"; //$NON-NLS-1$ + private static final String NEW = "BuildPropertyCommon.label.new"; //$NON-NLS-1$ + private static final String EDIT = "BuildPropertyCommon.label.edit"; //$NON-NLS-1$ + private static final String REMOVE = "BuildPropertyCommon.label.remove"; //$NON-NLS-1$ + private static final String UP = "BuildPropertyCommon.label.up"; //$NON-NLS-1$ + private static final String DOWN = "BuildPropertyCommon.label.down"; //$NON-NLS-1$ + + private static final String BROWSE = "BuildPathInfoBlock.browse"; //$NON-NLS-1$ + private static final String SYMBOL_TITLE = BROWSE + ".symbol"; //$NON-NLS-1$ + private static final String EDIT_SYMBOL_TITLE = BROWSE + ".symbol.edit"; //$NON-NLS-1$ + private static final String SYMBOL_LABEL = BROWSE + ".symbol.label"; //$NON-NLS-1$ + + private static final String DISCOVERED_GROUP = PREFIX + ".discoveredGroup.title"; //$NON-NLS-1$ + + private static final String DISC_COMMON_PREFIX = "ManageScannerConfigDialogCommon"; //$NON-NLS-1$ + private static final String SELECTED_LABEL = DISC_COMMON_PREFIX + ".discoveredGroup.selected.label"; //$NON-NLS-1$ + private static final String REMOVED_LABEL = DISC_COMMON_PREFIX + ".discoveredGroup.removed.label"; //$NON-NLS-1$ + private static final String REMOVE_DISCOVERED = DISC_COMMON_PREFIX + ".discoveredGroup.buttons.remove.label"; //$NON-NLS-1$ + private static final String RESTORE_DISCOVERED = DISC_COMMON_PREFIX + ".discoveredGroup.buttons.restore.label"; //$NON-NLS-1$ + private static final String DELETE_DISCOVERED = DISC_COMMON_PREFIX + ".discoveredGroup.buttons.delete.label"; //$NON-NLS-1$ + private static final String DELETE_ALL_DISCOVERED = DISC_COMMON_PREFIX + ".discoveredGroup.buttons.deleteAll.label"; //$NON-NLS-1$ + + private static final int PROJECT_LIST_MULTIPLIER = 15; + private static final int INITIAL_LIST_WIDTH = 40; + + private static final int ACTIVE = 0; + private static final int REMOVED = 1; + + private static final int DO_REMOVE = 0; + private static final int DO_RESTORE = 1; + + boolean alreadyCreated; // Set when dialog is created for the first time (vs. reopened) + private ArrayList returnSymbols; + private ArrayList userSymbols; + private LinkedHashMap discoveredSymbols; + private LinkedHashMap workingDiscoveredSymbols; // working copy of discoveredSymbols, until either OK or CANCEL is pressed + private boolean fDirty; + private boolean fWorkingDirty; + + private ICOptionContainer fContainer; + private IProject fProject; + private Shell fShell; + private MessageLine fStatusLine; + + private List userList; + private Button addSymbol; + private Button editSymbol; + private Button removeSymbol; + + private Group discoveredGroup; + private Label selectedLabel; + private Label removedLabel; + private List discActiveList; + private List discRemovedList; + private Button removeDiscSymbol; + private Button restoreDiscSymbol; + private Button deleteDiscSymbol; + private Button deleteAllDiscSymbols; + + /** + * @param parentShell + */ + protected ManageDefinedSymbolsDialog(Shell parentShell, ICOptionContainer container) { + super(parentShell); + fShell = parentShell; + fContainer = container; + fProject = fContainer.getProject(); + DiscoveredScannerInfo scanInfo; + if (fProject != null) { + scanInfo = (DiscoveredScannerInfo) DiscoveredScannerInfoProvider.getDefault().getScannerInformation(fProject); + } + else { + scanInfo = new DiscoveredScannerInfo(null); + MakeScannerInfo makeInfo = new MakeScannerInfo(null); + Preferences store = MakeCorePlugin.getDefault().getPluginPreferences(); + makeInfo.setPreprocessorSymbols(BuildPathInfoBlock.getSymbols(store)); + scanInfo.setUserScannerInfo(makeInfo); + } + userSymbols = new ArrayList(Arrays.asList(scanInfo.getUserSymbolDefinitions())); + discoveredSymbols = scanInfo.getDiscoveredSymbolDefinitions(); + setDirty(false); + fDirty = false; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + */ + protected void configureShell(Shell newShell) { + newShell.setText(getTitle(DIALOG_TITLE)); + super.configureShell(newShell); + } + + /** + * @return + */ + private String getTitle(String title) { + return MakeUIPlugin.getResourceString(title); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createDialogArea(Composite parent) { + setDirty(false); + Composite composite = (Composite) super.createDialogArea(parent); + ((GridLayout) composite.getLayout()).numColumns = 3; + initializeDialogUnits(composite); + + // create message line + fStatusLine = new MessageLine(composite); + fStatusLine.setAlignment(SWT.LEFT); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 3; +// gd.widthHint = convertWidthInCharsToPixels(50); + fStatusLine.setLayoutData(gd); + fStatusLine.setMessage(getTitle(DIALOG_TITLE)); + + createUserControls(composite); + createOptionsControls(composite); + createDiscoveredControls(composite); + + setListContents(); + userList.select(0); + enableUserButtons(); + discActiveList.select(0); + enableDiscoveredButtons(); + + return composite; + } + + /** + * + */ + private void setListContents() { + workingDiscoveredSymbols = new LinkedHashMap(discoveredSymbols); + + userList.setItems((String[]) userSymbols.toArray(new String[userSymbols.size()])); + discActiveList.setItems(getDiscDefinedSymbols(workingDiscoveredSymbols, ACTIVE)); + discRemovedList.setItems(getDiscDefinedSymbols(workingDiscoveredSymbols, REMOVED)); + } + + /** + * @param discoveredPaths + * @return + */ + private String[] getDiscDefinedSymbols(Map dSymbols, int type) { + ArrayList aSymbols = new ArrayList(); + for (Iterator i = dSymbols.keySet().iterator(); i.hasNext(); ) { + String symbol = (String) i.next(); + SymbolEntry values = (SymbolEntry) dSymbols.get(symbol); + java.util.List aValues = (type == ACTIVE ? values.getActiveRaw() : values.getRemovedRaw()); + aSymbols.addAll(aValues); + } + return (String[]) aSymbols.toArray(new String[aSymbols.size()]); + } + + private String[] getIncludes(Preferences prefs) { + String syms = prefs.getString(PREF_SYMBOLS); + return parseStringToList(syms); + } + + private String[] parseStringToList(String syms) { + if (syms != null && syms.length() > 0) { + StringTokenizer tok = new StringTokenizer(syms, ";"); //$NON-NLS-1$ + ArrayList list = new ArrayList(tok.countTokens()); + while (tok.hasMoreElements()) { + list.add(tok.nextToken()); + } + return (String[]) list.toArray(new String[list.size()]); + } + return new String[0]; + } + + /** + * @param composite + */ + private void createUserControls(Composite composite) { + // Create group + Group userGroup = ControlFactory.createGroup(composite, getTitle(USER_GROUP), 3); + ((GridData) userGroup.getLayoutData()).horizontalSpan = 2; + ((GridData) userGroup.getLayoutData()).grabExcessHorizontalSpace = false; + + // Create list + userList = new List(userGroup, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); + userList.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + enableUserButtons(); + } + }); + userList.addMouseListener(new MouseAdapter() { + public void mouseDoubleClick(MouseEvent e) { + editUserListItem(); + } + }); + + // Make it occupy the first column + GridData gd = new GridData(GridData.FILL_BOTH); + gd.grabExcessHorizontalSpace = true; + gd.horizontalSpan = 1; + gd.heightHint = getDefaultFontHeight(userList, PROJECT_LIST_MULTIPLIER); + gd.widthHint = convertWidthInCharsToPixels(INITIAL_LIST_WIDTH); + userList.setLayoutData(gd); + + // Create buttons + // Create a composite for the buttons + Composite pathButtonComp = ControlFactory.createComposite(userGroup, 1); + + // Add the buttons + addSymbol = ControlFactory.createPushButton(pathButtonComp, getTitle(NEW)); + addSymbol.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleAddSymbol(); + } + }); + addSymbol.setEnabled(true); + SWTUtil.setButtonDimensionHint(addSymbol); + + editSymbol = ControlFactory.createPushButton(pathButtonComp, getTitle(EDIT)); + editSymbol.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + editUserListItem(); + } + }); + editSymbol.setEnabled(true); + SWTUtil.setButtonDimensionHint(editSymbol); + + removeSymbol = ControlFactory.createPushButton(pathButtonComp, getTitle(REMOVE)); + removeSymbol.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleRemoveSymbol(); + } + }); + SWTUtil.setButtonDimensionHint(removeSymbol); + } + + protected void handleAddSymbol() { + // Popup an entry dialog + InputDialog dialog = new InputDialog(fShell, getTitle(SYMBOL_TITLE), + getTitle(SYMBOL_LABEL), "", null); //$NON-NLS-1$ + String symbol = null; + if (dialog.open() == Window.OK) { + symbol = dialog.getValue(); + if (symbol != null && symbol.length() > 0) { + setDirty(true); + userList.add(symbol); + userList.select(userList.getItemCount() - 1); + enableUserButtons(); + } + } + } + + /* + * Double-click handler to allow edit of path information + */ + protected void editUserListItem() { + // Edit the selection index + int index = userList.getSelectionIndex(); + if (index != -1) { + String selItem = userList.getItem(index); + if (selItem != null) { + InputDialog dialog = new InputDialog(fShell, getTitle(EDIT_SYMBOL_TITLE), + getTitle(SYMBOL_LABEL), selItem, null); + String newItem = null; + if (dialog.open() == Window.OK) { + newItem = dialog.getValue(); + if (newItem != null && !newItem.equals(selItem)) { + userList.setItem(index, newItem); + setDirty(true); + } + } + } + } + } + + protected void handleRemoveSymbol() { + // Get the selection index + int index = userList.getSelectionIndex(); + if (index == -1) { + return; + } + + // Remove the element at that index + userList.remove(index); + index = index - 1 < 0 ? 0 : index - 1; + userList.select(index); + setDirty(true); + + // Check if the buttons should still be enabled + enableUserButtons(); + } + + /* + * Enables the buttons on the path control if the right conditions are met + */ + protected void enableUserButtons() { + // Enable the remove button if there is at least 1 item in the list + int items = userList.getItemCount(); + if (items > 0) { + editSymbol.setEnabled(true); + removeSymbol.setEnabled(true); + // Enable the up/down buttons depending on what item is selected + int index = userList.getSelectionIndex(); + } else { + editSymbol.setEnabled(false); + removeSymbol.setEnabled(false); + } + } + + /** + * @param composite + */ + private void createOptionsControls(Composite composite) { + // TODO Auto-generated method stub + + } + + /** + * @param composite + */ + private void createDiscoveredControls(Composite composite) { + // Create group + discoveredGroup = ControlFactory.createGroup(composite, getTitle(DISCOVERED_GROUP), 3); + ((GridData) discoveredGroup.getLayoutData()).horizontalSpan = 3; + ((GridData) discoveredGroup.getLayoutData()).grabExcessHorizontalSpace = true; + + // Create composite +// Composite c1 = ControlFactory.createComposite(discoveredGroup, 1); + Composite c1 = discoveredGroup; + + // Create label Selected: + selectedLabel = ControlFactory.createLabel(c1, getTitle(SELECTED_LABEL)); + ((GridData) selectedLabel.getLayoutData()).horizontalSpan = 1; + + // Add a dummy label + ControlFactory.createLabel(discoveredGroup, "");//$NON-NLS-1$ + + // Create label Removed: + removedLabel = ControlFactory.createLabel(c1, getTitle(REMOVED_LABEL)); + ((GridData) removedLabel.getLayoutData()).horizontalSpan = 1; + + // Create list + discActiveList = new List(c1, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); + discActiveList.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + discRemovedList.deselectAll(); + enableDiscoveredButtons(); + } + }); + // Make it occupy the first column + GridData gd = new GridData(GridData.FILL_BOTH); + gd.grabExcessHorizontalSpace = true; + gd.horizontalSpan = 1; + gd.heightHint = getDefaultFontHeight(discActiveList, PROJECT_LIST_MULTIPLIER); + gd.widthHint = convertWidthInCharsToPixels(INITIAL_LIST_WIDTH); + discActiveList.setLayoutData(gd); + + // Create buttons + // Create a composite for the buttons + Composite pathButtonComp = ControlFactory.createComposite(discoveredGroup, 1); + + // Add the buttons + removeDiscSymbol = ControlFactory.createPushButton(pathButtonComp, getTitle(REMOVE_DISCOVERED)); + removeDiscSymbol.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleRemoveRestoreDiscSymbol(DO_REMOVE); + } + }); + removeDiscSymbol.setEnabled(true); + SWTUtil.setButtonDimensionHint(removeDiscSymbol); + + restoreDiscSymbol = ControlFactory.createPushButton(pathButtonComp, getTitle(RESTORE_DISCOVERED)); + restoreDiscSymbol.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleRemoveRestoreDiscSymbol(DO_RESTORE); + } + }); + restoreDiscSymbol.setEnabled(true); + SWTUtil.setButtonDimensionHint(restoreDiscSymbol); + + Label sep = ControlFactory.createSeparator(pathButtonComp, 1); + + deleteDiscSymbol = ControlFactory.createPushButton(pathButtonComp, getTitle(DELETE_DISCOVERED)); + deleteDiscSymbol.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleDeleteDiscSymbol(); + } + }); + deleteDiscSymbol.setEnabled(true); + SWTUtil.setButtonDimensionHint(deleteDiscSymbol); + + deleteAllDiscSymbols = ControlFactory.createPushButton(pathButtonComp, getTitle(DELETE_ALL_DISCOVERED)); + deleteAllDiscSymbols.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleDeleteAllDiscSymbols(); + } + }); + deleteAllDiscSymbols.setEnabled(true); + SWTUtil.setButtonDimensionHint(deleteAllDiscSymbols); + + // Create composite +// Composite c2 = ControlFactory.createComposite(discoveredGroup, 1); + Composite c2 = discoveredGroup; + + // Create list + discRemovedList = new List(c2, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); + discRemovedList.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + discActiveList.deselectAll(); + enableDiscoveredButtons(); + } + }); + // Make it occupy the first column + GridData gd2 = new GridData(GridData.FILL_BOTH); + gd2.grabExcessHorizontalSpace = true; + gd2.horizontalSpan = 1; + gd2.heightHint = getDefaultFontHeight(discRemovedList, PROJECT_LIST_MULTIPLIER); + gd2.widthHint = convertWidthInCharsToPixels(INITIAL_LIST_WIDTH); + discRemovedList.setLayoutData(gd2); + } + + /** + * + */ + protected void handleRemoveRestoreDiscSymbol(int type) { + if (workingDiscoveredSymbols != null) { + List discList = discRemovedList; + List discOtherList = discActiveList; + boolean newStatus = true; // active + if (type == DO_REMOVE) { + discList = discActiveList; + discOtherList = discRemovedList; + newStatus = false; // removed + } + + int id = discList.getSelectionIndex(); + if (id != -1) { + String symbol = discList.getItem(id); + String key = getSymbolKey(symbol); + String value = getSymbolValue(symbol); + // find it in the discoveredSymbols Map of SymbolEntries + SymbolEntry se = (SymbolEntry) workingDiscoveredSymbols.get(key); + if (se != null) { + se = new SymbolEntry(se); // deep copy + se.replace(value, newStatus); + workingDiscoveredSymbols.put(key, se); + // update UI + discActiveList.setItems(getDiscDefinedSymbols(workingDiscoveredSymbols, ACTIVE)); + discRemovedList.setItems(getDiscDefinedSymbols(workingDiscoveredSymbols, REMOVED)); + discOtherList.setSelection(discOtherList.indexOf(symbol)); + enableDiscoveredButtons(); + setDirty(true); + } + else { + //TODO VMIR generate an error + } + } + } + } + + /** + * + */ + protected void handleDeleteDiscSymbol() { + deleteDiscSymbol(REMOVED); + deleteDiscSymbol(ACTIVE); + } + + private void deleteDiscSymbol(int type) { + List discList = discRemovedList; + if (type == ACTIVE) { + discList = discActiveList; + } + int id = discList.getSelectionIndex(); + if (id >= 0) { + String symbol = discList.getItem(id); + // remove it from the Map of SymbolEntries + String key = getSymbolKey(symbol); + String value = getSymbolValue(symbol); + // find it in the discoveredSymbols Map of SymbolEntries + SymbolEntry se = (SymbolEntry) workingDiscoveredSymbols.get(key); + if (se != null) { + se.remove(value); + } + else { + //TODO VMIR generate an error + } + + int items = discList.getItemCount(); + discList.setItems(getDiscDefinedSymbols(workingDiscoveredSymbols, type)); + if (items > 0) { + if (id >= items) { + id = items - 1; + } + discList.setSelection(id); + enableDiscoveredButtons(); + setDirty(true); + } + } + } + + /** + * Returns a symbol key (i.e. for DEF=1 returns DEF) + * + * @param symbol - in + * @param key - out + */ + private String getSymbolKey(String symbol) { + int index = symbol.indexOf('='); + if (index != -1) { + return symbol.substring(0, index); + } + return symbol; + } + + /** + * Returns a symbol value (i.e. for DEF=1 returns 1) + * + * @param symbol - in + * @param key - out (may be null) + */ + private String getSymbolValue(String symbol) { + int index = symbol.indexOf('='); + if (index != -1) { + return symbol.substring(index+1); + } + return null; + } + + /** + * + */ + protected void handleDeleteAllDiscSymbols() { + ScannerInfoCollector.getInstance().deleteAllSymbols(fProject); + workingDiscoveredSymbols.clear(); + discActiveList.setItems(getDiscDefinedSymbols(workingDiscoveredSymbols, ACTIVE)); + discRemovedList.setItems(getDiscDefinedSymbols(workingDiscoveredSymbols, REMOVED)); + enableDiscoveredButtons(); + setDirty(true); + } + + /** + * + */ + protected void enableDiscoveredButtons() { + discoveredGroup.setEnabled(fProject != null); + selectedLabel.setEnabled(fProject != null); + discActiveList.setEnabled(fProject != null); + removedLabel.setEnabled(fProject != null); + discRemovedList.setEnabled(fProject != null); + + int activeItems = discActiveList.getItemCount(); + int activeSeclection = discActiveList.getSelectionIndex(); + int removedItems = discRemovedList.getItemCount(); + int removedSelection = discRemovedList.getSelectionIndex(); + // To maintain the proper TAB order of enabled buttons + if (activeItems > 0 && activeSeclection >= 0) { + removeDiscSymbol.setEnabled(activeItems > 0 && activeSeclection >= 0); + restoreDiscSymbol.setEnabled(removedItems > 0 && removedSelection >= 0); + } + else { + restoreDiscSymbol.setEnabled(removedItems > 0 && removedSelection >= 0); + removeDiscSymbol.setEnabled(activeItems > 0 && activeSeclection >= 0); + } + deleteDiscSymbol.setEnabled((activeItems > 0 && activeSeclection >= 0) || + (removedItems > 0 && removedSelection >= 0)); + deleteAllDiscSymbols.setEnabled(activeItems > 0 || removedItems > 0); + } + + /** + * Get the defualt widget height for the supplied control. + * @return int + * @param control - the control being queried about fonts + * @param lines - the number of lines to be shown on the table. + */ + private static int getDefaultFontHeight(Control control, int lines) { + FontData[] viewerFontData = control.getFont().getFontData(); + int fontHeight = 10; + + //If we have no font data use our guess + if (viewerFontData.length > 0) + fontHeight = viewerFontData[0].getHeight(); + return lines * fontHeight; + } + + /** + * @return + */ + public String[] getManagedSymbols() { + if (returnSymbols == null) { + return new String[0]; + } + return (String[]) returnSymbols.toArray(new String[returnSymbols.size()]); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) + */ + protected void buttonPressed(int buttonId) { + if (IDialogConstants.OK_ID == buttonId) { + // Store user part + userSymbols = new ArrayList(Arrays.asList(userList.getItems())); + // Store discovered part + discoveredSymbols = workingDiscoveredSymbols; + // Return sum of user and active discovered paths + returnSymbols = new ArrayList(userSymbols.size() + discActiveList.getItemCount()); + returnSymbols.addAll(userSymbols); + returnSymbols.addAll(new ArrayList(Arrays.asList(discActiveList.getItems()))); + + fDirty = fWorkingDirty; + } + else if (IDialogConstants.CANCEL_ID == buttonId) { + workingDiscoveredSymbols = null; + setDirty(false); + } + super.buttonPressed(buttonId); + } + + private void setDirty(boolean dirty) { + fWorkingDirty = dirty; + } + + /** + * Called by BuildPathInfoBlock.performApply + * @param info + */ + public void saveTo(DiscoveredScannerInfo info) { + if (fDirty || (fProject == null && fContainer.getProject() != null)) {// New Standard Make project wizard + info.setUserDefinedSymbols(userSymbols); + info.setDiscoveredSymbolDefinitions(discoveredSymbols); + } + setDirty(false); + fDirty = false; + } + + /** + * Called by BuildPathInfoBlock.performDefaults + */ + public void restore() { + if (fProject != null) { + userSymbols = new ArrayList(Arrays.asList(BuildPathInfoBlock.getSymbols( + MakeCorePlugin.getDefault().getPluginPreferences()))); + } + else { + userSymbols = new ArrayList(); + } + discoveredSymbols = new LinkedHashMap(); + fDirty = true; + } +} diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/ManageIncludePathsDialog.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/ManageIncludePathsDialog.java new file mode 100644 index 00000000000..b388f46e9ed --- /dev/null +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/ManageIncludePathsDialog.java @@ -0,0 +1,721 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.make.ui.dialogs; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.StringTokenizer; + +import org.eclipse.cdt.internal.ui.util.SWTUtil; +import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.MakeScannerInfo; +import org.eclipse.cdt.make.core.scannerconfig.DiscoveredScannerInfo; +import org.eclipse.cdt.make.core.scannerconfig.DiscoveredScannerInfoProvider; +import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerInfoCollector; +import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; +import org.eclipse.cdt.make.internal.ui.MessageLine; +import org.eclipse.cdt.ui.dialogs.ICOptionContainer; +import org.eclipse.cdt.utils.ui.controls.ControlFactory; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.Preferences; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Shell; + +/** + * Manage include paths dialog + * + * @author vhirsl + */ +public class ManageIncludePathsDialog extends Dialog { + private static final String PREF_INCLUDES = "ScannerIncludes"; //$NON-NLS-1$ + + private static final String PREFIX = "ManageIncludePathsDialog"; //$NON-NLS-1$ + private static final String DIALOG_TITLE = PREFIX + ".title"; //$NON-NLS-1$ + private static final String USER_GROUP = PREFIX + ".userGroup.title"; //$NON-NLS-1$ + private static final String NEW = "BuildPropertyCommon.label.new"; //$NON-NLS-1$ + private static final String EDIT = "BuildPropertyCommon.label.edit"; //$NON-NLS-1$ + private static final String REMOVE = "BuildPropertyCommon.label.remove"; //$NON-NLS-1$ + private static final String UP = "BuildPropertyCommon.label.up"; //$NON-NLS-1$ + private static final String DOWN = "BuildPropertyCommon.label.down"; //$NON-NLS-1$ + + private static final String BROWSE = "BuildPathInfoBlock.browse"; //$NON-NLS-1$ + private static final String PATH_TITLE = BROWSE + ".path"; //$NON-NLS-1$ + private static final String EDIT_PATH_TITLE = BROWSE + ".path.edit"; //$NON-NLS-1$ + private static final String PATH_LABEL = BROWSE + ".path.label"; //$NON-NLS-1$ + + private static final String DISCOVERED_GROUP = PREFIX + ".discoveredGroup.title"; //$NON-NLS-1$ + + private static final String DISC_COMMON_PREFIX = "ManageScannerConfigDialogCommon"; //$NON-NLS-1$ + private static final String SELECTED_LABEL = DISC_COMMON_PREFIX + ".discoveredGroup.selected.label"; //$NON-NLS-1$ + private static final String REMOVED_LABEL = DISC_COMMON_PREFIX + ".discoveredGroup.removed.label"; //$NON-NLS-1$ + private static final String REMOVE_DISCOVERED = DISC_COMMON_PREFIX + ".discoveredGroup.buttons.remove.label"; //$NON-NLS-1$ + private static final String RESTORE_DISCOVERED = DISC_COMMON_PREFIX + ".discoveredGroup.buttons.restore.label"; //$NON-NLS-1$ + private static final String DELETE_DISCOVERED = DISC_COMMON_PREFIX + ".discoveredGroup.buttons.delete.label"; //$NON-NLS-1$ + private static final String DELETE_ALL_DISCOVERED = DISC_COMMON_PREFIX + ".discoveredGroup.buttons.deleteAll.label"; //$NON-NLS-1$ + + private static final int PROJECT_LIST_MULTIPLIER = 15; + private static final int INITIAL_LIST_WIDTH = 40; + + private static final int ACTIVE = 0; + private static final int REMOVED = 1; + + private static final int DO_REMOVE = 0; + private static final int DO_RESTORE = 1; + + private ArrayList returnPaths; + private ArrayList userPaths; + private LinkedHashMap discoveredPaths; + private LinkedHashMap workingDiscoveredPaths; // working copy of discoveredPaths, until either OK or CANCEL is pressed + private boolean fDirty; + private boolean fWorkingDirty; + + private ICOptionContainer fContainer; + private IProject fProject; + private Shell fShell; + private MessageLine fStatusLine; + + private List userList; + private Button addPath; + private Button editPath; + private Button removePath; + private Button pathUp; + private Button pathDown; + + private Group discoveredGroup; + private Label selectedLabel; + private Label removedLabel; + private List discActiveList; + private List discRemovedList; + private Button removeDiscPath; + private Button restoreDiscPath; + private Button deleteDiscPath; + private Button deleteAllDiscPaths; + + /** + * @param parentShell + */ + protected ManageIncludePathsDialog(Shell parentShell, ICOptionContainer container) { + super(parentShell); + fShell = parentShell; + fContainer = container; + fProject = fContainer.getProject(); + DiscoveredScannerInfo scanInfo; + if (fProject != null) { + scanInfo = (DiscoveredScannerInfo) DiscoveredScannerInfoProvider.getDefault().getScannerInformation(fProject); + } + else { + scanInfo = new DiscoveredScannerInfo(null); + MakeScannerInfo makeInfo = new MakeScannerInfo(null); + Preferences store = MakeCorePlugin.getDefault().getPluginPreferences(); + makeInfo.setIncludePaths(BuildPathInfoBlock.getIncludes(store)); + scanInfo.setUserScannerInfo(makeInfo); + } + userPaths = new ArrayList(Arrays.asList(scanInfo.getUserIncludePaths())); + discoveredPaths = scanInfo.getDiscoveredIncludePaths(); + setDirty(false); + fDirty = false; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + */ + protected void configureShell(Shell newShell) { + newShell.setText(getTitle(DIALOG_TITLE)); + super.configureShell(newShell); + } + + /** + * @return + */ + private String getTitle(String title) { + return MakeUIPlugin.getResourceString(title); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + ((GridLayout) composite.getLayout()).numColumns = 3; + initializeDialogUnits(composite); + + // create message line + fStatusLine = new MessageLine(composite); + fStatusLine.setAlignment(SWT.LEFT); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 3; +// gd.widthHint = convertWidthInCharsToPixels(50); + fStatusLine.setLayoutData(gd); + fStatusLine.setMessage(getTitle(DIALOG_TITLE)); + + createUserControls(composite); + createOptionsControls(composite); + createDiscoveredControls(composite); + + setListContents(); + userList.select(0); + enableUserButtons(); + discActiveList.select(0); + enableDiscoveredButtons(); + + return composite; + } + + /** + * + */ + private void setListContents() { + workingDiscoveredPaths = new LinkedHashMap(discoveredPaths); + + userList.setItems((String[]) userPaths.toArray(new String[userPaths.size()])); + discActiveList.setItems(getDiscIncludePaths(workingDiscoveredPaths, ACTIVE)); + discRemovedList.setItems(getDiscIncludePaths(workingDiscoveredPaths, REMOVED)); + } + + /** + * @param discoveredPaths + * @return + */ + private String[] getDiscIncludePaths(LinkedHashMap dPaths, int type) { + ArrayList aPaths = new ArrayList(); + boolean compareValue = (type == ACTIVE ? false : true); + for (Iterator i = dPaths.keySet().iterator(); i.hasNext(); ) { + String path = (String) i.next(); + if (((Boolean) dPaths.get(path)).booleanValue() == compareValue) { + aPaths.add(path); + } + } + return (String[]) aPaths.toArray(new String[aPaths.size()]); + } + + private String[] getIncludes(Preferences prefs) { + String syms = prefs.getString(PREF_INCLUDES); + return parseStringToList(syms); + } + + private String[] parseStringToList(String syms) { + if (syms != null && syms.length() > 0) { + StringTokenizer tok = new StringTokenizer(syms, ";"); //$NON-NLS-1$ + ArrayList list = new ArrayList(tok.countTokens()); + while (tok.hasMoreElements()) { + list.add(tok.nextToken()); + } + return (String[]) list.toArray(new String[list.size()]); + } + return new String[0]; + } + + /** + * @param composite + */ + private void createUserControls(Composite composite) { + // Create group + Group userGroup = ControlFactory.createGroup(composite, getTitle(USER_GROUP), 3); + ((GridData) userGroup.getLayoutData()).horizontalSpan = 2; + ((GridData) userGroup.getLayoutData()).grabExcessHorizontalSpace = false; + + // Create list + userList = new List(userGroup, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); + userList.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + enableUserButtons(); + } + }); + userList.addMouseListener(new MouseAdapter() { + public void mouseDoubleClick(MouseEvent e) { + editUserListItem(); + } + }); + + // Make it occupy the first column + GridData gd = new GridData(GridData.FILL_BOTH); + gd.grabExcessHorizontalSpace = true; + gd.horizontalSpan = 1; + gd.heightHint = getDefaultFontHeight(userList, PROJECT_LIST_MULTIPLIER); + gd.widthHint = convertWidthInCharsToPixels(INITIAL_LIST_WIDTH); + userList.setLayoutData(gd); + + // Create buttons + // Create a composite for the buttons + Composite pathButtonComp = ControlFactory.createComposite(userGroup, 1); + + // Add the buttons + addPath = ControlFactory.createPushButton(pathButtonComp, getTitle(NEW)); + addPath.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleAddPath(); + } + }); + addPath.setEnabled(true); + SWTUtil.setButtonDimensionHint(addPath); + + editPath = ControlFactory.createPushButton(pathButtonComp, getTitle(EDIT)); + editPath.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + editUserListItem(); + } + }); + editPath.setEnabled(true); + SWTUtil.setButtonDimensionHint(editPath); + + removePath = ControlFactory.createPushButton(pathButtonComp, getTitle(REMOVE)); + removePath.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleRemovePath(); + } + }); + SWTUtil.setButtonDimensionHint(removePath); + + pathUp = ControlFactory.createPushButton(pathButtonComp, getTitle(UP)); + pathUp.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handlePathUp(); + } + }); + SWTUtil.setButtonDimensionHint(pathUp); + + pathDown = ControlFactory.createPushButton(pathButtonComp, getTitle(DOWN)); + pathDown.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handlePathDown(); + } + }); + SWTUtil.setButtonDimensionHint(pathDown); + } + + protected void handleAddPath() { + // Popup an entry dialog + InputDialog dialog = new BuildPathInfoBlock. + SelectPathInputDialog(fShell, getTitle(PATH_TITLE), getTitle(PATH_LABEL), "", null); //$NON-NLS-1$ + String path = null; + if (dialog.open() == Window.OK) { + path = dialog.getValue(); + if (path != null && path.length() > 0) { + setDirty(true); + userList.add(path); + userList.select(userList.getItemCount() - 1); + enableUserButtons(); + } + } + } + + /* + * Double-click handler to allow edit of path information + */ + protected void editUserListItem() { + // Edit the selection index + int index = userList.getSelectionIndex(); + if (index != -1) { + String selItem = userList.getItem(index); + if (selItem != null) { + InputDialog dialog = new BuildPathInfoBlock.SelectPathInputDialog( + fShell, getTitle(EDIT_PATH_TITLE), getTitle(PATH_LABEL), selItem, null); + String newItem = null; + if (dialog.open() == Window.OK) { + newItem = dialog.getValue(); + if (newItem != null && !newItem.equals(selItem)) { + userList.setItem(index, newItem); + setDirty(true); + } + } + } + } + } + + protected void handleRemovePath() { + // Get the selection index + int index = userList.getSelectionIndex(); + if (index == -1) { + return; + } + + // Remove the element at that index + userList.remove(index); + index = index - 1 < 0 ? 0 : index - 1; + userList.select(index); + setDirty(true); + + // Check if the buttons should still be enabled + enableUserButtons(); + } + + protected void handlePathUp() { + // Get the selection index + int index = userList.getSelectionIndex(); + if (index == -1 || index == 0) { + return; + } + // Swap the items in the list + String selItem = userList.getItem(index); + userList.remove(index); + userList.add(selItem, --index); + setDirty(true); + + // Keep the index selected + userList.select(index); + enableUserButtons(); + } + + protected void handlePathDown() { + // Get the selection index + int index = userList.getSelectionIndex(); + int items = userList.getItemCount(); + if (index == -1 || index == items - 1) { + return; + } + // Swap the items in the list + String selItem = userList.getItem(index); + userList.remove(index); + if (index + 1 == items) { + userList.add(selItem); + } else { + userList.add(selItem, ++index); + } + setDirty(true); + + // Keep the swapped item selected + userList.select(index); + enableUserButtons(); + } + + /* + * Enables the buttons on the path control if the right conditions are met + */ + protected void enableUserButtons() { + // Enable the remove button if there is at least 1 item in the list + int items = userList.getItemCount(); + if (items > 0) { + editPath.setEnabled(true); + removePath.setEnabled(true); + // Enable the up/down buttons depending on what item is selected + int index = userList.getSelectionIndex(); + pathUp.setEnabled(items > 1 && index > 0); + pathDown.setEnabled(items > 1 && index < (items - 1)); + } else { + editPath.setEnabled(false); + removePath.setEnabled(false); + pathUp.setEnabled(false); + pathDown.setEnabled(false); + } + } + + /** + * @param composite + */ + private void createOptionsControls(Composite composite) { + // TODO Auto-generated method stub + + } + + /** + * @param composite + */ + private void createDiscoveredControls(Composite composite) { + // Create group + discoveredGroup = ControlFactory.createGroup(composite, getTitle(DISCOVERED_GROUP), 3); + ((GridData) discoveredGroup.getLayoutData()).horizontalSpan = 3; + ((GridData) discoveredGroup.getLayoutData()).grabExcessHorizontalSpace = true; + + // Create label Selected: + selectedLabel = ControlFactory.createLabel(discoveredGroup, getTitle(SELECTED_LABEL)); + ((GridData) selectedLabel.getLayoutData()).horizontalSpan = 1; + + // Add a dummy label + ControlFactory.createLabel(discoveredGroup, "");//$NON-NLS-1$ + + // Create label Removed: + removedLabel = ControlFactory.createLabel(discoveredGroup, getTitle(REMOVED_LABEL)); + ((GridData) removedLabel.getLayoutData()).horizontalSpan = 1; + + // Create list + discActiveList = new List(discoveredGroup, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); + discActiveList.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + discRemovedList.deselectAll(); + enableDiscoveredButtons(); + } + }); + // Make it occupy the first column + GridData gd = new GridData(GridData.FILL_BOTH); + gd.grabExcessHorizontalSpace = true; + gd.horizontalSpan = 1; + gd.heightHint = getDefaultFontHeight(discActiveList, PROJECT_LIST_MULTIPLIER); + gd.widthHint = convertWidthInCharsToPixels(INITIAL_LIST_WIDTH); + discActiveList.setLayoutData(gd); + + // Create buttons + // Create a composite for the buttons + Composite pathButtonComp = ControlFactory.createComposite(discoveredGroup, 1); + + // Add the buttons + removeDiscPath = ControlFactory.createPushButton(pathButtonComp, getTitle(REMOVE_DISCOVERED)); + removeDiscPath.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleRemoveRestoreDiscPath(DO_REMOVE); + } + }); + removeDiscPath.setEnabled(true); + SWTUtil.setButtonDimensionHint(removeDiscPath); + + restoreDiscPath = ControlFactory.createPushButton(pathButtonComp, getTitle(RESTORE_DISCOVERED)); + restoreDiscPath.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleRemoveRestoreDiscPath(DO_RESTORE); + } + }); + restoreDiscPath.setEnabled(true); + SWTUtil.setButtonDimensionHint(restoreDiscPath); + + Label sep = ControlFactory.createSeparator(pathButtonComp, 1); + + deleteDiscPath = ControlFactory.createPushButton(pathButtonComp, getTitle(DELETE_DISCOVERED)); + deleteDiscPath.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleDeleteDiscPath(); + } + }); + deleteDiscPath.setEnabled(true); + SWTUtil.setButtonDimensionHint(deleteDiscPath); + + deleteAllDiscPaths = ControlFactory.createPushButton(pathButtonComp, getTitle(DELETE_ALL_DISCOVERED)); + deleteAllDiscPaths.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleDeleteAllDiscPath(); + } + }); + deleteAllDiscPaths.setEnabled(true); + SWTUtil.setButtonDimensionHint(deleteAllDiscPaths); + + // Create list + discRemovedList = new List(discoveredGroup, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); + discRemovedList.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + discActiveList.deselectAll(); + enableDiscoveredButtons(); + } + }); + // Make it occupy the first column + GridData gd2 = new GridData(GridData.FILL_BOTH); + gd2.grabExcessHorizontalSpace = true; + gd2.horizontalSpan = 1; + gd2.heightHint = getDefaultFontHeight(discRemovedList, PROJECT_LIST_MULTIPLIER); + gd2.widthHint = convertWidthInCharsToPixels(INITIAL_LIST_WIDTH); + discRemovedList.setLayoutData(gd2); + } + + /** + * + */ + protected void handleRemoveRestoreDiscPath(int type) { + if (workingDiscoveredPaths != null) { + List discList = discRemovedList; + List discOtherList = discActiveList; + boolean compareValue = true; // removed + if (type == DO_REMOVE) { + discList = discActiveList; + discOtherList = discRemovedList; + compareValue = false; + } + + int id = discList.getSelectionIndex(); + if (id != -1) { + String path = discList.getItem(id); + // find it in the discoveredPaths LinkedHashMap + Boolean value = (Boolean) workingDiscoveredPaths.get(path); + if (value != null) { + if (value.booleanValue() == compareValue) { + workingDiscoveredPaths.put(path, Boolean.valueOf(!compareValue)); + // update UI + discActiveList.setItems(getDiscIncludePaths(workingDiscoveredPaths, ACTIVE)); + discRemovedList.setItems(getDiscIncludePaths(workingDiscoveredPaths, REMOVED)); + discOtherList.setSelection(discOtherList.indexOf(path)); + enableDiscoveredButtons(); + setDirty(true); + } + } + } + } + } + + /** + * + */ + protected void handleDeleteDiscPath() { + deleteDiscPath(REMOVED); + deleteDiscPath(ACTIVE); + } + + /** + * @param discList + * @param type + */ + private void deleteDiscPath(int type) { + List discList = discRemovedList; + if (type == ACTIVE) { + discList = discActiveList; + } + int id = discList.getSelectionIndex(); + if (id >= 0) { + String path = discList.getItem(id); + workingDiscoveredPaths.remove(path); + discList.setItems(getDiscIncludePaths(workingDiscoveredPaths, type)); + int items = discList.getItemCount(); + if (items > 0) { + if (id >= items) { + id = items - 1; + } + discList.setSelection(id); + enableDiscoveredButtons(); + setDirty(true); + } + } + } + + /** + * + */ + protected void handleDeleteAllDiscPath() { + ScannerInfoCollector.getInstance().deleteAllPaths(fProject); + workingDiscoveredPaths.clear(); + discActiveList.setItems(getDiscIncludePaths(workingDiscoveredPaths, ACTIVE)); + discRemovedList.setItems(getDiscIncludePaths(workingDiscoveredPaths, REMOVED)); + enableDiscoveredButtons(); + setDirty(true); + } + + /** + * + */ + protected void enableDiscoveredButtons() { + discoveredGroup.setEnabled(fProject != null); + selectedLabel.setEnabled(fProject != null); + discActiveList.setEnabled(fProject != null); + removedLabel.setEnabled(fProject != null); + discRemovedList.setEnabled(fProject != null); + + int activeItems = discActiveList.getItemCount(); + int activeSeclection = discActiveList.getSelectionIndex(); + int removedItems = discRemovedList.getItemCount(); + int removedSelection = discRemovedList.getSelectionIndex(); + // To maintain the proper TAB order of enabled buttons + if (activeItems > 0 && activeSeclection >= 0) { + removeDiscPath.setEnabled(activeItems > 0 && activeSeclection >= 0); + restoreDiscPath.setEnabled(removedItems > 0 && removedSelection >= 0); + } + else { + restoreDiscPath.setEnabled(removedItems > 0 && removedSelection >= 0); + removeDiscPath.setEnabled(activeItems > 0 && activeSeclection >= 0); + } + deleteDiscPath.setEnabled((activeItems > 0 && activeSeclection >= 0) || + (removedItems > 0 && removedSelection >= 0)); + deleteAllDiscPaths.setEnabled(activeItems > 0 || removedItems > 0); + } + + /** + * Get the defualt widget height for the supplied control. + * @return int + * @param control - the control being queried about fonts + * @param lines - the number of lines to be shown on the table. + */ + private static int getDefaultFontHeight(Control control, int lines) { + FontData[] viewerFontData = control.getFont().getFontData(); + int fontHeight = 10; + + //If we have no font data use our guess + if (viewerFontData.length > 0) + fontHeight = viewerFontData[0].getHeight(); + return lines * fontHeight; + } + + /** + * @return + */ + public String[] getManagedIncludes() { + if (returnPaths == null) { + return new String[0]; + } + return (String[]) returnPaths.toArray(new String[returnPaths.size()]); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) + */ + protected void buttonPressed(int buttonId) { + if (IDialogConstants.OK_ID == buttonId) { + // Store user part + userPaths = new ArrayList(Arrays.asList(userList.getItems())); + // Store discovered part + discoveredPaths = workingDiscoveredPaths; + // Return sum of user and active discovered paths + returnPaths = new ArrayList(userPaths.size() + discActiveList.getItemCount()); + returnPaths.addAll(userPaths); + returnPaths.addAll(new ArrayList(Arrays.asList(discActiveList.getItems()))); + + fDirty = fWorkingDirty; + } + else if (IDialogConstants.CANCEL_ID == buttonId) { + workingDiscoveredPaths = null; + setDirty(false); + } + super.buttonPressed(buttonId); + } + + private void setDirty(boolean dirty) { + fWorkingDirty = dirty; + } + + /** + * Called by BuildPathInfoBlock.performApply + * @param info + */ + public void saveTo(DiscoveredScannerInfo info) { + if (fDirty || (fProject == null && fContainer.getProject() != null)) {// New Standard Make project wizard + info.setUserIncludePaths(userPaths); + info.setDiscoveredIncludePaths(discoveredPaths); + } + setDirty(false); + fDirty = false; + } + + /** + * Called by BuildPathInfoBlock.performDefaults + */ + public void restore() { + if (fProject != null) { + userPaths = new ArrayList(Arrays.asList(BuildPathInfoBlock.getIncludes( + MakeCorePlugin.getDefault().getPluginPreferences()))); + } + else { + userPaths = new ArrayList(); + } + discoveredPaths = new LinkedHashMap(); + fDirty = true; + } +} diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/ScannerConfigOptionsDialog.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/ScannerConfigOptionsDialog.java new file mode 100644 index 00000000000..434becab873 --- /dev/null +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/ScannerConfigOptionsDialog.java @@ -0,0 +1,574 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.make.ui.dialogs; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo; +import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigBuilder; +import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; +import org.eclipse.cdt.make.internal.ui.MessageLine; +import org.eclipse.cdt.ui.dialogs.ICOptionContainer; +import org.eclipse.cdt.utils.ui.controls.ControlFactory; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Preferences; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** + * A dialog to set scanner config discovery options + * + * @author vhirsl + */ +public class ScannerConfigOptionsDialog extends Dialog { + private static final String PREFIX = "ScannerConfigOptionsDialog"; //$NON-NLS-1$ + private static final String DIALOG_TITLE = PREFIX + ".title"; //$NON-NLS-1$ + private static final String SI_BUILD_PARSER_GROUP = PREFIX + ".siBuilder.parser.group_label"; //$NON-NLS-1$ + private static final String ENABLE_SI_BUILD_PARSER = PREFIX + ".siBuilder.parser.enable.label"; //$NON-NLS-1$ + private static final String SI_BUILD_PARSER_LABEL = PREFIX + ".siBuilder.parser.label"; //$NON-NLS-1$ + private static final String SI_PROVIDER_CMD_GROUP = PREFIX + ".siProvider.cmd.group_label"; //$NON-NLS-1$ + private static final String ENABLE_SI_PROVIDER_COMMAND = PREFIX + ".siProvider.cmd.enable.label"; //$NON-NLS-1$ + private static final String SI_PROVIDER_CMD_USE_DEFAULT = PREFIX + ".siProvider.cmd.use_default"; //$NON-NLS-1$ + private static final String SI_PROVIDER_CMD_LABEL = PREFIX + ".siProvider.cmd.label"; //$NON-NLS-1$ + private static final String SI_PROVIDER_PARSER_LABEL = PREFIX + ".siProvider.parser.label"; //$NON-NLS-1$ + private static final String SI_PROVIDER_CMD_ERROR_MESSAGE = PREFIX + ".siProvider.cmd.error_message"; //$NON-NLS-1$ + + private MessageLine fStatusLine; + private Button defESIProviderCommandButton; + private Text esiProviderCommand; + private Button enableBuilderParserButton; + private Combo makeBuilderSIParserComboBox; + private Button enableProviderCommandButton; + private Combo esiProviderParserComboBox; + + private ICOptionContainer fContainer; + private Preferences fPrefs; + private IScannerConfigBuilderInfo fBuildInfo; + private boolean fInitialized; + private Map builderParsers = new HashMap(); + private String initialBuilderParserId = null; + private Map providerParsers = new HashMap(); + private String initialProviderParserId = null; + + /** + * Local store for Scanner Config discovery setting + * + * @author vhirsl + */ + protected class LocalStore implements IScannerConfigBuilderInfo { + private boolean fAutoDiscoveryEnabled; + private boolean fMakeBuilderConsoleParserEnabled; + private String fMakeBuilderConsoleParserId; + private boolean fESIProviderCommandEnabled; + private boolean fDefaultESIProviderCmd; + private IPath fESIProviderCommand; + private String fESIProviderArguments; + private String fESIProviderConsoleParserId; + + public LocalStore(IScannerConfigBuilderInfo info) { + try { + setAutoDiscoveryEnabled(info.isAutoDiscoveryEnabled()); + setMakeBuilderConsoleParserEnabled(info.isMakeBuilderConsoleParserEnabled()); + setMakeBuilderConsoleParserId(info.getMakeBuilderConsoleParserId()); + setESIProviderCommandEnabled(info.isESIProviderCommandEnabled()); + setUseDefaultESIProviderCmd(info.isDefaultESIProviderCmd()); + setESIProviderCommand(info.getESIProviderCommand()); + setESIProviderArguments(info.getESIProviderArguments()); + setESIProviderConsoleParserId(info.getESIProviderConsoleParserId()); + } catch (CoreException e) { + } + } + + public boolean isAutoDiscoveryEnabled() { + return fAutoDiscoveryEnabled; + } + public void setAutoDiscoveryEnabled(boolean enabled) throws CoreException { + fAutoDiscoveryEnabled = enabled; + } + + public boolean isMakeBuilderConsoleParserEnabled() { + return fMakeBuilderConsoleParserEnabled; + } + public void setMakeBuilderConsoleParserEnabled(boolean enabled) throws CoreException { + fMakeBuilderConsoleParserEnabled = enabled; + } + + public String getMakeBuilderConsoleParserId() { + return fMakeBuilderConsoleParserId; + } + public void setMakeBuilderConsoleParserId(String parserId) throws CoreException { + fMakeBuilderConsoleParserId = new String(parserId); + + } + + public boolean isESIProviderCommandEnabled() { + return fESIProviderCommandEnabled; + } + public void setESIProviderCommandEnabled(boolean enabled) throws CoreException { + fESIProviderCommandEnabled = enabled; + } + + public boolean isDefaultESIProviderCmd() { + return fDefaultESIProviderCmd; + } + public void setUseDefaultESIProviderCmd(boolean on) throws CoreException { + fDefaultESIProviderCmd = on; + } + + public IPath getESIProviderCommand() { + return fESIProviderCommand; + } + public void setESIProviderCommand(IPath command) throws CoreException { + fESIProviderCommand = new Path(command.toString()); + } + + public String getESIProviderArguments() { + return fESIProviderArguments; + } + public void setESIProviderArguments(String args) throws CoreException { + fESIProviderArguments = new String(args); + } + + public String getESIProviderConsoleParserId() { + return fESIProviderConsoleParserId; + } + public void setESIProviderConsoleParserId(String parserId) throws CoreException { + fESIProviderConsoleParserId = new String(parserId); + } + } + + /** + * A temporary page to retrieve SC options from preferences + * Not to be shown + * + * @param container + */ + ScannerConfigOptionsDialog(ICOptionContainer container) { + super(null); + fInitialized = false; + fContainer = container; + fPrefs = fContainer.getPreferences(); + IScannerConfigBuilderInfo fInfo = MakeCorePlugin.createScannerConfigBuildInfo(fPrefs, ScannerConfigBuilder.BUILDER_ID, false); + // Create local store + fBuildInfo = new LocalStore(fInfo); + } + /** + * @param parentShell + * @param container + */ + ScannerConfigOptionsDialog(Shell parentShell, ICOptionContainer container) { + super(parentShell); + fInitialized = true; + fContainer = container; + IProject project = fContainer.getProject(); + fPrefs = fContainer.getPreferences(); + + IScannerConfigBuilderInfo fInfo; + if (project != null) { + try { + fInfo = MakeCorePlugin.createScannerConfigBuildInfo(project, ScannerConfigBuilder.BUILDER_ID); + } + catch (CoreException e) { +// fInitialized = false; + fInfo = MakeCorePlugin.createScannerConfigBuildInfo(fPrefs, ScannerConfigBuilder.BUILDER_ID, true); + } + } + else { + fInfo = MakeCorePlugin.createScannerConfigBuildInfo(fPrefs, ScannerConfigBuilder.BUILDER_ID, false); + } + retrieveSIConsoleParsers(); + initialBuilderParserId = fInfo.getMakeBuilderConsoleParserId(); //$NON-NLS-1$ + initialProviderParserId = fInfo.getESIProviderConsoleParserId(); //$NON-NLS-1$ + + // Create local store + fBuildInfo = new LocalStore(fInfo); + } + + /** + * Fills console parser maps + */ + private void retrieveSIConsoleParsers() { + IExtensionPoint ep = MakeCorePlugin.getDefault().getDescriptor(). + getExtensionPoint(MakeCorePlugin.SI_CONSOLE_PARSER_SIMPLE_ID); + if (ep != null) { + IExtension[] extensions = ep.getExtensions(); + for (int i = 0; i < extensions.length; ++i) { + String parserId = extensions[i].getUniqueIdentifier(); + String label = extensions[i].getLabel(); + IConfigurationElement[] elements = extensions[i].getConfigurationElements(); + String commandId = elements[0].getAttribute("commandId"); //$NON-NLS-1$ + if (commandId.equals("makeBuilder") || commandId.equals("all")) { //$NON-NLS-1$//$NON-NLS-2$ + builderParsers.put(label, parserId); + } + if (commandId.equals("externalScannerInfoProvider") || commandId.equals("all")) { //$NON-NLS-1$//$NON-NLS-2$ + providerParsers.put(label, parserId); + } + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + */ + protected void configureShell(Shell newShell) { + newShell.setText(getTitle(DIALOG_TITLE)); + super.configureShell(newShell); + } + + /** + * @return MakeUIPlugin resource string + */ + private String getTitle(String title) { + return MakeUIPlugin.getResourceString(title); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + initializeDialogUnits(composite); + + // create message line + fStatusLine = new MessageLine(composite); + fStatusLine.setAlignment(SWT.LEFT); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); +// gd.widthHint = convertWidthInCharsToPixels(50); + fStatusLine.setLayoutData(gd); + fStatusLine.setMessage(getTitle(DIALOG_TITLE)); + + createBuildOutputParserControls(composite); + createAfterBuildCmdControls(composite); + // enable controls depending on the state of auto discovery + enableAllControls(); + + return composite; + } + + /** + * + */ + private void storeCurrentValues() { + + } + + private void createBuildOutputParserControls(Composite parent) { +// ControlFactory.insertSpace(parent, 1, 10); + Group bopGroup = ControlFactory.createGroup(parent, + MakeUIPlugin.getResourceString(SI_BUILD_PARSER_GROUP), 2); + ((GridLayout)bopGroup.getLayout()).marginHeight = 5; + ((GridLayout)bopGroup.getLayout()).marginWidth = 5; + ((GridData)bopGroup.getLayoutData()).verticalAlignment = GridData.FILL; + + enableBuilderParserButton = ControlFactory.createCheckBox(bopGroup, + MakeUIPlugin.getResourceString(ENABLE_SI_BUILD_PARSER)); + ((GridData)enableBuilderParserButton.getLayoutData()).horizontalSpan = 2; + boolean enabledBuilderParser = fBuildInfo.isMakeBuilderConsoleParserEnabled(); + enableBuilderParserButton.setSelection(enabledBuilderParser); + enableBuilderParserButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + makeBuilderSIParserComboBox.setEnabled(isBuilderParserEnabled()); + } + }); + + Label label = ControlFactory.createLabel(bopGroup, + MakeUIPlugin.getResourceString(SI_BUILD_PARSER_LABEL)); + ((GridData)label.getLayoutData()).grabExcessHorizontalSpace = false; + + makeBuilderSIParserComboBox = new Combo(bopGroup, SWT.DROP_DOWN | SWT.READ_ONLY); + + // fill the combobox and set the initial value + Iterator items = builderParsers.keySet().iterator(); + while (items.hasNext()) { + String parser = (String) items.next(); + makeBuilderSIParserComboBox.add(parser); + if (initialBuilderParserId.equals(builderParsers.get(parser))) { + makeBuilderSIParserComboBox.setText(parser); + } + } + makeBuilderSIParserComboBox.setEnabled(enabledBuilderParser); + } + + private void createAfterBuildCmdControls(Composite parent) { + Group abcGroup = ControlFactory.createGroup(parent, + MakeUIPlugin.getResourceString(SI_PROVIDER_CMD_GROUP), 2); + ((GridData)abcGroup.getLayoutData()).horizontalSpan = 2; + + enableProviderCommandButton = ControlFactory.createCheckBox(abcGroup, + MakeUIPlugin.getResourceString(ENABLE_SI_PROVIDER_COMMAND)); + ((GridData)enableProviderCommandButton.getLayoutData()).horizontalSpan = 2; + ((GridData)enableProviderCommandButton.getLayoutData()).horizontalAlignment = GridData.FILL_HORIZONTAL; + boolean enabledProviderCommand = fBuildInfo.isESIProviderCommandEnabled(); + enableProviderCommandButton.setSelection(enabledProviderCommand); + enableProviderCommandButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + defESIProviderCommandButton.setEnabled(isProviderCommandEnabled()); + esiProviderCommand.setEnabled(isProviderCommandEnabled() && !useDefaultESIProviderCmd()); + esiProviderParserComboBox.setEnabled(isProviderCommandEnabled()); + } + }); + + createESIProviderCmdControls(abcGroup); + + Label label = ControlFactory.createLabel(abcGroup, + MakeUIPlugin.getResourceString(SI_PROVIDER_PARSER_LABEL)); + ((GridData)label.getLayoutData()).grabExcessHorizontalSpace = false; + + esiProviderParserComboBox = new Combo(abcGroup, SWT.DROP_DOWN | SWT.READ_ONLY); + + // fill the combobox and set the initial value + Iterator items = providerParsers.keySet().iterator(); + while (items.hasNext()) { + String parser = (String) items.next(); + esiProviderParserComboBox.add(parser); + if (initialProviderParserId.equals(providerParsers.get(parser))) { + esiProviderParserComboBox.setText(parser); + } + } + defESIProviderCommandButton.setEnabled(enabledProviderCommand); + esiProviderCommand.setEnabled(enabledProviderCommand && !useDefaultESIProviderCmd()); + esiProviderParserComboBox.setEnabled(enabledProviderCommand); + } + + private void createESIProviderCmdControls(Composite parent) { + defESIProviderCommandButton = ControlFactory.createCheckBox(parent, + MakeUIPlugin.getResourceString(SI_PROVIDER_CMD_USE_DEFAULT)); + defESIProviderCommandButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + esiProviderCommand.setEnabled(!useDefaultESIProviderCmd()); + } + }); + ((GridData) (defESIProviderCommandButton.getLayoutData())).horizontalAlignment = GridData.FILL_HORIZONTAL; + ((GridData) (defESIProviderCommandButton.getLayoutData())).horizontalSpan = 2; + Label label = ControlFactory.createLabel(parent, + MakeUIPlugin.getResourceString(SI_PROVIDER_CMD_LABEL)); + ((GridData) (label.getLayoutData())).horizontalAlignment = GridData.BEGINNING; + ((GridData) (label.getLayoutData())).grabExcessHorizontalSpace = false; + esiProviderCommand = ControlFactory.createTextField(parent, SWT.SINGLE | SWT.BORDER); + ((GridData) (esiProviderCommand.getLayoutData())).horizontalAlignment = GridData.FILL; + ((GridData) (esiProviderCommand.getLayoutData())).grabExcessHorizontalSpace = true; + IPath sCommand = fBuildInfo.getESIProviderCommand(); + if (sCommand != null) { + StringBuffer cmd = new StringBuffer(sCommand.toOSString()); + String args = fBuildInfo.getESIProviderArguments(); + if (args != null && args.length() > 0) { + cmd.append(' '); + cmd.append(args); + } + esiProviderCommand.setText(cmd.toString()); + } + if (fBuildInfo.isDefaultESIProviderCmd()) { + esiProviderCommand.setEnabled(false); + } + esiProviderCommand.addListener(SWT.Modify, new Listener() { + public void handleEvent(Event e) { + handleProviderCommandModify(); + } + }); + defESIProviderCommandButton.setSelection(fBuildInfo.isDefaultESIProviderCmd()); + } + + /** + * + */ + protected void handleProviderCommandModify() { + String newCommand = esiProviderCommand.getText().trim(); + if (newCommand.length() == 0) { + fStatusLine.setErrorMessage(getTitle(SI_PROVIDER_CMD_ERROR_MESSAGE)); + getButton(IDialogConstants.OK_ID).setEnabled(false); + } + else { + fStatusLine.setErrorMessage(null); + getButton(IDialogConstants.OK_ID).setEnabled(true); + } + } + + /** + * @param enable + */ + private void enableAllControls() { + enableBuilderParserButton.setEnabled(true); + makeBuilderSIParserComboBox.setEnabled(isBuilderParserEnabled()); + enableProviderCommandButton.setEnabled(true); + defESIProviderCommandButton.setEnabled(isProviderCommandEnabled()); + esiProviderCommand.setEnabled(isProviderCommandEnabled() && !useDefaultESIProviderCmd()); + esiProviderParserComboBox.setEnabled(isProviderCommandEnabled()); + } + + private boolean useDefaultESIProviderCmd() { + return defESIProviderCommandButton.getSelection(); + } + + private String getSIProviderCommandLine() { + return esiProviderCommand.getText().trim(); + } + + private boolean isBuilderParserEnabled() { + return enableBuilderParserButton.getSelection(); + } + + private boolean isProviderCommandEnabled() { + return enableProviderCommandButton.getSelection(); + } + + /** + * Retrieves the state of scanner config discovery + * + * @return boolean + */ + public boolean isScannerConfigDiscoveryEnabled() { + return fBuildInfo.isAutoDiscoveryEnabled(); + } + + /** + * Enables or disables the scanner config discovery + * + * @param enabled (boolean) + */ + public void setScannerConfigDiscoveryEnabled(boolean enabled) { + try { + fBuildInfo.setAutoDiscoveryEnabled(enabled); + } + catch (CoreException e) { + } + } + + /** + * Called by BuildPathInfoBlock.performApply + * + * @param monitor + * @throws CoreException + */ + public void performApply(IProgressMonitor monitor) throws CoreException { + IProject project = fContainer.getProject(); + IScannerConfigBuilderInfo buildInfo; + if (project != null) { + buildInfo = MakeCorePlugin.createScannerConfigBuildInfo(project, ScannerConfigBuilder.BUILDER_ID); + } + else { + buildInfo = MakeCorePlugin.createScannerConfigBuildInfo(fPrefs, ScannerConfigBuilder.BUILDER_ID, false); + } + + buildInfo.setAutoDiscoveryEnabled(fBuildInfo.isAutoDiscoveryEnabled()); + if (fBuildInfo.isAutoDiscoveryEnabled()) { + buildInfo.setMakeBuilderConsoleParserEnabled(fBuildInfo.isMakeBuilderConsoleParserEnabled()); + if (fBuildInfo.isMakeBuilderConsoleParserEnabled()) { + buildInfo.setMakeBuilderConsoleParserId(fBuildInfo.getMakeBuilderConsoleParserId()); + } + buildInfo.setESIProviderCommandEnabled(fBuildInfo.isESIProviderCommandEnabled()); + if (fBuildInfo.isESIProviderCommandEnabled()) { + buildInfo.setUseDefaultESIProviderCmd(fBuildInfo.isDefaultESIProviderCmd()); + if (!fBuildInfo.isDefaultESIProviderCmd()) { + buildInfo.setESIProviderCommand(fBuildInfo.getESIProviderCommand()); + buildInfo.setESIProviderArguments(fBuildInfo.getESIProviderArguments()); + } + buildInfo.setESIProviderConsoleParserId(fBuildInfo.getESIProviderConsoleParserId()); + } + } + } + + /** + * @param buildInfo + * @throws CoreException + */ + private void storeSIProviderCommandLine(IScannerConfigBuilderInfo buildInfo) throws CoreException { + String esiProviderLine = getSIProviderCommandLine(); + int start = 0; + int end = -1; + if (esiProviderLine.startsWith("\"")) { //$NON-NLS-1$ + start = 1; + end = esiProviderLine.indexOf('"', 1); + } + else { + end = esiProviderLine.indexOf(' '); + } + IPath path; + if (end == -1) { + path = new Path(esiProviderLine); + } else { + path = new Path(esiProviderLine.substring(start, end)); + } + buildInfo.setESIProviderCommand(path); + String args = ""; //$NON-NLS-1$ + if (end != -1) { + args = esiProviderLine.substring(end + 1); + } + buildInfo.setESIProviderArguments(args); + } + + /** + * Called by BuildPathInfoBlock.performDefaults + */ + public void performDefaults() { + IScannerConfigBuilderInfo buildInfo; + // Populate with the default values + if (fContainer.getProject() != null) { + // get the preferences + buildInfo = MakeCorePlugin.createScannerConfigBuildInfo(fPrefs, ScannerConfigBuilder.BUILDER_ID, false); + } + else { + // get the defaults + buildInfo = MakeCorePlugin.createScannerConfigBuildInfo(fPrefs, ScannerConfigBuilder.BUILDER_ID, true); + } + + fBuildInfo = new LocalStore(buildInfo); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#okPressed() + */ + protected void okPressed() { + // Store UI values to the LocalStore + try { + fBuildInfo.setAutoDiscoveryEnabled(isScannerConfigDiscoveryEnabled()); + fBuildInfo.setMakeBuilderConsoleParserEnabled(isBuilderParserEnabled()); + fBuildInfo.setMakeBuilderConsoleParserId((String)builderParsers.get(makeBuilderSIParserComboBox.getText())); + fBuildInfo.setESIProviderCommandEnabled(isProviderCommandEnabled()); + fBuildInfo.setUseDefaultESIProviderCmd(useDefaultESIProviderCmd()); + storeSIProviderCommandLine(fBuildInfo); + fBuildInfo.setESIProviderConsoleParserId((String)providerParsers.get(esiProviderParserComboBox.getText())); + } catch (CoreException e) { + } + super.okPressed(); + } + + /** + * @return true if successfully initialized, false if not + */ + public boolean isInitialized() { + return fInitialized; + } +}
\ No newline at end of file diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/ScannerConfigPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/ScannerConfigPage.java deleted file mode 100644 index b25c1f06f49..00000000000 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/ScannerConfigPage.java +++ /dev/null @@ -1,482 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - **********************************************************************/ -package org.eclipse.cdt.make.ui.dialogs; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage; -import org.eclipse.cdt.ui.dialogs.ICOptionContainer; -import org.eclipse.cdt.utils.ui.controls.ControlFactory; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; -import org.eclipse.cdt.make.core.MakeCorePlugin; -import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo; -import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigBuilder; -import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature; -import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; - -/** - * Scanner Config settings page - * - * @author vhirsl - */ -public class ScannerConfigPage extends AbstractCOptionPage { - private static final String PREFIX = "ScannerConfigPage"; //$NON-NLS-1$ - private static final String LABEL = PREFIX + ".label"; //$NON-NLS-1$ - private static final String DESC = PREFIX + ".desc"; //$NON-NLS-1$ - private static final String ACTIVATE_AUTO_DISCOVERY = PREFIX + ".activate"; //$NON-NLS-1$ - private static final String SI_BUILD_PARSER_GROUP = PREFIX + ".siBuilder.parser.group_label"; //$NON-NLS-1$ - private static final String ENABLE_SI_BUILD_PARSER = PREFIX + ".siBuilder.parser.enable.label"; //$NON-NLS-1$ - private static final String SI_BUILD_PARSER_LABEL = PREFIX + ".siBuilder.parser.label"; //$NON-NLS-1$ - private static final String SI_PROVIDER_CMD_GROUP = PREFIX + ".siProvider.cmd.group_label"; //$NON-NLS-1$ - private static final String ENABLE_SI_PROVIDER_COMMAND = PREFIX + ".siProvider.cmd.enable.label"; //$NON-NLS-1$ - private static final String SI_PROVIDER_CMD_USE_DEFAULT = PREFIX + ".siProvider.cmd.use_default"; //$NON-NLS-1$ - private static final String SI_PROVIDER_CMD_LABEL = PREFIX + ".siProvider.cmd.label"; //$NON-NLS-1$ - private static final String SI_PROVIDER_PARSER_LABEL = PREFIX + ".siProvider.parser.label"; //$NON-NLS-1$ - private static final String SI_PROVIDER_CMD_ERROR_MESSAGE = PREFIX + ".siProvider.cmd.error_message"; //$NON-NLS-1$ - - private boolean addTitle = false; - - private Button autoDiscovery; - - private Button defESIProviderCommandButton; - private Text esiProviderCommand; - - private Button enableBuilderParserButton; - private Combo makeBuilderSIParserComboBox; - private Button enableProviderCommandButton; - private Combo esiProviderParserComboBox; - - private IScannerConfigBuilderInfo fBuildInfo; - private Map builderParsers = new HashMap(); - private String initialBuilderParserId = null; - private Map providerParsers = new HashMap(); - private String initialProviderParserId = null; - - /** - * Default constructor - */ - public ScannerConfigPage() { - super(MakeUIPlugin.getResourceString(LABEL)); - setDescription(MakeUIPlugin.getResourceString(DESC)); - } - - /** - * @param addTitle - */ - public ScannerConfigPage(boolean addTitle) { - this(); - this.addTitle = addTitle; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#isValid() - */ - public boolean isValid() { - if (!useDefaultESIProviderCmd()) { - String cmd = getSIProviderCommandLine(); - if (cmd == null || cmd.length() == 0) { - return false; - } - } - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#setContainer(org.eclipse.cdt.ui.dialogs.ICOptionContainer) - */ - public void setContainer(ICOptionContainer container) { - super.setContainer(container); - IProject project = container.getProject(); - if (project != null) { - try { - fBuildInfo = MakeCorePlugin.createScannerConfigBuildInfo(project, ScannerConfigBuilder.BUILDER_ID); - } - catch (CoreException e) { - fBuildInfo = MakeCorePlugin.createScannerConfigBuildInfo(container.getPreferences(), ScannerConfigBuilder.BUILDER_ID, true); - } - } - else { - fBuildInfo = MakeCorePlugin.createScannerConfigBuildInfo(container.getPreferences(), ScannerConfigBuilder.BUILDER_ID, false); - } - retrieveSIConsoleParsers(); - initialBuilderParserId = fBuildInfo.getMakeBuilderConsoleParserId(); //$NON-NLS-1$ - initialProviderParserId = fBuildInfo.getESIProviderConsoleParserId(); //$NON-NLS-1$ - } - - /** - * Fills console parser maps - */ - private void retrieveSIConsoleParsers() { - IExtensionPoint ep = MakeCorePlugin.getDefault().getDescriptor(). - getExtensionPoint(MakeCorePlugin.SI_CONSOLE_PARSER_SIMPLE_ID); - if (ep != null) { - IExtension[] extensions = ep.getExtensions(); - for (int i = 0; i < extensions.length; ++i) { - String parserId = extensions[i].getUniqueIdentifier(); - String label = extensions[i].getLabel(); - IConfigurationElement[] elements = (IConfigurationElement[]) extensions[i].getConfigurationElements(); - String commandId = elements[0].getAttribute("commandId"); //$NON-NLS-1$ - if (commandId.equals("makeBuilder") || commandId.equals("all")) { //$NON-NLS-1$//$NON-NLS-2$ - builderParsers.put(label, parserId); - } - if (commandId.equals("externalScannerInfoProvider") || commandId.equals("all")) { //$NON-NLS-1$//$NON-NLS-2$ - providerParsers.put(label, parserId); - } - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt..dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor) - */ - public void performApply(IProgressMonitor monitor) throws CoreException { - // install/deinstall the scanner configuration builder - IProject project = getContainer().getProject(); - IScannerConfigBuilderInfo buildInfo; - if (project != null) { - if (autoDiscovery.getSelection()) { - ScannerConfigNature.addScannerConfigNature(project); - buildInfo = MakeCorePlugin.createScannerConfigBuildInfo(project, ScannerConfigBuilder.BUILDER_ID); - buildInfo.setAutoDiscoveryEnabled(autoDiscovery.getSelection()); - } - else { - ScannerConfigNature.removeScannerConfigNature(project); - return; - } - } - else { - buildInfo = MakeCorePlugin.createScannerConfigBuildInfo(getContainer().getPreferences(), ScannerConfigBuilder.BUILDER_ID, false); - buildInfo.setAutoDiscoveryEnabled(autoDiscovery.getSelection()); - } - - buildInfo.setMakeBuilderConsoleParserEnabled(enableBuilderParser()); - if (enableBuilderParser()) { - buildInfo.setMakeBuilderConsoleParserId( - (String)builderParsers.get(makeBuilderSIParserComboBox.getText())); - } - - buildInfo.setESIProviderCommandEnabled(enableProviderCommand()); - if (enableProviderCommand()) { - buildInfo.setUseDefaultESIProviderCmd(useDefaultESIProviderCmd()); - if (!useDefaultESIProviderCmd()) { - String esiProviderLine = getSIProviderCommandLine(); - int start = 0; - int end = -1; - if (esiProviderLine.startsWith("\"")) { //$NON-NLS-1$ - start = 1; - end = esiProviderLine.indexOf('"', 1); - } - else { - end = esiProviderLine.indexOf(' '); - } - IPath path; - if (end == -1) { - path = new Path(esiProviderLine); - } else { - path = new Path(esiProviderLine.substring(start, end)); - } - buildInfo.setESIProviderCommand(path); - String args = ""; //$NON-NLS-1$ - if (end != -1) { - args = esiProviderLine.substring(end + 1); - } - buildInfo.setESIProviderArguments(args); - } - buildInfo.setESIProviderConsoleParserId( - (String)providerParsers.get(esiProviderParserComboBox.getText())); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults() - */ - public void performDefaults() { - IScannerConfigBuilderInfo buildInfo; - // Populate with the default value - if (getContainer().getProject() != null) { - // get the preferences - buildInfo = MakeCorePlugin.createScannerConfigBuildInfo(getContainer().getPreferences(), - ScannerConfigBuilder.BUILDER_ID, false); - } - else { - // get the defaults - buildInfo = MakeCorePlugin.createScannerConfigBuildInfo(getContainer().getPreferences(), - ScannerConfigBuilder.BUILDER_ID, true); - } - - autoDiscovery.setSelection(buildInfo.isAutoDiscoveryEnabled()); - - enableBuilderParserButton.setSelection(buildInfo.isMakeBuilderConsoleParserEnabled()); - String builderParserId = buildInfo.getMakeBuilderConsoleParserId(); - for (Iterator i = builderParsers.keySet().iterator(); i.hasNext(); ) { - String builderParser = (String) i.next(); - if (builderParserId.equals((String) builderParsers.get(builderParser))) { - makeBuilderSIParserComboBox.setText(builderParser); - } - } - - enableProviderCommandButton.setSelection(buildInfo.isESIProviderCommandEnabled()); - defESIProviderCommandButton.setSelection(buildInfo.isDefaultESIProviderCmd()); - IPath sCommand = fBuildInfo.getESIProviderCommand(); - if (sCommand != null) { - StringBuffer cmd = new StringBuffer(sCommand.toOSString()); - String args = buildInfo.getESIProviderArguments(); - if (args != null && !args.equals("")) { //$NON-NLS-1$ - cmd.append(' '); - cmd.append(args); - } - esiProviderCommand.setText(cmd.toString()); - } - enableProviderCommandButton.setSelection(buildInfo.isESIProviderCommandEnabled()); - String providerParserId = buildInfo.getESIProviderConsoleParserId(); - for (Iterator i = providerParsers.keySet().iterator(); i.hasNext(); ) { - String providerParser = (String) i.next(); - if (providerParserId.equals((String) providerParsers.get(providerParser))) { - esiProviderParserComboBox.setText(providerParser); - } - } - // enable controls according to Auto Discovery button selection - enableAllControls(enableAutoDiscovery()); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) - */ - public void createControl(Composite parent) { - Composite composite = ControlFactory.createComposite(parent, 1); - setControl(composite); - - if (addTitle) { - addTitle(composite); - } - addSCDiscoveryState(composite); - addSeparator(composite); - createBuildOutputParserControls(composite); - createAfterBuildCmdControls(composite); - // enable controls depending on the state of auto discovery - enableAllControls(enableAutoDiscovery()); - } - - private void addTitle(Composite composite) { - //Label for dialog title - Label pathLabel = ControlFactory.createLabel(composite, - MakeUIPlugin.getResourceString(DESC)); - } - - private void addSCDiscoveryState(Composite parent) { - //Checkbox for enabling the discovery - ControlFactory.insertSpace(parent, 1, 10); - autoDiscovery = ControlFactory.createCheckBox(parent, - MakeUIPlugin.getResourceString(ACTIVATE_AUTO_DISCOVERY)); - autoDiscovery.setSelection(fBuildInfo.isAutoDiscoveryEnabled()); - autoDiscovery.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - enableAllControls(enableAutoDiscovery()); - getContainer().updateContainer(); - } - }); - } - - /** - * @param enable - */ - private void enableAllControls(boolean enable) { - enableBuilderParserButton.setEnabled(enable); - makeBuilderSIParserComboBox.setEnabled(enable && enableBuilderParser()); - enableProviderCommandButton.setEnabled(enable); - defESIProviderCommandButton.setEnabled(enable && enableProviderCommand()); - esiProviderCommand.setEnabled(enable && enableProviderCommand() && !useDefaultESIProviderCmd()); - esiProviderParserComboBox.setEnabled(enable && enableProviderCommand()); - } - - private void addSeparator(Composite parent) { - Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - separator.setLayoutData(gridData); - } - - private void createBuildOutputParserControls(Composite parent) { -// ControlFactory.insertSpace(parent, 1, 10); - Group bopGroup = ControlFactory.createGroup(parent, - MakeUIPlugin.getResourceString(SI_BUILD_PARSER_GROUP), 2); - ((GridLayout)bopGroup.getLayout()).marginHeight = 5; - ((GridLayout)bopGroup.getLayout()).marginWidth = 5; - ((GridData)bopGroup.getLayoutData()).verticalAlignment = GridData.FILL; - - enableBuilderParserButton = ControlFactory.createCheckBox(bopGroup, - MakeUIPlugin.getResourceString(ENABLE_SI_BUILD_PARSER)); - ((GridData)enableBuilderParserButton.getLayoutData()).horizontalSpan = 2; - boolean enabledBuilderParser = fBuildInfo.isMakeBuilderConsoleParserEnabled(); - enableBuilderParserButton.setSelection(enabledBuilderParser); - enableBuilderParserButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - makeBuilderSIParserComboBox.setEnabled(enableBuilderParser()); - getContainer().updateContainer(); - } - }); - - Label label = ControlFactory.createLabel(bopGroup, - MakeUIPlugin.getResourceString(SI_BUILD_PARSER_LABEL)); - ((GridData)label.getLayoutData()).grabExcessHorizontalSpace = false; - - makeBuilderSIParserComboBox = new Combo(bopGroup, SWT.DROP_DOWN | SWT.READ_ONLY); - - // fill the combobox and set the initial value - Iterator items = builderParsers.keySet().iterator(); - while (items.hasNext()) { - String parser = (String) items.next(); - makeBuilderSIParserComboBox.add(parser); - if (initialBuilderParserId.equals(builderParsers.get(parser))) { - makeBuilderSIParserComboBox.setText(parser); - } - } - makeBuilderSIParserComboBox.setEnabled(enabledBuilderParser); - } - - private void createAfterBuildCmdControls(Composite parent) { - Group abcGroup = ControlFactory.createGroup(parent, - MakeUIPlugin.getResourceString(SI_PROVIDER_CMD_GROUP), 2); - ((GridData)abcGroup.getLayoutData()).horizontalSpan = 2; - - enableProviderCommandButton = ControlFactory.createCheckBox(abcGroup, - MakeUIPlugin.getResourceString(ENABLE_SI_PROVIDER_COMMAND)); - ((GridData)enableProviderCommandButton.getLayoutData()).horizontalSpan = 2; - ((GridData)enableProviderCommandButton.getLayoutData()).horizontalAlignment = GridData.FILL_HORIZONTAL; - boolean enabledProviderCommand = fBuildInfo.isESIProviderCommandEnabled(); - enableProviderCommandButton.setSelection(enabledProviderCommand); - enableProviderCommandButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - defESIProviderCommandButton.setEnabled(enableProviderCommand()); - esiProviderCommand.setEnabled(enableProviderCommand() && !useDefaultESIProviderCmd()); - esiProviderParserComboBox.setEnabled(enableProviderCommand()); - getContainer().updateContainer(); - } - }); - - createESIProviderCmdControls(abcGroup); - - Label label = ControlFactory.createLabel(abcGroup, - MakeUIPlugin.getResourceString(SI_PROVIDER_PARSER_LABEL)); - ((GridData)label.getLayoutData()).grabExcessHorizontalSpace = false; - - esiProviderParserComboBox = new Combo(abcGroup, SWT.DROP_DOWN | SWT.READ_ONLY); - - // fill the combobox and set the initial value - Iterator items = providerParsers.keySet().iterator(); - while (items.hasNext()) { - String parser = (String) items.next(); - esiProviderParserComboBox.add(parser); - if (initialProviderParserId.equals(providerParsers.get(parser))) { - esiProviderParserComboBox.setText(parser); - } - } - defESIProviderCommandButton.setEnabled(enabledProviderCommand); - esiProviderCommand.setEnabled(enabledProviderCommand && !useDefaultESIProviderCmd()); - esiProviderParserComboBox.setEnabled(enabledProviderCommand); - } - - private void createESIProviderCmdControls(Composite parent) { - defESIProviderCommandButton = ControlFactory.createCheckBox(parent, - MakeUIPlugin.getResourceString(SI_PROVIDER_CMD_USE_DEFAULT)); - defESIProviderCommandButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - esiProviderCommand.setEnabled(!useDefaultESIProviderCmd()); - getContainer().updateContainer(); - } - }); - ((GridData) (defESIProviderCommandButton.getLayoutData())).horizontalAlignment = GridData.FILL_HORIZONTAL; - ((GridData) (defESIProviderCommandButton.getLayoutData())).horizontalSpan = 2; - Label label = ControlFactory.createLabel(parent, - MakeUIPlugin.getResourceString(SI_PROVIDER_CMD_LABEL)); - ((GridData) (label.getLayoutData())).horizontalAlignment = GridData.BEGINNING; - ((GridData) (label.getLayoutData())).grabExcessHorizontalSpace = false; - esiProviderCommand = ControlFactory.createTextField(parent, SWT.SINGLE | SWT.BORDER); - ((GridData) (esiProviderCommand.getLayoutData())).horizontalAlignment = GridData.FILL; - ((GridData) (esiProviderCommand.getLayoutData())).grabExcessHorizontalSpace = true; - esiProviderCommand.addListener(SWT.Modify, new Listener() { - public void handleEvent(Event e) { - getContainer().updateContainer(); - } - }); - IPath sCommand = fBuildInfo.getESIProviderCommand(); - if (sCommand != null) { - StringBuffer cmd = new StringBuffer(sCommand.toOSString()); - String args = fBuildInfo.getESIProviderArguments(); - if (args != null && args.length() > 0) { - cmd.append(' '); - cmd.append(args); - } - esiProviderCommand.setText(cmd.toString()); - } - if (fBuildInfo.isDefaultESIProviderCmd()) { - esiProviderCommand.setEnabled(false); - } - defESIProviderCommandButton.setSelection(fBuildInfo.isDefaultESIProviderCmd()); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.IDialogPage#getErrorMessage() - */ - public String getErrorMessage() { - if (!useDefaultESIProviderCmd()) { - String cmd = getSIProviderCommandLine(); - if (cmd == null || cmd.length() == 0) { - return MakeUIPlugin.getResourceString(SI_PROVIDER_CMD_ERROR_MESSAGE); -// return "Must enter a 'generate scanner info' command"; //$NON-NLS-1$ - } - } - return super.getErrorMessage(); - } - - private boolean enableAutoDiscovery() { - return autoDiscovery.getSelection(); - } - - private boolean useDefaultESIProviderCmd() { - return defESIProviderCommandButton.getSelection(); - } - - private String getSIProviderCommandLine() { - return esiProviderCommand.getText().trim(); - } - - private boolean enableBuilderParser() { - return enableBuilderParserButton.getSelection(); - } - - private boolean enableProviderCommand() { - return enableProviderCommandButton.getSelection(); - } -}
\ No newline at end of file diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/ConvertToMakeProjectWizardPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/ConvertToMakeProjectWizardPage.java index 2bff5329fad..2646d754c53 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/ConvertToMakeProjectWizardPage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/ConvertToMakeProjectWizardPage.java @@ -7,6 +7,7 @@ package org.eclipse.cdt.make.ui.wizards; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.make.core.MakeProjectNature; +import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.cdt.ui.wizards.conversion.ConvertProjectWizardPage; import org.eclipse.core.resources.IProject; @@ -78,6 +79,7 @@ public class ConvertToMakeProjectWizardPage extends ConvertProjectWizardPage { try { super.convertProject(project, new SubProgressMonitor(monitor, 1), projectID); MakeProjectNature.addNature(project, new SubProgressMonitor(monitor, 1)); + ScannerConfigNature.addScannerConfigNature(project); CCorePlugin.getDefault().mapCProjectOwner(project, projectID, true); } finally { monitor.done(); diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/MakeProjectWizardOptionPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/MakeProjectWizardOptionPage.java index 8a9fbcaec0a..44a18a49dd6 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/MakeProjectWizardOptionPage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/MakeProjectWizardOptionPage.java @@ -7,7 +7,6 @@ package org.eclipse.cdt.make.ui.wizards; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.internal.ui.MakeProjectOptionBlock; -import org.eclipse.cdt.make.ui.dialogs.ScannerConfigPage; import org.eclipse.cdt.ui.dialogs.ICOptionContainer; import org.eclipse.cdt.ui.dialogs.ReferenceBlock; import org.eclipse.cdt.ui.dialogs.TabFolderOptionBlock; @@ -41,7 +40,6 @@ public class MakeProjectWizardOptionPage extends NewCProjectWizardOptionPage { protected void addTabs() { addTab(new ReferenceBlock()); super.addTabs(); - addTab(new ScannerConfigPage()); } } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/NewMakeProjectWizard.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/NewMakeProjectWizard.java index 66b2758952c..a6b44de723d 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/NewMakeProjectWizard.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/NewMakeProjectWizard.java @@ -7,6 +7,7 @@ package org.eclipse.cdt.make.ui.wizards; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.core.MakeProjectNature; +import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.cdt.ui.wizards.NewCProjectWizard; import org.eclipse.core.runtime.CoreException; @@ -40,6 +41,7 @@ public abstract class NewMakeProjectWizard extends NewCProjectWizard { super.doRun(new SubProgressMonitor(monitor, 5)); MakeProjectNature.addNature(getProjectHandle(), new SubProgressMonitor(monitor, 1)); + ScannerConfigNature.addScannerConfigNature(getProjectHandle()); // Modify the project based on what the user has selected if (newProject != null) { |