1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Update to build model.

- ablility to add configs to target and set options on configs.
This commit is contained in:
Doug Schaefer 2003-04-17 19:21:40 +00:00
parent ec6fd870a4
commit b6956e3701
9 changed files with 292 additions and 175 deletions

View file

@ -16,10 +16,6 @@ public interface IBuildObject {
public String getId(); public String getId();
public void setId(String id);
public String getName(); public String getName();
public void setName(String name);
} }

View file

@ -37,4 +37,19 @@ public interface IConfiguration extends IBuildObject {
*/ */
public ITool[] getTools(); public ITool[] getTools();
/**
* Sets an option value for this configuration.
*
* @param option
* @param value
*/
public void setOption(IOption option, String value)
throws BuildException;
/**
* Sets an option value for this configuration.
* @param option
*/
public void setOption(IOption option, String[] value)
throws BuildException;
} }

View file

@ -33,13 +33,6 @@ public interface IOption extends IBuildObject {
*/ */
public IOptionCategory getCategory(); public IOptionCategory getCategory();
/**
* Set the option category for this option.
*
* @param category
*/
public void setCategory(IOptionCategory category);
/** /**
* Returns the name of this option. * Returns the name of this option.
* *
@ -68,35 +61,13 @@ public interface IOption extends IBuildObject {
* *
* @return * @return
*/ */
public String getStringValue(); public String getStringValue() throws BuildException;
/** /**
* Returns the current value for this option if it is a List of Strings. * Returns the current value for this option if it is a List of Strings.
* *
* @return * @return
*/ */
public String [] getStringListValue(); public String [] getStringListValue() throws BuildException;
/**
* Sets the value for this option in a given configuration.
* A new instance of the option for the configuration may be created.
* The appropriate new option is returned.
*
* @param config
* @param value
*/
public IOption setValue(IConfiguration config, String value)
throws BuildException;
/**
* Sets the value for this option in a given configuration.
* A new instance of the option for the configuration may be created.
* The appropriate new option is returned.
*
* @param config
* @param value
*/
public IOption setValue(IConfiguration config, String[] value)
throws BuildException;
} }

View file

@ -45,4 +45,24 @@ public interface ITarget extends IBuildObject {
*/ */
public IConfiguration[] getConfigurations(); public IConfiguration[] getConfigurations();
/**
* Creates a new configuration for the target. It is populated with
* the tools defined for that target and options set at their defaults.
*
* @param id id for this configuration.
* @return
*/
public IConfiguration createConfiguration(String id);
/**
* Creates a configuration for the target populated with the tools and
* options settings from the parent configuration. As options and tools
* change in the parent, unoverridden values are updated in the child
* config as well.
*
* @param parent
* @param id
* @return
*/
public IConfiguration createConfiguration(IConfiguration parent, String id);
} }

View file

