From e7a699b56cc22d4cd0797475f7a94b58654f2e22 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Mon, 7 Apr 2003 20:56:27 +0000 Subject: [PATCH] Updates to the new build model. --- .../core/build/managed/IConfiguration.java | 9 ++ .../cdt/core/build/managed/IOption.java | 28 ++++ .../cdt/core/build/managed/ITarget.java | 8 ++ .../build/managed/ManagedBuildManager.java | 134 ++++++++++-------- .../core/build/managed/Configuration.java | 44 ++++-- .../internal/core/build/managed/Option.java | 18 +++ .../core/build/managed/OptionCategory.java | 18 +++ .../core/build/managed/OptionReference.java | 18 +++ .../internal/core/build/managed/Target.java | 30 ++-- .../cdt/internal/core/build/managed/Tool.java | 1 - .../core/build/managed/ToolReference.java | 18 +++ .../schema/ManagedBuildTools.exsd | 10 +- .../build/managed/tests/AllBuildTests.java | 4 +- core/org.eclipse.cdt.ui.tests/plugin.xml | 10 +- 14 files changed, 256 insertions(+), 94 deletions(-) create mode 100644 core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Option.java create mode 100644 core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionCategory.java create mode 100644 core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionReference.java create mode 100644 core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ToolReference.java diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IConfiguration.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IConfiguration.java index a270c2cb76c..baf60b73276 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IConfiguration.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IConfiguration.java @@ -10,6 +10,8 @@ **********************************************************************/ package org.eclipse.cdt.core.build.managed; +import org.eclipse.core.resources.IProject; + /** * */ @@ -28,6 +30,13 @@ public interface IConfiguration { */ public ITarget getTarget(); + /** + * Returns the project owning this configuration + * or null if this configuration is not associated with a project. + * @return + */ + public IProject getProject(); + /** * Returns the configuration from which this configuration inherits * properties. diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOption.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOption.java index d7a1ece79cd..c9496aab0bc 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOption.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOption.java @@ -19,8 +19,16 @@ public interface IOption { public static final int STRING = 0; public static final int STRING_LIST = 1; + /** + * Returns the tool defining this option. + * + * @return + */ + public ITool getTool(); + /** * Returns the category for this option. + * * @return */ public IOptionCategory getCategory(); @@ -62,4 +70,24 @@ public interface IOption { */ public String [] getStringListValue(); + /** + * 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 setStringValue(IConfiguration config, String value); + + /** + * 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 setStringValue(IConfiguration config, String[] value); + } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java index 4e92b6b1571..ab668de4683 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java @@ -10,6 +10,8 @@ **********************************************************************/ package org.eclipse.cdt.core.build.managed; +import org.eclipse.core.resources.IProject; + /** * This class represents targets for the managed build process. A target * is some type of resource built using a given collection of tools. @@ -38,4 +40,10 @@ public interface ITarget { */ public ITool[] getTools(); + /** + * Returns all of the configurations defined by this target. + * @return + */ + public IConfiguration[] getAvailableConfigurations(IProject project); + } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java index 0d942a592a8..d5928218037 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java @@ -14,13 +14,17 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.internal.core.build.managed.Configuration; 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.IResource; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.QualifiedName; /** * This is the main entry point for getting at the build information @@ -28,20 +32,23 @@ import org.eclipse.core.runtime.IExtensionPoint; */ public class ManagedBuildManager { + private static final QualifiedName configProperty + = new QualifiedName(CCorePlugin.PLUGIN_ID, "config"); + /** - * Returns the list of platforms that are available to be used in - * conjunction with the given resource. Generally this will include - * platforms defined by extensions as well as platforms defined by + * Returns the list of targets that are available to be used in + * conjunction with the given project. Generally this will include + * targets defined by extensions as well as targets defined by * the project and all projects this project reference. * * @param project * @return */ - public static ITarget[] getAvailableTargets(IProject project) { + public static ITarget[] getTargets(IProject project) { // Make sure the extensions are loaded loadExtensions(); - // Get the platforms for this project and all referenced projects + // Get the targets for this project and all referenced projects // Create the array and copy the elements over ITarget[] targets = new ITarget[extensionTargets.size()]; @@ -52,27 +59,14 @@ public class ManagedBuildManager { return targets; } - /** - * Returns the list of configurations belonging to the given platform - * that can be applied to the given project. This does not include - * the configurations already applied to the project. - * - * @param resource - * @param platform - * @return - */ - public static IConfiguration [] getAvailableConfigurations(IProject project, ITarget platform) { - return null; - } - /** * Returns the list of configurations associated with the given project. * * @param project * @return */ - public static IConfiguration [] getConfigurations(IProject project) { - return null; + public static IConfiguration[] getConfigurations(IProject project) { + return getResourceConfigs(project); } /** @@ -82,53 +76,40 @@ public class ManagedBuildManager { * @return */ public static IConfiguration[] getConfigurations(IFile file) { - return null; + // TODO not ready for prime time... + return getResourceConfigs(file); } - + /** - * Creates a configuration containing the tools defined by the target. + * Adds a configuration containing the tools defined by the target to + * the given project. * * @param target * @param project * @return */ - public static IConfiguration createConfiguration(IProject project, ITarget target) { - return null; - } - - /** - * Creates a configuration that inherits from the parent configuration. - * - * @param origConfig - * @param resource - * @return - */ - public static IConfiguration createConfiguration(IProject project, IConfiguration parentConfig) { + public static IConfiguration addConfiguration(IProject project, ITarget target) { + Configuration config = new Configuration(project, target); return null; } /** - * Sets the String value for an option. + * Adds a configuration inheriting from the given configuration. * - * @param project - * @param config - * @param option - * @param value + * @param origConfig + * @param resource + * @return */ - public static void setOptionValue(IProject project, IConfiguration config, IOption option, String value) { + public static IConfiguration addConfiguration(IProject project, IConfiguration parentConfig) { + if (parentConfig.getProject() != null) + // Can only inherit from target configs + return null; + + Configuration config = new Configuration(project, parentConfig); + addResourceConfig(project, config); + return config; } - - /** - * Sets the String List value for an option. - * - * @param project - * @param config - * @param option - * @param value - */ - public static void setOptionValue(IProject project, IConfiguration config, IOption option, String[] value) { - } - + // Private stuff private static List extensionTargets; @@ -151,15 +132,56 @@ public class ManagedBuildManager { Target target = new Target(element.getAttribute("name")); extensionTargets.add(target); + List configs = null; IConfigurationElement[] targetElements = element.getChildren(); for (int k = 0; k < targetElements.length; ++k) { - IConfigurationElement platformElement = targetElements[k]; - if (platformElement.getName().equals("tool")) { - Tool tool = new Tool(platformElement.getAttribute("name"), target); + IConfigurationElement targetElement = targetElements[k]; + if (targetElement.getName().equals("tool")) { + Tool tool = new Tool(targetElement.getAttribute("name"), target); + } else if (targetElement.getName().equals("configuration")) { + if (configs == null) + configs = new ArrayList(); + configs.add(new Configuration(target)); } } + + if (configs != null) { + IConfiguration[] configArray = new IConfiguration[configs.size()]; + configArray = (IConfiguration[])configs.toArray(configArray); + target.setConfigurations(configArray); + } } } } } + + private static final IConfiguration[] emptyConfigs = new IConfiguration[0]; + + private static IConfiguration[] getResourceConfigs(IResource resource) { + IConfiguration[] configs = null; + + try { + configs = (IConfiguration[])resource.getSessionProperty(configProperty); + } catch (CoreException e) { + } + + return (configs != null) ? configs : emptyConfigs; + } + + private static void addResourceConfig(IResource resource, IConfiguration config) { + IConfiguration[] configs = getResourceConfigs(resource); + + IConfiguration[] newConfigs = new IConfiguration[configs.length + 1]; + for (int i = 0; i < configs.length; ++i) + newConfigs[i] = configs[i]; + newConfigs[configs.length] = config; + + try { + resource.setSessionProperty(configProperty, newConfigs); + } catch (CoreException e) { + } + + // TODO save the config info to the project build file + } + } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Configuration.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Configuration.java index 215a1fccc1f..42bfe0313c4 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Configuration.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Configuration.java @@ -10,9 +10,12 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.build.managed; +import java.util.List; + import org.eclipse.cdt.core.build.managed.IConfiguration; import org.eclipse.cdt.core.build.managed.ITarget; import org.eclipse.cdt.core.build.managed.ITool; +import org.eclipse.core.resources.IProject; /** * @@ -20,17 +23,30 @@ import org.eclipse.cdt.core.build.managed.ITool; public class Configuration implements IConfiguration { private String name; - private ITarget platform; + private ITarget target; + private IProject project; + private IConfiguration parent; + private List toolReference; - public Configuration(ITarget platform) { - this.platform = platform; + public Configuration(Target target) { + this.target = target; + } + + public Configuration(IProject project, ITarget target) { + this.project = project; + this.target = target; } + public Configuration(IProject project, IConfiguration parent) { + this.project = project; + this.parent = parent; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#getName() */ public String getName() { - return name; + return (name == null && parent != null) ? parent.getName() : name; } /* (non-Javadoc) @@ -40,13 +56,6 @@ public class Configuration implements IConfiguration { this.name = name; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.build.managed.IConfiguration#getPlatform() - */ - public ITarget getPlatform() { - return platform; - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#getTools() */ @@ -59,16 +68,21 @@ public class Configuration implements IConfiguration { * @see org.eclipse.cdt.core.build.managed.IConfiguration#getParent() */ public IConfiguration getParent() { - // TODO Auto-generated method stub - return null; + return parent; } /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IConfiguration#getTarget() */ public ITarget getTarget() { - // TODO Auto-generated method stub - return null; + return (target == null && parent != null) ? parent.getTarget() : target; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IConfiguration#getProject() + */ + public IProject getProject() { + return (project == null && parent != null) ? parent.getProject() : project; } } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Option.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Option.java new file mode 100644 index 00000000000..d8f8234f355 --- /dev/null +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Option.java @@ -0,0 +1,18 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.build.managed; + +/** + * + */ +public class Option { + +} diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionCategory.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionCategory.java new file mode 100644 index 00000000000..5909e1acc10 --- /dev/null +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionCategory.java @@ -0,0 +1,18 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.build.managed; + +/** + * + */ +public class OptionCategory { + +} diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionReference.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionReference.java new file mode 100644 index 00000000000..64eb468b4d2 --- /dev/null +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionReference.java @@ -0,0 +1,18 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.build.managed; + +/** + * + */ +public class OptionReference { + +} diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java index a09979ece39..e54de59d0e2 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java @@ -10,11 +10,10 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.build.managed; -import java.util.ArrayList; -import java.util.List; - +import org.eclipse.cdt.core.build.managed.IConfiguration; import org.eclipse.cdt.core.build.managed.ITarget; import org.eclipse.cdt.core.build.managed.ITool; +import org.eclipse.core.resources.IProject; /** * @@ -23,7 +22,8 @@ public class Target implements ITarget { private String name; private Target parent; - private List tools; + private ITool[] tools; + private IConfiguration[] configurations; public Target(String name) { this.name = name; @@ -47,7 +47,7 @@ public class Target implements ITarget { } private int getNumTools() { - int n = (tools == null) ? 0 : tools.size(); + int n = (tools == null) ? 0 : tools.length; if (parent != null) n += parent.getNumTools(); return n; @@ -59,22 +59,30 @@ public class Target implements ITarget { n = parent.addToolsToArray(toolArray, start); if (tools != null) { - for (int i = 0; i < tools.size(); ++i) - toolArray[n++] = (ITool)tools.get(i); + for (int i = 0; i < tools.length; ++i) + toolArray[n++] = (ITool)tools[i]; } return n; } + public ITool[] getTools() { ITool[] toolArray = new ITool[getNumTools()]; addToolsToArray(toolArray, 0); return toolArray; } + + public void setTools(ITool[] tools) { + this.tools = tools; + } - public void addTool(Tool tool) { - if (tools == null) - tools = new ArrayList(); - tools.add(tool); + public void setConfigurations(IConfiguration [] configurations) { + this.configurations = configurations; + } + + public IConfiguration[] getAvailableConfigurations(IProject project) { + // TODO Auto-generated method stub + return null; } } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Tool.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Tool.java index a730f60b719..4462a9b2925 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Tool.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Tool.java @@ -30,7 +30,6 @@ public class Tool implements ITool { public Tool(String name, Target target) { this(name); this.target = target; - target.addTool(this); } public String getName() { diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ToolReference.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ToolReference.java new file mode 100644 index 00000000000..b0608b98d84 --- /dev/null +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ToolReference.java @@ -0,0 +1,18 @@ +/********************************************************************** + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.build.managed; + +/** + * + */ +public class ToolReference { + +} diff --git a/core/org.eclipse.cdt.core/schema/ManagedBuildTools.exsd b/core/org.eclipse.cdt.core/schema/ManagedBuildTools.exsd index dede047e102..adc0e8c298b 100644 --- a/core/org.eclipse.cdt.core/schema/ManagedBuildTools.exsd +++ b/core/org.eclipse.cdt.core/schema/ManagedBuildTools.exsd @@ -177,13 +177,6 @@ - - - - - - - @@ -224,12 +217,13 @@ - Represents a type of resource that is the target of the build process, for example, a Linux Library. A target contains a sequence of tool definitions. Targets are arranged in an inheritance hierarchy where a target inherits the list of tools from it's parent and can add to or override tools in this list. + Represents a type of resource that is the target of the build process, for example, a Linux Library. A target contains a sequence of tool definitions and configurations. Targets are arranged in an inheritance hierarchy where a target inherits the list of tools from it's parent and can add to or override tools in this list. + diff --git a/core/org.eclipse.cdt.ui.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java b/core/org.eclipse.cdt.ui.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java index e2fe007b753..262f7f212d4 100644 --- a/core/org.eclipse.cdt.ui.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java +++ b/core/org.eclipse.cdt.ui.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java @@ -45,8 +45,8 @@ public class AllBuildTests extends TestCase { */ public void testExtensions() { // Note secret null parameter which means just extensions - ITarget[] targets = ManagedBuildManager.getAvailableTargets(null); - + ITarget[] targets = ManagedBuildManager.getTargets(null); + ITarget target = targets[0]; assertEquals(target.getName(), "Linux"); ITool[] tools = target.getTools(); diff --git a/core/org.eclipse.cdt.ui.tests/plugin.xml b/core/org.eclipse.cdt.ui.tests/plugin.xml index 14dc646b32c..dc93b91ed01 100644 --- a/core/org.eclipse.cdt.ui.tests/plugin.xml +++ b/core/org.eclipse.cdt.ui.tests/plugin.xml @@ -45,8 +45,8 @@ id="linux.compiler.flags">