Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2003-06-09 15:22:21 -0400
committerDoug Schaefer2003-06-09 15:22:21 -0400
commitda0c569bffa17674195771eb1bea9bb14c2386ef (patch)
tree27b91d12488fb7d8dad09e116a023b09f29c5e7e /core/org.eclipse.cdt.core/build
parente9adc8cbbbdaf99f2b679bbe01db9867da668cfb (diff)
downloadorg.eclipse.cdt-da0c569bffa17674195771eb1bea9bb14c2386ef.tar.gz
org.eclipse.cdt-da0c569bffa17674195771eb1bea9bb14c2386ef.tar.xz
org.eclipse.cdt-da0c569bffa17674195771eb1bea9bb14c2386ef.zip
Patch for Sean Evoy:
- Initial contribution of Managed Build UI.
Diffstat (limited to 'core/org.eclipse.cdt.core/build')
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IResourceBuildInfo.java124
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java83
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITool.java54
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java36
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Configuration.java2
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/OptionReference.java18
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ResourceBuildInfo.java225
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java70
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Tool.java144
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ToolReference.java78
10 files changed, 762 insertions, 72 deletions
diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IResourceBuildInfo.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IResourceBuildInfo.java
new file mode 100644
index 0000000000..c42170e900
--- /dev/null
+++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IResourceBuildInfo.java
@@ -0,0 +1,124 @@
+package org.eclipse.cdt.core.build.managed;
+
+import java.util.List;
+
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+***********************************************************************/
+
+public interface IResourceBuildInfo {
+
+ /**
+ * Add a new target to the build information for the receiver
+ *
+ * @param target
+ */
+ public void addTarget(ITarget target);
+
+ /**
+ * Returns the name of the artifact to build for the receiver.
+ *
+ * @return
+ */
+ public String getBuildArtifactName();
+
+ /**
+ * Get the default configuration associated with the receiver
+ *
+ * @return
+ */
+ public IConfiguration getDefaultConfiguration(ITarget target);
+
+
+ /**
+ * Returns the default target in the receiver.
+ *
+ * @return
+ */
+ public ITarget getDefaultTarget();
+
+ /**
+ * Answers the extension that will be built by the current configuration
+ * for the extension passed in the argument or <code>null</code>.
+ *
+ * @param resourceName
+ * @return
+ */
+ public String getOutputExtension(String resourceExtension);
+
+ /**
+ * Get the target specified in the argument.
+ *
+ * @param id
+ * @return
+ */
+ public ITarget getTarget(String id);
+
+ /**
+ * Get all of the targets associated with the receiver.
+ *
+ * @return
+ */
+ public List getTargets();
+
+ /**
+ * Returns a <code>String</code> containing the flags, including
+ * those overridden by the user, for the tool that handles the
+ * type of source file defined by the argument.
+ *
+ * @param extension
+ * @return
+ */
+ public String getFlagsForSource(String extension);
+
+ /**
+ * Returns a <code>String</code> containing the flags, including
+ * those overridden by the user, for the tool that handles the
+ * type of target defined by the argument.
+ *
+ * @param extension
+ * @return
+ */
+ public String getFlagsForTarget(String extension);
+
+ /**
+ * Returns a <code>String</code> containing the command-line invocation
+ * for the tool associated with the source extension.
+ *
+ * @param extension
+ * @return
+ */
+ public String getToolForSource(String extension);
+
+ /**
+ * Returns a <code>String</code> containing the command-line invocation
+ * for the tool associated with the target extension.
+ *
+ * @param extension
+ * @return
+ */
+ public String getToolForTarget(String extension);
+
+ /**
+ * Set the primary configuration for the receiver.
+ *
+ * @param configuration The <code>IConfiguration</code> that will be used as the default
+ * for all building.
+ */
+ public void setDefaultConfiguration(IConfiguration configuration);
+
+ /**
+ * Set the primary target for the receiver.
+ *
+ * @param target
+ */
+ public void setDefaultTarget(ITarget target);
+
+}
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 3a44a11fa4..2eefd1c879 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
@@ -19,36 +19,46 @@ import org.eclipse.core.resources.IResource;
public interface ITarget extends IBuildObject {
/**
- * Returns whether this target is abstract
+ * Creates a configuration for the target populated with the tools and
+ * options settings from the parent configuration. As options and tools
+ * change in the parent, unoverridden values are updated in the child
+ * config as well.
+ *
+ * @param parent
+ * @param id
* @return
*/
- public boolean isAbstract();
-
+ public IConfiguration createConfiguration(IConfiguration parent, String id);
+
/**
- * Gets the resource that this target is applied to.
+ * Creates a new configuration for the target. It is populated with
+ * the tools defined for that target and options set at their defaults.
*
+ * @param id id for this configuration.
* @return
*/
- public IResource getOwner();
-
+ public IConfiguration createConfiguration(String id);
+
/**
- * @return the <code>ITarget</code> that is the parent of the receiver.
+ * Get the name of the final build artifact.
+ *
+ * @return
*/
- public ITarget getParent();
+ public String getArtifactName();
/**
- * Returns the list of platform specific tools associated with this
- * platform.
- *
+ * Returns all of the configurations defined by this target.
* @return
*/
- public ITool[] getTools();
+ public IConfiguration[] getConfigurations();
/**
- * Returns all of the configurations defined by this target.
+ * Get the default extension that should be applied to build artifacts
+ * created by this target.
+ *
* @return
*/
- public IConfiguration[] getConfigurations();
+ public String getDefaultExtension();
/**
* Returns the configuration with the given id, or null if not found.
@@ -59,23 +69,46 @@ public interface ITarget extends IBuildObject {
public IConfiguration getConfiguration(String id);
/**
- * Creates a new configuration for the target. It is populated with
- * the tools defined for that target and options set at their defaults.
+ * Gets the resource that this target is applied to.
*
- * @param id id for this configuration.
* @return
*/
- public IConfiguration createConfiguration(String id);
+ public IResource getOwner();
+
+ /**
+ * @return the <code>ITarget</code> that is the parent of the receiver.
+ */
+ public ITarget getParent();
/**
- * Creates a configuration for the target populated with the tools and
- * options settings from the parent configuration. As options and tools
- * change in the parent, unoverridden values are updated in the child
- * config as well.
+ * Returns the list of platform specific tools associated with this
+ * platform.
*
- * @param parent
- * @param id
* @return
*/
- public IConfiguration createConfiguration(IConfiguration parent, String id);
+ public ITool[] getTools();
+
+ /**
+ * Returns whether this target is abstract.
+ * @return
+ */
+ public boolean isAbstract();
+
+ /**
+ * Answers <code>true</code> if the receiver is a target that is defined
+ * for testing purposes only, else <code>false</code>. A test target will
+ * not be shown in the UI but can still be manipulated programmatically.
+ *
+ * @return
+ */
+ public boolean isTestTarget();
+
+ /**
+ * Set the name of the artifact that will be produced when the receiver
+ * is built.
+ *
+ * @param name The name of the build artifact.
+ */
+ public void setBuildArtifact(String name);
+
}
diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITool.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITool.java
index 5878ce765b..89751c5d8e 100644
--- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITool.java
+++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITool.java
@@ -14,12 +14,24 @@ package org.eclipse.cdt.core.build.managed;
*
*/
public interface ITool extends IBuildObject {
+ public static final String WHITE_SPACE = " ";
/**
- * Return the target that defines this tool, if applicable
+ * Return <code>true</code> if the receiver builds files with the
+ * specified extension, else <code>false</code>.
+ *
+ * @param extension
* @return
*/
- public ITarget getTarget();
+ public boolean buildsFileType(String extension);
+
+ /**
+ * Get a particular option.
+ *
+ * @param id
+ * @return
+ */
+ public IOption getOption(String id);
/**
* Returns the options that may be customized for this tool.
@@ -27,12 +39,34 @@ public interface ITool extends IBuildObject {
public IOption[] getOptions();
/**
- * Get a particular option.
+ * Answer the output extension the receiver will create from the input,
+ * or <code>null</code> if the tool does not understand that extension.
*
- * @param id
+ * @param inputExtension The extension of the source file.
* @return
*/
- public IOption getOption(String id);
+ public String getOutputExtension(String inputExtension);
+
+ /**
+ * Return the target that defines this tool, if applicable
+ * @return
+ */
+ public ITarget getTarget();
+
+ /**
+ * Answers the command-line invocation defined for the receiver.
+ *
+ * @return
+ */
+ public String getToolCommand();
+
+ /**
+ * Answers the additional command line arguments the user has specified for
+ * the tool.
+ *
+ * @return
+ */
+ public String getToolFlags() throws BuildException ;
/**
* Options are organized into categories for UI purposes.
@@ -42,4 +76,14 @@ public interface ITool extends IBuildObject {
* @return
*/
public IOptionCategory getTopOptionCategory();
+
+ /**
+ * Answers <code>true</code> if the receiver builds a file with the extension specified
+ * in the argument, else <code>false</code>.
+ *
+ * @param outputExtension
+ * @return
+ */
+ public boolean producesFileType(String outputExtension);
+
}
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 149affb08b..7adb6cd147 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
@@ -108,7 +108,7 @@ public class ManagedBuildManager {
* @return
*/
public static ITarget[] getTargets(IResource resource) {
- ResourceBuildInfo buildInfo = getBuildInfo(resource);
+ IResourceBuildInfo buildInfo = getBuildInfo(resource);
if (buildInfo != null) {
List targets = buildInfo.getTargets();
@@ -121,7 +121,7 @@ public class ManagedBuildManager {
public static ITarget getTarget(IResource resource, String id) {
if (resource != null) {
- ResourceBuildInfo buildInfo = getBuildInfo(resource);
+ IResourceBuildInfo buildInfo = getBuildInfo(resource);
if (buildInfo != null)
return buildInfo.getTarget(id);
}
@@ -138,7 +138,7 @@ public class ManagedBuildManager {
*
* @param resource
* @param parentTarget
- * @return
+ * @return new <code>ITarget</code> with settings based on the parent passed in the arguments
* @throws BuildException
*/
public static ITarget createTarget(IResource resource, ITarget parentTarget)
@@ -167,6 +167,24 @@ public class ManagedBuildManager {
}
/**
+ * Sets the default configuration for the project. Note that this will also
+ * update the default target if needed.
+ *
+ * @param project
+ * @param newDefault
+ */
+ public static void setDefaultConfiguration(IProject project, IConfiguration newDefault) {
+ if (project == null || newDefault == null) {
+ return;
+ }
+ // Set the default in build information for the project
+ IResourceBuildInfo info = getBuildInfo(project);
+ if (info != null) {
+ info.setDefaultConfiguration(newDefault);
+ }
+ }
+
+ /**
* Set the string value for an option for a given config.
*
* @param config The configuration the option belongs to.
@@ -223,9 +241,8 @@ public class ManagedBuildManager {
Element rootElement = doc.createElement("buildInfo");
doc.appendChild(rootElement);
- // Populate from buildInfo
- // To do - find other resources also
- ResourceBuildInfo buildInfo = getBuildInfo(project);
+ // Save the build info
+ ResourceBuildInfo buildInfo = (ResourceBuildInfo) getBuildInfo(project);
if (buildInfo != null)
buildInfo.serialize(doc, rootElement);
@@ -276,8 +293,7 @@ public class ManagedBuildManager {
return;
extensionTargetsLoaded = true;
- IExtensionPoint extensionPoint
- = CCorePlugin.getDefault().getDescriptor().getExtensionPoint("ManagedBuildInfo");
+ IExtensionPoint extensionPoint = CCorePlugin.getDefault().getDescriptor().getExtensionPoint("ManagedBuildInfo");
IExtension[] extensions = extensionPoint.getExtensions();
for (int i = 0; i < extensions.length; ++i) {
IExtension extension = extensions[i];
@@ -313,7 +329,7 @@ public class ManagedBuildManager {
return buildInfo;
}
- public static ResourceBuildInfo getBuildInfo(IResource resource, boolean create) {
+ public static IResourceBuildInfo getBuildInfo(IResource resource, boolean create) {
// Make sure the extension information is loaded first
loadExtensions();
ResourceBuildInfo buildInfo = null;
@@ -338,7 +354,7 @@ public class ManagedBuildManager {
return buildInfo;
}
- public static ResourceBuildInfo getBuildInfo(IResource resource) {
+ public static IResourceBuildInfo getBuildInfo(IResource resource) {
return getBuildInfo(resource, false);
}
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 0a11759af6..1369bb6a94 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
@@ -258,7 +258,7 @@ public class Configuration extends BuildObject implements IConfiguration {
String oldValue;
// Check whether this is an enumerated option
if (option.getValueType() == IOption.ENUMERATED) {
- oldValue = option.getEnumCommand(option.getSelectedEnum());
+ oldValue = option.getSelectedEnum();
}
else {
oldValue = option.getStringValue();
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
index 6961ac68dc..66abdfc2df 100644
--- 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
@@ -30,10 +30,14 @@ import org.w3c.dom.NodeList;
*/
public class OptionReference implements IOption {
+ // Used for all option references that override the command
+ private String command;
+ // The option this reference overrides
private IOption option;
+ // The owner of the reference
private ToolReference owner;
+ // The actual value of the reference
private Object value;
- private String command;
/**
* Created internally.
@@ -69,7 +73,7 @@ public class OptionReference implements IOption {
value = element.getAttribute("defaultValue");
break;
case IOption.ENUMERATED:
- value = option.getEnumCommand(option.getSelectedEnum());
+ value = option.getSelectedEnum();
break;
case IOption.STRING_LIST:
List valueList = new ArrayList();
@@ -97,11 +101,11 @@ public class OptionReference implements IOption {
// value
switch (option.getValueType()) {
case IOption.BOOLEAN:
- value = new Boolean(element.getAttribute("value"));
+ value = new Boolean(element.getAttribute("defaultValue"));
break;
case IOption.STRING:
case IOption.ENUMERATED:
- value = (String) element.getAttribute("value");
+ value = (String) element.getAttribute("defaultValue");
break;
case IOption.STRING_LIST:
List valueList = new ArrayList();
@@ -130,11 +134,11 @@ public class OptionReference implements IOption {
// value
switch (option.getValueType()) {
case IOption.BOOLEAN:
- element.setAttribute("value", ((Boolean)value).toString());
+ element.setAttribute("defaultValue", ((Boolean)value).toString());
break;
case IOption.STRING:
case IOption.ENUMERATED:
- element.setAttribute("value", (String)value);
+ element.setAttribute("defaultValue", (String)value);
break;
case IOption.STRING_LIST:
ArrayList stringList = (ArrayList)value;
@@ -213,7 +217,7 @@ public class OptionReference implements IOption {
// Return the default defined for the enumeration in the manifest.
return option.getSelectedEnum();
} else {
- // Value will contain the selection of the user
+ // Value will contain the human-readable name of the enum
return (String) value;
}
}
diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ResourceBuildInfo.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ResourceBuildInfo.java
index a1a36e5f0e..82e3627c50 100644
--- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ResourceBuildInfo.java
+++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/ResourceBuildInfo.java
@@ -14,58 +14,263 @@ package org.eclipse.cdt.internal.core.build.managed;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
+import org.eclipse.cdt.core.build.managed.BuildException;
+import org.eclipse.cdt.core.build.managed.IConfiguration;
+import org.eclipse.cdt.core.build.managed.IResourceBuildInfo;
+import org.eclipse.cdt.core.build.managed.ITarget;
+import org.eclipse.cdt.core.build.managed.ITool;
import org.eclipse.core.resources.IResource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-public class ResourceBuildInfo {
+public class ResourceBuildInfo implements IResourceBuildInfo {
private IResource owner;
private Map targetMap;
private List targets;
-
+ private Map defaultConfigurations;
+ private ITarget defaultTarget;
+
public ResourceBuildInfo() {
targetMap = new HashMap();
targets = new ArrayList();
+ defaultConfigurations = new HashMap();
}
public ResourceBuildInfo(IResource owner, Element element) {
this();
-
+ // The id of the default configuration
+ String defaultTargetId = null;
+ List configIds = new ArrayList();
Node child = element.getFirstChild();
while (child != null) {
if (child.getNodeName().equals("target")) {
new Target(this, (Element)child);
+ } else if (child.getNodeName().equals("defaultConfig")) {
+ // We may not have read the config in yet, so just cache it
+ configIds.add(((Element)child).getAttribute("id"));
+ } else if (child.getNodeName().equals("defaultTarget")) {
+ defaultTargetId = ((Element)child).getAttribute("id");
}
child = child.getNextSibling();
}
+ // All the available targets have been read in
+ defaultTarget = (ITarget) targetMap.get(defaultTargetId);
+ // Now we have a misserable O(N^2) operation (oh well, the data sets are small)
+ ListIterator stringIter = configIds.listIterator();
+ while (stringIter.hasNext()){
+ String confId = (String) stringIter.next();
+ ListIterator targIter = targets.listIterator();
+ while (targIter.hasNext()) {
+ Target targ = (Target) targIter.next();
+ IConfiguration conf = targ.getConfiguration(confId);
+ if (conf != null) {
+ defaultConfigurations.put(targ.getId(), conf);
+ break;
+ }
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IResourceBuildInfo#addTarget(org.eclipse.cdt.core.build.managed.ITarget)
+ */
+ public void addTarget(ITarget target) {
+ targetMap.put(target.getId(), target);
+ targets.add(target);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IResourceBuildInfo#getBuildArtifactName()
+ */
+ public String getBuildArtifactName() {
+ // Get the default target and use its value
+ String name = getDefaultTarget().getArtifactName();
+ return name == null ? new String() : name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IResourceBuildInfo#getDefaultConfiguration()
+ */
+ public IConfiguration getDefaultConfiguration(ITarget target) {
+ // Get the default config associated with the defalt target
+ IConfiguration config = (IConfiguration) defaultConfigurations.get(target.getId());
+
+ // If null, look up the first configuration associated with the target
+ if (config == null) {
+ IConfiguration[] configs = getDefaultTarget().getConfigurations();
+ if (configs.length > 0) {
+ config = configs[0];
+ }
+ }
+ return config;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IResourceBuildInfo#getDefaultTarget()
+ */
+ public ITarget getDefaultTarget() {
+ if (defaultTarget == null) {
+ defaultTarget = (ITarget) targets.get(0);
+ }
+ return defaultTarget;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IResourceBuildInfo#getFlagsForSource(java.lang.String)
+ */
+ public String getFlagsForSource(String extension) {
+ // Get all the tools for the current config
+ IConfiguration config = getDefaultConfiguration(getDefaultTarget());
+ ITool[] tools = config.getTools();
+ for (int index = 0; index < tools.length; index++) {
+ ITool tool = tools[index];
+ if (tool.buildsFileType(extension)) {
+ String flags = new String();
+ try {
+ flags = tool.getToolFlags();
+ } catch (BuildException e) {
+ // Give it your best shot with the next tool
+ continue;
+ }
+ return flags;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IResourceBuildInfo#getToolFlags(java.lang.String)
+ */
+ public String getFlagsForTarget(String extension) {
+ // Get all the tools for the current config
+ IConfiguration config = getDefaultConfiguration(getDefaultTarget());
+ ITool[] tools = config.getTools();
+ for (int index = 0; index < tools.length; index++) {
+ ITool tool = tools[index];
+ if (tool.producesFileType(extension)) {
+ String flags = new String();
+ try {
+ flags = tool.getToolFlags();
+ } catch (BuildException e) {
+ // TODO: handle exception
+ }
+ return flags;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IResourceBuildInfo#getOutputExtension(java.lang.String)
+ */
+ public String getOutputExtension(String resourceExtension) {
+ // Get all the tools for the current config
+ IConfiguration config = getDefaultConfiguration(getDefaultTarget());
+ ITool[] tools = config.getTools();
+ for (int index = 0; index < tools.length; index++) {
+ ITool tool = tools[index];
+ String output = tool.getOutputExtension(resourceExtension);
+ if (output != null) {
+ return output;
+ }
+ }
+ return null;
}
public IResource getOwner() {
return owner;
}
-
- public Target getTarget(String id) {
- return (Target)targetMap.get(id);
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IResourceBuildInfo#getTarget(org.eclipse.cdt.core.build.managed.IConfiguration)
+ */
+ public ITarget getTarget(String id) {
+ return (ITarget) targetMap.get(id);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IResourceBuildInfo#getTargets(org.eclipse.cdt.core.build.managed.IConfiguration)
+ */
public List getTargets() {
return targets;
}
- public void addTarget(Target target) {
- targetMap.put(target.getId(), target);
- targets.add(target);
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IResourceBuildInfo#getToolForSource(java.lang.String)
+ */
+ public String getToolForSource(String extension) {
+ // Get all the tools for the current config
+ IConfiguration config = getDefaultConfiguration(getDefaultTarget());
+ ITool[] tools = config.getTools();
+ for (int index = 0; index < tools.length; index++) {
+ ITool tool = tools[index];
+ if (tool.buildsFileType(extension)) {
+ return tool.getToolCommand();
+ }
+ }
+ return null;
}
-
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IResourceBuildInfo#getToolInvocation(java.lang.String)
+ */
+ public String getToolForTarget(String extension) {
+ // Get all the tools for the current config
+ IConfiguration config = getDefaultConfiguration(getDefaultTarget());
+ ITool[] tools = config.getTools();
+ for (int index = 0; index < tools.length; index++) {
+ ITool tool = tools[index];
+ if (tool.producesFileType(extension)) {
+ return tool.getToolCommand();
+ }
+ }
+ return null;
+ }
+
public void serialize(Document doc, Element element) {
+ // Write out each target and their default config
for (int i = 0; i < targets.size(); ++i) {
Element targetElement = doc.createElement("target");
element.appendChild(targetElement);
((Target)targets.get(i)).serialize(doc, targetElement);
+ IConfiguration config = getDefaultConfiguration((ITarget)targets.get(i));
+ if (config != null) {
+ Element configEl = doc.createElement("defaultConfig");
+ element.appendChild(configEl);
+ configEl.setAttribute("id", config.getId());
+ }
+ }
+ // Persist the default target
+ if (getDefaultTarget() != null){
+ Element targEl = doc.createElement("defaultTarget");
+ element.appendChild(targEl);
+ targEl.setAttribute("id", getDefaultTarget().getId());
}
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IResourceBuildInfo#setDefaultConfiguration(org.eclipse.cdt.core.build.managed.IConfiguration)
+ */
+ public void setDefaultConfiguration(IConfiguration configuration) {
+ // Get the target associated with the argument
+ ITarget target = configuration.getTarget();
+ // Make sure it is the default
+ setDefaultTarget(target);
+ defaultConfigurations.put(target.getId(), configuration);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IResourceBuildInfo#setDefaultTarget(org.eclipse.cdt.core.build.managed.ITarget)
+ */
+ public void setDefaultTarget(ITarget target) {
+ if (defaultTarget != null && defaultTarget.getId().equals(target.getId())) {
+ return;
+ }
+ defaultTarget = target;
+ }
+
}
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 b9aec823e4..406972b567 100644
--- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java
+++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java
@@ -16,6 +16,7 @@ import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.build.managed.IConfiguration;
+import org.eclipse.cdt.core.build.managed.IResourceBuildInfo;
import org.eclipse.cdt.core.build.managed.ITarget;
import org.eclipse.cdt.core.build.managed.ITool;
import org.eclipse.cdt.core.build.managed.ManagedBuildManager;
@@ -37,8 +38,12 @@ public class Target extends BuildObject implements ITarget {
private List configurations;
private Map configMap;
private boolean isAbstract = false;
+ private boolean isTest = false;
+ private String artifactName;
+ private String defaultExtension;
private static final IConfiguration[] emptyConfigs = new IConfiguration[0];
+ private static final String EMPTY_STRING = new String();
public Target(IResource owner) {
this.owner = owner;
@@ -58,9 +63,12 @@ public class Target extends BuildObject implements ITarget {
this.parent = parent;
setId(parent.getId() + ".1");
setName(parent.getName());
+ this.artifactName = parent.getArtifactName();
+ this.defaultExtension = parent.getDefaultExtension();
+ this.isTest = parent.isTestTarget();
// Hook me up
- ResourceBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(owner, true);
+ IResourceBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(owner, true);
buildInfo.addTarget(this);
}
@@ -76,9 +84,16 @@ public class Target extends BuildObject implements ITarget {
// hook me up
ManagedBuildManager.addExtensionTarget(this);
- // name
+ // Get the target name
setName(element.getAttribute("name"));
+ // Get the name of the build artifact associated with target (usually
+ // in the plugin specification).
+ artifactName = element.getAttribute("artifactName");
+
+ // Get the default extension
+ defaultExtension = element.getAttribute("defaultExtension");
+
// parent
String parentId = element.getAttribute("parent");
if (parentId != null) {
@@ -93,6 +108,9 @@ public class Target extends BuildObject implements ITarget {
if ("true".equals(element.getAttribute("isAbstract")))
isAbstract = true;
+ // Is this a test target
+ isTest = ("true".equals(element.getAttribute("isTest")));
+
IConfigurationElement[] targetElements = element.getChildren();
for (int k = 0; k < targetElements.length; ++k) {
IConfigurationElement targetElement = targetElements[k];
@@ -123,6 +141,13 @@ public class Target extends BuildObject implements ITarget {
// name
setName(element.getAttribute("name"));
+ // Get the name of the build artifact associated with target (should
+ // contain what the user entered in the UI).
+ artifactName = element.getAttribute("artifactName");
+
+ // Get the default extension
+ defaultExtension = element.getAttribute("defaultExtension");
+
// parent
String parentId = element.getAttribute("parent");
if (parentId != null)
@@ -131,6 +156,9 @@ public class Target extends BuildObject implements ITarget {
// isAbstract
if ("true".equals(element.getAttribute("isAbstract")))
isAbstract = true;
+
+ // Is this a test target
+ isTest = ("true".equals(element.getAttribute("isTest")));
Node child = element.getFirstChild();
while (child != null) {
@@ -139,8 +167,6 @@ public class Target extends BuildObject implements ITarget {
}
child = child.getNextSibling();
}
-
-
}
/**
@@ -155,7 +181,10 @@ public class Target extends BuildObject implements ITarget {
if (parent != null)
element.setAttribute("parent", parent.getId());
element.setAttribute("isAbstract", isAbstract ? "true" : "false");
-
+ element.setAttribute("artifactName", getArtifactName());
+ element.setAttribute("defaultExtension", getDefaultExtension());
+ element.setAttribute("isTest", isTest ? "true" : "false");
+
if (configurations != null)
for (int i = 0; i < configurations.size(); ++i) {
Configuration config = (Configuration)configurations.get(i);
@@ -231,6 +260,24 @@ public class Target extends BuildObject implements ITarget {
return emptyConfigs;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#getDefaultExtension()
+ */
+ public String getDefaultExtension() {
+ return defaultExtension == null ? EMPTY_STRING : defaultExtension;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#getArtifactName()
+ */
+ public String getArtifactName() {
+ // Return name or an empty string
+ return artifactName == null ? EMPTY_STRING : artifactName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#getConfiguration()
+ */
public IConfiguration getConfiguration(String id) {
return (IConfiguration)configMap.get(id);
}
@@ -252,6 +299,13 @@ public class Target extends BuildObject implements ITarget {
}
/* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#isTestTarget()
+ */
+ public boolean isTestTarget() {
+ return isTest;
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.ITarget#createConfiguration()
*/
public IConfiguration createConfiguration(String id) {
@@ -265,4 +319,10 @@ public class Target extends BuildObject implements ITarget {
return new Configuration(this, parent, id);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#setBuildArtifact(java.lang.String)
+ */
+ public void setBuildArtifact(String name) {
+ artifactName = name;
+ }
}
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 320f6b5061..713663b02e 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
@@ -13,8 +13,11 @@ package org.eclipse.cdt.internal.core.build.managed;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
+import java.util.StringTokenizer;
+import org.eclipse.cdt.core.build.managed.BuildException;
import org.eclipse.cdt.core.build.managed.IConfiguration;
import org.eclipse.cdt.core.build.managed.IOption;
import org.eclipse.cdt.core.build.managed.IOptionCategory;
@@ -29,19 +32,30 @@ import org.eclipse.core.runtime.IConfigurationElement;
*/
public class Tool extends BuildObject implements ITool, IOptionCategory {
+ private static final String DEFAULT_SEPARATOR = ",";
+ private static final IOptionCategory[] EMPTY_CATEGORIES = new IOptionCategory[0];
+ private static final IOption[] EMPTY_OPTIONS = new IOption[0];
+
private ITarget target;
private List options;
private Map optionMap;
private List childOptionCategories;
private Map categoryMap;
-
- private static IOption[] emptyOptions = new IOption[0];
- private static IOptionCategory[] emptyCategories = new IOptionCategory[0];
+ private String command;
+ private List inputExtensions;
+ private String outputExtension;
public Tool(Target target) {
this.target = target;
}
+ /**
+ * Constructor to create a new tool in the build model based on the information
+ * defined in the plugin.xml manifest.
+ *
+ * @param target The target the receiver will belong to.
+ * @param element The element containing the information.
+ */
public Tool(Target target, IConfigurationElement element) {
this(target);
@@ -53,6 +67,25 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
// name
setName(element.getAttribute("name"));
+
+ // Get the supported input file extension
+ String inputs = element.getAttribute("sources") == null ?
+ new String() :
+ element.getAttribute("sources");
+ StringTokenizer tokenizer = new StringTokenizer(inputs, DEFAULT_SEPARATOR);
+ while (tokenizer.hasMoreElements()) {
+ getInputExtensions().add(tokenizer.nextElement());
+ }
+
+ // Get the output extension
+ outputExtension = element.getAttribute("outputs") == null ?
+ new String() :
+ element.getAttribute("outputs");
+
+ // Get the tool invocation
+ command = element.getAttribute("command") == null ?
+ new String() :
+ element.getAttribute("command");
// set up the category map
categoryMap = new HashMap();
@@ -70,10 +103,6 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
}
}
- public ITarget getTarget() {
- return target;
- }
-
public IOptionCategory getOptionCategory(String id) {
return (IOptionCategory)categoryMap.get(id);
}
@@ -82,6 +111,13 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
categoryMap.put(category.getId(), category);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITool#handlesFileType(java.lang.String)
+ */
+ public boolean buildsFileType(String extension) {
+ return getInputExtensions().contains(extension);
+ }
+
void addChildCategory(IOptionCategory category) {
if (childOptionCategories == null)
childOptionCategories = new ArrayList();
@@ -92,7 +128,7 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
if (options != null)
return (IOption[])options.toArray(new IOption[options.size()]);
else
- return emptyOptions;
+ return EMPTY_OPTIONS;
}
public void addOption(Option option) {
@@ -115,7 +151,17 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
if (childOptionCategories != null)
return (IOptionCategory[])childOptionCategories.toArray(new IOptionCategory[childOptionCategories.size()]);
else
- return emptyCategories;
+ return EMPTY_CATEGORIES;
+ }
+
+ /* (non-Javadoc)
+ * @return
+ */
+ private List getInputExtensions() {
+ if (inputExtensions == null) {
+ inputExtensions = new ArrayList();
+ }
+ return inputExtensions;
}
/* (non-Javadoc)
@@ -138,6 +184,10 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
return null;
}
+ public ITarget getTarget() {
+ return target;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOptionCategory#getTool()
*/
@@ -146,6 +196,61 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
}
/* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITool#getToolCommand()
+ */
+ public String getToolCommand() {
+ return command;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITool#getToolFlags()
+ */
+ public String getToolFlags() throws BuildException {
+ // Get all of the options
+ StringBuffer buf = new StringBuffer();
+ IOption[] opts = getOptions();
+ for (int index = 0; index < opts.length; index++) {
+ IOption option = opts[index];
+ switch (option.getValueType()) {
+ case IOption.BOOLEAN :
+ if (option.getBooleanValue()) {
+ buf.append(option.getCommand() + WHITE_SPACE);
+ }
+ break;
+
+ case IOption.ENUMERATED :
+ String enum = option.getEnumCommand(option.getSelectedEnum());
+ if (enum.length() > 0) {
+ buf.append(enum + WHITE_SPACE);
+ }
+ break;
+
+ case IOption.STRING :
+ String val = option.getStringValue();
+ if (val.length() > 0) {
+ buf.append(val + WHITE_SPACE);
+ }
+ break;
+
+ case IOption.STRING_LIST :
+ String cmd = option.getCommand();
+ String[] list = option.getStringListValue();
+ for (int j = 0; j < list.length; j++) {
+ String temp = list[j];
+ buf.append(cmd + temp + WHITE_SPACE);
+ }
+ break;
+
+ default :
+ break;
+ }
+
+ }
+
+ return buf.toString();
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOptionCategory#getOptions(org.eclipse.cdt.core.build.managed.ITool)
*/
public IOption[] getOptions(IConfiguration configuration) {
@@ -183,4 +288,25 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
return (IOption)optionMap.get(id);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITool#getOutput(java.lang.String)
+ */
+ public String getOutputExtension(String inputExtension) {
+ // Examine the list of input extensions
+ ListIterator iter = getInputExtensions().listIterator();
+ while (iter.hasNext()) {
+ if (((String)iter.next()).equals(inputExtension)) {
+ return outputExtension;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITool#producesFileType(java.lang.String)
+ */
+ public boolean producesFileType(String outputExtension) {
+ return outputExtension.equals(this.outputExtension);
+ }
+
}
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
index f1bb01997b..57bbfb4808 100644
--- 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
@@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import org.eclipse.cdt.core.build.managed.BuildException;
import org.eclipse.cdt.core.build.managed.IConfiguration;
import org.eclipse.cdt.core.build.managed.IOption;
import org.eclipse.cdt.core.build.managed.IOptionCategory;
@@ -122,6 +123,61 @@ public class ToolReference implements ITool {
}
/* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITool#getToolCommand()
+ */
+ public String getToolCommand() {
+ return parent.getToolCommand();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITool#getToolFlags()
+ */
+ public String getToolFlags() throws BuildException {
+ // Get all of the options
+ StringBuffer buf = new StringBuffer();
+ IOption[] opts = getOptions();
+ for (int index = 0; index < opts.length; index++) {
+ IOption option = opts[index];
+ switch (option.getValueType()) {
+ case IOption.BOOLEAN :
+ if (option.getBooleanValue()) {
+ buf.append(option.getCommand() + WHITE_SPACE);
+ }
+ break;
+
+ case IOption.ENUMERATED :
+ String enum = option.getEnumCommand(option.getSelectedEnum());
+ if (enum.length() > 0) {
+ buf.append(enum + WHITE_SPACE);
+ }
+ break;
+
+ case IOption.STRING :
+ String val = option.getStringValue();
+ if (val.length() > 0) {
+ buf.append(val + WHITE_SPACE);
+ }
+ break;
+
+ case IOption.STRING_LIST :
+ String cmd = option.getCommand();
+ String[] list = option.getStringListValue();
+ for (int j = 0; j < list.length; j++) {
+ String temp = list[j];
+ buf.append(cmd + temp + WHITE_SPACE);
+ }
+ break;
+
+ default :
+ break;
+ }
+
+ }
+
+ return buf.toString().trim();
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.ITool#createOption()
*/
public IOption createOption() {
@@ -160,6 +216,13 @@ public class ToolReference implements ITool {
}
/* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITool#producesFileType(java.lang.String)
+ */
+ public boolean producesFileType(String outputExtension) {
+ return parent.producesFileType(outputExtension);
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IBuildObject#getId()
*/
public String getId() {
@@ -220,6 +283,13 @@ public class ToolReference implements ITool {
}
/* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITool#handlesFileType(java.lang.String)
+ */
+ public boolean buildsFileType(String extension) {
+ return parent.buildsFileType(extension);
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.ITool#getOption(java.lang.String)
*/
public IOption getOption(String id) {
@@ -227,4 +297,12 @@ public class ToolReference implements ITool {
return null;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITool#getOutput(java.lang.String)
+ */
+ public String getOutputExtension(String inputExtension) {
+ return parent.getOutputExtension(inputExtension);
+ }
+
+
}

Back to the top