Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Fix for bugzilla 44159: Cannot change Build properties after renaming project


Hi all,
This patch is for the 1.2 stream only. It is a subset of a larger patch I am waiting to release for the 2.0 stream. I had not intended to submit this to the 1.2 stream, but the patch actually solves 44163 and 51379. The fix is actually quite minor and poses no risk to other Managed Build features. I have regression tested it against the 1.2 head on Linux and Win32. The patch to the core and an updated JUnit test are included below. I leave it to the committers to decide if this is an appropriate 1.2 patch at this time.

Sean Evoy
Rational Software - IBM Software Group
Ottawa, Ontario, Canada

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.core/ChangeLog,v
retrieving revision 1.13.2.2
diff -u -r1.13.2.2 ChangeLog
--- ChangeLog	27 Oct 2003 20:45:01 -0000	1.13.2.2
+++ ChangeLog	13 Feb 2004 19:09:16 -0000
@@ -1,3 +1,17 @@
+2004-02-13 Sean Evoy
+	Fix for critical bug 44163.
+	The managed build info would become confused when the project it was associated
+	with was renamed. The project still stored the build information in its session 
+	data, but the internal reference to the owner project was not updated in the 
+	build info. Now, when the build info is retrieved from a project, the manager 
+	asks the info to do a sanity test to check the identity of the true owner against 
+	the owner the it thinks it has. If they differ, the build information updates its 
+	owner and the owner of all the targets it maintains for the project.
+	* src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java	
+	* src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java
+	* src/org/eclipse/cdt/managedbuilder/core/ITarget.java
+	* src/org/eclipse/cdt/managedbuilder/internal/core/Target.java
+
 2003-10-23 Bogdan Gheorghe
 	Updated the indexManager.perfomConcurrentJob call in MakefileGenerator
 	
Index: src/org/eclipse/cdt/managedbuilder/core/ITarget.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITarget.java,v
retrieving revision 1.4
diff -u -r1.4 ITarget.java
--- src/org/eclipse/cdt/managedbuilder/core/ITarget.java	26 Sep 2003 00:20:13 -0000	1.4
+++ src/org/eclipse/cdt/managedbuilder/core/ITarget.java	13 Feb 2004 19:09:16 -0000
@@ -182,4 +182,13 @@
 	 */
 	public void setMakeCommand(String command);
 
+	/**
+	 * Compares the identity of the argument with the resource that the receiver 
+	 * <i>thinks</i> is its owner. If they do not match, the owner is updated to 
+	 * the argument.
+	 * 
+	 * @param resource
+	 */
+	public void updateOwner(IResource resource);
+
 }
Index: src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java,v
retrieving revision 1.2
diff -u -r1.2 ManagedBuildManager.java
--- src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java	16 Sep 2003 21:27:58 -0000	1.2
+++ src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java	13 Feb 2004 19:09:16 -0000
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2003 IBM Corporation and others.
+ * Copyright (c) 2003, 2004 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
@@ -459,6 +459,9 @@
 		ManagedBuildInfo buildInfo = null;
 		try {
 			buildInfo = (ManagedBuildInfo)resource.getSessionProperty(buildInfoProperty);
+			if (buildInfo != null) {
+				buildInfo.updateOwner(resource);
+			}
 		} catch (CoreException e) {
 			return buildInfo;
 		}
Index: src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java,v
retrieving revision 1.7
diff -u -r1.7 ManagedBuildInfo.java
--- src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java	1 Oct 2003 23:56:36 -0000	1.7
+++ src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java	13 Feb 2004 19:09:17 -0000
@@ -867,4 +867,23 @@
 		this.isDirty = isDirty;
 	}
 
+	/**
+	 * Compares the identity of the argument with the project the receiver
+	 * <i>thinks</i> its owner should be. If it is different, the owner is
+	 * updated to the argument, and each target associated with the project is
+	 * asked to do the same.
+	 * 
+	 * @param resource
+	 */
+	public void updateOwner(IResource resource) {
+		if (resource != null && !owner.equals(resource)) {
+			owner = resource;
+			Iterator iter = targets.listIterator();
+			while (iter.hasNext()) {
+				ITarget target = (ITarget) iter.next();
+				target.updateOwner(resource);
+			}
+		}
+	}
+
 }
