mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Work on the Build Model.
- Model is maturing - Loading/saving moved into the objects themselves - Project build info saved to/loaded from a file
This commit is contained in:
parent
5eb714f36f
commit
e6d765afcd
15 changed files with 1012 additions and 220 deletions
|
@ -85,7 +85,8 @@ public interface IOption extends IBuildObject {
|
||||||
* @param config
|
* @param config
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
public IOption setStringValue(IConfiguration config, String value);
|
public IOption setValue(IConfiguration config, String value)
|
||||||
|
throws BuildException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value for this option in a given configuration.
|
* Sets the value for this option in a given configuration.
|
||||||
|
@ -95,6 +96,7 @@ public interface IOption extends IBuildObject {
|
||||||
* @param config
|
* @param config
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
public IOption setStringValue(IConfiguration config, String[] value);
|
public IOption setValue(IConfiguration config, String[] value)
|
||||||
|
throws BuildException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,20 +23,13 @@ public interface IOptionCategory extends IBuildObject {
|
||||||
public IOptionCategory[] getChildCategories();
|
public IOptionCategory[] getChildCategories();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new child category for this category.
|
* Returns the options in this category for a given configuration.
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public IOptionCategory createChildCategory();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the options in this category for a given tool.
|
|
||||||
*
|
*
|
||||||
* @param tool
|
* @param tool
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public IOption[] getOptions(ITool tool);
|
public IOption[] getOptions(IConfiguration configuration);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the category that owns this category, or null if this is the
|
* Returns the category that owns this category, or null if this is the
|
||||||
* top category for a tool.
|
* top category for a tool.
|
||||||
|
|
|
@ -18,6 +18,12 @@ import org.eclipse.core.resources.IResource;
|
||||||
*/
|
*/
|
||||||
public interface ITarget extends IBuildObject {
|
public interface ITarget extends IBuildObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this target is abstract
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isAbstract();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the resource that this target is applied to.
|
* Gets the resource that this target is applied to.
|
||||||
*
|
*
|
||||||
|
@ -33,34 +39,10 @@ public interface ITarget extends IBuildObject {
|
||||||
*/
|
*/
|
||||||
public ITool[] getTools();
|
public ITool[] getTools();
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new tool.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ITool createTool();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all of the configurations defined by this target.
|
* Returns all of the configurations defined by this target.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public IConfiguration[] getConfigurations();
|
public IConfiguration[] getConfigurations();
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new configuration for this target.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public IConfiguration createConfiguration()
|
|
||||||
throws BuildException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new configuration based on the parent config for this target.
|
|
||||||
*
|
|
||||||
* @param parentConfig
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public IConfiguration createConfiguration(IConfiguration parentConfig)
|
|
||||||
throws BuildException;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,12 +27,12 @@ public interface ITool extends IBuildObject {
|
||||||
public IOption[] getOptions();
|
public IOption[] getOptions();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new option for this tool. Generally, this should only be
|
* Get a particular option.
|
||||||
* done by the extension and project data loaders.
|
|
||||||
*
|
*
|
||||||
|
* @param id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public IOption createOption();
|
public IOption getOption(String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options are organized into categories for UI purposes.
|
* Options are organized into categories for UI purposes.
|
||||||
|
|
|
@ -10,15 +10,27 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.core.build.managed;
|
package org.eclipse.cdt.core.build.managed;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.internal.core.build.managed.Configuration;
|
import org.eclipse.cdt.internal.core.build.managed.ResourceBuildInfo;
|
||||||
import org.eclipse.cdt.internal.core.build.managed.Target;
|
import org.eclipse.cdt.internal.core.build.managed.Target;
|
||||||
import org.eclipse.cdt.internal.core.build.managed.Tool;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -26,6 +38,9 @@ import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IExtension;
|
import org.eclipse.core.runtime.IExtension;
|
||||||
import org.eclipse.core.runtime.IExtensionPoint;
|
import org.eclipse.core.runtime.IExtensionPoint;
|
||||||
import org.eclipse.core.runtime.QualifiedName;
|
import org.eclipse.core.runtime.QualifiedName;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the main entry point for getting at the build information
|
* This is the main entry point for getting at the build information
|
||||||
|
@ -33,13 +48,16 @@ import org.eclipse.core.runtime.QualifiedName;
|
||||||
*/
|
*/
|
||||||
public class ManagedBuildManager {
|
public class ManagedBuildManager {
|
||||||
|
|
||||||
private static final QualifiedName ownedTargetsProperty
|
private static final QualifiedName buildInfoProperty
|
||||||
= new QualifiedName(CCorePlugin.PLUGIN_ID, "ownedTargets");
|
= new QualifiedName(CCorePlugin.PLUGIN_ID, "buildInfo");
|
||||||
private static final QualifiedName definedTargetsProperty
|
|
||||||
= new QualifiedName(CCorePlugin.PLUGIN_ID, "definedTargets");
|
|
||||||
|
|
||||||
private static final ITarget[] emptyTargets = new ITarget[0];
|
private static final ITarget[] emptyTargets = new ITarget[0];
|
||||||
|
|
||||||
|
// Targets defined by extensions (i.e., not associated with a resource)
|
||||||
|
private static boolean extensionTargetsLoaded = false;
|
||||||
|
private static List extensionTargets;
|
||||||
|
private static Map extensionTargetMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of targets that are defined by this project,
|
* Returns the list of targets that are defined by this project,
|
||||||
* projects referenced by this project, and by the extensions.
|
* projects referenced by this project, and by the extensions.
|
||||||
|
@ -53,13 +71,7 @@ public class ManagedBuildManager {
|
||||||
|
|
||||||
// Get the targets for this project and all referenced projects
|
// Get the targets for this project and all referenced projects
|
||||||
List definedTargets = null;
|
List definedTargets = null;
|
||||||
|
// To Do
|
||||||
if (project != null) {
|
|
||||||
try {
|
|
||||||
definedTargets = (List)project.getSessionProperty(definedTargetsProperty);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the array and copy the elements over
|
// Create the array and copy the elements over
|
||||||
int size = extensionTargets.size()
|
int size = extensionTargets.size()
|
||||||
|
@ -86,15 +98,30 @@ public class ManagedBuildManager {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static ITarget[] getTargets(IResource resource) {
|
public static ITarget[] getTargets(IResource resource) {
|
||||||
List targets = getOwnedTargetsProperty(resource);
|
ResourceBuildInfo buildInfo = getBuildInfo(resource);
|
||||||
|
|
||||||
if (targets != null) {
|
if (buildInfo != null) {
|
||||||
|
List targets = buildInfo.getTargets();
|
||||||
return (ITarget[])targets.toArray(new ITarget[targets.size()]);
|
return (ITarget[])targets.toArray(new ITarget[targets.size()]);
|
||||||
} else {
|
} else {
|
||||||
return emptyTargets;
|
return emptyTargets;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ITarget getTarget(IResource resource, String id) {
|
||||||
|
if (resource != null) {
|
||||||
|
ResourceBuildInfo buildInfo = getBuildInfo(resource);
|
||||||
|
if (buildInfo != null)
|
||||||
|
return buildInfo.getTarget(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
ITarget target = (ITarget)extensionTargetMap.get(id);
|
||||||
|
if (target != null)
|
||||||
|
return target;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new target to the resource based on the parentTarget.
|
* Adds a new target to the resource based on the parentTarget.
|
||||||
*
|
*
|
||||||
|
@ -103,7 +130,7 @@ public class ManagedBuildManager {
|
||||||
* @return
|
* @return
|
||||||
* @throws BuildException
|
* @throws BuildException
|
||||||
*/
|
*/
|
||||||
public static ITarget addTarget(IResource resource, ITarget parentTarget)
|
public static ITarget createTarget(IResource resource, ITarget parentTarget)
|
||||||
throws BuildException
|
throws BuildException
|
||||||
{
|
{
|
||||||
IResource owner = parentTarget.getOwner();
|
IResource owner = parentTarget.getOwner();
|
||||||
|
@ -113,7 +140,7 @@ public class ManagedBuildManager {
|
||||||
return parentTarget;
|
return parentTarget;
|
||||||
|
|
||||||
if (resource instanceof IProject) {
|
if (resource instanceof IProject) {
|
||||||
// Owner must be null
|
// Must be an extension target (why?)
|
||||||
if (owner != null)
|
if (owner != null)
|
||||||
throw new BuildException("addTarget: owner not null");
|
throw new BuildException("addTarget: owner not null");
|
||||||
} else {
|
} else {
|
||||||
|
@ -125,19 +152,7 @@ public class ManagedBuildManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Passed validation
|
// Passed validation
|
||||||
List targets = getOwnedTargetsProperty(resource);
|
return new Target(resource, parentTarget);
|
||||||
if (targets == null) {
|
|
||||||
targets = new ArrayList();
|
|
||||||
try {
|
|
||||||
resource.setSessionProperty(ownedTargetsProperty, targets);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
throw new BuildException("addTarget: could not add property");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Target newTarget = new Target(resource, parentTarget);
|
|
||||||
targets.add(newTarget);
|
|
||||||
return newTarget;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,19 +162,65 @@ public class ManagedBuildManager {
|
||||||
* @param project
|
* @param project
|
||||||
*/
|
*/
|
||||||
public static void saveBuildInfo(IProject project) {
|
public static void saveBuildInfo(IProject project) {
|
||||||
|
// Create document
|
||||||
|
Document doc = new DocumentImpl();
|
||||||
|
Element rootElement = doc.createElement("buildInfo");
|
||||||
|
doc.appendChild(rootElement);
|
||||||
|
|
||||||
|
// Populate from buildInfo
|
||||||
|
// To do - find other resources also
|
||||||
|
ResourceBuildInfo 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(".cdtbuild");
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeBuildInfo(IResource resource) {
|
||||||
|
try {
|
||||||
|
resource.setSessionProperty(buildInfoProperty, null);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private stuff
|
// Private stuff
|
||||||
|
|
||||||
private static List extensionTargets;
|
public static void addExtensionTarget(Target target) {
|
||||||
|
if (extensionTargets == null) {
|
||||||
private static void loadExtensions() {
|
extensionTargets = new ArrayList();
|
||||||
if (extensionTargets != null)
|
extensionTargetMap = new HashMap();
|
||||||
return;
|
}
|
||||||
|
|
||||||
extensionTargets = new ArrayList();
|
|
||||||
Map targetMap = new HashMap();
|
|
||||||
|
|
||||||
|
extensionTargets.add(target);
|
||||||
|
extensionTargetMap.put(target.getId(), target);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadExtensions() {
|
||||||
|
if (extensionTargetsLoaded)
|
||||||
|
return;
|
||||||
|
extensionTargetsLoaded = true;
|
||||||
|
|
||||||
IExtensionPoint extensionPoint
|
IExtensionPoint extensionPoint
|
||||||
= CCorePlugin.getDefault().getDescriptor().getExtensionPoint("ManagedBuildInfo");
|
= CCorePlugin.getDefault().getDescriptor().getExtensionPoint("ManagedBuildInfo");
|
||||||
IExtension[] extensions = extensionPoint.getExtensions();
|
IExtension[] extensions = extensionPoint.getExtensions();
|
||||||
|
@ -169,61 +230,58 @@ public class ManagedBuildManager {
|
||||||
for (int j = 0; j < elements.length; ++j) {
|
for (int j = 0; j < elements.length; ++j) {
|
||||||
IConfigurationElement element = elements[j];
|
IConfigurationElement element = elements[j];
|
||||||
if (element.getName().equals("target")) {
|
if (element.getName().equals("target")) {
|
||||||
String parentId = element.getAttribute("parent");
|
new Target(element);
|
||||||
Target target = null;
|
|
||||||
if (parentId != null)
|
|
||||||
target = new Target(null, (Target)targetMap.get(parentId));
|
|
||||||
else
|
|
||||||
target = new Target(null);
|
|
||||||
target.setName(element.getAttribute("name"));
|
|
||||||
extensionTargets.add(target);
|
|
||||||
targetMap.put(element.getAttribute("id"), target);
|
|
||||||
|
|
||||||
IConfigurationElement[] targetElements = element.getChildren();
|
|
||||||
for (int k = 0; k < targetElements.length; ++k) {
|
|
||||||
IConfigurationElement targetElement = targetElements[k];
|
|
||||||
if (targetElement.getName().equals("tool")) {
|
|
||||||
ITool tool = target.createTool();
|
|
||||||
tool.setName(targetElement.getAttribute("name"));
|
|
||||||
|
|
||||||
Map categoryMap = new HashMap();
|
|
||||||
categoryMap.put(targetElement.getAttribute("id"), tool.getTopOptionCategory());
|
|
||||||
IConfigurationElement[] toolElements = targetElement.getChildren();
|
|
||||||
for (int l = 0; l < toolElements.length; ++l) {
|
|
||||||
IConfigurationElement toolElement = toolElements[l];
|
|
||||||
if (toolElement.getName().equals("option")) {
|
|
||||||
IOption option = tool.createOption();
|
|
||||||
option.setName(toolElement.getAttribute("name"));
|
|
||||||
|
|
||||||
String categoryId = toolElement.getAttribute("category");
|
|
||||||
if (categoryId != null)
|
|
||||||
option.setCategory((IOptionCategory)categoryMap.get(categoryId));
|
|
||||||
} else if (toolElement.getName().equals("optionCategory")) {
|
|
||||||
IOptionCategory owner = (IOptionCategory)categoryMap.get(toolElement.getAttribute("owner"));
|
|
||||||
IOptionCategory category = owner.createChildCategory();
|
|
||||||
category.setName(toolElement.getAttribute("name"));
|
|
||||||
categoryMap.put(toolElement.getAttribute("id"), category);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (targetElement.getName().equals("configuration")) {
|
|
||||||
try {
|
|
||||||
IConfiguration config = target.createConfiguration();
|
|
||||||
config.setName(targetElement.getAttribute("name"));
|
|
||||||
} catch (BuildException e) {
|
|
||||||
// Not sure what to do here.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List getOwnedTargetsProperty(IResource resource) {
|
private static ResourceBuildInfo loadBuildInfo(IProject project) {
|
||||||
try {
|
ResourceBuildInfo buildInfo = null;
|
||||||
return (List)resource.getSessionProperty(ownedTargetsProperty);
|
IFile file = project.getFile(".cdtbuild");
|
||||||
} catch (CoreException e) {
|
if (!file.exists())
|
||||||
return null;
|
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("buildInfo")) {
|
||||||
|
buildInfo = new ResourceBuildInfo(project, (Element)rootElement);
|
||||||
|
project.setSessionProperty(buildInfoProperty, buildInfo);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
buildInfo = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return buildInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResourceBuildInfo getBuildInfo(IResource resource, boolean create) {
|
||||||
|
ResourceBuildInfo buildInfo = null;
|
||||||
|
try {
|
||||||
|
buildInfo = (ResourceBuildInfo)resource.getSessionProperty(buildInfoProperty);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buildInfo == null && resource instanceof IProject) {
|
||||||
|
buildInfo = loadBuildInfo((IProject)resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buildInfo == null && create) {
|
||||||
|
try {
|
||||||
|
buildInfo = new ResourceBuildInfo();
|
||||||
|
resource.setSessionProperty(buildInfoProperty, buildInfo);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
buildInfo = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return buildInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResourceBuildInfo getBuildInfo(IResource resource) {
|
||||||
|
return getBuildInfo(resource, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,14 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.build.managed;
|
package org.eclipse.cdt.internal.core.build.managed;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
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.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -24,7 +26,7 @@ public class Configuration extends BuildObject implements IConfiguration {
|
||||||
|
|
||||||
private ITarget target;
|
private ITarget target;
|
||||||
private IConfiguration parent;
|
private IConfiguration parent;
|
||||||
private List toolReference;
|
private List toolReferences;
|
||||||
|
|
||||||
public Configuration(Target target) {
|
public Configuration(Target target) {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
@ -34,6 +36,27 @@ public class Configuration extends BuildObject implements IConfiguration {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Configuration(Target target, IConfigurationElement element) {
|
||||||
|
this(target);
|
||||||
|
|
||||||
|
// id
|
||||||
|
setId(element.getAttribute("id"));
|
||||||
|
|
||||||
|
// hook me up
|
||||||
|
target.addConfiguration(this);
|
||||||
|
|
||||||
|
// name
|
||||||
|
setName(element.getAttribute("name"));
|
||||||
|
|
||||||
|
IConfigurationElement[] configElements = element.getChildren();
|
||||||
|
for (int l = 0; l < configElements.length; ++l) {
|
||||||
|
IConfigurationElement configElement = configElements[l];
|
||||||
|
if (configElement.getName().equals("toolRef")) {
|
||||||
|
new ToolReference(this, configElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.build.managed.IConfiguration#getName()
|
* @see org.eclipse.cdt.core.build.managed.IConfiguration#getName()
|
||||||
*/
|
*/
|
||||||
|
@ -45,8 +68,18 @@ public class Configuration extends BuildObject implements IConfiguration {
|
||||||
* @see org.eclipse.cdt.core.build.managed.IConfiguration#getTools()
|
* @see org.eclipse.cdt.core.build.managed.IConfiguration#getTools()
|
||||||
*/
|
*/
|
||||||
public ITool[] getTools() {
|
public ITool[] getTools() {
|
||||||
// TODO Auto-generated method stub
|
ITool[] tools = parent != null
|
||||||
return null;
|
? parent.getTools()
|
||||||
|
: target.getTools();
|
||||||
|
|
||||||
|
// Replace tools with overrides
|
||||||
|
for (int i = 0; i < tools.length; ++i) {
|
||||||
|
ToolReference ref = getToolReference(tools[i]);
|
||||||
|
if (ref != null)
|
||||||
|
tools[i] = ref;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tools;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -70,4 +103,25 @@ public class Configuration extends BuildObject implements IConfiguration {
|
||||||
return getTarget().getOwner();
|
return getTarget().getOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the reference for a given tool.
|
||||||
|
*
|
||||||
|
* @param tool
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private ToolReference getToolReference(ITool tool) {
|
||||||
|
if (toolReferences != null)
|
||||||
|
for (int i = 0; i < toolReferences.size(); ++i) {
|
||||||
|
ToolReference toolRef = (ToolReference)toolReferences.get(i);
|
||||||
|
if (toolRef.references(tool))
|
||||||
|
return toolRef;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addToolReference(ToolReference toolRef) {
|
||||||
|
if (toolReferences == null)
|
||||||
|
toolReferences = new ArrayList();
|
||||||
|
toolReferences.add(toolRef);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,14 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.build.managed;
|
package org.eclipse.cdt.internal.core.build.managed;
|
||||||
|
|
||||||
|
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.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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -22,40 +26,66 @@ public class Option extends BuildObject implements IOption {
|
||||||
|
|
||||||
private ITool tool;
|
private ITool tool;
|
||||||
private IOptionCategory category;
|
private IOptionCategory category;
|
||||||
|
private List enumValues;
|
||||||
|
|
||||||
|
private int valueType;
|
||||||
|
private Object value;
|
||||||
|
|
||||||
|
private static final String[] emptyStrings = new String[0];
|
||||||
|
|
||||||
public Option(ITool tool) {
|
public Option(ITool tool) {
|
||||||
this.tool = tool;
|
this.tool = tool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Option(Tool tool, IConfigurationElement element) {
|
||||||
|
this(tool);
|
||||||
|
|
||||||
|
// id
|
||||||
|
setId(element.getAttribute("id"));
|
||||||
|
|
||||||
|
// hook me up
|
||||||
|
tool.addOption(this);
|
||||||
|
|
||||||
|
// name
|
||||||
|
setName(element.getAttribute("name"));
|
||||||
|
|
||||||
|
// category
|
||||||
|
String categoryId = element.getAttribute("category");
|
||||||
|
if (categoryId != null)
|
||||||
|
setCategory(tool.getOptionCategory(categoryId));
|
||||||
|
}
|
||||||
|
|
||||||
/* (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 enumValues != null
|
||||||
return null;
|
? (String[])enumValues.toArray(new String[enumValues.size()])
|
||||||
|
: emptyStrings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (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() {
|
||||||
return (category != null) ? category : getTool().getTopOptionCategory();
|
return category != null ? category : getTool().getTopOptionCategory();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (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() {
|
||||||
// TODO Auto-generated method stub
|
List v = (List)value;
|
||||||
return null;
|
return v != null
|
||||||
|
? (String[])v.toArray(new String[v.size()])
|
||||||
|
: emptyStrings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (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() {
|
||||||
// TODO Auto-generated method stub
|
return (String)value;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -69,24 +99,45 @@ public class Option extends BuildObject implements IOption {
|
||||||
* @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 valueType;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.build.managed.IOption#setStringValue(org.eclipse.cdt.core.build.managed.IConfiguration, java.lang.String)
|
* @see org.eclipse.cdt.core.build.managed.IOption#setStringValue(org.eclipse.cdt.core.build.managed.IConfiguration, java.lang.String)
|
||||||
*/
|
*/
|
||||||
public IOption setStringValue(IConfiguration config, String value) {
|
public IOption setValue(IConfiguration config, String value)
|
||||||
// TODO Auto-generated method stub
|
throws BuildException
|
||||||
return null;
|
{
|
||||||
|
if (valueType != IOption.STRING)
|
||||||
|
throw new BuildException("Bad value for type");
|
||||||
|
|
||||||
|
if (config == null) {
|
||||||
|
this.value = value;
|
||||||
|
return this;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Magic time
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.build.managed.IOption#setStringValue(org.eclipse.cdt.core.build.managed.IConfiguration, java.lang.String[])
|
* @see org.eclipse.cdt.core.build.managed.IOption#setStringValue(org.eclipse.cdt.core.build.managed.IConfiguration, java.lang.String[])
|
||||||
*/
|
*/
|
||||||
public IOption setStringValue(IConfiguration config, String[] value) {
|
public IOption setValue(IConfiguration config, String[] value)
|
||||||
// TODO Auto-generated method stub
|
throws BuildException
|
||||||
return null;
|
{
|
||||||
|
if (valueType != IOption.STRING_LIST)
|
||||||
|
throw new BuildException("Bad value for type");
|
||||||
|
|
||||||
|
if (config == null) {
|
||||||
|
this.value = value;
|
||||||
|
return this;
|
||||||
|
} else {
|
||||||
|
// More magic
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -13,9 +13,11 @@ 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.IConfiguration;
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -31,6 +33,28 @@ public class OptionCategory extends BuildObject implements IOptionCategory {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OptionCategory(Tool tool, IConfigurationElement element) {
|
||||||
|
String parentId = element.getAttribute("parent");
|
||||||
|
if (parentId != null)
|
||||||
|
owner = tool.getOptionCategory(element.getAttribute("parent"));
|
||||||
|
else
|
||||||
|
owner = tool;
|
||||||
|
|
||||||
|
// id
|
||||||
|
setId(element.getAttribute("id"));
|
||||||
|
|
||||||
|
// Name
|
||||||
|
setName(element.getAttribute("name"));
|
||||||
|
|
||||||
|
// Hook me in
|
||||||
|
if (owner instanceof Tool)
|
||||||
|
((Tool)owner).addChildCategory(this);
|
||||||
|
else
|
||||||
|
((OptionCategory)owner).addChildCategory(this);
|
||||||
|
|
||||||
|
tool.addOptionCategory(this);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.build.managed.IOptionCategory#getChildCategories()
|
* @see org.eclipse.cdt.core.build.managed.IOptionCategory#getChildCategories()
|
||||||
*/
|
*/
|
||||||
|
@ -41,17 +65,10 @@ public class OptionCategory extends BuildObject implements IOptionCategory {
|
||||||
return emtpyCategories;
|
return emtpyCategories;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
public void addChildCategory(OptionCategory category) {
|
||||||
* @see org.eclipse.cdt.core.build.managed.IOptionCategory#createChildCategory()
|
|
||||||
*/
|
|
||||||
public IOptionCategory createChildCategory() {
|
|
||||||
IOptionCategory category = new OptionCategory(this);
|
|
||||||
|
|
||||||
if (children == null)
|
if (children == null)
|
||||||
children = new ArrayList();
|
children = new ArrayList();
|
||||||
children.add(category);
|
children.add(category);
|
||||||
|
|
||||||
return category;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -72,16 +89,31 @@ public class OptionCategory extends BuildObject implements IOptionCategory {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.build.managed.IOptionCategory#getOptions(org.eclipse.cdt.core.build.managed.ITool)
|
* @see org.eclipse.cdt.core.build.managed.IOptionCategory#getOptions(org.eclipse.cdt.core.build.managed.ITool)
|
||||||
*/
|
*/
|
||||||
public IOption[] getOptions(ITool tool) {
|
public IOption[] getOptions(IConfiguration configuration) {
|
||||||
List myOptions = new ArrayList();
|
ITool tool = getTool();
|
||||||
|
if (configuration != null) {
|
||||||
|
// TODO don't like this much
|
||||||
|
ITool[] tools = configuration.getTools();
|
||||||
|
for (int i = 0; i < tools.length; ++i) {
|
||||||
|
if (tools[i] instanceof ToolReference) {
|
||||||
|
if (((ToolReference)tools[i]).references(tool)) {
|
||||||
|
tool = tools[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (tools[i].equals(tool))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IOption[] allOptions = tool.getOptions();
|
IOption[] allOptions = tool.getOptions();
|
||||||
|
List myOptions = new ArrayList();
|
||||||
|
|
||||||
for (int i = 0; i < allOptions.length; ++i) {
|
for (int i = 0; i < allOptions.length; ++i) {
|
||||||
IOption option = allOptions[i];
|
IOption option = allOptions[i];
|
||||||
if (option.getCategory().equals(this))
|
if (option.getCategory().equals(this))
|
||||||
myOptions.add(option);
|
myOptions.add(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (IOption[])myOptions.toArray(new IOption[myOptions.size()]);
|
return (IOption[])myOptions.toArray(new IOption[myOptions.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,145 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
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.IOption;
|
||||||
|
import org.eclipse.cdt.core.build.managed.IOptionCategory;
|
||||||
|
import org.eclipse.cdt.core.build.managed.ITool;
|
||||||
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class OptionReference {
|
public class OptionReference implements IOption {
|
||||||
|
|
||||||
|
private IOption option;
|
||||||
|
private ITool tool;
|
||||||
|
|
||||||
|
public OptionReference(IOption option, ITool tool) {
|
||||||
|
this.option = option;
|
||||||
|
this.tool = tool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OptionReference(ToolReference owner, IConfigurationElement element) {
|
||||||
|
this.tool = owner;
|
||||||
|
|
||||||
|
option = tool.getOption(element.getAttribute("id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.IOption#getApplicableValues()
|
||||||
|
*/
|
||||||
|
public String[] getApplicableValues() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.IOption#getCategory()
|
||||||
|
*/
|
||||||
|
public IOptionCategory getCategory() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.IBuildObject#getName()
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.IOption#getStringListValue()
|
||||||
|
*/
|
||||||
|
public String[] getStringListValue() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.IOption#getStringValue()
|
||||||
|
*/
|
||||||
|
public String getStringValue() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.IOption#getTool()
|
||||||
|
*/
|
||||||
|
public ITool getTool() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.IOption#getValueType()
|
||||||
|
*/
|
||||||
|
public int getValueType() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
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)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.IBuildObject#getId()
|
||||||
|
*/
|
||||||
|
public String getId() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
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) {
|
||||||
|
if (equals(target))
|
||||||
|
// we are the target
|
||||||
|
return true;
|
||||||
|
else if (option instanceof OptionReference)
|
||||||
|
// check the reference we are overriding
|
||||||
|
return ((OptionReference)option).references(target);
|
||||||
|
else
|
||||||
|
// the real reference
|
||||||
|
return option.equals(target);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Created on Apr 13, 2003
|
||||||
|
*
|
||||||
|
* To change the template for this generated file go to
|
||||||
|
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.internal.core.build.managed;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dschaefe
|
||||||
|
*
|
||||||
|
* To change the template for this generated type comment go to
|
||||||
|
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||||
|
*/
|
||||||
|
public class ResourceBuildInfo {
|
||||||
|
|
||||||
|
private IResource owner;
|
||||||
|
private Map targetMap;
|
||||||
|
private List targets;
|
||||||
|
|
||||||
|
public ResourceBuildInfo() {
|
||||||
|
targetMap = new HashMap();
|
||||||
|
targets = new ArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceBuildInfo(IResource owner, Element element) {
|
||||||
|
this();
|
||||||
|
|
||||||
|
Node child = element.getFirstChild();
|
||||||
|
while (child != null) {
|
||||||
|
if (child.getNodeName().equals("target")) {
|
||||||
|
new Target(this, (Element)child);
|
||||||
|
}
|
||||||
|
|
||||||
|
child = child.getNextSibling();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IResource getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Target getTarget(String id) {
|
||||||
|
return (Target)targetMap.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List getTargets() {
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addTarget(Target target) {
|
||||||
|
targetMap.put(target.getId(), target);
|
||||||
|
targets.add(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void serialize(Document doc, Element element) {
|
||||||
|
for (int i = 0; i < targets.size(); ++i) {
|
||||||
|
Element targetElement = doc.createElement("target");
|
||||||
|
element.appendChild(targetElement);
|
||||||
|
((Target)targets.get(i)).serialize(doc, targetElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,14 +11,20 @@
|
||||||
package org.eclipse.cdt.internal.core.build.managed;
|
package org.eclipse.cdt.internal.core.build.managed;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.build.managed.BuildException;
|
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.core.resources.IProject;
|
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.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -28,7 +34,9 @@ public class Target extends BuildObject implements ITarget {
|
||||||
private ITarget parent;
|
private ITarget parent;
|
||||||
private IResource owner;
|
private IResource owner;
|
||||||
private List tools;
|
private List tools;
|
||||||
|
private Map toolMap;
|
||||||
private List configurations;
|
private List configurations;
|
||||||
|
private boolean isAbstract = false;
|
||||||
|
|
||||||
private static final IConfiguration[] emptyConfigs = new IConfiguration[0];
|
private static final IConfiguration[] emptyConfigs = new IConfiguration[0];
|
||||||
|
|
||||||
|
@ -37,22 +45,99 @@ public class Target extends BuildObject implements ITarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resource is allowed to be null to represent a ISV target def.
|
* Create a target owned by a resource based on a parent target
|
||||||
*
|
|
||||||
* @param parent
|
* @param parent
|
||||||
*/
|
*/
|
||||||
public Target(IResource owner, ITarget parent) {
|
public Target(IResource owner, ITarget parent) {
|
||||||
this.owner = owner;
|
this(owner);
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
|
||||||
// Inherit the configs from the parent
|
inheritConfigs();
|
||||||
|
|
||||||
|
// Copy the parent's identity
|
||||||
|
setId(parent.getId());
|
||||||
|
setName(parent.getName());
|
||||||
|
|
||||||
|
// Hook me up
|
||||||
|
ResourceBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(owner, true);
|
||||||
|
buildInfo.addTarget(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructor is called to create a target defined by an extension.
|
||||||
|
*
|
||||||
|
* @param element
|
||||||
|
*/
|
||||||
|
public Target(IConfigurationElement element) {
|
||||||
|
// id
|
||||||
|
setId(element.getAttribute("id"));
|
||||||
|
|
||||||
|
// hook me up
|
||||||
|
ManagedBuildManager.addExtensionTarget(this);
|
||||||
|
|
||||||
|
// name
|
||||||
|
setName(element.getAttribute("name"));
|
||||||
|
|
||||||
|
// parent
|
||||||
|
String parentId = element.getAttribute("parent");
|
||||||
|
if (parentId != null) {
|
||||||
|
parent = ManagedBuildManager.getTarget(null, parentId);
|
||||||
|
|
||||||
|
// Inherit the configs from the parent
|
||||||
|
inheritConfigs();
|
||||||
|
}
|
||||||
|
|
||||||
|
// isAbstract
|
||||||
|
if ("true".equals(element.getAttribute("isAbstract")))
|
||||||
|
isAbstract = true;
|
||||||
|
|
||||||
|
IConfigurationElement[] targetElements = element.getChildren();
|
||||||
|
for (int k = 0; k < targetElements.length; ++k) {
|
||||||
|
IConfigurationElement targetElement = targetElements[k];
|
||||||
|
if (targetElement.getName().equals("tool")) {
|
||||||
|
new Tool(this, targetElement);
|
||||||
|
} else if (targetElement.getName().equals("configuration")) {
|
||||||
|
new Configuration(this, targetElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Target(ResourceBuildInfo buildInfo, Element element) {
|
||||||
|
this(buildInfo.getOwner());
|
||||||
|
|
||||||
|
// id
|
||||||
|
setId(element.getAttribute("id"));
|
||||||
|
|
||||||
|
// hook me up
|
||||||
|
buildInfo.addTarget(this);
|
||||||
|
|
||||||
|
// name
|
||||||
|
setName(element.getAttribute("name"));
|
||||||
|
|
||||||
|
// parent
|
||||||
|
String parentId = element.getAttribute("parent");
|
||||||
|
if (parentId != null) {
|
||||||
|
parent = ManagedBuildManager.getTarget(null, parentId);
|
||||||
|
|
||||||
|
// Inherit the configs from the parent
|
||||||
|
inheritConfigs();
|
||||||
|
}
|
||||||
|
|
||||||
|
// isAbstract
|
||||||
|
if ("true".equals(element.getAttribute("isAbstract")))
|
||||||
|
isAbstract = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
private void inheritConfigs() {
|
||||||
IConfiguration[] parentConfigs = parent.getConfigurations();
|
IConfiguration[] parentConfigs = parent.getConfigurations();
|
||||||
if (parentConfigs.length > 0)
|
if (parentConfigs.length > 0)
|
||||||
configurations = new ArrayList(parentConfigs.length);
|
configurations = new ArrayList(parentConfigs.length);
|
||||||
for (int i = 0; i < parentConfigs.length; ++i)
|
for (int i = 0; i < parentConfigs.length; ++i)
|
||||||
configurations.add(new Configuration(parentConfigs[i]));
|
configurations.add(new Configuration(parentConfigs[i]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return (name == null && parent != null) ? parent.getName() : name;
|
return (name == null && parent != null) ? parent.getName() : name;
|
||||||
}
|
}
|
||||||
|
@ -91,14 +176,18 @@ public class Target extends BuildObject implements ITarget {
|
||||||
return toolArray;
|
return toolArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITool createTool() {
|
public ITool getTool(String id) {
|
||||||
ITool tool = new Tool(this);
|
return (ITool)toolMap.get(id);
|
||||||
|
}
|
||||||
if (tools == null)
|
|
||||||
|
public void addTool(ITool tool) {
|
||||||
|
if (tools == null) {
|
||||||
tools = new ArrayList();
|
tools = new ArrayList();
|
||||||
tools.add(tool);
|
toolMap = new HashMap();
|
||||||
|
}
|
||||||
|
|
||||||
return tool;
|
tools.add(tool);
|
||||||
|
toolMap.put(tool.getId(), tool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfiguration[] getConfigurations() {
|
public IConfiguration[] getConfigurations() {
|
||||||
|
@ -108,6 +197,12 @@ public class Target extends BuildObject implements ITarget {
|
||||||
return emptyConfigs;
|
return emptyConfigs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addConfiguration(IConfiguration configuration) {
|
||||||
|
if (configurations == null)
|
||||||
|
configurations = new ArrayList();
|
||||||
|
configurations.add(configuration);
|
||||||
|
}
|
||||||
|
|
||||||
private void addLocalConfiguration(IConfiguration configuration) {
|
private void addLocalConfiguration(IConfiguration configuration) {
|
||||||
if (configurations == null)
|
if (configurations == null)
|
||||||
configurations = new ArrayList();
|
configurations = new ArrayList();
|
||||||
|
@ -143,4 +238,18 @@ public class Target extends BuildObject implements ITarget {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.ITarget#isAbstract()
|
||||||
|
*/
|
||||||
|
public boolean isAbstract() {
|
||||||
|
return isAbstract;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void serialize(Document doc, Element element) {
|
||||||
|
element.setAttribute("id", getId());
|
||||||
|
element.setAttribute("name", getName());
|
||||||
|
if (parent != null)
|
||||||
|
element.setAttribute("parent", parent.getId());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,12 +11,16 @@
|
||||||
package org.eclipse.cdt.internal.core.build.managed;
|
package org.eclipse.cdt.internal.core.build.managed;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.build.managed.IConfiguration;
|
||||||
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.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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a tool that can be invoked during a build.
|
* Represents a tool that can be invoked during a build.
|
||||||
|
@ -27,8 +31,9 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
|
||||||
|
|
||||||
private ITarget target;
|
private ITarget target;
|
||||||
private List options;
|
private List options;
|
||||||
private IOptionCategory topOptionCategory;
|
private Map optionMap;
|
||||||
private List childOptionCategories;
|
private List childOptionCategories;
|
||||||
|
private Map categoryMap;
|
||||||
|
|
||||||
private static IOption[] emptyOptions = new IOption[0];
|
private static IOption[] emptyOptions = new IOption[0];
|
||||||
private static IOptionCategory[] emptyCategories = new IOptionCategory[0];
|
private static IOptionCategory[] emptyCategories = new IOptionCategory[0];
|
||||||
|
@ -37,10 +42,52 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Tool(Target target, IConfigurationElement element) {
|
||||||
|
this(target);
|
||||||
|
|
||||||
|
// id
|
||||||
|
setId(element.getAttribute("id"));
|
||||||
|
|
||||||
|
// hook me up
|
||||||
|
target.addTool(this);
|
||||||
|
|
||||||
|
// name
|
||||||
|
setName(element.getAttribute("name"));
|
||||||
|
|
||||||
|
// set up the category map
|
||||||
|
categoryMap = new HashMap();
|
||||||
|
addOptionCategory(this);
|
||||||
|
|
||||||
|
// Check for options
|
||||||
|
IConfigurationElement[] toolElements = element.getChildren();
|
||||||
|
for (int l = 0; l < toolElements.length; ++l) {
|
||||||
|
IConfigurationElement toolElement = toolElements[l];
|
||||||
|
if (toolElement.getName().equals("option")) {
|
||||||
|
new Option(this, toolElement);
|
||||||
|
} else if (toolElement.getName().equals("optionCategory")) {
|
||||||
|
new OptionCategory(this, toolElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ITarget getTarget() {
|
public ITarget getTarget() {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IOptionCategory getOptionCategory(String id) {
|
||||||
|
return (IOptionCategory)categoryMap.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void addOptionCategory(IOptionCategory category) {
|
||||||
|
categoryMap.put(category.getId(), category);
|
||||||
|
}
|
||||||
|
|
||||||
|
void addChildCategory(IOptionCategory category) {
|
||||||
|
if (childOptionCategories == null)
|
||||||
|
childOptionCategories = new ArrayList();
|
||||||
|
childOptionCategories.add(category);
|
||||||
|
}
|
||||||
|
|
||||||
public IOption[] getOptions() {
|
public IOption[] getOptions() {
|
||||||
if (options != null)
|
if (options != null)
|
||||||
return (IOption[])options.toArray(new IOption[options.size()]);
|
return (IOption[])options.toArray(new IOption[options.size()]);
|
||||||
|
@ -48,19 +95,12 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
|
||||||
return emptyOptions;
|
return emptyOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
public void addOption(Option option) {
|
||||||
* @see org.eclipse.cdt.core.build.managed.ITool#createOption()
|
|
||||||
*/
|
|
||||||
public IOption createOption() {
|
|
||||||
IOption option = new Option(this);
|
|
||||||
|
|
||||||
if (options == null)
|
if (options == null)
|
||||||
options = new ArrayList();
|
options = new ArrayList();
|
||||||
options.add(option);
|
options.add(option);
|
||||||
|
|
||||||
return option;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IOptionCategory getTopOptionCategory() {
|
public IOptionCategory getTopOptionCategory() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -105,17 +145,40 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.build.managed.IOptionCategory#getOptions(org.eclipse.cdt.core.build.managed.ITool)
|
* @see org.eclipse.cdt.core.build.managed.IOptionCategory#getOptions(org.eclipse.cdt.core.build.managed.ITool)
|
||||||
*/
|
*/
|
||||||
public IOption[] getOptions(ITool tool) {
|
public IOption[] getOptions(IConfiguration configuration) {
|
||||||
List myOptions = new ArrayList();
|
ITool tool = this;
|
||||||
|
if (configuration != null) {
|
||||||
|
// TODO don't like this much
|
||||||
|
ITool[] tools = configuration.getTools();
|
||||||
|
for (int i = 0; i < tools.length; ++i) {
|
||||||
|
if (tools[i] instanceof ToolReference) {
|
||||||
|
if (((ToolReference)tools[i]).references(tool)) {
|
||||||
|
tool = tools[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (tools[i].equals(tool))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IOption[] allOptions = tool.getOptions();
|
IOption[] allOptions = tool.getOptions();
|
||||||
|
List myOptions = new ArrayList();
|
||||||
|
|
||||||
for (int i = 0; i < allOptions.length; ++i) {
|
for (int i = 0; i < allOptions.length; ++i) {
|
||||||
IOption option = allOptions[i];
|
IOption option = allOptions[i];
|
||||||
if (option.getCategory() == null || option.getCategory().equals(this))
|
if (option.getCategory().equals(this))
|
||||||
myOptions.add(option);
|
myOptions.add(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (IOption[])myOptions.toArray(new IOption[myOptions.size()]);
|
return (IOption[])myOptions.toArray(new IOption[myOptions.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.ITool#getOption(java.lang.String)
|
||||||
|
*/
|
||||||
|
public IOption getOption(String id) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,160 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.build.managed;
|
package org.eclipse.cdt.internal.core.build.managed;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.build.managed.IConfiguration;
|
||||||
|
import org.eclipse.cdt.core.build.managed.IOption;
|
||||||
|
import org.eclipse.cdt.core.build.managed.IOptionCategory;
|
||||||
|
import org.eclipse.cdt.core.build.managed.ITarget;
|
||||||
|
import org.eclipse.cdt.core.build.managed.ITool;
|
||||||
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ToolReference {
|
public class ToolReference implements ITool {
|
||||||
|
|
||||||
|
private ITool parent;
|
||||||
|
private IConfiguration owner;
|
||||||
|
private List optionReferences;
|
||||||
|
private Map optionRefMap;
|
||||||
|
|
||||||
|
public ToolReference(ITool parent, IConfiguration owner) {
|
||||||
|
this.parent = parent;
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToolReference(Configuration owner, IConfigurationElement element) {
|
||||||
|
this.owner = owner;
|
||||||
|
|
||||||
|
parent = ((Target)owner.getTarget()).getTool(element.getAttribute("id"));
|
||||||
|
|
||||||
|
owner.addToolReference(this);
|
||||||
|
|
||||||
|
IConfigurationElement[] toolElements = element.getChildren();
|
||||||
|
for (int m = 0; m < toolElements.length; ++m) {
|
||||||
|
IConfigurationElement toolElement = toolElements[m];
|
||||||
|
if (toolElement.getName().equals("optionRef")) {
|
||||||
|
new OptionReference(this, toolElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITool getTool() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.ITool#createOption()
|
||||||
|
*/
|
||||||
|
public IOption createOption() {
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.ITool#getOptions()
|
||||||
|
*/
|
||||||
|
public IOption[] getOptions() {
|
||||||
|
IOption[] options = parent.getOptions();
|
||||||
|
|
||||||
|
// Replace with our references
|
||||||
|
for (int i = 0; i < options.length; ++i) {
|
||||||
|
OptionReference ref = getOptionReference(options[i]);
|
||||||
|
if (ref != null)
|
||||||
|
options[i] = ref;
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.ITool#getTarget()
|
||||||
|
*/
|
||||||
|
public ITarget getTarget() {
|
||||||
|
return owner.getTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.ITool#getTopOptionCategory()
|
||||||
|
*/
|
||||||
|
public IOptionCategory getTopOptionCategory() {
|
||||||
|
return parent.getTopOptionCategory();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.IBuildObject#getId()
|
||||||
|
*/
|
||||||
|
public String getId() {
|
||||||
|
return parent.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.IBuildObject#getName()
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return parent.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.IBuildObject#setId(java.lang.String)
|
||||||
|
*/
|
||||||
|
public void setId(String id) {
|
||||||
|
// Not allowed
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.IBuildObject#setName(java.lang.String)
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
// Not allowed
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean references(ITool target) {
|
||||||
|
if (equals(target))
|
||||||
|
// we are the target
|
||||||
|
return true;
|
||||||
|
else if (parent instanceof ToolReference)
|
||||||
|
// check the reference we are overriding
|
||||||
|
return ((ToolReference)parent).references(target);
|
||||||
|
else
|
||||||
|
// the real reference
|
||||||
|
return parent.equals(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
private OptionReference getOptionReference(IOption option) {
|
||||||
|
if (optionReferences != null)
|
||||||
|
for (int i = 0; i < optionReferences.size(); ++i) {
|
||||||
|
OptionReference optionRef = (OptionReference)optionReferences.get(i);
|
||||||
|
if (optionRef.references(option))
|
||||||
|
return optionRef;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOptionReference(OptionReference optionRef) {
|
||||||
|
if (optionReferences == null)
|
||||||
|
optionReferences = new ArrayList();
|
||||||
|
optionReferences.add(optionRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.build.managed.ITool#getOption(java.lang.String)
|
||||||
|
*/
|
||||||
|
public IOption getOption(String id) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,19 @@ import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
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.IOption;
|
||||||
import org.eclipse.cdt.core.build.managed.IOptionCategory;
|
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.cdt.core.build.managed.ManagedBuildManager;
|
import org.eclipse.cdt.core.build.managed.ManagedBuildManager;
|
||||||
|
import org.eclipse.cdt.internal.core.build.managed.ToolReference;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -34,6 +41,7 @@ public class AllBuildTests extends TestCase {
|
||||||
TestSuite suite = new TestSuite();
|
TestSuite suite = new TestSuite();
|
||||||
|
|
||||||
suite.addTest(new AllBuildTests("testExtensions"));
|
suite.addTest(new AllBuildTests("testExtensions"));
|
||||||
|
suite.addTest(new AllBuildTests("testProject"));
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
@ -59,34 +67,7 @@ public class AllBuildTests extends TestCase {
|
||||||
if (target.getName().equals("Test Root")) {
|
if (target.getName().equals("Test Root")) {
|
||||||
testRoot = target;
|
testRoot = target;
|
||||||
|
|
||||||
// Tools
|
checkRootTarget(testRoot);
|
||||||
ITool[] tools = testRoot.getTools();
|
|
||||||
// Root Tool
|
|
||||||
ITool rootTool = tools[0];
|
|
||||||
assertEquals("Root Tool", rootTool.getName());
|
|
||||||
// Options
|
|
||||||
IOption[] options = rootTool.getOptions();
|
|
||||||
assertEquals(2, options.length);
|
|
||||||
assertEquals("Option in Top", options[0].getName());
|
|
||||||
assertEquals("Option in Category", options[1].getName());
|
|
||||||
// Option Categories
|
|
||||||
IOptionCategory topCategory = rootTool.getTopOptionCategory();
|
|
||||||
assertEquals("Root Tool", topCategory.getName());
|
|
||||||
options = topCategory.getOptions(rootTool);
|
|
||||||
assertEquals(1, options.length);
|
|
||||||
assertEquals("Option in Top", options[0].getName());
|
|
||||||
IOptionCategory[] categories = topCategory.getChildCategories();
|
|
||||||
assertEquals(1, categories.length);
|
|
||||||
assertEquals("Category", categories[0].getName());
|
|
||||||
options = categories[0].getOptions(rootTool);
|
|
||||||
assertEquals(1, options.length);
|
|
||||||
assertEquals("Option in Category", options[0].getName());
|
|
||||||
|
|
||||||
// Configs
|
|
||||||
IConfiguration[] configs = testRoot.getConfigurations();
|
|
||||||
// Root Config
|
|
||||||
IConfiguration rootConfig = configs[0];
|
|
||||||
assertEquals("Root Config", rootConfig.getName());
|
|
||||||
|
|
||||||
} else if (target.getName().equals("Test Sub")) {
|
} else if (target.getName().equals("Test Sub")) {
|
||||||
testSub = target;
|
testSub = target;
|
||||||
|
@ -105,8 +86,9 @@ public class AllBuildTests extends TestCase {
|
||||||
// Root Config
|
// Root Config
|
||||||
IConfiguration rootConfig = configs[0];
|
IConfiguration rootConfig = configs[0];
|
||||||
assertEquals("Root Config", rootConfig.getName());
|
assertEquals("Root Config", rootConfig.getName());
|
||||||
|
assertEquals("Root Override Config", configs[1].getName());
|
||||||
// Sub Config
|
// Sub Config
|
||||||
IConfiguration subConfig = configs[1];
|
IConfiguration subConfig = configs[2];
|
||||||
assertEquals("Sub Config", subConfig.getName());
|
assertEquals("Sub Config", subConfig.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,4 +96,97 @@ public class AllBuildTests extends TestCase {
|
||||||
assertNotNull(testRoot);
|
assertNotNull(testRoot);
|
||||||
assertNotNull(testSub);
|
assertNotNull(testSub);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testProject() throws CoreException, BuildException {
|
||||||
|
// Create new project
|
||||||
|
IProject project = createProject("BuildTest");
|
||||||
|
|
||||||
|
assertEquals(0, ManagedBuildManager.getTargets(project).length);
|
||||||
|
|
||||||
|
// Find the base target definition
|
||||||
|
ITarget targetDef = ManagedBuildManager.getTarget(project, "test.root");
|
||||||
|
assertNotNull(targetDef);
|
||||||
|
|
||||||
|
// Create the target for our project
|
||||||
|
ITarget newTarget = ManagedBuildManager.createTarget(project, targetDef);
|
||||||
|
assertEquals(newTarget.getName(), targetDef.getName());
|
||||||
|
assertFalse(newTarget.equals(targetDef));
|
||||||
|
|
||||||
|
ITarget[] targets = ManagedBuildManager.getTargets(project);
|
||||||
|
assertEquals(1, targets.length);
|
||||||
|
ITarget target = targets[0];
|
||||||
|
assertEquals(target, newTarget);
|
||||||
|
assertFalse(target.equals(targetDef));
|
||||||
|
|
||||||
|
checkRootTarget(target);
|
||||||
|
|
||||||
|
// Save, close, reopen and test again
|
||||||
|
ManagedBuildManager.saveBuildInfo(project);
|
||||||
|
project.close(null);
|
||||||
|
ManagedBuildManager.removeBuildInfo(project);
|
||||||
|
project.open(null);
|
||||||
|
|
||||||
|
targets = ManagedBuildManager.getTargets(project);
|
||||||
|
assertEquals(1, targets.length);
|
||||||
|
checkRootTarget(targets[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
IProject createProject(String name) throws CoreException {
|
||||||
|
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||||
|
IProject project = root.getProject(name);
|
||||||
|
if (!project.exists()) {
|
||||||
|
project.create(null);
|
||||||
|
} else {
|
||||||
|
project.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!project.isOpen()) {
|
||||||
|
project.open(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//CCorePlugin.getDefault().convertProjectToC(project, null, CCorePlugin.PLUGIN_ID + ".make", true);
|
||||||
|
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkRootTarget(ITarget target) {
|
||||||
|
// Tools
|
||||||
|
ITool[] tools = target.getTools();
|
||||||
|
// Root Tool
|
||||||
|
ITool rootTool = tools[0];
|
||||||
|
assertEquals("Root Tool", rootTool.getName());
|
||||||
|
// Options
|
||||||
|
IOption[] options = rootTool.getOptions();
|
||||||
|
assertEquals(2, options.length);
|
||||||
|
assertEquals("Option in Top", options[0].getName());
|
||||||
|
assertEquals("Option in Category", options[1].getName());
|
||||||
|
// Option Categories
|
||||||
|
IOptionCategory topCategory = rootTool.getTopOptionCategory();
|
||||||
|
assertEquals("Root Tool", topCategory.getName());
|
||||||
|
options = topCategory.getOptions(null);
|
||||||
|
assertEquals(1, options.length);
|
||||||
|
assertEquals("Option in Top", options[0].getName());
|
||||||
|
IOptionCategory[] categories = topCategory.getChildCategories();
|
||||||
|
assertEquals(1, categories.length);
|
||||||
|
assertEquals("Category", categories[0].getName());
|
||||||
|
options = categories[0].getOptions(null);
|
||||||
|
assertEquals(1, options.length);
|
||||||
|
assertEquals("Option in Category", options[0].getName());
|
||||||
|
|
||||||
|
// Configs
|
||||||
|
IConfiguration[] configs = target.getConfigurations();
|
||||||
|
// Root Config
|
||||||
|
IConfiguration rootConfig = configs[0];
|
||||||
|
assertEquals("Root Config", rootConfig.getName());
|
||||||
|
// Tools
|
||||||
|
tools = rootConfig.getTools();
|
||||||
|
assertEquals(1, tools.length);
|
||||||
|
assertEquals("Root Tool", tools[0].getName());
|
||||||
|
// Root Override Config
|
||||||
|
assertEquals("Root Override Config", configs[1].getName());
|
||||||
|
tools = configs[1].getTools();
|
||||||
|
assertTrue(tools[0] instanceof ToolReference);
|
||||||
|
options = tools[0].getOptions();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,11 +94,8 @@
|
||||||
</target>
|
</target>
|
||||||
<target
|
<target
|
||||||
name="Test Root"
|
name="Test Root"
|
||||||
|
isAbstract="false"
|
||||||
id="test.root">
|
id="test.root">
|
||||||
<configuration
|
|
||||||
name="Root Config"
|
|
||||||
id="root.config">
|
|
||||||
</configuration>
|
|
||||||
<tool
|
<tool
|
||||||
name="Root Tool"
|
name="Root Tool"
|
||||||
id="root.tool">
|
id="root.tool">
|
||||||
|
@ -117,10 +114,26 @@
|
||||||
id="childOption">
|
id="childOption">
|
||||||
</option>
|
</option>
|
||||||
</tool>
|
</tool>
|
||||||
|
<configuration
|
||||||
|
name="Root Config"
|
||||||
|
id="root.config">
|
||||||
|
</configuration>
|
||||||
|
<configuration
|
||||||
|
name="Root Override Config"
|
||||||
|
id="root.override.config">
|
||||||
|
<toolRef
|
||||||
|
id="root.tool">
|
||||||
|
<optionRef
|
||||||
|
value="x"
|
||||||
|
id="topOption">
|
||||||
|
</optionRef>
|
||||||
|
</toolRef>
|
||||||
|
</configuration>
|
||||||
</target>
|
</target>
|
||||||
<target
|
<target
|
||||||
name="Test Sub"
|
name="Test Sub"
|
||||||
parent="test.root"
|
parent="test.root"
|
||||||
|
isAbstract="false"
|
||||||
id="test.sub">
|
id="test.sub">
|
||||||
<configuration
|
<configuration
|
||||||
name="Sub Config"
|
name="Sub Config"
|
||||||
|
|
Loading…
Add table
Reference in a new issue