[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] CDT2.0 Scanner Configuration discovery - initial work
|
This patch contains initial work for Scanner Configuration discovery
feature. Also there is a simple UI interface. The feature is disabled by
default so it does not harm existing projects. If turned on, it will
populate C/C++ Make Project's Paths and Symbols tab with discovered info.
The discovered include paths are in their original form and may be
unusable by scanner. Further refinements are coming along.
Please, apply to the head branch.
Thanks,
Vladimir Hirsl
Rational Software - IBM Software Group
Ottawa, Ontario, Canada
Index: plugin.properties
===================================================================
retrieving revision 1.2
diff -u -r1.2 plugin.properties
--- plugin.properties 19 Aug 2003 20:17:28 -0000 1.2
+++ plugin.properties 9 Feb 2004 22:03:28 -0000
@@ -3,4 +3,13 @@
extensionTargetBuilder.name=Target Builder Extension
natureMake.name=CDT Make Nature
-builderMake.name=CDT Makefile Builder
\ No newline at end of file
+builderMake.name=CDT Makefile Builder
+
+natureScannerConfig.name=Scanner Configuration Nature
+builderScannerConfig.name=Scanner Configuration Builder
+extensionSpecsBuilder.name=C/C++ Compiler Specs Builder Extension
+specsBuilder.name=Specs Builder
+
+epGnuCommandLine.name=CDT GNU C/C++ Scanner Info Parser
+epGnuCompilerSpecs.name=CDT GNU C/C++ Specs Parser
+spGnuSpecsBuilder.name=CDT GNU C/C++ Specs Builder
Index: plugin.xml
===================================================================
retrieving revision 1.11
diff -u -r1.11 plugin.xml
--- plugin.xml 5 Jan 2004 20:26:09 -0000 1.11
+++ plugin.xml 9 Feb 2004 22:03:28 -0000
@@ -21,6 +21,7 @@
<extension-point id="MakeTargetBuilder" name="%extensionTargetBuilder.name" schema="schema/MakeTargetBuilder.exsd"/>
+ <extension-point id="SpecsBuilder" name="%extensionSpecsBuilder.name" schema="schema/SpecsBuilder.exsd"/>
<extension
id="MakeScannerProvider"
@@ -75,6 +76,64 @@
<builder
builderID="org.eclipse.cdt.make.core.makeBuilder"
id="org.eclipse.cdt.make.MakeTargetBuilder">
+ </builder>
+ </extension>
+ <extension
+ id="GCCCommandLineParser"
+ name="%epGnuCommandLine.name"
+ point="org.eclipse.cdt.core.ErrorParser">
+ <errorparser
+ class="org.eclipse.cdt.make.core.scannerconfig.gnu.GCCScannerInfoParser">
+ </errorparser>
+ </extension>
+ <extension
+ id="GCCSpecsParser"
+ name="%epGnuCompilerSpecs.name"
+ point="org.eclipse.cdt.core.ErrorParser">
+ <errorparser
+ class="org.eclipse.cdt.make.core.scannerconfig.gnu.GCCCompilerSpecsParser">
+ </errorparser>
+ </extension>
+ <extension
+ point="org.eclipse.cdt.make.core.SpecsBuilder">
+ <specsbuilder
+ name="%spGnuSpecsBuilder.name"
+ class="org.eclipse.cdt.make.core.scannerconfig.gnu.GCCSpecsBuilder"
+ id="org.eclipse.cdt.make.core.GCCSpecsBuilder">
+ </specsbuilder>
+ </extension>
+ <extension
+ id="ScannerConfigNature"
+ name="%natureScannerConfig.name"
+ point="org.eclipse.core.resources.natures">
+ <requires-nature
+ id="org.eclipse.cdt.make.core.makeNature">
+ </requires-nature>
+ <runtime>
+ <run
+ class="org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature">
+ </run>
+ </runtime>
+ <builder
+ id="org.eclipse.cdt.make.core.ScannerConfigBuilder">
+ </builder>
+ </extension>
+ <extension
+ id="ScannerConfigBuilder"
+ name="%builderScannerConfig.name"
+ point="org.eclipse.core.resources.builders">
+ <builder
+ hasNature="true">
+ <run
+ class="org.eclipse.cdt.make.core.scannerconfig.ScannerConfigBuilder">
+ </run>
+ </builder>
+ </extension>
+ <extension
+ point="org.eclipse.cdt.make.core.MakeTargetBuilder">
+ <builder
+ builderID="org.eclipse.cdt.make.core.scannerconfig.ScannerConfigBuilder"
+ id="org.eclipse.cdt.make.core.scannerconfig.ScannerConfigTargetBuilder">
</builder>
</extension>
Index: src/org/eclipse/cdt/make/core/MakeCorePlugin.java
===================================================================
retrieving revision 1.11
diff -u -r1.11 MakeCorePlugin.java
--- src/org/eclipse/cdt/make/core/MakeCorePlugin.java 24 Sep 2003 18:03:36 -0000 1.11
+++ src/org/eclipse/cdt/make/core/MakeCorePlugin.java 9 Feb 2004 22:03:29 -0000
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2002,2003 QNX Software Systems and others.
+ * Copyright (c) 2002,2004 QNX Software Systems 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
@@ -10,6 +10,8 @@
***********************************************************************/
package org.eclipse.cdt.make.core;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
@@ -19,13 +21,21 @@
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.make.core.makefile.IMakefile;
+import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo;
+import org.eclipse.cdt.make.core.scannerconfig.ISpecsBuilder;
+import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigBuilder;
import org.eclipse.cdt.make.internal.core.BuildInfoFactory;
import org.eclipse.cdt.make.internal.core.MakeTargetManager;
import org.eclipse.cdt.make.internal.core.makefile.gnu.GNUMakefile;
+import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerConfigInfoFactory;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
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.IPluginDescriptor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
@@ -40,6 +50,14 @@
public static final String MAKE_PROJECT_ID = MakeCorePlugin.getUniqueIdentifier() + ".make";
private MakeTargetManager fTargetManager;
public static final String OLD_BUILDER_ID = "org.eclipse.cdt.core.cbuilder"; //$NON-NLS-1$
+
+ private static final String SPECS_BUILDER_SIMPLE_ID = "SpecsBuilder"; //$NON-NLS-1$
+ private static final String ID_ATTR = "id"; //$NON-NLS-1$
+ public static final String GCC_SPECS_BUILDER_ID = MakeCorePlugin.getUniqueIdentifier() + ".GCCSpecsBuilder"; //$NON-NLS-1$
+
+ public static final String CPP_SPECS_FILE = "specs.cpp"; //$NON-NLS-1$
+ public static final String C_SPECS_FILE = "specs.c"; //$NON-NLS-1$
+
//The shared instance.
private static MakeCorePlugin plugin;
//Resource bundle.
@@ -56,6 +74,7 @@
} catch (MissingResourceException x) {
resourceBundle = null;
}
+ createSpecs();
}
/**
@@ -131,6 +150,13 @@
} catch (CoreException e) {
}
getPluginPreferences().setDefault(CCorePlugin.PREF_BINARY_PARSER, CCorePlugin.PLUGIN_ID + ".ELF"); //$NON-NLS-1$
+
+ // default plugin preferences for scanner configuration discovery
+ IScannerConfigBuilderInfo scInfo = createScannerConfigBuildInfo(getPluginPreferences(), ScannerConfigBuilder.BUILDER_ID, true);
+ try {
+ scInfo.setAutoDiscoveryEnabled(false);
+ } catch (CoreException e) {
+ }
}
public static IMakeBuilderInfo createBuildInfo(Preferences prefs, String builderID, boolean useDefaults) {
@@ -177,6 +203,82 @@
fTargetManager.shutdown();
fTargetManager = null;
}
+ }
+
+ /*
+ * Following methods create IScannerConfigBuilderInfo
+ * Delegating requests to ScannerConfigInfoFactory
+ */
+ public static IScannerConfigBuilderInfo createScannerConfigBuildInfo(
+ Preferences prefs, String builderID, boolean useDefaults) {
+ return ScannerConfigInfoFactory.create(prefs, builderID, useDefaults);
+ }
+
+ public static IScannerConfigBuilderInfo createScannerConfigBuildInfo(
+ IProject project, String builderID) throws CoreException {
+ return ScannerConfigInfoFactory.create(project, builderID);
+ }
+
+ public static IScannerConfigBuilderInfo createScannerConfigBuildInfo(
+ Map args, String builderID) {
+ return ScannerConfigInfoFactory.create(args, builderID);
+ }
+
+ public static IPath getWorkingDirectory() {
+ return MakeCorePlugin.getDefault().getStateLocation();
+ }
+
+ private void createSpecs() {
+ IPath path = getWorkingDirectory();
+ try {
+ createSpecsFile(path, CPP_SPECS_FILE);
+ createSpecsFile(path, C_SPECS_FILE);
+ } catch (CoreException e) {
+ log(e);
+ }
+ }
+
+ private void createSpecsFile(IPath path, String fileName) throws CoreException {
+ IPath specs = path.append(fileName);
+ File specsFile = specs.toFile();
+ if (!specsFile.exists()) {
+ try {
+ FileOutputStream file = new FileOutputStream(specsFile);
+ file.write('\n');
+ file.close();
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ MakeCorePlugin.getDefault().getDescriptor().getUniqueIdentifier(),
+ -1, "Error writing specs file", e));
+ }
+ }
+ }
+
+ /**
+ * @param toolset - id specifying compiler toolset i.e. GCC
+ * @return builder - new instance of a 'specs' builder
+ */
+ public ISpecsBuilder loadSpecsBuilder(String id) {
+ ISpecsBuilder[] empty = new ISpecsBuilder[0];
+ try {
+ IExtensionPoint extension = getDescriptor().getExtensionPoint(SPECS_BUILDER_SIMPLE_ID);
+ if (extension != null) {
+ IExtension[] extensions = extension.getExtensions();
+ for (int i = 0; i < extensions.length; i++) {
+ IConfigurationElement[] configElements = extensions[i]. getConfigurationElements();
+ for (int j = 0; j < configElements.length; j++) {
+ String tool = configElements[j].getAttribute(ID_ATTR);
+ if (tool != null && tool.equals((id))) {
+ ISpecsBuilder builder = (ISpecsBuilder) configElements[j].createExecutableExtension("class");
+ return builder;
+ }
+ }
+ }
+ }
+ } catch (CoreException e) {
+ log(e);
+ }
+ return null;
}
}
Index: src/org/eclipse/cdt/make/core/PluginResources.properties
===================================================================
retrieving revision 1.4
diff -u -r1.4 PluginResources.properties
--- src/org/eclipse/cdt/make/core/PluginResources.properties 24 Sep 2003 14:20:21 -0000 1.4
+++ src/org/eclipse/cdt/make/core/PluginResources.properties 9 Feb 2004 22:03:29 -0000
@@ -11,3 +11,13 @@
MakeTargetProvider.add_temporary_target=Cannot add temporart Target to manager.
MakeTargetProvider.target_exists=Target exists
MakeTargetProvider.failed_initializing_targets=Failed initializing build targets
+
+ScannerConfigBuilder.Invoking_Builder=Scanner Configuration update ...
+SpecsBuilder.Reading_Specs=Reading specs ...
+SpecsBuilder.Parsing_Output=Parsing output...
+
+ScannerInfoCollector.Processing=Processing discovered scanner configuration ...
+ScannerInfoCollector.Updating=Updating Scanner Configuration for project
+
Index: schema/SpecsBuilder.exsd
===================================================================
RCS file: schema/SpecsBuilder.exsd
diff -N schema/SpecsBuilder.exsd
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ schema/SpecsBuilder.exsd 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,116 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.vmir.cdt.scannerconfig">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.vmir.cdt.scannerconfig" id="SpecsBuilders" name="C/C++ Compiler Specs Builder"/>
+ </appInfo>
+ <documentation>
+ This extension point is used to plug in particular compiler specs builder.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="specsbuilder" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="specsbuilder">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ A fully qualified name of the Java class that implements <samp>org.vmir.cdt.scannerconfig.core.ISpecsBuilder</samp> interface.
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.vmir.cdt.scannerconfig.core.ISpecsBuilder"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ A unique id of this specs builder.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ An optional name of this specs builder.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ Plug-ins that want to extend this extension point must implement <samp>org.vmir.cdt.scannerconfig.core.ISpecsBuilder</samp> interface or extend <samp>org.vmir.cdt.scannerconfig.core.ASpecsBuilder</samp> abstract base class.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ org.vmir.cdt.scannerconfig plugin provides default implementation of the GNU C/C++ compiler specs builder.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
Index: src/org/eclipse/cdt/make/core/scannerconfig/IScannerConfigBuilderInfo.java
===================================================================
RCS file: src/org/eclipse/cdt/make/core/scannerconfig/IScannerConfigBuilderInfo.java
diff -N src/org/eclipse/cdt/make/core/scannerconfig/IScannerConfigBuilderInfo.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/make/core/scannerconfig/IScannerConfigBuilderInfo.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,24 @@
+/**********************************************************************
+ * 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 org.eclipse.core.runtime.CoreException;
+
+/**
+ * Settings for ScannerConfigBuilder
+ *
+ * @author vhirsl
+ */
+public interface IScannerConfigBuilderInfo {
+ boolean isAutoDiscoveryEnabled();
+ void setAutoDiscoveryEnabled(boolean enabled) throws CoreException;
+}
Index: src/org/eclipse/cdt/make/core/scannerconfig/ISpecsBuilder.java
===================================================================
RCS file: src/org/eclipse/cdt/make/core/scannerconfig/ISpecsBuilder.java
diff -N src/org/eclipse/cdt/make/core/scannerconfig/ISpecsBuilder.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/make/core/scannerconfig/ISpecsBuilder.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,38 @@
+/**********************************************************************
+ * 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 org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * Interface for C/++ specs builders
+ *
+ * @author vhirsl
+ */
+public interface ISpecsBuilder {
+ /**
+ * Initializes specs builder
+ *
+ * @param workingDirectory - where the compiler will be invoked
+ * @param current project - current project being built
+ */
+ public void initialize(IPath workingDirectory, IProject currentProject);
+ /**
+ * Invokes a C/C++ compiler with target specific options to generate
+ * compiler specs.
+ *
+ * @param monitor
+ * @param targetSpecificOptions - array of options affecting compiler specs
+ */
+ public boolean invokeCompiler(IProgressMonitor monitor, String[] targetSpecificOptions);
+}
Index: src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigBuilder.java
===================================================================
RCS file: src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigBuilder.java
diff -N src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigBuilder.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigBuilder.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,45 @@
+/**********************************************************************
+ * 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 org.eclipse.cdt.core.resources.ACBuilder;
+import org.eclipse.cdt.make.core.MakeCorePlugin;
+import org.eclipse.core.resources.IProject;
+import java.util.Map;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.SubProgressMonitor;
+
+/**
+ * Runs after standard make builder.
+ * Consolidates discovered scanner configuration and updates project's scanner configuration.
+ *
+ * @see IncrementalProjectBuilder
+ */
+public class ScannerConfigBuilder extends ACBuilder {
+ public final static String BUILDER_ID = MakeCorePlugin.getUniqueIdentifier() + ".ScannerConfigBuilder"; //$NON-NLS-1$
+ /**
+ * TODO: Implement the "ScannerConfigBuilder" constructor.
+ */
+ public ScannerConfigBuilder() {
+ }
+
+ /**
+ * TODO: Implement "build".
+ * @see IncrementalProjectBuilder#build
+ */
+ protected IProject [] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
+ monitor.beginTask("", 100); //$NON-NLS-1$
+ monitor.subTask(MakeCorePlugin.getResourceString("ScannerConfigBuilder.Invoking_Builder") + getProject().getName());
+ ScannerInfoCollector.getInstance().updateScannerConfiguration(getProject(), new SubProgressMonitor(monitor, 100));
+ return getProject().getReferencedProjects();
+ }
+}
Index: src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigNature.java
===================================================================
RCS file: src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigNature.java
diff -N src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigNature.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/make/core/scannerconfig/ScannerConfigNature.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,131 @@
+/**********************************************************************
+ * 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 org.eclipse.cdt.make.core.MakeCorePlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IProjectNature;
+
+/**
+ * @see IProjectNature
+ */
+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
+ */
+ public void configure() throws CoreException {
+ IProjectDescription description = getProject().getDescription();
+ ICommand[] commands = description.getBuildSpec();
+ for (int i = 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(ScannerConfigBuilder.BUILDER_ID)) {
+ return;
+ }
+ }
+ ICommand command = description.newCommand();
+ command.setBuilderName(ScannerConfigBuilder.BUILDER_ID);
+ ICommand[] newCommands = new ICommand[commands.length + 1];
+ System.arraycopy(commands, 0, newCommands, 0, commands.length);
+ newCommands[commands.length] = command;
+ description.setBuildSpec(newCommands);
+ getProject().setDescription(description, null);
+ }
+
+ /**
+ * @see IProjectNature#deconfigure
+ */
+ public void deconfigure() throws CoreException {
+ IProjectDescription description = getProject().getDescription();
+ ICommand[] commands = description.getBuildSpec();
+ for (int i = 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(ScannerConfigBuilder.BUILDER_ID)) {
+ ICommand[] newCommands = new ICommand[commands.length - 1];
+ System.arraycopy(commands, 0, newCommands, 0, i);
+ System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
+ description.setBuildSpec(newCommands);
+ break;
+ }
+ }
+ getProject().setDescription(description, null);
+ }
+
+ /**
+ * @see IProjectNature#getProject
+ */
+ public IProject getProject() {
+ return fProject;
+ }
+
+ /**
+ * @see IProjectNature#setProject
+ */
+ public void setProject(IProject project) {
+ fProject = project;
+ }
+
+ static public void addScannerConfigNature(IProject project) throws CoreException {
+ if (project.hasNature(NATURE_ID))
+ return;
+
+ IProjectDescription description = project.getDescription();
+ 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);
+ }
+
+ static public void removeScannerConfigNature(IProject project) throws CoreException {
+ IProjectDescription description = project.getDescription();
+ String[] ids = description.getNatureIds();
+ for (int i = 0; i < ids.length; ++i) {
+ if (ids[i].equals(NATURE_ID)) {
+ String[] newIds = new String[ids.length - 1];
+ System.arraycopy(ids, 0, newIds, 0, i);
+ System.arraycopy(ids, i + 1, newIds, i, ids.length - i - 1);
+ description.setNatureIds(newIds);
+ project.setDescription(description, null);
+ }
+ }
+ }
+
+ /**
+ * Returns build command as stored in .project file
+ *
+ * @param project
+ * @param builderID
+ * @return ICommand
+ * @throws CoreException
+ */
+ public static ICommand getBuildSpec(IProject project, String builderID) throws CoreException {
+ IProjectDescription description = project.getDescription();
+ ICommand[] commands = description.getBuildSpec();
+ for (int i = 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(builderID)) {
+ return commands[i];
+ }
+ }
+ return null;
+ }
+}
Index: src/org/eclipse/cdt/make/core/scannerconfig/ScannerInfoCollector.java
===================================================================
RCS file: src/org/eclipse/cdt/make/core/scannerconfig/ScannerInfoCollector.java
diff -N src/org/eclipse/cdt/make/core/scannerconfig/ScannerInfoCollector.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/make/core/scannerconfig/ScannerInfoCollector.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,347 @@
+/**********************************************************************
+ * 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.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.cdt.core.CCProjectNature;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.CProjectNature;
+import org.eclipse.cdt.core.parser.IScannerInfo;
+import org.eclipse.cdt.core.parser.IScannerInfoProvider;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.ISafeRunnable;
+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.util.SymbolEntry;
+
+
+/**
+ * Singleton object that collects scanner config updates from ScannerInfoParser
+ * and updates scanner config when the project's build is done.
+ *
+ * @author vhirsl
+ */
+public class ScannerInfoCollector {
+//implements IBuildEventListener {
+
+ // Singleton
+ private static ScannerInfoCollector instance = new ScannerInfoCollector();
+ private Map discoveredIncludes;
+ private Map discoveredSymbols;
+ private Map discoveredTSO; // target specific options
+ // cumulative values
+ private Map sumDiscoveredIncludes;
+ private Map sumDiscoveredSymbols;
+ private Map sumDiscoveredTSO; // target specific options
+
+ private IProject currentProject; // project being built
+
+ private ScannerInfoCollector() {
+// BuildEventListenerManager.getInstance().
+// addBuildDoneListener(MakeBuilder.BUILDER_ID, this);
+ discoveredIncludes = new HashMap();
+ discoveredSymbols = new HashMap();
+ discoveredTSO = new HashMap();
+
+ sumDiscoveredIncludes = new HashMap();
+ sumDiscoveredSymbols = new HashMap();
+ sumDiscoveredTSO = new HashMap();
+ }
+
+ public static ScannerInfoCollector getInstance() {
+ return instance;
+ }
+
+ /**
+ * Published method to receive per file contributions to ScannerInfo
+ *
+ * @param project
+ * @param includes
+ * @param symbols
+ * @param targetSpecificOptions
+ */
+ public void contributeToScannerConfig(IProject project, List includes, List symbols, List targetSpecificOptions) {
+ try {
+ if (project.hasNature(MakeProjectNature.NATURE_ID) && // limits to StandardMake projects
+ (project.hasNature(CProjectNature.C_NATURE_ID) ||
+ project.hasNature(CCProjectNature.CC_NATURE_ID))) {
+
+ String projectName = project.getName();
+ contribute(projectName, discoveredIncludes, includes);
+ contribute(projectName, discoveredSymbols, symbols);
+ contribute(projectName, discoveredTSO, targetSpecificOptions);
+ }
+ }
+ catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Published method to receive compiler specified contributions to ScannerInfo
+ *
+ * @param includes
+ * @param symbols
+ */
+ public void contributeToScannerConfig(List includes, List symbols) {
+ contributeToScannerConfig(currentProject, includes, symbols, null);
+ }
+
+ /**
+ * @param project
+ * @param discovered symbols | includes | targetSpecificOptions
+ * @param delta symbols | includes | targetSpecificOptions
+ * @return true if there is a change in discovered symbols | includes | targetSpecificOptions
+ */
+ private boolean contribute(String projectName, Map discovered, List delta) {
+ if (delta == null || delta.isEmpty())
+ return false;
+ Set projectDiscovered = (Set) discovered.get(projectName);
+ if (projectDiscovered == null) {
+ projectDiscovered = new HashSet();
+ discovered.put(projectName, projectDiscovered);
+ }
+ boolean added = false;
+ for (Iterator i = delta.iterator(); i.hasNext(); ) {
+ String item = (String) i.next();
+ added = projectDiscovered.add(item);
+ }
+ return added;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.resources.IBuildDoneListener#buildStarted(java.lang.String, org.eclipse.core.resources.IProject)
+ */
+// public void buildStarted(String builderId, IProject project) {
+// currentProject = project;
+// }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.resources.IBuildDoneListener#buildDone(java.lang.String, org.eclipse.core.resources.IProject, String[], int, org.eclipse.core.runtime.IProgressMonitor)
+ */
+// public void buildDone(String builderId,
+// IProject project,
+// String[] targets,
+// int buildResult,
+// IProgressMonitor monitor) {
+// // in case buildStarted event was missed
+// if (currentProject == null)
+// currentProject = project;
+// if (builderId.equals(MakeBuilder.BUILDER_ID) &&
+// buildResult == IBuildEventListener.BUILD_OK) {
+// boolean targetFound = false;
+// // check the build targets and see if there is any that is also a full build target
+// try {
+// IMakeBuilderInfo projectInfo = MakeCorePlugin.createBuildInfo(project, builderId);
+// String[] buildTargets = MakeBuilder.makeArray(projectInfo.getFullBuildTarget());
+// List buildTargetsList = Arrays.asList(buildTargets);
+// for (int i = 0; i < targets.length; i++) {
+// if (targets[i].equals("clean")) { // $NON-NLS-1$
+// continue;
+// }
+// if (buildTargetsList.contains(targets[i])) {
+// targetFound = true;
+// break;
+// }
+// }
+// } catch (CoreException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+// if (targetFound) {
+// String projectName = project.getName();
+// // check TSO for the project
+// getCompilerScannerInfo(project, (Set) discoveredTSO.get(projectName), new SubProgressMonitor(monitor, 10));
+// updateScannerConfig(project, new SubProgressMonitor(monitor, 10));
+// }
+// }
+// }
+
+ /**
+ * @param project
+ * @param monitor
+ */
+ private void updateScannerConfig(IProject project, IProgressMonitor monitor) {
+ IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
+ monitor.beginTask(MakeCorePlugin.getResourceString("ScannerInfoCollector.Processing"), 100);
+ if (provider != null) {
+ IScannerInfo scanInfo = provider.getScannerInformation(project);
+ if (scanInfo != null) {
+ if (scanInfo instanceof MakeScannerInfo) {
+ MakeScannerInfo makeScanInfo = (MakeScannerInfo)scanInfo;
+ String projectName = project.getName();
+
+ monitor.subTask(MakeCorePlugin.getResourceString("ScannerInfoCollector.Processing"));
+ if (scannerConfigNeedsUpdate(makeScanInfo, projectName)) {
+ monitor.worked(50);
+ monitor.subTask(MakeCorePlugin.getResourceString("ScannerInfoCollector.Updating") + projectName);
+
+ try {
+ // update scanner configuration
+ makeScanInfo.update();
+ monitor.worked(50);
+ } catch (CoreException e) {
+ // TODO : VMIR create a marker?
+ MakeCorePlugin.log(e);
+ }
+ }
+ }
+ }
+ }
+ monitor.done();
+ }
+
+ /**
+ * @param scanInfo
+ * @param projectName
+ * @return
+ */
+ private boolean scannerConfigNeedsUpdate(MakeScannerInfo makeScanInfo, String projectName) {
+ // TODO : VMIR to implement other variants
+ // Compare discovered include paths and symbol definitions with the ones from scanInfo.
+ // For now returns true allways; invalidates discovered scanner info
+ Set includes = (Set) discoveredIncludes.get(projectName);
+ Set symbols = (Set) discoveredSymbols.get(projectName);
+ if (includes == null && symbols == null)
+ return false;
+
+ Set sumIncludes = (Set) sumDiscoveredIncludes.get(projectName);
+ if (sumIncludes == null) {
+ sumIncludes = new HashSet();
+ sumDiscoveredIncludes.put(projectName, sumIncludes);
+ }
+ Map sumSymbols = (Map) sumDiscoveredSymbols.get(projectName);
+ if (sumSymbols == null) {
+ sumSymbols = new HashMap();
+ sumDiscoveredSymbols.put(projectName, sumSymbols);
+ }
+
+ boolean addedIncludes = sumIncludes.addAll(includes);
+ boolean addedSymbols = addAllSymbols(sumSymbols, symbols);
+
+ String[] persistedIncludes = makeScanInfo.getIncludePaths();
+ Map persistedSymbols = makeScanInfo.getDefinedSymbols();
+
+ makeScanInfo.setIncludePaths((String[])sumIncludes.toArray(new String[sumIncludes.size()]));
+ makeScanInfo.setPreprocessorSymbols((String[])getAllSymbols(sumSymbols).toArray(new String[sumSymbols.size()]));
+
+ // invalidate discovered include paths and symbol definitions
+ discoveredIncludes.put(projectName, null);
+ discoveredSymbols.put(projectName, null);
+
+ return (addedIncludes | addedSymbols);
+ }
+
+ /**
+ * Adds all new discovered symbols/values to the existing ones.
+ *
+ * @param sumSymbols - a map of [String, Set] where Set is a SymbolEntry
+ * @param symbols
+ * @return
+ */
+ private boolean addAllSymbols(Map sumSymbols, Set symbols) {
+ boolean rc = false;
+ for (Iterator i = symbols.iterator(); i.hasNext(); ) {
+ String symbol = (String) i.next();
+ 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) sumSymbols.get(key);
+ if (sEntry == null) {
+ sEntry = new SymbolEntry(key, value, true);
+ rc = true;
+ }
+ else {
+ rc |= sEntry.add(value);
+ }
+ sumSymbols.put(key, sEntry);
+ }
+ return rc;
+ }
+
+ /**
+ * Gets all discovered symbols with preferred values
+ * @param sumSymbols
+ * @return
+ */
+ private Set getAllSymbols(Map sumSymbols) {
+ Set symbols = (Set) sumSymbols.entrySet();
+ Set rv = new HashSet(symbols.size());
+ for (Iterator i = symbols.iterator(); i.hasNext(); ) {
+ SymbolEntry sEntry = (SymbolEntry) ((Map.Entry) i.next()).getValue();
+ rv.add(sEntry.getPreferedRaw());
+ }
+ return rv;
+ }
+
+ private void getCompilerScannerInfo(final IProject project,
+ final Set tso,
+ final IProgressMonitor monitor) {
+ // Call specs builder to get compiler's scanner info
+ final ISpecsBuilder specsBuilder = MakeCorePlugin.getDefault().
+ loadSpecsBuilder(MakeCorePlugin.GCC_SPECS_BUILDER_ID);
+ if (specsBuilder != null) {
+ ISafeRunnable runnable = new ISafeRunnable() {
+ public void run() {
+ specsBuilder.initialize(MakeCorePlugin.getWorkingDirectory(), project);
+ if (tso == null) {
+ specsBuilder.invokeCompiler(monitor, new String[0]);
+ }
+ else {
+ specsBuilder.invokeCompiler(monitor, (String[])tso.toArray(new String[tso.size()]));
+ }
+ }
+
+ public void handleException(Throwable exception) {
+ MakeCorePlugin.log(exception);
+ }
+ };
+ Platform.run(runnable);
+ }
+ }
+
+ /**
+ * @param project
+ * @param monitor
+ */
+ public void updateScannerConfiguration(IProject project, IProgressMonitor monitor) {
+ currentProject = project;
+ String projectName = project.getName();
+ // check TSO for the project
+ monitor.beginTask("", 100); //$NON-NLS-1$
+ getCompilerScannerInfo(project, (Set) discoveredTSO.get(projectName), new SubProgressMonitor(monitor, 60));
+ updateScannerConfig(project, new SubProgressMonitor(monitor, 40));
+
+ // delete discovered scanner config
+ discoveredIncludes.put(projectName, null);
+ discoveredSymbols.put(projectName, null);
+ discoveredTSO.put(projectName, null);
+ }
+
+}
Index: src/org/eclipse/cdt/make/core/scannerconfig/gnu/GCCCompilerSpecsParser.java
===================================================================
RCS file: src/org/eclipse/cdt/make/core/scannerconfig/gnu/GCCCompilerSpecsParser.java
diff -N src/org/eclipse/cdt/make/core/scannerconfig/gnu/GCCCompilerSpecsParser.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/make/core/scannerconfig/gnu/GCCCompilerSpecsParser.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,90 @@
+/**********************************************************************
+ * Copyright (c) 2003 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.gnu;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.cdt.core.ErrorParserManager;
+import org.eclipse.cdt.core.IErrorParser;
+
+import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoCollector;
+
+/**
+ * Parses output of gcc -c -v specs.c or
+ * g++ -c -v specs.cpp
+ * command
+ *
+ * @author vhirsl
+ */
+public class GCCCompilerSpecsParser implements IErrorParser {
+ private final int STATE_BEGIN = 0;
+ private final int STATE_SPECS_STARTED = 1;
+ private final int STATE_INCLUDES_STARTED = 2;
+
+ private int state = STATE_BEGIN;
+ private List symbols = new ArrayList();
+ private List includes = new ArrayList();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.IErrorParser#processLine(java.lang.String, org.eclipse.cdt.core.ErrorParserManager)
+ */
+ public boolean processLine(String line, ErrorParserManager eoParser) {
+ boolean rc = false;
+ // Known patterns:
+ // (a) gcc|g++ ... -Dxxx -Iyyy ...
+ switch (state) {
+ case STATE_BEGIN:
+ if (line.startsWith("Reading specs from")) { //$NON-NLS-1$
+ state = STATE_SPECS_STARTED;
+ }
+ return rc;
+ case STATE_SPECS_STARTED:
+ if (line.indexOf("-D") != -1) { //$NON-NLS-1$
+ // line contains -Ds, extract them
+ StringTokenizer scanner = new StringTokenizer(line);
+ if (scanner.countTokens() <= 1)
+ return rc;
+ for (String token = scanner.nextToken(); scanner.hasMoreTokens(); token = scanner.nextToken()) {
+ if (token.startsWith("-D")) { //$NON-NLS-1$
+ String symbol = token.substring(2);
+ if (!symbols.contains(symbol))
+ symbols.add(symbol);
+ }
+ }
+ }
+ // now get all the includes
+ if (line.startsWith("#include") && line.endsWith("search starts here:")) { //$NON-NLS-1$ //$NON-NLS-2$
+ state = STATE_INCLUDES_STARTED;
+ }
+ return rc;
+ case STATE_INCLUDES_STARTED:
+ if (line.startsWith("#include") && line.endsWith("search starts here:")) { //$NON-NLS-1$ //$NON-NLS-2$
+ state = STATE_INCLUDES_STARTED;
+ }
+ else if (line.startsWith("End of search list.")) { //$NON-NLS-1$
+ state = STATE_BEGIN;
+ break;
+ }
+ else {
+ if (!includes.contains(line))
+ includes.add(line);
+ }
+ return rc;
+ }
+
+ ScannerInfoCollector.getInstance().contributeToScannerConfig(includes, symbols);
+
+ return rc;
+ }
+
+}
Index: src/org/eclipse/cdt/make/core/scannerconfig/gnu/GCCScannerInfoParser.java
===================================================================
RCS file: src/org/eclipse/cdt/make/core/scannerconfig/gnu/GCCScannerInfoParser.java
diff -N src/org/eclipse/cdt/make/core/scannerconfig/gnu/GCCScannerInfoParser.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/make/core/scannerconfig/gnu/GCCScannerInfoParser.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,123 @@
+/**********************************************************************
+ * Copyright (c) 2003 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.gnu;
+
+import java.util.StringTokenizer;
+
+import org.eclipse.cdt.core.ErrorParserManager;
+import org.eclipse.cdt.core.IErrorParser;
+import org.eclipse.cdt.core.IMarkerGenerator;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoCollector;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Parses gcc and g++ output for -I and -D parameters.
+ *
+ * @author vhirsl
+ */
+public class GCCScannerInfoParser implements IErrorParser {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.IErrorParser#processLine(java.lang.String, org.eclipse.cdt.core.ErrorParserManager)
+ */
+ public boolean processLine(String line, ErrorParserManager eoParser) {
+ boolean rc = false;
+ // Known patterns:
+ // (a) gcc|g++ ... -Dxxx -Iyyy ...
+ 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$
+ // Recognized gcc or g++ compiler invocation
+ List includes = new ArrayList();
+ List symbols = new ArrayList();
+ List targetSpecificOptions = new ArrayList();
+
+ rc = true;
+ String fileName = null;
+ String desc = "Found";
+ while (scanner.hasMoreTokens()) {
+ token = scanner.nextToken();
+ if (token.startsWith("-D")) {
+ String symbol = token.substring(2);
+ if (!symbols.contains(symbol))
+ symbols.add(symbol);
+ }
+ else if (token.startsWith("-I")) {
+ String iPath = token.substring(2);
+ if (!includes.contains(iPath))
+ includes.add(iPath);
+ }
+ else if (token.equals("-mwin32") ||
+ token.equals("-mno-win32") ||
+ token.equals("-mno-cygwin") ||
+ token.equals("-ansi") ||
+ token.equals("-nostdinc")) {
+ if (!targetSpecificOptions.contains(token))
+ targetSpecificOptions.add(token);
+ }
+ else {
+ String possibleFileName = token.toLowerCase();
+ if (possibleFileName.endsWith(".c") ||
+ possibleFileName.endsWith(".cpp") ||
+ possibleFileName.endsWith(".cc") ||
+ possibleFileName.endsWith(".cxx")) {
+ fileName = token;
+ }
+ }
+ }
+
+ IFile file = null;
+ if (fileName != null) {
+ file = eoParser.findFilePath(fileName);
+
+ if (file == null) {
+ // Parse the entire project.
+ file = eoParser.findFileName(fileName);
+ if (file != null) {
+ // If there is a conflict set the error on the project.
+ if (eoParser.isConflictingName(fileName)) {
+ desc = "*" + desc;
+ file = null;
+ }
+ }
+ }
+
+ // Contribute discovered includes and symbols to the ScannerInfoCollector
+ if (file != null) {
+ IProject project = file.getProject();
+ ScannerInfoCollector.getInstance().
+ contributeToScannerConfig(project, includes, symbols, targetSpecificOptions);
+ }
+ }
+
+ // TODO : VMIR remove when debugging is done
+ int severity = IMarkerGenerator.SEVERITY_INFO;
+
+ for (Iterator i = includes.iterator(); i.hasNext(); ) {
+ String iPath = (String)i.next();
+ eoParser.generateMarker(file, -1, "Found an include path: "+iPath, severity, iPath);
+ }
+ for (Iterator i = symbols.iterator(); i.hasNext(); ) {
+ String symbol = (String)i.next();
+ eoParser.generateMarker(file, -1, "Found a symbol definition: "+symbol, severity, symbol);
+ }
+
+ }
+ return false;
+ }
+}
Index: src/org/eclipse/cdt/make/core/scannerconfig/gnu/GCCSpecsBuilder.java
===================================================================
RCS file: src/org/eclipse/cdt/make/core/scannerconfig/gnu/GCCSpecsBuilder.java
diff -N src/org/eclipse/cdt/make/core/scannerconfig/gnu/GCCSpecsBuilder.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/make/core/scannerconfig/gnu/GCCSpecsBuilder.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,181 @@
+/**********************************************************************
+ * Copyright (c) 2003 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.gnu;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.eclipse.cdt.core.CCProjectNature;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.CProjectNature;
+import org.eclipse.cdt.core.CommandLauncher;
+import org.eclipse.cdt.core.ErrorParserManager;
+import org.eclipse.cdt.core.resources.IConsole;
+import org.eclipse.cdt.make.core.MakeCorePlugin;
+import org.eclipse.cdt.make.internal.core.StreamMonitor;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.SubProgressMonitor;
+
+import org.eclipse.cdt.make.core.scannerconfig.ISpecsBuilder;
+
+/**
+ * New type
+ *
+ * @author vhirsl
+ */
+public class GCCSpecsBuilder implements ISpecsBuilder {
+
+ private static final String BUILD_ERROR = "MakeBuilder.buildError"; //$NON-NLS-1$
+ private static final String SPECS_ERROR_PARSER = MakeCorePlugin.getUniqueIdentifier() + ".GCCSpecsParser"; //$NON-NLS-1$
+ private static final String SPECS_BUILDER_CONSOLE_ID = MakeCorePlugin.getUniqueIdentifier() + ".SpecsBuilderConsole"; //$NON-NLS-1$
+
+ private IPath workingDirectory;
+ private IProject currentProject;
+ private IPath compileCommand;
+ private String targetFile;
+
+ /* (non-Javadoc)
+ * @see org.vmir.cdt.scannerconfig.make.core.ISpecsBuilder#initialize(org.eclipse.core.runtime.IPath, org.eclipse.core.resources.IProject)
+ */
+ public void initialize(IPath workingDirectory, IProject currentProject) {
+ this.workingDirectory = workingDirectory;
+ this.currentProject = currentProject;
+ try {
+ if (currentProject.hasNature(CCProjectNature.CC_NATURE_ID)) {
+ compileCommand = new Path("g++"); //$NON-NLS-1$
+ targetFile = MakeCorePlugin.CPP_SPECS_FILE;
+ }
+ else if (currentProject.hasNature(CProjectNature.C_NATURE_ID)) {
+ compileCommand = new Path("gcc"); //$NON-NLS-1$
+ targetFile = MakeCorePlugin.C_SPECS_FILE;
+ }
+ else {
+ compileCommand = null;
+ }
+ } catch (CoreException e) {
+ compileCommand = null;
+ CCorePlugin.log(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.vmir.cdt.scannerconfig.make.core.ISpecsBuilder#invokeCompiler(org.eclipse.core.runtime.IProgressMonitor, java.lang.String[])
+ */
+ public boolean invokeCompiler(IProgressMonitor monitor, String[] targetSpecificOptions) {
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ monitor.beginTask(MakeCorePlugin.getResourceString("SpecsBuilder.Reading_Specs"), 100); //$NON-NLS-1$
+
+ try {
+ if (compileCommand != null) {
+ IConsole console = CCorePlugin.getDefault().getConsole("SPECS_BUILDER_CONSOLE_ID");
+ console.start(currentProject);
+
+ OutputStream cos = console.getOutputStream();
+
+ // Before launching give visual cues via the monitor
+ monitor.subTask(MakeCorePlugin.getResourceString("SpecsBuilder.Reading_Specs")); //$NON-NLS-1$
+
+ String errMsg = null;
+ CommandLauncher launcher = new CommandLauncher();
+ // Print the command for visual interaction.
+ launcher.showCommand(true);
+
+ // Set the environmennt, some scripts may need the CWD var to be set.
+ Properties props = launcher.getEnvironment();
+ props.put("CWD", workingDirectory.toOSString()); //$NON-NLS-1$
+ props.put("PWD", workingDirectory.toOSString()); //$NON-NLS-1$
+ String[] env = null;
+ ArrayList envList = new ArrayList();
+ Enumeration names = props.propertyNames();
+ if (names != null) {
+ while (names.hasMoreElements()) {
+ String key = (String) names.nextElement();
+ envList.add(key + "=" + props.getProperty(key)); //$NON-NLS-1$
+ }
+ env = (String[]) envList.toArray(new String[envList.size()]);
+ }
+ String[] compileArguments = new String[3 + targetSpecificOptions.length];
+ compileArguments[0] = "-c"; //$NON-NLS-1$
+ compileArguments[1] = "-v"; //$NON-NLS-1$
+ compileArguments[2] = targetFile;
+ for (int i = 0; i < targetSpecificOptions.length; i++) {
+ compileArguments[i+3] = targetSpecificOptions[i];
+ }
+ StringBuffer sb = new StringBuffer(128);
+ for (int i = 0; i < compileArguments.length; i++) {
+ sb.append(' ');
+ sb.append(compileArguments[i]);
+ }
+ String ca = sb.toString();
+
+ monitor.subTask(MakeCorePlugin.getResourceString("SpecsBuilder.Invoking_Command") + compileCommand.toString() + ca); //$NON-NLS-1$
+ cos = new StreamMonitor(new SubProgressMonitor(monitor, 70), cos, 100);
+ ErrorParserManager epm = new ErrorParserManager(currentProject, null, new String[] {SPECS_ERROR_PARSER});
+ epm.setOutputStream(cos);
+ OutputStream stdout = epm.getOutputStream();
+ OutputStream stderr = epm.getOutputStream();
+ Process p = launcher.execute(compileCommand, compileArguments, env, workingDirectory);
+ if (p != null) {
+ try {
+ // Close the input of the Process explicitely.
+ // We will never write to it.
+ p.getOutputStream().close();
+ } catch (IOException e) {
+ }
+ if (launcher.waitAndRead(stdout, stderr, new SubProgressMonitor(monitor, 0))
+ != CommandLauncher.OK)
+ errMsg = launcher.getErrorMessage();
+ monitor.subTask(MakeCorePlugin.getResourceString("SpecsBuilder.Parsing_Output")); //$NON-NLS-1$
+
+ } else {
+ errMsg = launcher.getErrorMessage();
+ }
+
+ if (errMsg != null) {
+ StringBuffer buf = new StringBuffer(compileCommand.toString() + " "); //$NON-NLS-1$
+ for (int i = 0; i < compileArguments.length; i++) {
+ buf.append(compileArguments[i]);
+ buf.append(' ');
+ }
+
+ String errorDesc = MakeCorePlugin.getFormattedString(BUILD_ERROR, buf.toString());
+ buf = new StringBuffer(errorDesc);
+ buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
+ buf.append("(").append(errMsg).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
+ cos.write(buf.toString().getBytes());
+ cos.flush();
+ }
+
+ stdout.close();
+ stderr.close();
+
+// monitor.subTask(MakeCorePlugin.getResourceString("MakeBuilder.Creating_Markers")); //$NON-NLS-1$
+// epm.reportProblems();
+ cos.close();
+ }
+ } catch (Exception e) {
+ CCorePlugin.log(e);
+ } finally {
+ monitor.done();
+ }
+ return true;
+ }
+}
Index: src/org/eclipse/cdt/make/core/scannerconfig/util/SymbolEntry.java
===================================================================
RCS file: src/org/eclipse/cdt/make/core/scannerconfig/util/SymbolEntry.java
diff -N src/org/eclipse/cdt/make/core/scannerconfig/util/SymbolEntry.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/make/core/scannerconfig/util/SymbolEntry.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,127 @@
+/**********************************************************************
+ * 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.util;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+
+/**
+ * Represents a symbol definition with possible multiple values
+ * example:
+ * LOG_LEVEL
+ * LOG_LEVEL = 2
+ * LOG_LEVEL = LOG_BASE + 1
+ * @author vhirsl
+ */
+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
+
+ public SymbolEntry(String name) {
+ this.name = name;
+ }
+ public SymbolEntry(String name, String value) {
+ this(name);
+ if (values == null) {
+ values = new HashSet();
+ }
+ values.add(value);
+ }
+ public SymbolEntry(String name, String value, boolean preferred) {
+ this(name, value);
+ if (preferred) {
+ preferredValue = value;
+ }
+ }
+
+ public boolean add(String value) {
+ if (values == null) {
+ values = new HashSet();
+ }
+ if (preferredValue == null) {
+ preferredValue = value;
+ }
+ return values.add(value);
+ }
+ public boolean add(String value, boolean preferred) {
+ boolean rc = add(value);
+ if (preferred) {
+ preferredValue = value;
+ }
+ return rc;
+ }
+ public boolean addAll(SymbolEntry se) {
+ return values.addAll(se.values);
+ }
+
+ public void removeAll() {
+ values = null;
+ preferredValue = null;
+ }
+
+ public String getPrefered() {
+ return name+ "=" + (preferredValue == null ? UNSPECIFIED_VALUE : preferredValue);//$NON-NLS-1$
+ }
+ public String getPreferedRaw() {
+ return name + (preferredValue == null ? "" : "=" + preferredValue);//$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ 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 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 Set getAll() {
+ if (values == null)
+ return null;
+ Set rv = new HashSet(values.size());
+ for (Iterator i = values.iterator(); i.hasNext(); ) {
+ String val = (String) i.next();
+ rv.add(name + "=" + (val == null ? UNSPECIFIED_VALUE : val));//$NON-NLS-1$
+ }
+ return rv;
+ }
+ public Set getAllRaw() {
+ if (values == null)
+ return null;
+ Set rv = new HashSet(values.size());
+ for (Iterator i = values.iterator(); i.hasNext(); ) {
+ String val = (String) i.next();
+ rv.add(name + (val == null ? "" : "=" + val));//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return rv;
+ }
+
+}
Index: src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerConfigInfoFactory.java
===================================================================
RCS file: src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerConfigInfoFactory.java
diff -N src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerConfigInfoFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/make/internal/core/scannerconfig/ScannerConfigInfoFactory.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,169 @@
+/**********************************************************************
+ * 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.core.scannerconfig;
+
+import java.util.Map;
+
+import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.cdt.make.core.MakeCorePlugin;
+import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo;
+import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature;
+
+/**
+ * Creates a ScannerConfigBuilderInfo variant
+ * @author vhirsl
+ */
+public class ScannerConfigInfoFactory {
+ private static final String PREFIX = MakeCorePlugin.getUniqueIdentifier();
+
+ static final String BUILD_SCANNER_CONFIG_ENABLED = PREFIX + ".ScannerConfigDiscoveryEnabled"; //$NON-NLS-1$
+
+ /**
+ *
+ * @author vhirsl
+ */
+ private abstract static class Store implements IScannerConfigBuilderInfo {
+ /* (non-Javadoc)
+ * @see org.vmir.cdt.scannerconfig.make.core.IScannerConfigBuilderInfo#isAutoDiscoveryEnabled()
+ */
+ public boolean isAutoDiscoveryEnabled() {
+ return getBoolean(BUILD_SCANNER_CONFIG_ENABLED);
+ }
+
+ /* (non-Javadoc)
+ * @see org.vmir.cdt.scannerconfig.make.core.IScannerConfigBuilderInfo#setAutoDiscoveryEnabled(boolean)
+ */
+ public void setAutoDiscoveryEnabled(boolean enabled) throws CoreException {
+ putString(BUILD_SCANNER_CONFIG_ENABLED, Boolean.toString(enabled));
+ }
+
+ protected boolean getBoolean(String property) {
+ return Boolean.valueOf(getString(property)).booleanValue();
+ }
+ protected abstract String getBuilderID();
+ protected abstract String getString(String property);
+ protected abstract void putString(String name, String value) throws CoreException;
+ }
+
+ /**
+ *
+ * @author vhirsl
+ */
+ private static class Preference extends Store {
+ private Preferences prefs;
+ private String builderID;
+ private boolean useDefaults;
+
+ Preference(Preferences prefs, String builderID, boolean useDefaults) {
+ this.prefs = prefs;
+ this.builderID = builderID;
+ this.useDefaults = useDefaults;
+ }
+
+ protected void putString(String name, String value) {
+ if (useDefaults) {
+ prefs.setDefault(name, value);
+ } else {
+ prefs.setValue(name, value);
+ }
+ }
+
+ protected String getString(String property) {
+ if (useDefaults) {
+ return prefs.getDefaultString(property);
+ }
+ return prefs.getString(property);
+ }
+
+ protected String getBuilderID() {
+ return builderID;
+ }
+ }
+
+ private static class BuildProperty extends Store {
+ private IProject project;
+ private String builderID;
+ private Map args;
+
+ BuildProperty(IProject project, String builderID) throws CoreException {
+ this.project = project;
+ this.builderID = builderID;
+ ICommand builder = ScannerConfigNature.getBuildSpec(project, builderID);
+ if (builder == null) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ MakeCorePlugin.getUniqueIdentifier(), -1,
+ MakeCorePlugin.getResourceString("ScannerConfigInfoFactory.Missing_Builder")//$NON-NLS-1$
+ + builderID, null));
+ }
+ args = builder.getArguments();
+ }
+
+ protected void putString(String name, String value) throws CoreException {
+ String curValue = (String) args.get(name);
+ if (curValue != null && curValue.equals(value)) {
+ return;
+ }
+ ICommand builder = ScannerConfigNature.getBuildSpec(project, builderID);
+ args.put(name, value);
+ builder.setArguments(args);
+ project.setDescription(project.getDescription(), null);
+ }
+
+ protected String getString(String name) {
+ String value = (String) args.get(name);
+ return value == null ? "" : value; //$NON-NLS-1$
+ }
+
+ protected String getBuilderID() {
+ return builderID;
+ }
+ }
+
+ private static class BuildArguments extends Store {
+ private Map args;
+ private String builderID;
+
+ BuildArguments(Map args, String builderID) {
+ this.args = args;
+ this.builderID = builderID;
+ }
+
+ protected void putString(String name, String value) {
+ args.put(name, value);
+ }
+
+ protected String getString(String name) {
+ return (String) args.get(name);
+ }
+
+ protected String getBuilderID() {
+ return builderID;
+ }
+ }
+
+ public static IScannerConfigBuilderInfo create(Preferences prefs, String builderID, boolean useDefaults) {
+ return new ScannerConfigInfoFactory.Preference(prefs, builderID, useDefaults);
+ }
+
+ public static IScannerConfigBuilderInfo create(IProject project, String builderID) throws CoreException {
+ return new ScannerConfigInfoFactory.BuildProperty(project, builderID);
+ }
+
+ public static IScannerConfigBuilderInfo create(Map args, String builderID) {
+ return new ScannerConfigInfoFactory.BuildArguments(args, builderID);
+ }
+}
Index: plugin.properties
===================================================================
retrieving revision 1.7
diff -u -r1.7 plugin.properties
--- plugin.properties 17 Oct 2003 02:34:10 -0000 1.7
+++ plugin.properties 9 Feb 2004 22:05:10 -0000
@@ -46,3 +46,5 @@
MakefileEditor.name=Makefile Editor
+PropertyScannerConfig.name=Project Scanner Configuration Discovery
+PreferenceScannerConfig.name=Scanner Configuration Discovery
Index: plugin.xml
===================================================================
retrieving revision 1.26
diff -u -r1.26 plugin.xml
--- plugin.xml 2 Feb 2004 20:04:46 -0000 1.26
+++ plugin.xml 9 Feb 2004 22:05:11 -0000
@@ -399,5 +399,28 @@
</actionSet>
</perspectiveExtension>
</extension>
+ <extension
+ point="org.eclipse.ui.propertyPages">
+ <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.preferencePages">
+ <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>
+ </extension>
</plugin>
Index: src/org/eclipse/cdt/make/internal/ui/preferences/ScannerConfigPreferencePage.java
===================================================================
RCS file: src/org/eclipse/cdt/make/internal/ui/preferences/ScannerConfigPreferencePage.java
diff -N src/org/eclipse/cdt/make/internal/ui/preferences/ScannerConfigPreferencePage.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/make/internal/ui/preferences/ScannerConfigPreferencePage.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,95 @@
+package org.eclipse.cdt.make.internal.ui.preferences;
+
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.cdt.ui.dialogs.ICOptionContainer;
+import org.eclipse.cdt.ui.dialogs.ICOptionPage;
+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;
+
+/**
+ * TODO: Provide description for "ScannerConfigPreferencePage".
+ * @see PreferencePage
+ */
+public class ScannerConfigPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, ICOptionContainer {
+
+ private ICOptionPage fScannerConfigPage;
+
+ public ScannerConfigPreferencePage() {
+ super();
+ }
+
+ /**
+ * @see PreferencePage#init
+ */
+ public void init(IWorkbench workbench) {
+ }
+
+ /**
+ * @see PreferencePage#createContents
+ */
+ protected Control createContents(Composite parent) {
+ fScannerConfigPage = createClientPage();
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new FillLayout());
+
+ fScannerConfigPage.createControl(composite);
+
+ return composite;
+ }
+
+ /**
+ * @return
+ */
+ private ICOptionPage createClientPage() {
+ ScannerConfigPage clientPage = new ScannerConfigPage(this);
+ return clientPage;
+ }
+
+ 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() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (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();
+ }
+}
Index: src/org/eclipse/cdt/make/internal/ui/properties/ScannerConfigPropertyPage.java
===================================================================
RCS file: src/org/eclipse/cdt/make/internal/ui/properties/ScannerConfigPropertyPage.java
diff -N src/org/eclipse/cdt/make/internal/ui/properties/ScannerConfigPropertyPage.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/make/internal/ui/properties/ScannerConfigPropertyPage.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,83 @@
+package org.eclipse.cdt.make.internal.ui.properties;
+
+import org.eclipse.cdt.ui.dialogs.ICOptionContainer;
+import org.eclipse.cdt.ui.dialogs.ICOptionPage;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+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;
+
+public class ScannerConfigPropertyPage extends PropertyPage implements ICOptionContainer {
+
+ private ICOptionPage fScannerConfigPage;
+
+ public ScannerConfigPropertyPage() {
+ super();
+ }
+
+ /**
+ * @see PreferencePage#createContents(Composite)
+ */
+ protected Control createContents(Composite parent) {
+ fScannerConfigPage = createClientPage();
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new FillLayout());
+
+ fScannerConfigPage.createControl(composite);
+
+ return composite;
+ }
+
+ /**
+ * @return
+ */
+ private ICOptionPage createClientPage() {
+ ScannerConfigPage clientPage = new ScannerConfigPage(this);
+ return clientPage;
+ }
+
+ 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() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (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();
+ }
+
+}
Index: src/org/eclipse/cdt/make/ui/dialogs/ScannerConfigPage.java
===================================================================
RCS file: src/org/eclipse/cdt/make/ui/dialogs/ScannerConfigPage.java
diff -N src/org/eclipse/cdt/make/ui/dialogs/ScannerConfigPage.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/make/ui/dialogs/ScannerConfigPage.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,145 @@
+/**********************************************************************
+ * 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 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.IProgressMonitor;
+import org.eclipse.swt.SWT;
+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.Label;
+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;
+
+/**
+ *
+ * @author vhirsl
+ */
+public class ScannerConfigPage extends AbstractCOptionPage {
+
+ private static final String TITLE = "Scanner configuration discovery settings."; //$NON-NLS-1$
+ private static final String ACTIVATE_AUTO_DISCOVERY = "Automate scanner configuration discovery"; //$NON-NLS-1$
+
+ private Button autoDiscovery;
+ private Text ownerText;
+
+ IScannerConfigBuilderInfo fBuildInfo;
+
+ /**
+ * @param preferences
+ */
+ public ScannerConfigPage(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);
+ }
+ }
+
+ /* (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);
+ }
+ }
+ else {
+ buildInfo = MakeCorePlugin.createScannerConfigBuildInfo(getContainer().getPreferences(), ScannerConfigBuilder.BUILDER_ID, false);
+ buildInfo.setAutoDiscoveryEnabled(autoDiscovery.getSelection());
+ }
+ }
+
+ /* (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());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ composite.setLayout(layout);
+ GridData data = new GridData(GridData.FILL);
+ data.grabExcessHorizontalSpace = true;
+ composite.setLayoutData(data);
+// Composite composite = createDefaultComposite(parent);
+
+ addSCDiscoveryState(composite);
+ addSeparator(composite);
+ }
+
+ private void addSCDiscoveryState(Composite parent) {
+ Composite composite = parent;//createDefaultComposite(parent);
+
+ //Label for dialog title
+ setDescription(TITLE);
+ Label pathLabel = ControlFactory.createLabel(composite, TITLE);
+
+ //Checkbox for enabling the discovery
+ ControlFactory.insertSpace(parent, 1, 10);
+ autoDiscovery = ControlFactory.createCheckBox(composite, ACTIVATE_AUTO_DISCOVERY);
+ autoDiscovery.setSelection(fBuildInfo.isAutoDiscoveryEnabled());
+ }
+
+ 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);
+ }
+
+}