Index: src/org/eclipse/cdt/managedbuilder/internal/core/Target.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Target.java,v
retrieving revision 1.5
diff -u -r1.5 Target.java
--- src/org/eclipse/cdt/managedbuilder/internal/core/Target.java	1 Oct 2003 23:56:36 -0000	1.5
+++ src/org/eclipse/cdt/managedbuilder/internal/core/Target.java	13 Feb 2004 19:09:17 -0000
@@ -523,4 +523,13 @@
 		}
 	}
 
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.managedbuilder.core.ITarget#updateOwner(org.eclipse.core.resources.IResource)
+	 */
+	public void updateOwner(IResource resource) {
+		if (resource != null && !owner.equals(resource)) {
+			owner = resource;
+		}
+	}
+
 }
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.131.2.7
diff -u -r1.131.2.7 ChangeLog
--- ChangeLog	30 Jan 2004 16:13:25 -0000	1.131.2.7
+++ ChangeLog	13 Feb 2004 19:08:45 -0000
@@ -1,3 +1,9 @@
+Sean Evoy 2004-02-13
+	Fix for critical bug 44163.
+	Added test to make sure the build information for a project is sane 
+	after the project is renamed.
+	* build/org/eclipse/cdt/core/build/managed/tests/ManagedBuildTests.java
+
 2004-01-29 John Camelon
 	Added ScannerTestCase::testBug50821().  
 
Index: build/org/eclipse/cdt/core/build/managed/tests/ManagedBuildTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/build/org/eclipse/cdt/core/build/managed/tests/ManagedBuildTests.java,v
retrieving revision 1.14
diff -u -r1.14 ManagedBuildTests.java
--- build/org/eclipse/cdt/core/build/managed/tests/ManagedBuildTests.java	1 Oct 2003 23:56:13 -0000	1.14
+++ build/org/eclipse/cdt/core/build/managed/tests/ManagedBuildTests.java	13 Feb 2004 19:08:45 -0000
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2003 IBM Corporation and others.
+ * Copyright (c) 2003, 2004 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
@@ -65,6 +65,7 @@
 	private static final String enumVal = "Another Enum";
 	private static final String[] listVal = {"_DEBUG", "/usr/include", "libglade.a"};
 	private static final String projectName = "ManagedBuildTest";
+	private static final String projectRename = "ManagedBuildRedux";
 	private static final String rootExt = "toor";
 	private static final String stringVal = "-c -Wall";
 	private static final String subExt = "bus";
@@ -84,6 +85,7 @@
 		suite.addTest(new ManagedBuildTests("testMakeCommandManipulation"));
 		suite.addTest(new ManagedBuildTests("testScannerInfoInterface"));
 		suite.addTest(new ManagedBuildTests("testBug43450"));
+		suite.addTest(new ManagedBuildTests("testProjectRename"));
 		suite.addTest(new ManagedBuildTests("cleanup"));
 		
 		return suite;
@@ -477,6 +479,119 @@
 		ManagedBuildManager.removeBuildInfo(project);
 	}
 	