@ -123,7 +123,7 @@ public class ManagedBuildManager {
} }
/** /**
* Adds a new target to the resource based on the parentTarget. * Creates a new target for the resource based on the parentTarget.
* *
* @param resource * @param resource
* @param parentTarget * @param parentTarget
@ -155,6 +155,26 @@ public class ManagedBuildManager {
return new Target(resource, parentTarget); return new Target(resource, parentTarget);
} }
/**
* Set the string value for an option for a given config.
*
* @param config
* @param option
* @param value
*/
public static void setOption(IConfiguration config, IOption option, String value) {
}
/**
* Set the string array value for an option for a given config.
*
* @param config
* @param option
* @param value
*/
public static void setOption(IConfiguration config, IOption option, String[] value) {
}
/** /**
* Saves the build information associated with a project and all resources * Saves the build information associated with a project and all resources
* in the project to the build info file. * in the project to the build info file.

View file

@ -13,11 +13,15 @@ package org.eclipse.cdt.internal.core.build.managed;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.build.managed.BuildException;
import org.eclipse.cdt.core.build.managed.IConfiguration; import org.eclipse.cdt.core.build.managed.IConfiguration;
import org.eclipse.cdt.core.build.managed.IOption;
import org.eclipse.cdt.core.build.managed.ITarget; import org.eclipse.cdt.core.build.managed.ITarget;
import org.eclipse.cdt.core.build.managed.ITool; import org.eclipse.cdt.core.build.managed.ITool;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/** /**
* *
@ -28,16 +32,28 @@ public class Configuration extends BuildObject implements IConfiguration {
private IConfiguration parent; private IConfiguration parent;
private List toolReferences; private List toolReferences;
public Configuration(Target target) { /**
* A fresh new configuration for a target.
* @param target
* @param id
*/
public Configuration(Target target, String id) {
this.id = id;
this.target = target; this.target = target;
target.addConfiguration(this);
} }
public Configuration(IConfiguration parent) { public Configuration(Target target, IConfiguration parent, String id) {
this.id = id;
this.target = target;
this.parent = parent; this.parent = parent;
target.addConfiguration(this);
} }
public Configuration(Target target, IConfigurationElement element) { public Configuration(Target target, IConfigurationElement element) {
this(target); this.target = target;
// id // id
setId(element.getAttribute("id")); setId(element.getAttribute("id"));
@ -57,6 +73,20 @@ public class Configuration extends BuildObject implements IConfiguration {
} }
} }
public void serealize(Document doc, Element element) {
element.setAttribute("id", id);
element.setAttribute("name", name);
if (parent != null)
element.setAttribute("parent", parent.getId());
if (toolReferences != null)
for (int i = 0; i < toolReferences.size(); ++i) {
ToolReference toolRef = (ToolReference)toolReferences.get(i);
Element toolRefElement = doc.createElement("toolRef");
toolRef.serealize(doc, toolRefElement);
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IConfiguration#getName() * @see org.eclipse.cdt.core.build.managed.IConfiguration#getName()
*/ */
@ -124,4 +154,37 @@ public class Configuration extends BuildObject implements IConfiguration {
toolReferences = new ArrayList(); toolReferences = new ArrayList();
toolReferences.add(toolRef); toolReferences.add(toolRef);
} }
public OptionReference createOptionReference(IOption option) {
if (option instanceof OptionReference) {
OptionReference optionRef = (OptionReference)option;
ToolReference toolRef = optionRef.getToolReference();
if (toolRef.getConfiguration().equals(this))
return optionRef;
else {
toolRef = new ToolReference(this, toolRef);
return toolRef.createOptionReference(option);
}
} else {
ToolReference toolRef = getToolReference(option.getTool());
if (toolRef == null)
toolRef = new ToolReference(this, option.getTool());
return toolRef.createOptionReference(option);
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IConfiguration#setOption(org.eclipse.cdt.core.build.managed.IOption, java.lang.String)
*/
public void setOption(IOption option, String value) throws BuildException {
createOptionReference(option).setValue(value);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IConfiguration#setOption(org.eclipse.cdt.core.build.managed.IOption, java.lang.String[])
*/
public void setOption(IOption option, String[] value) throws BuildException {
createOptionReference(option).setValue(value);
}
} }

View file

@ -10,11 +10,13 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.internal.core.build.managed; package org.eclipse.cdt.internal.core.build.managed;
import org.eclipse.cdt.core.build.managed.IConfiguration; import org.eclipse.cdt.core.build.managed.BuildException;
import org.eclipse.cdt.core.build.managed.IOption; import org.eclipse.cdt.core.build.managed.IOption;
import org.eclipse.cdt.core.build.managed.IOptionCategory; import org.eclipse.cdt.core.build.managed.IOptionCategory;
import org.eclipse.cdt.core.build.managed.ITool; import org.eclipse.cdt.core.build.managed.ITool;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/** /**
* *
@ -22,121 +24,127 @@ import org.eclipse.core.runtime.IConfigurationElement;
public class OptionReference implements IOption { public class OptionReference implements IOption {
private IOption option; private IOption option;
private ITool tool; private ToolReference owner;
private Object value;
public OptionReference(IOption option, ITool tool) { /**
* Created internally.
*
* @param owner
* @param option
*/
public OptionReference(ToolReference owner, IOption option) {
this.owner = owner;
this.option = option; this.option = option;
this.tool = tool;
owner.addOptionReference(this);
} }
/**
* Created from extension.
*
* @param owner
* @param element
*/
public OptionReference(ToolReference owner, IConfigurationElement element) { public OptionReference(ToolReference owner, IConfigurationElement element) {
this.tool = owner; this.owner = owner;
option = owner.getOption(element.getAttribute("id"));
option = tool.getOption(element.getAttribute("id")); owner.addOptionReference(this);
}
/**
* Created from project file.
*
* @param owner
* @param element
*/
public OptionReference(ToolReference owner, Element element) {
this.owner = owner;
option = owner.getOption(element.getAttribute("id"));
owner.addOptionReference(this);
}
/**
* Write out to project file.
*
* @param doc
* @param element
*/
public void serealize(Document doc, Element element) {
element.setAttribute("id", option.getId());
option = owner.getOption(element.getAttribute("id"));
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOption#getApplicableValues() * @see org.eclipse.cdt.core.build.managed.IOption#getApplicableValues()
*/ */
public String[] getApplicableValues() { public String[] getApplicableValues() {
// TODO Auto-generated method stub return option.getApplicableValues();
return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOption#getCategory() * @see org.eclipse.cdt.core.build.managed.IOption#getCategory()
*/ */
public IOptionCategory getCategory() { public IOptionCategory getCategory() {
// TODO Auto-generated method stub return option.getCategory();
return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IBuildObject#getName() * @see org.eclipse.cdt.core.build.managed.IBuildObject#getName()
*/ */
public String getName() { public String getName() {
// TODO Auto-generated method stub return option.getName();
return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOption#getStringListValue() * @see org.eclipse.cdt.core.build.managed.IOption#getStringListValue()
*/ */
public String[] getStringListValue() { public String[] getStringListValue() throws BuildException {
// TODO Auto-generated method stub if (value == null)
return null; return option.getStringListValue();
else if (getValueType() == IOption.STRING_LIST)
return (String[])value;
else
throw new BuildException("bad value type");
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOption#getStringValue() * @see org.eclipse.cdt.core.build.managed.IOption#getStringValue()
*/ */
public String getStringValue() { public String getStringValue() throws BuildException {
// TODO Auto-generated method stub if (value == null)
return null; return option.getStringValue();
else if (getValueType() == IOption.STRING)
return (String)value;
else
throw new BuildException("bad value type");
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOption#getTool() * @see org.eclipse.cdt.core.build.managed.IOption#getTool()
*/ */
public ITool getTool() { public ITool getTool() {
// TODO Auto-generated method stub return owner;
return null; }
public ToolReference getToolReference() {
return owner;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOption#getValueType() * @see org.eclipse.cdt.core.build.managed.IOption#getValueType()
*/ */
public int getValueType() { public int getValueType() {
// TODO Auto-generated method stub return option.getValueType();
return 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOption#setCategory(org.eclipse.cdt.core.build.managed.IOptionCategory)
*/
public void setCategory(IOptionCategory category) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOption#setStringValue(org.eclipse.cdt.core.build.managed.IConfiguration, java.lang.String)
*/
public IOption setValue(IConfiguration config, String value) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOption#setStringValue(org.eclipse.cdt.core.build.managed.IConfiguration, java.lang.String[])
*/
public IOption setValue(IConfiguration config, String[] value) {
// TODO Auto-generated method stub
return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IBuildObject#getId() * @see org.eclipse.cdt.core.build.managed.IBuildObject#getId()
*/ */
public String getId() { public String getId() {
// TODO Auto-generated method stub return option.getId();
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IBuildObject#setId(java.lang.String)
*/
public void setId(String id) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IBuildObject#setName(java.lang.String)
*/
public void setName(String name) {
// TODO Auto-generated method stub
} }
public boolean references(IOption target) { public boolean references(IOption target) {
@ -151,4 +159,17 @@ public class OptionReference implements IOption {
return option.equals(target); return option.equals(target);
} }
public void setValue(String value) throws BuildException {
if (getValueType() == IOption.STRING)
this.value = value;
else
throw new BuildException("bad value type");
}
public void setValue(String [] value) throws BuildException {
if (getValueType() == IOption.STRING_LIST)
this.value = value;
else
throw new BuildException("bad value type");
}
} }

View file

@ -15,12 +15,10 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.build.managed.BuildException;
import org.eclipse.cdt.core.build.managed.IConfiguration; import org.eclipse.cdt.core.build.managed.IConfiguration;
import org.eclipse.cdt.core.build.managed.ITarget; import org.eclipse.cdt.core.build.managed.ITarget;
import org.eclipse.cdt.core.build.managed.ITool; import org.eclipse.cdt.core.build.managed.ITool;
import org.eclipse.cdt.core.build.managed.ManagedBuildManager; import org.eclipse.cdt.core.build.managed.ManagedBuildManager;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -46,14 +44,14 @@ public class Target extends BuildObject implements ITarget {
/** /**
* Create a target owned by a resource based on a parent target * Create a target owned by a resource based on a parent target
*
* @param owner
* @param parent * @param parent
*/ */
public Target(IResource owner, ITarget parent) { public Target(IResource owner, ITarget parent) {
this(owner); this(owner);
this.parent = parent; this.parent = parent;
inheritConfigs();
// Copy the parent's identity // Copy the parent's identity
setId(parent.getId()); setId(parent.getId());
setName(parent.getName()); setName(parent.getName());
@ -80,13 +78,9 @@ public class Target extends BuildObject implements ITarget {
// parent // parent
String parentId = element.getAttribute("parent"); String parentId = element.getAttribute("parent");
if (parentId != null) { if (parentId != null)
parent = ManagedBuildManager.getTarget(null, parentId); parent = ManagedBuildManager.getTarget(null, parentId);
// Inherit the configs from the parent
inheritConfigs();
}
// isAbstract // isAbstract
if ("true".equals(element.getAttribute("isAbstract"))) if ("true".equals(element.getAttribute("isAbstract")))
isAbstract = true; isAbstract = true;
@ -103,6 +97,12 @@ public class Target extends BuildObject implements ITarget {
} }
/**
* Create target from project file
*
* @param buildInfo
* @param element
*/
public Target(ResourceBuildInfo buildInfo, Element element) { public Target(ResourceBuildInfo buildInfo, Element element) {
this(buildInfo.getOwner()); this(buildInfo.getOwner());
@ -117,25 +117,28 @@ public class Target extends BuildObject implements ITarget {
// parent // parent
String parentId = element.getAttribute("parent"); String parentId = element.getAttribute("parent");
if (parentId != null) { if (parentId != null)
parent = ManagedBuildManager.getTarget(null, parentId); parent = ManagedBuildManager.getTarget(null, parentId);
// Inherit the configs from the parent
inheritConfigs();
}
// isAbstract // isAbstract
if ("true".equals(element.getAttribute("isAbstract"))) if ("true".equals(element.getAttribute("isAbstract")))
isAbstract = true; isAbstract = true;
} }
private void inheritConfigs() {
IConfiguration[] parentConfigs = parent.getConfigurations();
if (parentConfigs.length > 0)
configurations = new ArrayList(parentConfigs.length);
for (int i = 0; i < parentConfigs.length; ++i)
configurations.add(new Configuration(parentConfigs[i]));
public void serialize(Document doc, Element element) {
element.setAttribute("id", getId());
element.setAttribute("name", getName());
if (parent != null)
element.setAttribute("parent", parent.getId());
element.setAttribute("isAbstract", isAbstract ? "true" : "false");
if (configurations != null)
for (int i = 0; i < configurations.size(); ++i) {
Configuration config = (Configuration)configurations.get(i);
Element configElement = doc.createElement("configuration");
config.serealize(doc, configElement);
}
} }
public String getName() { public String getName() {
@ -209,35 +212,6 @@ public class Target extends BuildObject implements ITarget {
configurations.add(configuration); configurations.add(configuration);
} }
public IConfiguration createConfiguration()
throws BuildException
{
IConfiguration config = new Configuration(this);
addLocalConfiguration(config);
return config;
}
public IConfiguration createConfiguration(IConfiguration parentConfig)
throws BuildException
{
IResource parentOwner = parentConfig.getOwner();
if (owner instanceof IProject) {
// parent must be owned by the same project
if (!owner.equals(parentOwner))
throw new BuildException("addConfiguration: parent must be in same project");
} else {
// parent must be owned by the project
if (!owner.getProject().equals(parentOwner))
throw new BuildException("addConfiguration: parent must be in owning project");
}
// Validation passed
IConfiguration config = new Configuration(parentConfig);
addLocalConfiguration(config);
return config;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.ITarget#isAbstract() * @see org.eclipse.cdt.core.build.managed.ITarget#isAbstract()
*/ */
@ -245,11 +219,18 @@ public class Target extends BuildObject implements ITarget {
return isAbstract; return isAbstract;
} }
public void serialize(Document doc, Element element) { /* (non-Javadoc)
element.setAttribute("id", getId()); * @see org.eclipse.cdt.core.build.managed.ITarget#createConfiguration()
element.setAttribute("name", getName()); */
if (parent != null) public IConfiguration createConfiguration(String id) {
element.setAttribute("parent", parent.getId()); return new Configuration(this, id);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.ITarget#createConfiguration(org.eclipse.cdt.core.build.managed.IConfiguration)
*/
public IConfiguration createConfiguration(IConfiguration parent, String id) {
return new Configuration(this, parent, id);
} }
} }

View file

@ -20,6 +20,8 @@ import org.eclipse.cdt.core.build.managed.IOptionCategory;
import org.eclipse.cdt.core.build.managed.ITarget; import org.eclipse.cdt.core.build.managed.ITarget;
import org.eclipse.cdt.core.build.managed.ITool; import org.eclipse.cdt.core.build.managed.ITool;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/** /**
* *
@ -31,11 +33,25 @@ public class ToolReference implements ITool {
private List optionReferences; private List optionReferences;
private Map optionRefMap; private Map optionRefMap;
public ToolReference(ITool parent, IConfiguration owner) { /**
this.parent = parent; * Created on the fly.
*
* @param owner
* @param parent
*/
public ToolReference(Configuration owner, ITool parent) {
this.owner = owner; this.owner = owner;
this.parent = parent;
owner.addToolReference(this);
} }
/**
* Created from extension.
*
* @param owner
* @param element
*/
public ToolReference(Configuration owner, IConfigurationElement element) { public ToolReference(Configuration owner, IConfigurationElement element) {
this.owner = owner; this.owner = owner;
@ -52,6 +68,24 @@ public class ToolReference implements ITool {
} }
} }
public ToolReference(Configuration owner, Element element) {
}
public void serealize(Document doc, Element element) {
element.setAttribute("id", parent.getId());
if (optionReferences != null)
for (int i = 0; i < optionReferences.size(); ++i) {
OptionReference optionRef = (OptionReference)optionReferences.get(i);
Element optionRefElement = doc.createElement("optionRef");
optionRef.serealize(doc, optionRefElement);
}
}
public IConfiguration getConfiguration() {
return owner;
}
public ITool getTool() { public ITool getTool() {
return parent; return parent;
} }
@ -144,6 +178,10 @@ public class ToolReference implements ITool {
return null; return null;
} }
public OptionReference createOptionReference(IOption option) {
return new OptionReference(this, option);
}
public void addOptionReference(OptionReference optionRef) { public void addOptionReference(OptionReference optionRef) {
if (optionReferences == null) if (optionReferences == null)
optionReferences = new ArrayList(); optionReferences = new ArrayList();
@ -158,12 +196,4 @@ public class ToolReference implements ITool {
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.ITool#createOption(org.eclipse.cdt.core.build.managed.IConfiguration)
*/
public IOption createOption(IConfiguration config) {
// TODO Auto-generated method stub
return null;
}
} }