Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Applied Patch: New build model enhancements

Still working on bringing sanity to the new build model.

 

BTW, this stuff isn't hooked in anywhere, at least not yet...

 

Doug Schaefer

Rational Software - IBM Software Group

Ottawa (Kanata), Ontario, Canada

 

Index: build/org/eclipse/cdt/core/build/managed/BuildException.java
===================================================================
RCS file: build/org/eclipse/cdt/core/build/managed/BuildException.java
diff -N build/org/eclipse/cdt/core/build/managed/BuildException.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ build/org/eclipse/cdt/core/build/managed/BuildException.java	9 Apr 2003 15:11:37 -0000
@@ -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);
+	}
+
+}
Index: build/org/eclipse/cdt/core/build/managed/IConfiguration.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IConfiguration.java,v
retrieving revision 1.2
diff -u -r1.2 IConfiguration.java
--- build/org/eclipse/cdt/core/build/managed/IConfiguration.java	7 Apr 2003 20:56:27 -0000	1.2
+++ build/org/eclipse/cdt/core/build/managed/IConfiguration.java	9 Apr 2003 15:11:37 -0000
@@ -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 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
Index: build/org/eclipse/cdt/core/build/managed/IOptionCategory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/IOptionCategory.java,v
retrieving revision 1.1
diff -u -r1.1 IOptionCategory.java
--- build/org/eclipse/cdt/core/build/managed/IOptionCategory.java	7 Apr 2003 02:47:01 -0000	1.1
+++ build/org/eclipse/cdt/core/build/managed/IOptionCategory.java	9 Apr 2003 15:11:37 -0000
@@ -16,6 +16,13 @@
 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 IOptionCategory[] getChildCategories();
 	
+	public IOptionCategory getOwner();
+	
+	public ITool getTool();
 }
Index: build/org/eclipse/cdt/core/build/managed/ITarget.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ITarget.java,v
retrieving revision 1.2
diff -u -r1.2 ITarget.java
--- build/org/eclipse/cdt/core/build/managed/ITarget.java	7 Apr 2003 20:56:27 -0000	1.2
+++ build/org/eclipse/cdt/core/build/managed/ITarget.java	9 Apr 2003 15:11:37 -0000
@@ -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 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 @@
 	 * 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;
 
 }
Index: build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java,v
retrieving revision 1.2
diff -u -r1.2 ManagedBuildManager.java
--- build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java	7 Apr 2003 20:56:27 -0000	1.2
+++ build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java	9 Apr 2003 15:11:37 -0000
@@ -17,7 +17,6 @@
 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 @@
  */
 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();
+		
+		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");
+			}
+		}
 		
-		Configuration config = new Configuration(project, parentConfig);
-		addResourceConfig(project, config);
-		return config;
+		Target newTarget = new Target(resource, parentTarget);
+		targets.add(newTarget);
+		return newTarget;
 	}
-
+	
 	// Private stuff
 	
 	private static List extensionTargets;
@@ -129,59 +157,29 @@
 			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
 	}
-
 }
Index: build/org/eclipse/cdt/internal/core/build/managed/Configuration.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Configuration.java,v
retrieving revision 1.2
diff -u -r1.2 Configuration.java
--- build/org/eclipse/cdt/internal/core/build/managed/Configuration.java	7 Apr 2003 20:56:27 -0000	1.2
+++ build/org/eclipse/cdt/internal/core/build/managed/Configuration.java	9 Apr 2003 15:11:37 -0000
@@ -15,7 +15,7 @@
 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 @@
 
 	private String name;
 	private ITarget target;
-	private IProject project;
 	private IConfiguration parent;
 	private List toolReference;
 	
@@ -32,13 +31,7 @@
 		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 @@
 	}
 
 	/* (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();
 	}
 
 }
Index: build/org/eclipse/cdt/internal/core/build/managed/Target.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/build/org/eclipse/cdt/internal/core/build/managed/Target.java,v
retrieving revision 1.2
diff -u -r1.2 Target.java
--- build/org/eclipse/cdt/internal/core/build/managed/Target.java	7 Apr 2003 20:56:27 -0000	1.2
+++ build/org/eclipse/cdt/internal/core/build/managed/Target.java	9 Apr 2003 15:11:37 -0000
@@ -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 @@
 public class Target implements ITarget {
 
 	private String name;
-	private Target parent;
-	private ITool[] tools;
-	private IConfiguration[] configurations;
-
-	public Target(String name) {
-		this.name = name;
-	}
-	
-	public Target(String name, Target parent) {
-		this(name);
+	private ITarget parent;
+	private IResource owner;
+	private List tools;
+	private List configurations;
+
+	public Target(IResource owner) {
+		this.owner = owner;
+	}
+	
+	/**
+	 * 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 @@
 		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 @@
 		return toolArray;
 	}
 
-	public void setTools(ITool[] tools) {
-		this.tools = tools;
-	}
-	
-	public void setConfigurations(IConfiguration [] configurations) {
-		this.configurations = configurations;
-	}
-	
-	public IConfiguration[] getAvailableConfigurations(IProject project) {
-		// TODO Auto-generated method stub
+	public void addTool(ITool tool){
+		if (tools == null)
+			tools = new ArrayList();
+		tools.add(tool);
+	}
+	
+	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);
+	}
+	
+	/* (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;
 	}
 
 }
Index: plugin.xml
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/plugin.xml,v
retrieving revision 1.5
diff -u -r1.5 plugin.xml
--- plugin.xml	7 Apr 2003 20:56:24 -0000	1.5
+++ plugin.xml	9 Apr 2003 15:12:02 -0000
@@ -91,6 +91,10 @@
                id="org.eclipse.cdt.ui.tests.tool.linux.ar">
          </tool>
       </target>
+      <target
+            name="Test Root"
+            id="test.root">
+      </target>
    </extension>
 
 </plugin>
Index: build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java,v
retrieving revision 1.2
diff -u -r1.2 AllBuildTests.java
--- build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java	7 Apr 2003 20:56:24 -0000	1.2
+++ build/org/eclipse/cdt/core/build/managed/tests/AllBuildTests.java	9 Apr 2003 15:12:02 -0000
@@ -15,7 +15,6 @@
 import junit.framework.TestSuite;
 
 import org.eclipse.cdt.core.build.managed.ITarget;
-import org.eclipse.cdt.core.build.managed.ITool;
 import org.eclipse.cdt.core.build.managed.ManagedBuildManager;
 
 /**
@@ -44,13 +43,19 @@
 	 * defined in this plugin
 	 */
 	public void testExtensions() {
+		boolean testRootFound = false;
+		
 		// Note secret null parameter which means just extensions
-		ITarget[] targets = ManagedBuildManager.getTargets(null);
+		ITarget[] targets = ManagedBuildManager.getDefinedTargets(null);
 
-		ITarget target = targets[0];
-		assertEquals(target.getName(), "Linux");
-		ITool[] tools = target.getTools();
-		ITool tool = tools[0];
-		assertEquals(tool.getName(), "Compiler");
+		for (int i = 0; i < targets.length; ++i) {
+			ITarget target = targets[i];
+			
+			if (target.getName().equals("Test Root")) {
+				testRootFound = true;
+			}
+		}
+		
+		assertTrue(testRootFound);
 	}
 }

Back to the top