+	/**
+	 * Tests that bugzilla 44163 has been addressed. After a project was renamed, the 
+	 * build information mistakenly referred to the old project as its owner. This
+	 * caused a number of searches on the information to fail. In this bug, it was the 
+	 * list of tools that could not be determined. In other cases, the information 
+	 * retrieval caused NPEs because the old owner no longer existed.
+	 */
+	public void testProjectRename() {
+		// Open the test project
+		IProject project = null;
+		try {
+			project = createProject(projectName);
+		} catch (CoreException e) {
+			fail("Failed to open project: " + e.getLocalizedMessage());
+		}
+		
+		// Rename the project
+		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();	
+		IResource newResource = workspaceRoot.findMember(projectRename);
+		if (newResource != null) {
+			try {
+				newResource.delete(IResource.KEEP_HISTORY, new NullProgressMonitor());
+			} catch (CoreException e) {
+				fail("Failed to delete old project " + projectRename + ": " + e.getLocalizedMessage());
+			}		
+		}
+		IProjectDescription description = null;
+		try {
+			description = project.getDescription();
+		} catch (CoreException e) {
+			fail("Failed to find project descriptor for " + projectName + ": " + e.getLocalizedMessage());
+		}
+		description.setName(projectRename);
+		try {
+			project.move(description, IResource.FORCE | IResource.SHALLOW, new NullProgressMonitor());
+		} catch (CoreException e) {
+			fail("Failed to rename project: " + e.getLocalizedMessage());
+		}
+		try {
+			project = createProject(projectRename);
+		} catch (CoreException e) {
+			fail("Failed to open renamed project: " + e.getLocalizedMessage());
+		}
+
+		// By now there should be 2 targets with 3 configs
+		ITarget[] definedTargets = ManagedBuildManager.getTargets(project);
+		assertEquals(2, definedTargets.length);
+		ITarget rootTarget = definedTargets[0];
+		IConfiguration[] definedConfigs = rootTarget.getConfigurations(); 		
+		assertEquals(3, definedConfigs.length);
+		IConfiguration baseConfig = definedConfigs[0];
+		
+		// There is only one tool
+		ITool[] definedTools = baseConfig.getTools();
+		assertEquals(1, definedTools.length);
+		ITool rootTool = definedTools[0];
+		
+		// Get the options 2 in top category and 2 in its child
+		IOptionCategory topCategory = rootTool.getTopOptionCategory();
+		assertEquals("Root Tool", topCategory.getName());
+		IOption[] options = topCategory.getOptions(null);
+		assertEquals(2, options.length);
+		IOptionCategory[] categories = topCategory.getChildCategories();
+		assertEquals(1, categories.length);
+		options = categories[0].getOptions(null);
+		assertEquals(2, options.length);
+		
+		// Set the name back
+		newResource = workspaceRoot.findMember(projectName);
+		if (newResource != null) {
+			try {
+				newResource.delete(IResource.KEEP_HISTORY, new NullProgressMonitor());
+			} catch (CoreException e) {
+				fail("Failed to delete old project " + projectName + ": " + e.getLocalizedMessage());
+			}		
+		}
+		try {
+			description = project.getDescription();
+		} catch (CoreException e) {
+			fail("Failed to find project descriptor for " + projectRename + ": " + e.getLocalizedMessage());
+		}
+		description.setName(projectName);
+		try {
+			project.move(description, IResource.FORCE | IResource.SHALLOW, new NullProgressMonitor());
+		} catch (CoreException e) {
+			fail("Failed to re-rename project: " + e.getLocalizedMessage());
+		}
+		try {
+			project = createProject(projectName);
+		} catch (CoreException e) {
+			fail("Failed to open re-renamed project: " + e.getLocalizedMessage());
+		}
+
+		// Do it all again
+		definedTargets = ManagedBuildManager.getTargets(project);
+		assertEquals(2, definedTargets.length);
+		rootTarget = definedTargets[0];
+		definedConfigs = rootTarget.getConfigurations(); 		
+		assertEquals(3, definedConfigs.length);
+		baseConfig = definedConfigs[0];
+		definedTools = baseConfig.getTools();
+		assertEquals(1, definedTools.length);
+		rootTool = definedTools[0];
+		topCategory = rootTool.getTopOptionCategory();
+		assertEquals("Root Tool", topCategory.getName());
+		options = topCategory.getOptions(null);
+		assertEquals(2, options.length);
+		categories = topCategory.getChildCategories();
+		assertEquals(1, categories.length);
+		options = categories[0].getOptions(null);
+		assertEquals(2, options.length);
+	}
+	
 	private void addManagedBuildNature (IProject project) {
 		// Add the managed build nature
 		try {
@@ -908,7 +1023,7 @@
 		
 		return project;	
 	}
-	
+		
 	/**
 	 * Remove the <code>IProject</code> with the name specified in the argument from the 
 	 * receiver's workspace.

Back to the top