Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2003-04-09 11:14:56 -0400
committerDoug Schaefer2003-04-09 11:14:56 -0400
commit9e35ee6963b0f865483894c97ca74f10095277cf (patch)
treebcec0421372ed0c68ef936d47bd9f8aeb3a516ea /core/org.eclipse.cdt.core/build
parentef5944b36b683e2216312067484cc5f92526c3bc (diff)
downloadorg.eclipse.cdt-9e35ee6963b0f865483894c97ca74f10095277cf.tar.gz
org.eclipse.cdt-9e35ee6963b0f865483894c97ca74f10095277cf.tar.xz
org.eclipse.cdt-9e35ee6963b0f865483894c97ca74f10095277cf.zip
A little more sanity to the new build model.
Diffstat (limited to 'core/org.eclipse.cdt.core/build')
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/BuildException.java21
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IConfiguration.java7
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOptionCategory.java10
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java29
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java170
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Configuration.java17
-rw-r--r--core/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java100
7 files changed, 230 insertions, 124 deletions
diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/BuildException.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/BuildException.java
new file mode 100644
index 0000000000..4ba6c708d7
--- /dev/null
+++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/BuildException.java
@@ -0,0 +1,21 @@
+/*
+ * Created on Apr 9, 2003
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package org.eclipse.cdt.core.build.managed;
+
+/**
+ * @author dschaefe
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class BuildException extends Exception {
+
+ public BuildException(String msg) {
+ super(msg);
+ }
+
+}
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 baf60b7327..9fef24e56b 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,7 +10,7 @@
**********************************************************************/
package org.eclipse.cdt.core.build.managed;
-import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
/**
*
@@ -31,11 +31,10 @@ public interface IConfiguration {
public ITarget getTarget();
/**
- * Returns the project owning this configuration
- * or null if this configuration is not associated with a project.
+ * Returns the resource that owns the target that owns the configuration.
* @return
*/
- public IProject getProject();
+ public IResource getOwner();
/**
* Returns the configuration from which this configuration inherits
diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOptionCategory.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOptionCategory.java
index 99f429c17b..8d66327e80 100644
--- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOptionCategory.java
+++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOptionCategory.java
@@ -16,6 +16,13 @@ package org.eclipse.cdt.core.build.managed;
public interface IOptionCategory {
/**
+ * Returns the name of the option category.
+ *
+ * @return
+ */
+ public String getName();
+
+ /**
* Returns the options that have been assigned to this category.
*
* @return
@@ -29,4 +36,7 @@ public interface IOptionCategory {
*/
public IOptionCategory[] getChildCategories();
+ public IOptionCategory getOwner();
+
+ public ITool getTool();
}
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 ab668de468..eb4f682ac5 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,7 +10,7 @@
**********************************************************************/
package org.eclipse.cdt.core.build.managed;
-import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
/**
* This class represents targets for the managed build process. A target
@@ -33,6 +33,13 @@ public interface ITarget {
public ITarget getParent();
/**
+ * Gets the resource that this target is applied to.
+ *
+ * @return
+ */
+ public IResource getOwner();
+
+ /**
* Returns the list of platform specific tools associated with this
* platform.
*
@@ -44,6 +51,24 @@ public interface ITarget {
* Returns all of the configurations defined by this target.
* @return
*/
- public IConfiguration[] getAvailableConfigurations(IProject project);
+ public IConfiguration[] getConfigurations();
+
+ /**
+ * Creates a new configuration for the given resource.
+ *
+ * @param resource
+ * @return
+ */
+ public IConfiguration addConfiguration(IResource resource)
+ throws BuildException;
+
+ /**
+ * Creates a new configuration for the given resource based on the parent config
+ * @param resource
+ * @param parentConfig
+ * @return
+ */
+ public IConfiguration addConfiguration(IResource resource, IConfiguration parentConfig)
+ throws BuildException;
}
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 d592821803..ec0c2fae02 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
@@ -17,7 +17,6 @@ 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;
@@ -32,84 +31,113 @@ import org.eclipse.core.runtime.QualifiedName;
*/
public class ManagedBuildManager {
- private static final QualifiedName configProperty
- = new QualifiedName(CCorePlugin.PLUGIN_ID, "config");
-
+ private static final QualifiedName ownedTargetsProperty
+ = new QualifiedName(CCorePlugin.PLUGIN_ID, "ownedTargets");
+ private static final QualifiedName definedTargetsProperty
+ = new QualifiedName(CCorePlugin.PLUGIN_ID, "definedTargets");
+
+ private static final ITarget[] emptyTargets = new ITarget[0];
+
/**
- * 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.
+ * Returns the list of targets that are defined by this project,
+ * projects referenced by this project, and by the extensions.
*
* @param project
* @return
*/
- public static ITarget[] getTargets(IProject project) {
+ public static ITarget[] getDefinedTargets(IProject project) {
// Make sure the extensions are loaded
loadExtensions();
// Get the targets for this project and all referenced projects
-
+ List definedTargets = null;
+
+ if (project != null) {
+ try {
+ definedTargets = (List)project.getSessionProperty(definedTargetsProperty);
+ } catch (CoreException e) {
+ }
+ }
+
// Create the array and copy the elements over
- ITarget[] targets = new ITarget[extensionTargets.size()];
+ int size = extensionTargets.size()
+ + (definedTargets != null ? definedTargets.size() : 0);
+
+ ITarget[] targets = new ITarget[size];
+ int n = 0;
for (int i = 0; i < extensionTargets.size(); ++i)
- targets[i] = (ITarget)extensionTargets.get(i);
-
+ targets[n++] = (ITarget)extensionTargets.get(i);
+
+ if (definedTargets != null)
+ for (int i = 0; i < definedTargets.size(); ++i)
+ targets[n++] = (ITarget)definedTargets.get(i);
+
return targets;
}
/**
- * Returns the list of configurations associated with the given project.
+ * Returns the targets owned by this project. If none are owned,
+ * an empty array is returned.
*
* @param project
* @return
*/
- public static IConfiguration[] getConfigurations(IProject project) {
- return getResourceConfigs(project);
- }
-
- /**
- * Returns the list of configurations associated with a given file.
- *
- * @param file
- * @return
- */
- public static IConfiguration[] getConfigurations(IFile file) {
- // TODO not ready for prime time...
- return getResourceConfigs(file);
- }
-
- /**
- * Adds a configuration containing the tools defined by the target to
- * the given project.
- *
- * @param target
- * @param project
- * @return
- */
- public static IConfiguration addConfiguration(IProject project, ITarget target) {
- Configuration config = new Configuration(project, target);
- return null;
+ public static ITarget[] getTargets(IResource resource) {
+ List targets = getOwnedTargetsProperty(resource);
+
+ if (targets != null) {
+ return (ITarget[])targets.toArray(new ITarget[targets.size()]);
+ } else {
+ return emptyTargets;
+ }
}
/**
- * Adds a configuration inheriting from the given configuration.
+ * Adds a new target to the resource based on the parentTarget.
*
- * @param origConfig
* @param resource
+ * @param parentTarget
* @return
+ * @throws BuildException
*/
- public static IConfiguration addConfiguration(IProject project, IConfiguration parentConfig) {
- if (parentConfig.getProject() != null)
- // Can only inherit from target configs
- return null;
+ public static ITarget addTarget(IResource resource, ITarget parentTarget)
+ throws BuildException
+ {
+ IResource owner = parentTarget.getOwner();
- Configuration config = new Configuration(project, parentConfig);
- addResourceConfig(project, config);
- return config;
+ if (owner != null && owner.equals(resource))
+ // Already added
+ return parentTarget;
+
+ if (resource instanceof IProject) {
+ // Owner must be null
+ if (owner != null)
+ throw new BuildException("addTarget: owner not null");
+ } else {
+ // Owner must be owned by the project containing this resource
+ if (owner == null)
+ throw new BuildException("addTarget: null owner");
+ if (!owner.equals(resource.getProject()))
+ throw new BuildException("addTarget: owner not project");
+ }
+
+ // Passed validation
+ List targets = getOwnedTargetsProperty(resource);
+ 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;
}
-
+
// Private stuff
private static List extensionTargets;
@@ -129,59 +157,29 @@ public class ManagedBuildManager {
for (int j = 0; j < elements.length; ++j) {
IConfigurationElement element = elements[j];
if (element.getName().equals("target")) {
- Target target = new Target(element.getAttribute("name"));
+ Target target = new Target(null);
+ target.setName(element.getAttribute("name"));
extensionTargets.add(target);
- List configs = null;
IConfigurationElement[] targetElements = element.getChildren();
for (int k = 0; k < targetElements.length; ++k) {
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));
+ target.addConfiguration(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;
-
+ private static List getOwnedTargetsProperty(IResource resource) {
try {
- resource.setSessionProperty(configProperty, newConfigs);
+ return (List)resource.getSessionProperty(ownedTargetsProperty);
} catch (CoreException e) {
+ return null;
}
-
- // 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 42bfe0313c..5835b12b69 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
@@ -15,7 +15,7 @@ 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;
+import org.eclipse.core.resources.IResource;
/**
*
@@ -24,7 +24,6 @@ public class Configuration implements IConfiguration {
private String name;
private ITarget target;
- private IProject project;
private IConfiguration parent;
private List toolReference;
@@ -32,13 +31,7 @@ public class Configuration implements IConfiguration {
this.target = target;
}
- public Configuration(IProject project, ITarget target) {
- this.project = project;
- this.target = target;
- }
-
- public Configuration(IProject project, IConfiguration parent) {
- this.project = project;
+ public Configuration(IConfiguration parent) {
this.parent = parent;
}
@@ -79,10 +72,10 @@ public class Configuration implements IConfiguration {
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.core.build.managed.IConfiguration#getProject()
+ * @see org.eclipse.cdt.core.build.managed.IConfiguration#getOwner()
*/
- public IProject getProject() {
- return (project == null && parent != null) ? parent.getProject() : project;
+ public IResource getOwner() {
+ return getTarget().getOwner();
}
}
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 e54de59d0e..300fade816 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,10 +10,16 @@
**********************************************************************/
package org.eclipse.cdt.internal.core.build.managed;
+import java.util.ArrayList;
+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.ITarget;
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.IResource;
/**
*
@@ -21,21 +27,34 @@ import org.eclipse.core.resources.IProject;
public class Target implements ITarget {
private String name;
- private Target parent;
- private ITool[] tools;
- private IConfiguration[] configurations;
+ private ITarget parent;
+ private IResource owner;
+ private List tools;
+ private List configurations;
- public Target(String name) {
- this.name = name;
+ public Target(IResource owner) {
+ this.owner = owner;
}
- public Target(String name, Target parent) {
- this(name);
+ /**
+ * Resource is allowed to be null to represent a ISV target def.
+ *
+ * @param parent
+ */
+ public Target(IResource owner, ITarget parent) {
+ this.owner = owner;
this.parent = parent;
+
+ // Inherit the configs from the parent
+ IConfiguration[] parentConfigs = parent.getConfigurations();
+ if (parentConfigs.length > 0)
+ configurations = new ArrayList(parentConfigs.length);
+ for (int i = 0; i < parentConfigs.length; ++i)
+ configurations.add(new Configuration(parentConfigs[i]));
}
-
+
public String getName() {
- return name;
+ return (name == null && parent != null) ? parent.getName() : name;
}
public ITarget getParent() {
@@ -46,21 +65,25 @@ public class Target implements ITarget {
this.name = name;
}
+ public IResource getOwner() {
+ return owner;
+ }
+
private int getNumTools() {
- int n = (tools == null) ? 0 : tools.length;
+ int n = (tools == null) ? 0 : tools.size();
if (parent != null)
- n += parent.getNumTools();
+ n += ((Target)parent).getNumTools();
return n;
}
private int addToolsToArray(ITool[] toolArray, int start) {
int n = start;
if (parent != null)
- n = parent.addToolsToArray(toolArray, start);
+ n = ((Target)parent).addToolsToArray(toolArray, start);
if (tools != null) {
- for (int i = 0; i < tools.length; ++i)
- toolArray[n++] = (ITool)tools[i];
+ for (int i = 0; i < tools.size(); ++i)
+ toolArray[n++] = (ITool)tools.get(i);
}
return n;
@@ -72,17 +95,54 @@ public class Target implements ITarget {
return toolArray;
}
- public void setTools(ITool[] tools) {
- this.tools = tools;
+ public void addTool(ITool tool){
+ if (tools == null)
+ tools = new ArrayList();
+ tools.add(tool);
}
- public void setConfigurations(IConfiguration [] configurations) {
- this.configurations = configurations;
+ public IConfiguration[] getConfigurations() {
+ return (IConfiguration[])configurations.toArray(new IConfiguration[configurations.size()]);
+ }
+
+ public void addConfiguration(IConfiguration configuration) {
+ if (configurations == null)
+ configurations = new ArrayList();
+ configurations.add(configuration);
}
- public IConfiguration[] getAvailableConfigurations(IProject project) {
- // TODO Auto-generated method stub
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITarget#addConfiguration(org.eclipse.core.resources.IResource)
+ */
+ public IConfiguration addConfiguration(IResource resource)
+ throws BuildException
+ {
+ Target target = (Target)ManagedBuildManager.addTarget(resource, this);
+ IConfiguration config = new Configuration(target);
+ target.addConfiguration(config);
return null;
}
+ public IConfiguration addConfiguration(IResource resource, IConfiguration parentConfig)
+ throws BuildException
+ {
+ IResource parentOwner = parentConfig.getOwner();
+
+ if (resource instanceof IProject) {
+ // parent must be owned by the same project
+ if (!resource.equals(parentOwner))
+ throw new BuildException("addConfiguration: parent must be in same project");
+ } else {
+ // parent must be owned by the project
+ if (!resource.getProject().equals(parentOwner))
+ throw new BuildException("addConfiguration: parent must be in owning project");
+ }
+
+ // Validation passed
+ Target target = (Target)ManagedBuildManager.addTarget(resource, this);
+ IConfiguration config = new Configuration(parentConfig);
+ target.addConfiguration(config);
+ return config;
+ }
+
}

Back to the top