Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Camelon2003-07-04 14:36:47 -0400
committerJohn Camelon2003-07-04 14:36:47 -0400
commit8b844d54f156b1a762e4719145cd624225a82839 (patch)
tree404326aee3385f2e385658368fb1709b9c550b36 /core/org.eclipse.cdt.core/build
parent2e6093590f9042739ece8f185717dc2fdfe0f67a (diff)
downloadorg.eclipse.cdt-8b844d54f156b1a762e4719145cd624225a82839.tar.gz
org.eclipse.cdt-8b844d54f156b1a762e4719145cd624225a82839.tar.xz
org.eclipse.cdt-8b844d54f156b1a762e4719145cd624225a82839.zip
Patch for Sean Evoy.
The change logs contain an overview of what has been done to implement a new interface between a build model (any build model) and clients of the model that need to extract include search paths and defined symbols. For the most part, I have tried to leave the old build system as unchanged as possible. For example, project properties like the make search path, and whether or not to continue on build failures are still stored as persistent properties on the project through the CNature (ugh). The new information I have added is managed by a new build manager on a per-project basis and is associated with a project as a session property. The information is persisted in the 'cdtbuild' file introduced by the new managed build system.
Diffstat (limited to 'core/org.eclipse.cdt.core/build')
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IManagedBuildInfo.java (renamed from core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IResourceBuildInfo.java)2
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IManagedBuildPathInfo.java32
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java172
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/standard/StandardBuildManager.java308
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ManagedBuildInfo.java (renamed from core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ResourceBuildInfo.java)42
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java6
6 files changed, 488 insertions, 74 deletions
diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IResourceBuildInfo.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IManagedBuildInfo.java
index c42170e900..7684d41f98 100644
--- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IResourceBuildInfo.java
+++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IManagedBuildInfo.java
@@ -13,7 +13,7 @@ import java.util.List;
* IBM Rational Software - Initial API and implementation
***********************************************************************/
-public interface IResourceBuildInfo {
+public interface IManagedBuildInfo {
/**
* Add a new target to the build information for the receiver
diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IManagedBuildPathInfo.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IManagedBuildPathInfo.java
deleted file mode 100644
index 03fbcc20f1..0000000000
--- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IManagedBuildPathInfo.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.eclipse.cdt.core.build.managed;
-
-/**********************************************************************
- * Copyright (c) 2002,2003 Rational Software Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- *
- * Contributors:
- * IBM Rational Software - Initial API and implementation
-***********************************************************************/
-
-public interface IManagedBuildPathInfo {
- /**
- * Answers a <code>String</code> array containing all the defined
- * preprocessor symbols. If there are no defined symbols, the receiver
- * will return an empty array, never <code>null</code>
- *
- * @return
- */
- public String[] getDefinedSymbols();
-
- /**
- * Answers a <code>String</code> array containing all the known include
- * search paths. If there are no paths defined, the receiver will
- * return an empty array, never <code>null</code>
- *
- * @return
- */
- public String[] getIncludePaths();
-}
diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java
index 8d261f0d54..fe6443a259 100644
--- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java
+++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java
@@ -17,6 +17,7 @@ import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
@@ -28,7 +29,8 @@ import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.Serializer;
import org.apache.xml.serialize.SerializerFactory;
import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.internal.core.build.managed.ResourceBuildInfo;
+import org.eclipse.cdt.core.parser.*;
+import org.eclipse.cdt.internal.core.build.managed.ManagedBuildInfo;
import org.eclipse.cdt.internal.core.build.managed.Target;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -46,11 +48,12 @@ import org.w3c.dom.Node;
* This is the main entry point for getting at the build information
* for the managed build system.
*/
-public class ManagedBuildManager {
+public class ManagedBuildManager implements IScannerInfoProvider {
private static final QualifiedName buildInfoProperty
- = new QualifiedName(CCorePlugin.PLUGIN_ID, "buildInfo");
-
+ = new QualifiedName(CCorePlugin.PLUGIN_ID, "managedBuildInfo");
+ private static final String ROOT_ELEM_NAME = "ManagedProjectBuildInfo";
+ private static final String FILE_NAME = ".cdtbuild";
private static final ITarget[] emptyTargets = new ITarget[0];
// Targets defined by extensions (i.e., not associated with a resource)
@@ -58,6 +61,9 @@ public class ManagedBuildManager {
private static List extensionTargets;
private static Map extensionTargetMap;
+ // Listeners interested in build model changes
+ private static Map buildModelListeners;
+
/**
* Returns the list of targets that are defined by this project,
* projects referenced by this project, and by the extensions.
@@ -108,7 +114,7 @@ public class ManagedBuildManager {
* @return
*/
public static ITarget[] getTargets(IResource resource) {
- IResourceBuildInfo buildInfo = getBuildInfo(resource);
+ IManagedBuildInfo buildInfo = getBuildInfo(resource);
if (buildInfo != null) {
List targets = buildInfo.getTargets();
@@ -131,7 +137,7 @@ public class ManagedBuildManager {
ITarget target = null;
// Check if the target is spec'd in the build info for the resource
if (resource != null) {
- IResourceBuildInfo buildInfo = getBuildInfo(resource);
+ IManagedBuildInfo buildInfo = getBuildInfo(resource);
if (buildInfo != null)
target = buildInfo.getTarget(id);
}
@@ -187,13 +193,35 @@ public class ManagedBuildManager {
return;
}
// Set the default in build information for the project
- IResourceBuildInfo info = getBuildInfo(project);
+ IManagedBuildInfo info = getBuildInfo(project);
if (info != null) {
info.setDefaultConfiguration(newDefault);
}
}
/**
+ * @param config
+ * @param option
+ */
+ private static void setDirty(IConfiguration config, IOption option) {
+ // Don't bother unless this is something that effect the
+ if (!(option.getValueType() == IOption.INCLUDE_PATH
+ || option.getValueType() == IOption.PREPROCESSOR_SYMBOLS)) {
+ return;
+ }
+ // Figure out if there is a listener for this change
+ IResource resource = config.getOwner();
+ List listeners = (List) getBuildModelListeners().get(resource);
+ if (listeners == null) {
+ return;
+ }
+ ListIterator iter = listeners.listIterator();
+ while (iter.hasNext()) {
+ ((IScannerInfoChangeListener)iter.next()).changeNotification(resource, getScannerInfo(resource));
+ }
+ }
+
+ /**
* Set the string value for an option for a given config.
*
* @param config The configuration the option belongs to.
@@ -203,6 +231,7 @@ public class ManagedBuildManager {
public static void setOption(IConfiguration config, IOption option, boolean value) {
try {
config.setOption(option, value);
+ setDirty(config, option);
} catch (BuildException e) {
return;
}
@@ -218,6 +247,7 @@ public class ManagedBuildManager {
public static void setOption(IConfiguration config, IOption option, String value) {
try {
config.setOption(option, value);
+ setDirty(config, option);
} catch (BuildException e) {
return;
}
@@ -233,6 +263,7 @@ public class ManagedBuildManager {
public static void setOption(IConfiguration config, IOption option, String[] value) {
try {
config.setOption(option, value);
+ setDirty(config, option);
} catch (BuildException e) {
return;
}
@@ -247,11 +278,11 @@ public class ManagedBuildManager {
public static void saveBuildInfo(IProject project) {
// Create document
Document doc = new DocumentImpl();
- Element rootElement = doc.createElement("buildInfo");
+ Element rootElement = doc.createElement(ROOT_ELEM_NAME);
doc.appendChild(rootElement);
// Save the build info
- ResourceBuildInfo buildInfo = (ResourceBuildInfo) getBuildInfo(project);
+ ManagedBuildInfo buildInfo = (ManagedBuildInfo) getBuildInfo(project);
if (buildInfo != null)
buildInfo.serialize(doc, rootElement);
@@ -266,7 +297,7 @@ public class ManagedBuildManager {
= SerializerFactory.getSerializerFactory(Method.XML).makeSerializer(new OutputStreamWriter(s, "UTF8"), format);
serializer.asDOMSerializer().serialize(doc);
xml = s.toString("UTF8"); //$NON-NLS-1$
- IFile rscFile = project.getFile(".cdtbuild");
+ IFile rscFile = project.getFile(FILE_NAME);
InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
// update the resource content
if (rscFile.exists()) {
@@ -316,9 +347,9 @@ public class ManagedBuildManager {
}
}
- private static ResourceBuildInfo loadBuildInfo(IProject project) {
- ResourceBuildInfo buildInfo = null;
- IFile file = project.getFile(".cdtbuild");
+ private static ManagedBuildInfo loadBuildInfo(IProject project) {
+ ManagedBuildInfo buildInfo = null;
+ IFile file = project.getFile(FILE_NAME);
if (!file.exists())
return null;
@@ -327,8 +358,8 @@ public class ManagedBuildManager {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(stream);
Node rootElement = document.getFirstChild();
- if (rootElement.getNodeName().equals("buildInfo")) {
- buildInfo = new ResourceBuildInfo(project, (Element)rootElement);
+ if (rootElement.getNodeName().equals(ROOT_ELEM_NAME)) {
+ buildInfo = new ManagedBuildInfo(project, (Element)rootElement);
project.setSessionProperty(buildInfoProperty, buildInfo);
}
} catch (Exception e) {
@@ -338,13 +369,14 @@ public class ManagedBuildManager {
return buildInfo;
}
- private static ResourceBuildInfo findBuildInfo(IResource resource, boolean create) {
+ private static ManagedBuildInfo findBuildInfo(IResource resource, boolean create) {
// Make sure the extension information is loaded first
loadExtensions();
- ResourceBuildInfo buildInfo = null;
+ ManagedBuildInfo buildInfo = null;
try {
- buildInfo = (ResourceBuildInfo)resource.getSessionProperty(buildInfoProperty);
+ buildInfo = (ManagedBuildInfo)resource.getSessionProperty(buildInfoProperty);
} catch (CoreException e) {
+ return buildInfo;
}
if (buildInfo == null && resource instanceof IProject) {
@@ -353,7 +385,7 @@ public class ManagedBuildManager {
if (buildInfo == null && create) {
try {
- buildInfo = new ResourceBuildInfo();
+ buildInfo = new ManagedBuildInfo();
resource.setSessionProperty(buildInfoProperty, buildInfo);
} catch (CoreException e) {
buildInfo = null;
@@ -363,12 +395,22 @@ public class ManagedBuildManager {
return buildInfo;
}
- public static IResourceBuildInfo getBuildInfo(IResource resource, boolean create) {
- return (IResourceBuildInfo) findBuildInfo(resource, create);
+ public static IManagedBuildInfo getBuildInfo(IResource resource, boolean create) {
+ return (IManagedBuildInfo) findBuildInfo(resource, create);
}
- public static IResourceBuildInfo getBuildInfo(IResource resource) {
- return (IResourceBuildInfo) findBuildInfo(resource, false);
+ public static IManagedBuildInfo getBuildInfo(IResource resource) {
+ return (IManagedBuildInfo) findBuildInfo(resource, false);
+ }
+
+ /*
+ * @return
+ */
+ private static Map getBuildModelListeners() {
+ if (buildModelListeners == null) {
+ buildModelListeners = new HashMap();
+ }
+ return buildModelListeners;
}
/**
@@ -378,8 +420,88 @@ public class ManagedBuildManager {
* @param resource
* @return
*/
- public static IManagedBuildPathInfo getBuildPathInfo(IResource resource) {
- return (IManagedBuildPathInfo) getBuildInfo(resource, false);
+ private static IScannerInfo getScannerInfo(IResource resource) {
+ return (IScannerInfo) getBuildInfo(resource, false);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#subscribe(org.eclipse.cdt.core.parser.IScannerInfoChangeListener)
+ */
+ public synchronized void subscribe(IResource resource, IScannerInfoChangeListener listener) {
+ IResource project = null;
+ if (resource instanceof IProject) {
+ project = resource;
+ } else if (resource instanceof IFile) {
+ project = ((IFile)resource).getProject();
+ } else {
+ return;
+ }
+ // Get listeners for this resource
+ Map map = getBuildModelListeners();
+ List list = (List) map.get(project);
+ if (list == null) {
+ // Create a new list
+ list = new ArrayList();
+ }
+ if (!list.contains(listener)) {
+ // Add the new listener for the resource
+ list.add(listener);
+ map.put(project, list);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#managesResource(org.eclipse.core.resources.IResource)
+ */
+ public boolean managesResource(IResource resource) {
+ // The managed build manager manages build information for the
+ // resource IFF it it is a project and has a build file with the proper
+ // root element
+ IProject project = null;
+ if (resource instanceof IProject){
+ project = (IProject)resource;
+ } else if (resource instanceof IFile) {
+ project = ((IFile)resource).getProject();
+ } else {
+ return false;
+ }
+ IFile file = project.getFile(FILE_NAME);
+ if (file.exists()) {
+ try {
+ InputStream stream = file.getContents();
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document document = parser.parse(stream);
+ Node rootElement = document.getFirstChild();
+ if (rootElement.getNodeName().equals(ROOT_ELEM_NAME)) {
+ return true;
+ }
+ } catch (Exception e) {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#unsubscribe(org.eclipse.cdt.core.parser.IScannerInfoChangeListener)
+ */
+ public synchronized void unsubscribe(IResource resource, IScannerInfoChangeListener listener) {
+ IResource project = null;
+ if (resource instanceof IProject) {
+ project = resource;
+ } else if (resource instanceof IFile) {
+ project = ((IFile)resource).getProject();
+ } else {
+ return;
+ }
+ // Remove the listener
+ Map map = getBuildModelListeners();
+ List list = (List) map.get(project);
+ if (list != null && !list.isEmpty()) {
+ // The list is not empty so try to remove listener
+ list.remove(listener);
+ map.put(project, list);
+ }
}
}
diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/standard/StandardBuildManager.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/standard/StandardBuildManager.java
new file mode 100644
index 0000000000..263e307cbd
--- /dev/null
+++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/standard/StandardBuildManager.java
@@ -0,0 +1,308 @@
+package org.eclipse.cdt.core.build.standard;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.xerces.dom.DocumentImpl;
+import org.apache.xml.serialize.Method;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.Serializer;
+import org.apache.xml.serialize.SerializerFactory;
+import org.eclipse.cdt.core.BuildInfoFactory;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.parser.IScannerInfo;
+import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
+import org.eclipse.cdt.core.parser.IScannerInfoProvider;
+import org.eclipse.cdt.core.resources.IStandardBuildInfo;
+import org.eclipse.core.resources.IFile;
+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;
+
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+***********************************************************************/
+
+public class StandardBuildManager implements IScannerInfoProvider {
+ // Name we will use to store build property with the project
+ private static final QualifiedName buildInfoProperty
+ = new QualifiedName(CCorePlugin.PLUGIN_ID, "standardBuildInfo");
+
+ // Listeners interested in build model changes
+ private static Map buildModelListeners;
+
+ private static final String FILE_NAME = ".cdtbuild";
+ private static final String ROOT_ELEM_NAME = "StandardProjectBuildInfo";
+
+ /**
+ * @param project
+ * @return
+ */
+ private static IStandardBuildInfo findBuildInfo(IResource resource, boolean create) {
+ IStandardBuildInfo buildInfo = null;
+ // See if there's already one associated with the resource for this session
+ try {
+ buildInfo = (IStandardBuildInfo)resource.getSessionProperty(buildInfoProperty);
+ } catch (CoreException e) {
+ return buildInfo;
+ }
+
+ // Try to load one for the project
+ if (buildInfo == null && resource instanceof IProject) {
+ buildInfo = loadBuildInfo((IProject)resource);
+ }
+
+ // There is nothing persisted for the session, or saved in a file so
+ // create a build info object
+ if (buildInfo == null && create) {
+ buildInfo = BuildInfoFactory.create((IProject)resource);
+ try {
+ ((IProject)resource).setSessionProperty(buildInfoProperty, buildInfo);
+ } catch (CoreException e) {
+ buildInfo = null;
+ }
+ }
+ return buildInfo;
+ }
+
+ public static IStandardBuildInfo getBuildInfo(IProject project) {
+ return findBuildInfo(project, false);
+ }
+
+ public static IStandardBuildInfo getBuildInfo(IProject project, boolean create) {
+ return findBuildInfo(project, create);
+ }
+
+ /*
+ * @return
+ */
+ private static synchronized Map getBuildModelListeners() {
+ if (buildModelListeners == null) {
+ buildModelListeners = new HashMap();
+ }
+ return buildModelListeners;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#managesResource(org.eclipse.core.resources.IResource)
+ */
+ public boolean managesResource(IResource resource) {
+ /*
+ * Answers true if this project has a build info associated with it
+ */
+
+ IProject project = null;
+ if (resource instanceof IProject) {
+ project = (IProject)resource;
+ } else if (resource instanceof IFile) {
+ project = ((IFile)resource).getProject();
+ } else {
+ return false;
+ }
+
+ // Look for (but do not create) the build information
+ IStandardBuildInfo info = getBuildInfo(project);
+
+ // If there's info, I manage the resource
+ return info == null ? false : true;
+ }
+
+ public static void setPreprocessorSymbols(IProject project, String[] symbols) {
+ // Get the information for the project
+ IStandardBuildInfo info = getBuildInfo(project);
+ // Set the new information
+ if (info != null) {
+ String[] oldSymbols = info.getPreprocessorSymbols();
+ if (!Arrays.equals(oldSymbols, symbols)) {
+ info.setPreprocessorSymbols(symbols);
+ // Alert the listeners
+ setScannerInfoDirty(project, info);
+ }
+ }
+ }
+
+ public static void setIncludePaths(IProject project, String[] paths) {
+ // Get the build info for the project
+ IStandardBuildInfo info = getBuildInfo(project);
+ if (info != null) {
+ String[] oldPaths = info.getIncludePaths();
+ if (!Arrays.equals(oldPaths, paths)) {
+ info.setIncludePaths(paths);
+ setScannerInfoDirty(project, info);
+ }
+ }
+ }
+
+ /**
+ * @param project
+ * @param info
+ */
+ private static void setScannerInfoDirty(IProject project, IStandardBuildInfo info) {
+ // Call in the cavalry
+ List listeners = (List) getBuildModelListeners().get(project);
+ if (listeners == null) {
+ return;
+ }
+ ListIterator iter = listeners.listIterator();
+ while (iter.hasNext()) {
+ ((IScannerInfoChangeListener)iter.next()).changeNotification(project, (IScannerInfo) info);
+ }
+
+ }
+
+ /*
+ * 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 static IStandardBuildInfo loadBuildInfo(IProject project) {
+ IStandardBuildInfo buildInfo = null;
+ IFile file = project.getFile(FILE_NAME);
+ if (!file.exists())
+ return null;
+
+ try {
+ InputStream stream = file.getContents();
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document document = parser.parse(stream);
+ Node rootElement = document.getFirstChild();
+ if (rootElement.getNodeName().equals(ROOT_ELEM_NAME)) {
+ buildInfo = BuildInfoFactory.create(project, (Element)rootElement);
+ project.setSessionProperty(buildInfoProperty, buildInfo);
+ }
+ } catch (Exception e) {
+ buildInfo = null;
+ }
+
+ return buildInfo;
+ }
+
+ /**
+ * 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 removeBuildInfo(IResource resource) {
+ try {
+ resource.setSessionProperty(buildInfoProperty, 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 project
+ */
+ public static void saveBuildInfo(IProject project) {
+ // Create document
+ Document doc = new DocumentImpl();
+ Element rootElement = doc.createElement(ROOT_ELEM_NAME);
+ doc.appendChild(rootElement);
+
+ // Save the build info
+ IStandardBuildInfo buildInfo = getBuildInfo(project);
+ if (buildInfo != null)
+ buildInfo.serialize(doc, rootElement);
+
+ // Save the document
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+ format.setLineSeparator(System.getProperty("line.separator")); //$NON-NLS-1$
+ String xml = null;
+ try {
+ Serializer serializer = SerializerFactory.getSerializerFactory(Method.XML).makeSerializer(new OutputStreamWriter(s, "UTF8"), format);
+ serializer.asDOMSerializer().serialize(doc);
+ xml = s.toString("UTF8"); //$NON-NLS-1$
+ IFile rscFile = project.getFile(FILE_NAME);
+ InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
+ // update the resource content
+ if (rscFile.exists()) {
+ rscFile.setContents(inputStream, IResource.FORCE, null);
+ } else {
+ rscFile.create(inputStream, IResource.FORCE, null);
+ }
+ } catch (Exception e) {
+ return;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#subscribe(org.eclipse.core.resources.IResource, org.eclipse.cdt.core.parser.IScannerInfoChangeListener)
+ */
+ public synchronized void subscribe(IResource resource, IScannerInfoChangeListener listener) {
+ IResource project = null;
+ if (resource instanceof IProject) {
+ project = resource;
+ } else if (resource instanceof IFile) {
+ project = ((IFile)resource).getProject();
+ } else {
+ return;
+ }
+ // Get listeners for this resource
+ Map map = getBuildModelListeners();
+ List list = (List) map.get(project);
+ if (list == null) {
+ // Create a new list
+ list = new ArrayList();
+ }
+ if (!list.contains(listener)) {
+ // Add the new listener for the resource
+ list.add(listener);
+ map.put(project, list);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#unsubscribe(org.eclipse.core.resources.IResource, org.eclipse.cdt.core.parser.IScannerInfoChangeListener)
+ */
+ public synchronized void unsubscribe(IResource resource, IScannerInfoChangeListener listener) {
+ IResource project = null;
+ if (resource instanceof IProject) {
+ project = resource;
+ } else if (resource instanceof IFile) {
+ project = ((IFile)resource).getProject();
+ } else {
+ return;
+ }
+ // Remove the listener
+ Map map = getBuildModelListeners();
+ List list = (List) map.get(project);
+ if (list != null && !list.isEmpty()) {
+ // The list is not empty so try to remove listener
+ list.remove(listener);
+ map.put(project, list);
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ResourceBuildInfo.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ManagedBuildInfo.java
index 8cd236cbad..04502ea575 100644
--- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ResourceBuildInfo.java
+++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ManagedBuildInfo.java
@@ -19,18 +19,18 @@ import java.util.ListIterator;
import java.util.Map;
import org.eclipse.cdt.core.build.managed.BuildException;
-import org.eclipse.cdt.core.build.managed.IManagedBuildPathInfo;
import org.eclipse.cdt.core.build.managed.IConfiguration;
import org.eclipse.cdt.core.build.managed.IOption;
-import org.eclipse.cdt.core.build.managed.IResourceBuildInfo;
+import org.eclipse.cdt.core.build.managed.IManagedBuildInfo;
import org.eclipse.cdt.core.build.managed.ITarget;
import org.eclipse.cdt.core.build.managed.ITool;
+import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.core.resources.IResource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-public class ResourceBuildInfo implements IResourceBuildInfo, IManagedBuildPathInfo {
+public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
private IResource owner;
private Map targetMap;
@@ -38,13 +38,13 @@ public class ResourceBuildInfo implements IResourceBuildInfo, IManagedBuildPathI
private Map defaultConfigurations;
private ITarget defaultTarget;
- public ResourceBuildInfo() {
+ public ManagedBuildInfo() {
targetMap = new HashMap();
targets = new ArrayList();
defaultConfigurations = new HashMap();
}
- public ResourceBuildInfo(IResource owner, Element element) {
+ public ManagedBuildInfo(IResource owner, Element element) {
this();
// The id of the default configuration
String defaultTargetId = null;
@@ -277,11 +277,11 @@ public class ResourceBuildInfo implements IResourceBuildInfo, IManagedBuildPathI
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.core.build.managed.IBuildParseInfo#getDefinedSymbols()
+ * @see org.eclipse.cdt.core.build.managed.IScannerInfo#getDefinedSymbols()
*/
- public String[] getDefinedSymbols() {
- // Return the include paths for the default configuration
- ArrayList paths = new ArrayList();
+ public Map getDefinedSymbols() {
+ // Return the defined symbols for the default configuration
+ HashMap symbols = new HashMap();
IConfiguration config = getDefaultConfiguration(getDefaultTarget());
ITool[] tools = config.getTools();
for (int i = 0; i < tools.length; i++) {
@@ -291,7 +291,24 @@ public class ResourceBuildInfo implements IResourceBuildInfo, IManagedBuildPathI
IOption option = opts[j];
if (option.getValueType() == IOption.PREPROCESSOR_SYMBOLS) {
try {
- paths.addAll(Arrays.asList(option.getDefinedSymbols()));
+ String[] symbolList = option.getDefinedSymbols();
+ for (int k = 0; k < symbolList.length; k++) {
+ String symbol = symbolList[k];
+ if (symbol.length() == 0){
+ continue;
+ }
+ String key = new String();
+ String value = new String();
+ int index = symbol.indexOf("=");
+ if (index != -1) {
+ key = symbol.substring(0, index).trim();
+ value = symbol.substring(index + 1).trim();
+ } else {
+ key = symbol.trim();
+ }
+ symbols.put(key, value);
+ }
+
} catch (BuildException e) {
// we should never get here
continue;
@@ -299,12 +316,11 @@ public class ResourceBuildInfo implements IResourceBuildInfo, IManagedBuildPathI
}
}
}
- paths.trimToSize();
- return (String[])paths.toArray(new String[paths.size()]);
+ return symbols;
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.core.build.managed.IBuildParseInfo#getIncludePaths()
+ * @see org.eclipse.cdt.core.build.managed.IScannerInfo#getIncludePaths()
*/
public String[] getIncludePaths() {
// Return the include paths for the default configuration
diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java
index 406972b567..b01bf3ba74 100644
--- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java
+++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java
@@ -16,7 +16,7 @@ import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.build.managed.IConfiguration;
-import org.eclipse.cdt.core.build.managed.IResourceBuildInfo;
+import org.eclipse.cdt.core.build.managed.IManagedBuildInfo;
import org.eclipse.cdt.core.build.managed.ITarget;
import org.eclipse.cdt.core.build.managed.ITool;
import org.eclipse.cdt.core.build.managed.ManagedBuildManager;
@@ -68,7 +68,7 @@ public class Target extends BuildObject implements ITarget {
this.isTest = parent.isTestTarget();
// Hook me up
- IResourceBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(owner, true);
+ IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(owner, true);
buildInfo.addTarget(this);
}
@@ -129,7 +129,7 @@ public class Target extends BuildObject implements ITarget {
* @param buildInfo
* @param element
*/
- public Target(ResourceBuildInfo buildInfo, Element element) {
+ public Target(ManagedBuildInfo buildInfo, Element element) {
this(buildInfo.getOwner());
// id

Back to the top