Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Sennikovsky2006-04-14 14:18:07 -0400
committerMikhail Sennikovsky2006-04-14 14:18:07 -0400
commitd21adaeeb299058a59a045ae4dbe9335d59050d3 (patch)
tree61206f263004102d63256f97905ebafc523abc14 /build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core
parent6051a416ba0b631aabaecaf4bbc70f4cb1249146 (diff)
downloadorg.eclipse.cdt-d21adaeeb299058a59a045ae4dbe9335d59050d3.tar.gz
org.eclipse.cdt-d21adaeeb299058a59a045ae4dbe9335d59050d3.tar.xz
org.eclipse.cdt-d21adaeeb299058a59a045ae4dbe9335d59050d3.zip
1. Internal builder integration into managed builder core and UI
2. Rebuild state persistence 3. More smart active configuration change handling 4. Rebuild is initiated when active config is changed now 5. Other bug-fixes
Diffstat (limited to 'build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core')
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java198
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java91
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java13
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedProject.java3
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties1
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PropertyManager.java372
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceChangeHandler.java1
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java17
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java24
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java20
10 files changed, 711 insertions, 29 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java
index f8f1011e9e..ca079ad4ba 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java
@@ -44,6 +44,7 @@ import org.eclipse.cdt.managedbuilder.macros.IConfigurationBuildMacroSupplier;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.PluginVersionIdentifier;
@@ -80,6 +81,43 @@ public class Configuration extends BuildObject implements IConfiguration {
private boolean resolved = true;
private boolean isTemporary = false;
+ //property name for holding the rebuild state
+ private static final String REBUILD_STATE = "rebuildState"; //$NON-NLS-1$
+
+ //The resource delta passed to the builder is not always up-to-date
+ //for the given configuration because between two builds of the same configuration
+ //any number of other configuration builds may occur
+ //that is why we need to keep some information regarding what happened
+ //with the resource tree between the two configuration builds
+ //
+ //The trivial approach implemented currently is to hold
+ //the general information of whether some resources were
+ //removed,changed,etc. and detect whether the rebuild is needed
+ //based upon this information
+ //
+ //In the future we might implement some more smart mechanism
+ //for tracking delta, e.g calculate the pre-cinfiguration resource delta, etc.
+ //
+ //property for holding the resource change state
+ private static final String RC_CHANGE_STATE = "rcState"; //$NON-NLS-1$
+ //resource change state
+ private int resourceChangeState;
+
+ //Internal Builder state
+ //NOTE: these are temporary properties
+ //In the future we are going present the Internal Builder
+ //as a special Builder object of the tool-chain and implement the internal
+ //builder enabling/disabling as the Builder substitution functionality
+ //
+ //property that holds the Internal Builder enable state
+ private static final String INTERNAL_BUILDER_ENABLED = "internalBuilderOn"; //$NON-NLS-1$
+ //property that holds the internal builder mode
+ private static final String INTERNAL_BUILDER_IGNORE_ERR = "internalBuilderIgnoreErr"; //$NON-NLS-1$
+ //Internal Builder enable state
+ private boolean internalBuilderEnabled;
+ //Internal Builder mode
+ private boolean internalBuilderIgnoreErr;
+
/*
* C O N S T R U C T O R S
@@ -215,6 +253,28 @@ public class Configuration extends BuildObject implements IConfiguration {
addResourceConfiguration(resConfig);
}
}
+
+ PropertyManager mngr = PropertyManager.getInstance();
+ String rebuild = mngr.getProperty(this, REBUILD_STATE);
+ if(rebuild == null || Boolean.parseBoolean(rebuild))
+ rebuildNeeded = true;
+
+ String rcChangeState = mngr.getProperty(this, RC_CHANGE_STATE);
+ if(rcChangeState == null)
+ resourceChangeState = ~0;
+ else {
+ try {
+ resourceChangeState = Integer.parseInt(rcChangeState);
+ } catch (NumberFormatException e){
+ resourceChangeState = ~0;
+ }
+ }
+
+ internalBuilderEnabled = Boolean.parseBoolean(
+ mngr.getProperty(this, INTERNAL_BUILDER_ENABLED));
+ String tmp = mngr.getProperty(this, INTERNAL_BUILDER_IGNORE_ERR);
+ if(tmp == null || Boolean.parseBoolean(tmp))
+ internalBuilderIgnoreErr = true;
}
/**
@@ -267,6 +327,9 @@ public class Configuration extends BuildObject implements IConfiguration {
postannouncebuildStep = new String(cloneConfig.postannouncebuildStep);
}
+ internalBuilderEnabled = cloneConfig.internalBuilderEnabled;
+ internalBuilderIgnoreErr = cloneConfig.internalBuilderIgnoreErr;
+
// Clone the configuration's children
// Tool Chain
String subId;
@@ -522,6 +585,8 @@ public class Configuration extends BuildObject implements IConfiguration {
element.appendChild(resElement);
resConfig.serialize(doc, resElement);
}
+
+ PropertyManager.getInstance().serialize(this);
// I am clean now
isDirty = false;
@@ -1314,8 +1379,10 @@ public class Configuration extends BuildObject implements IConfiguration {
}
public boolean needsRebuild(boolean checkChildren) {
- if(rebuildNeeded || !checkChildren)
- return rebuildNeeded;
+ boolean needRebuild = rebuildNeeded || resourceChangesRequireRebuild();
+
+ if(needRebuild || !checkChildren)
+ return needRebuild;
if(toolChain.needsRebuild())
return true;
@@ -1365,18 +1432,25 @@ public class Configuration extends BuildObject implements IConfiguration {
if(isExtensionElement() && rebuild)
return;
- rebuildNeeded = rebuild;
+ if(rebuildNeeded != rebuild){
+ rebuildNeeded = rebuild;
+ saveRebuildState();
+ }
if(!rebuildNeeded){
+ setResourceChangeState(0);
+
toolChain.setRebuildState(false);
- for(Iterator iter = resourceConfigurationList.iterator();iter.hasNext();){
- IResourceConfiguration rcCfg = (IResourceConfiguration)iter.next();
- rcCfg.setRebuildState(false);
-
- ITool tools[] = rcCfg.getToolsToInvoke();
- for(int i = 0; i < tools.length; i++){
- tools[i].setRebuildState(false);
+ if(resourceConfigurationList != null){
+ for(Iterator iter = resourceConfigurationList.iterator();iter.hasNext();){
+ IResourceConfiguration rcCfg = (IResourceConfiguration)iter.next();
+ rcCfg.setRebuildState(false);
+
+ ITool tools[] = rcCfg.getToolsToInvoke();
+ for(int i = 0; i < tools.length; i++){
+ tools[i].setRebuildState(false);
+ }
}
}
@@ -1582,4 +1656,108 @@ public class Configuration extends BuildObject implements IConfiguration {
return tool;
}
+
+ /*
+ * The resource delta passed to the builder is not always up-to-date
+ * for the given configuration because between two builds of the same configuration
+ * any number of other configuration builds may occur
+ * that is why we need to keep some information regarding what happened
+ * with the resource tree between the two configuration builds
+ *
+ * The trivial approach implemented currently is to hold
+ * the general information of whether some resources were
+ * removed,changed,etc. and detect whether the rebuild is needed
+ * based upon this information
+ *
+ * This method adds the resource change state for the configuration
+ * specifying the resource change type performed on the project
+ * reported while building another configuration
+ * The method is not exported to the public API since delta handling
+ * mechanism will likely to be changed in the future
+ *
+ * In the future we might implement some more smart mechanism
+ * for tracking delta, e.g calculate the pre-cinfiguration resource delta, etc.
+ *
+ */
+ public void addResourceChangeState(int state){
+ setResourceChangeState(state | resourceChangeState);
+ }
+
+ private void setResourceChangeState(int state){
+ if(resourceChangeState != state){
+ resourceChangeState = state;
+ saveResourceChangeState();
+ }
+ }
+
+ private boolean resourceChangesRequireRebuild(){
+ return isInternalBuilderEnabled() ?
+ resourceChangeState != 0 :
+ (resourceChangeState & IResourceDelta.REMOVED) == IResourceDelta.REMOVED;
+ }
+
+ private void saveRebuildState(){
+ PropertyManager.getInstance().setProperty(this, REBUILD_STATE, Boolean.toString(rebuildNeeded));
+ }
+
+ private void saveResourceChangeState(){
+ PropertyManager.getInstance().setProperty(this, RC_CHANGE_STATE, Integer.toString(resourceChangeState));
+ }
+
+ /*
+ * Internal Builder state API
+ * NOTE: this is a temporary API
+ * In the future we are going present the Internal Builder
+ * as a special Builder object of the tool-chain and implement the internal
+ * builder enabling/disabling as the Builder substitution functionality
+ *
+ */
+
+ /*
+ * this method is used for enabling/disabling the internal builder
+ * for the given configuration
+ *
+ * @param enable boolean
+ */
+ public void enableInternalBuilder(boolean enable){
+ if(internalBuilderEnabled != enable){
+ internalBuilderEnabled = enable;
+ PropertyManager.getInstance().setProperty(this, INTERNAL_BUILDER_ENABLED, Boolean.toString(internalBuilderEnabled));
+ }
+ }
+
+ /*
+ * returns whether the internal builder is enabled
+ *
+ * @return boolean
+ */
+ public boolean isInternalBuilderEnabled(){
+ return internalBuilderEnabled;
+ }
+
+ /*
+ *
+ * sets the Internal Builder mode
+ *
+ * @param ignore if true, internal builder will ignore
+ * build errors while building,
+ * otherwise it will stop at the first build error
+ */
+ public void setInternalBuilderIgnoreErr(boolean ignore){
+ if(internalBuilderIgnoreErr != ignore){
+ internalBuilderIgnoreErr = ignore;
+ PropertyManager.getInstance().setProperty(this, INTERNAL_BUILDER_IGNORE_ERR, Boolean.toString(internalBuilderIgnoreErr));
+ }
+ }
+
+ /*
+ * returns the Internal Builder mode
+ * if true, internal builder will ignore build errors while building,
+ * otherwise it will stop at the first build error
+ *
+ * @return boolean
+ */
+ public boolean getInternalBuilderIgnoreErr(){
+ return internalBuilderIgnoreErr;
+ }
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java
index 283bf75941..09c94d3211 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java
@@ -208,6 +208,81 @@ public class GeneratedMakefileBuilder extends ACBuilder {
}
}
+ private static class OtherConfigVerifier implements IResourceDeltaVisitor {
+ IConfiguration config;
+ IConfiguration configs[];
+ Configuration otherConfigs[];
+ int resourceChangeState;
+
+ private static final IPath[] ignoreList = {
+ new Path(".cdtproject"), //$NON-NLS-1$
+ new Path(".cproject"), //$NON-NLS-1$
+ new Path(".cdtbuild"), //$NON-NLS-1$
+ new Path(".settings"), //$NON-NLS-1$
+ };
+
+ OtherConfigVerifier(IConfiguration cfg){
+ config = cfg;
+ configs = cfg.getManagedProject().getConfigurations();
+ otherConfigs = new Configuration[configs.length - 1];
+ int counter = 0;
+ for(int i = 0; i < configs.length; i++){
+ if(configs[i] != config)
+ otherConfigs[counter++] = (Configuration)configs[i];
+ }
+ }
+
+ public boolean visit(IResourceDelta delta) throws CoreException {
+
+ IResource rc = delta.getResource();
+ if(rc.getType() == IResource.FILE){
+ if(isResourceValuable(rc))
+ resourceChangeState |= delta.getKind();
+ return false;
+ }
+ return !isGeneratedForConfig(rc, config) && isResourceValuable(rc);
+ }
+
+ public void updateOtherConfigs(IResourceDelta delta){
+ if(delta == null)
+ resourceChangeState = ~0;
+ else {
+ try {
+ delta.accept(this);
+ } catch (CoreException e) {
+ resourceChangeState = ~0;
+ }
+ }
+
+ setResourceChangeStateForOtherConfigs();
+ }
+
+ private void setResourceChangeStateForOtherConfigs(){
+ for(int i = 0; i < otherConfigs.length; i++){
+ otherConfigs[i].addResourceChangeState(resourceChangeState);
+ }
+ }
+
+ private boolean isGeneratedForConfig(IResource resource, IConfiguration cfg) {
+ // Is this a generated directory ...
+ IPath path = resource.getProjectRelativePath();
+ IPath root = new Path(cfg.getName());
+ // It is if it is a root of the resource pathname
+ if (root.isPrefixOf(path))
+ return true;
+ return false;
+ }
+
+ private boolean isResourceValuable(IResource rc){
+ IPath path = rc.getProjectRelativePath();
+ for(int i = 0; i < ignoreList.length; i++){
+ if(ignoreList[i].equals(path))
+ return false;
+ }
+ return true;
+ }
+ }
+
// String constants
private static final String BUILD_ERROR = "ManagedMakeBuilder.message.error"; //$NON-NLS-1$
private static final String BUILD_FINISHED = "ManagedMakeBuilder.message.finished"; //$NON-NLS-1$
@@ -340,18 +415,16 @@ public class GeneratedMakefileBuilder extends ACBuilder {
IConfiguration cfg = info.getDefaultConfiguration();
-// Uncomment the below code for using the Internal Builder
-// TODO: the info of what builder is to be used
-// should be held in and obtained from the Configuration
-/*
- if(true){
- invokeInternalBuilder(cfg, kind != FULL_BUILD, true, monitor);
+ updateOtherConfigs(cfg, kind);
+
+ if(((Configuration)cfg).isInternalBuilderEnabled()){
+ invokeInternalBuilder(cfg, kind != FULL_BUILD, ((Configuration)cfg).getInternalBuilderIgnoreErr(), monitor);
// Scrub the build info the project
info.setRebuildState(false);
return referencedProjects;
}
-*/
+
// Create a makefile generator for the build
IManagedBuilderMakefileGenerator generator = ManagedBuildManager.getBuildfileGenerator(info.getDefaultConfiguration());
generator.initialize(getProject(), info, monitor);
@@ -474,6 +547,10 @@ public class GeneratedMakefileBuilder extends ACBuilder {
return referencedProjects;
}
+ private void updateOtherConfigs(IConfiguration cfg, int buildKind){
+ new OtherConfigVerifier(cfg).updateOtherConfigs(buildKind == FULL_BUILD ? null : getDelta(getProject()));
+ }
+
/**
* Check whether the build has been canceled. Cancellation requests
* propagated to the caller by throwing <code>OperationCanceledException</code>.
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java
index 9ad4fa2589..33bdb114a5 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java
@@ -18,8 +18,6 @@ import java.util.List;
import java.util.Map;
import java.util.Vector;
-import org.eclipse.cdt.core.CCProjectNature;
-import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
@@ -950,8 +948,15 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
defaultConfig = configuration;
defaultConfigId = configuration.getId();
- defaultConfig.setRebuildState(true);
-
+ IProject proj = getOwner().getProject();
+ IResource cdtbuildFile = proj.findMember(ManagedBuildManager.SETTINGS_FILE_NAME);
+ if(cdtbuildFile != null){
+ try {
+ cdtbuildFile.touch(new NullProgressMonitor());
+ } catch (CoreException e) {
+ //TODO: log an error
+ }
+ }
// TODO: is this appropriate?
persistDefaultConfiguration();
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedProject.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedProject.java
index bc276ea078..fad07ac222 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedProject.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedProject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2005 Intel Corporation and others.
+ * Copyright (c) 2004, 2006 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -313,6 +313,7 @@ public class ManagedProject extends BuildObject implements IManagedProject {
ManagedBuildManager.performValueHandlerEvent(config,
IManagedOptionValueHandler.EVENT_CLOSE);
+ PropertyManager.getInstance().clearProperties(config);
getConfigurationList().remove(config);
getConfigurationMap().remove(removeId);
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties
index 62249c1c28..7ad3ff4739 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties
@@ -29,6 +29,7 @@ ManagedMakeBuilder.message.finished = Build complete for project {0}
ManagedMakeBuilder.message.cancelled = Build cancelled
ManagedMakeBuilder.message.finished.with.errs = Build completed with errors
ManagedMakeBuilder.message.internal.builder.error = Build failed: Internal builder error occured
+ManagedMakeBuilder.message.stopped.error=Build error occured, build is stopped
ManagedMakeBuilder.message.clean.deleting.output=Removing build artifacts from {0}
ManagedMakeBuilder.message.clean.build.clean=Trying a make clean in {0}
ManagedMakeBuilder.type.clean = Clean-only build
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PropertyManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PropertyManager.java
new file mode 100644
index 0000000000..abff32ce5b
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PropertyManager.java
@@ -0,0 +1,372 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.core;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import org.eclipse.cdt.managedbuilder.core.IBuildObject;
+import org.eclipse.cdt.managedbuilder.core.IBuilder;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
+import org.eclipse.cdt.managedbuilder.core.ITool;
+import org.eclipse.cdt.managedbuilder.core.IToolChain;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.QualifiedName;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+
+/**
+ * This class allows specifying BuildObject-specific persisted properties
+ * The properties are stored as project preferences for now
+ *
+ */
+public class PropertyManager {
+ private static final String PROPS_PROPERTY = "properties"; //$NON-NLS-1$
+ private static final QualifiedName propsSessionProperty = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), PROPS_PROPERTY);
+
+ private static final String NODE_NAME = "properties"; //$NON-NLS-1$
+
+ private static PropertyManager fInstance;
+
+ private PropertyManager(){
+ }
+
+ public static PropertyManager getInstance(){
+ if(fInstance == null)
+ fInstance = new PropertyManager();
+ return fInstance;
+ }
+
+ protected void setProperty(IConfiguration cfg, IBuildObject bo, String prop, String value){
+ Properties props = getProperties(cfg, bo);
+ if(props != null)
+ props.setProperty(prop, value);
+ }
+
+ protected String getProperty(IConfiguration cfg, IBuildObject bo, String prop){
+ Properties props = getProperties(cfg, bo);
+ if(props != null)
+ return props.getProperty(prop);
+ return null;
+ }
+
+ protected Properties getProperties(IConfiguration cfg, IBuildObject bo){
+ return loadProperties(cfg, bo);
+ }
+
+ protected Map getLoaddedData(IConfiguration cfg){
+ Map map = null;
+ try {
+ IProject proj = cfg.getOwner().getProject();
+ map = (Map)proj.getSessionProperty(propsSessionProperty);
+ if(map == null){
+ map = new HashMap();
+ proj.setSessionProperty(propsSessionProperty, map);
+ }
+ map = (Map)map.get(cfg.getId());
+ } catch (CoreException e) {
+ }
+ return map;
+ }
+
+ protected void clearLoaddedData(IConfiguration cfg){
+ IProject proj = cfg.getOwner().getProject();
+ try {
+ proj.setSessionProperty(propsSessionProperty, null);
+ } catch (CoreException e) {
+ }
+ }
+
+ protected Properties loadProperties(IConfiguration cfg, IBuildObject bo){
+ Map map = getData(cfg);
+
+ return getPropsFromData(map, bo);
+ }
+
+ protected Properties getPropsFromData(Map data, IBuildObject bo){
+ Object oVal = data.get(bo.getId());
+ Properties props = null;
+ if(oVal instanceof String){
+ props = stringToProps((String)oVal);
+ data.put(bo.getId(), props);
+ } else if (oVal instanceof Properties){
+ props = (Properties)oVal;
+ }
+
+ if(props == null){
+ props = new Properties();
+ data.put(bo.getId(), props);
+ }
+
+ return props;
+ }
+
+
+ protected void storeData(IConfiguration cfg){
+ Map map = getLoaddedData(cfg);
+
+ if(map != null)
+ storeData(cfg, map);
+ }
+
+ protected Properties mapToProps(Map map){
+ Properties props = null;
+ if(map != null && map.size() > 0){
+ props = new Properties();
+ for(Iterator iter = map.entrySet().iterator(); iter.hasNext();){
+ Map.Entry entry = (Map.Entry)iter.next();
+ String key = (String)entry.getKey();
+ String value = null;
+ Object oVal = entry.getValue();
+ if(oVal instanceof Properties){
+ value = propsToString((Properties)oVal);
+ } else if (oVal instanceof String){
+ value = (String)oVal;
+ }
+
+ if(key != null && value != null)
+ props.setProperty(key, value);
+ }
+ }
+
+ return props;
+ }
+
+ protected String propsToString(Properties props){
+ if(props == null || props.size() == 0)
+ return null;
+
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ try {
+ props.store(stream, ""); //$NON-NLS-1$
+ } catch (IOException e1) {
+ }
+
+ byte[] bytes= stream.toByteArray();
+
+ String value = null;
+ try {
+ value= new String(bytes, "UTF-8"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ value= new String(bytes);
+ }
+ return value;
+ }
+
+ protected Properties stringToProps(String str){
+ Properties props = null;
+ if(str != null){
+ props = new Properties();
+ byte[] bytes;
+ try {
+ bytes = str.getBytes("UTF-8"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ bytes = str.getBytes();
+ }
+
+ ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
+ try {
+ props.load(stream);
+ } catch (IOException e) {
+ props = null;
+ }
+ }
+ return props;
+ }
+
+ protected void storeData(IConfiguration cfg, Map map){
+ String str = null;
+ Properties props = mapToProps(map);
+
+ str = propsToString(props);
+
+ storeString(cfg, str);
+ }
+
+ protected void storeString(IConfiguration cfg, String str){
+ IProject proj = cfg.getOwner().getProject();
+
+ Preferences prefs = getNode(proj);
+ if(prefs != null){
+ if(str != null)
+ prefs.put(cfg.getId(), str);
+ else
+ prefs.remove(cfg.getId());
+ try {
+ prefs.flush();
+ } catch (BackingStoreException e) {
+ }
+ }
+ }
+
+ protected String loadString(IConfiguration cfg){
+ IProject proj = cfg.getOwner().getProject();
+
+ if(proj == null || !proj.exists() || !proj.isOpen())
+ return null;
+
+ String str = null;
+ Preferences prefs = getNode(proj);
+ if(prefs != null)
+ str = prefs.get(cfg.getId(), null);
+ return str;
+ }
+
+ protected Preferences getNode(IProject project){
+ Preferences prefs = new ProjectScope(project).getNode(ManagedBuilderCorePlugin.getUniqueIdentifier());
+ if(prefs != null)
+ return prefs.node(NODE_NAME);
+ return null;
+ }
+
+
+ protected Map getData(IConfiguration cfg){
+ Map map = getLoaddedData(cfg);
+
+ if(map == null){
+ map = loadData(cfg);
+
+ setLoaddedData(cfg, map);
+ }
+
+ return map;
+ }
+
+ protected Map loadData(IConfiguration cfg){
+ Map map = null;
+ String str = loadString(cfg);
+
+ Properties props = stringToProps(str);
+
+ map = propsToMap(props);
+
+ if(map == null)
+ map = new HashMap();
+
+ return map;
+ }
+
+ protected Map propsToMap(Properties props){
+ if(props != null)
+ return new HashMap(props);
+ return null;
+ }
+
+ protected void setLoaddedData(IConfiguration cfg, Map data){
+ try {
+ IProject proj = cfg.getOwner().getProject();
+ Map map = (Map)proj.getSessionProperty(propsSessionProperty);
+ if(map == null){
+ map = new HashMap();
+ proj.setSessionProperty(propsSessionProperty, map);
+ }
+ map.put(cfg.getId(), data);
+ } catch (CoreException e) {
+ }
+ }
+
+ public void setProperty(IConfiguration cfg, String key, String value){
+ setProperty(cfg, cfg, key, value);
+ }
+
+ public void setProperty(IResourceConfiguration rcCfg, String key, String value){
+ setProperty(rcCfg.getParent(), rcCfg, key, value);
+ }
+
+ public void setProperty(IToolChain tc, String key, String value){
+ setProperty(tc.getParent(), tc, key, value);
+ }
+
+ public void setProperty(ITool tool, String key, String value){
+ setProperty(getConfiguration(tool), tool, key, value);
+ }
+
+ public void setProperty(IBuilder builder, String key, String value){
+ setProperty(getConfiguration(builder), builder, key, value);
+ }
+
+ public String getProperty(IConfiguration cfg, String key){
+ return getProperty(cfg, cfg, key);
+ }
+
+ public String getProperty(IResourceConfiguration rcCfg, String key){
+ return getProperty(rcCfg.getParent(), rcCfg, key);
+ }
+
+ public String getProperty(IToolChain tc, String key){
+ return getProperty(tc.getParent(), tc, key);
+ }
+
+ public String getProperty(ITool tool, String key){
+ return getProperty(getConfiguration(tool), tool, key);
+ }
+
+ public String getProperty(IBuilder builder, String key){
+ return getProperty(getConfiguration(builder), builder, key);
+ }
+
+ public void clearProperties(IConfiguration cfg){
+ clearLoaddedData(cfg);
+ storeData(cfg, null);
+ }
+
+ private IConfiguration getConfiguration(IBuilder builder){
+ IToolChain tc = builder.getParent();
+ if(tc != null)
+ return tc.getParent();
+ return null;
+ }
+
+ private IConfiguration getConfiguration(ITool tool){
+ IBuildObject p = tool.getParent();
+ IConfiguration cfg = null;
+ if(p instanceof IToolChain){
+ cfg = ((IToolChain)p).getParent();
+ } else if(p instanceof IResourceConfiguration){
+ cfg = ((IResourceConfiguration)p).getParent();
+ }
+ return cfg;
+ }
+
+ public void serialize(IConfiguration cfg){
+ if(cfg.isTemporary())
+ return;
+
+ storeData(cfg);
+ }
+
+ public void serialize(){
+ IProject projects[] = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for(int i = 0; i < projects.length; i++){
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(projects[i], false);
+ if(info != null && info.isValid() && info.getManagedProject() != null){
+ IConfiguration cfgs[] = info.getManagedProject().getConfigurations();
+ for(int j = 0; j < cfgs.length; j++){
+ serialize(cfgs[j]);
+ }
+ }
+ }
+ }
+
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceChangeHandler.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceChangeHandler.java
index 6c0a0f99fb..ec3193dceb 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceChangeHandler.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceChangeHandler.java
@@ -436,6 +436,7 @@ public class ResourceChangeHandler implements IResourceChangeListener, ISavePart
// No state to be saved by the plug-in, but request a
// resource delta to be used on next activation.
context.needDelta();
+ PropertyManager.getInstance().serialize();
}
/* (non-Javadoc)
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java
index 54814e8959..dd76775c3d 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java
@@ -38,6 +38,9 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi
private static final String EMPTY_STRING = new String();
+ //property name for holding the rebuild state
+ private static final String REBUILD_STATE = "rebuildState"; //$NON-NLS-1$
+
// Parent and children
private IConfiguration parent;
private List toolList;
@@ -112,6 +115,10 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi
addTool(tool);
}
}
+
+ String rebuild = PropertyManager.getInstance().getProperty(this, REBUILD_STATE);
+ if(rebuild == null || Boolean.parseBoolean(rebuild))
+ rebuildState = true;
}
public ResourceConfiguration(IConfiguration parent, String id, String resourceName, String path){
@@ -888,7 +895,10 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi
if(isExtensionResourceConfiguration() && rebuild)
return;
- rebuildState = rebuild;
+ if(rebuildState != rebuild){
+ rebuildState = rebuild;
+ saveRebuildState();
+ }
if(!rebuildState){
ITool tools[] = getToolsToInvoke();
@@ -898,4 +908,9 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi
}
}
+
+ private void saveRebuildState(){
+ PropertyManager.getInstance().setProperty(this, REBUILD_STATE, Boolean.toString(rebuildState));
+ }
+
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java
index b955d3cda9..f6277388c1 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java
@@ -75,6 +75,9 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory {
public static final String DEFAULT_PATTERN = "${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}"; //$NON-NLS-1$
public static final String DEFAULT_CBS_PATTERN = "${COMMAND}"; //$NON-NLS-1$
+ //property name for holding the rebuild state
+ private static final String REBUILD_STATE = "rebuildState"; //$NON-NLS-1$
+
private static final String DEFAULT_SEPARATOR = ","; //$NON-NLS-1$
//private static final IOptionCategory[] EMPTY_CATEGORIES = new IOptionCategory[0];
//private static final IOption[] EMPTY_OPTIONS = new IOption[0];
@@ -291,6 +294,11 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory {
addOutputType(outputType);
}
}
+
+ String rebuild = PropertyManager.getInstance().getProperty(this, REBUILD_STATE);
+ if(rebuild == null || Boolean.parseBoolean(rebuild))
+ rebuildState = true;
+
}
/**
@@ -872,7 +880,9 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory {
// Save as URL in string form
element.setAttribute(IOptionCategory.ICON, iconPathURL.toString());
}
-
+
+ saveRebuildState();
+
// I am clean now
isDirty = false;
} catch (Exception e) {
@@ -2861,7 +2871,10 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory {
if(isExtensionElement() && rebuild)
return;
- rebuildState = rebuild;
+ if(rebuildState != rebuild){
+ rebuildState = rebuild;
+ saveRebuildState();
+ }
if(!rebuild){
super.setRebuildState(rebuild);
@@ -2881,7 +2894,10 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory {
}
}
}
-
-
}
+
+ private void saveRebuildState(){
+ PropertyManager.getInstance().setProperty(this, REBUILD_STATE, Boolean.toString(needsRebuild()));
+ }
+
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java
index f963c02f86..859d6da209 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java
@@ -50,6 +50,8 @@ public class ToolChain extends HoldsOptions implements IToolChain {
private static final String EMPTY_STRING = new String();
+ private static final String REBUILD_STATE = "rebuildState"; //$NON-NLS-1$
+
private static final boolean resolvedDefault = true;
// Superclass
@@ -234,6 +236,11 @@ public class ToolChain extends HoldsOptions implements IToolChain {
}
}
+
+ String rebuild = PropertyManager.getInstance().getProperty(this, REBUILD_STATE);
+ if(rebuild == null || Boolean.parseBoolean(rebuild))
+ rebuildState = true;
+
}
/**
@@ -683,7 +690,9 @@ public class ToolChain extends HoldsOptions implements IToolChain {
if(userDefinedEnvironment != null)
EnvironmentVariableProvider.fUserSupplier.storeEnvironment(getParent(),true);
-
+
+ saveRebuildState();
+
// I am clean now
isDirty = false;
} catch (Exception e) {
@@ -1746,9 +1755,16 @@ public class ToolChain extends HoldsOptions implements IToolChain {
if(isExtensionElement() && rebuild)
return;
- rebuildState = rebuild;
+ if(rebuildState != rebuild){
+ rebuildState = rebuild;
+ saveRebuildState();
+ }
if(!rebuild)
super.setRebuildState(rebuild);
}
+
+ private void saveRebuildState(){
+ PropertyManager.getInstance().setProperty(this, REBUILD_STATE, Boolean.toString(needsRebuild()));
+ }
}

Back to the top