Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] patch and JUnit tests for bugzilla report #104515

Hi,

 

Here is the patch for bugzilla report #104515. I also a couple of Junit tests. As I can’t create a patch with .zip files, I am attaching .zip files separately. Please copy the zip files in the following way.

 

i)                Create the directory “org.eclipse.cdt.managedbuilder.core.tests/resources/toolChainConversionProjects/test20” and copy the test20.zip file into the directory.

ii)                   Create the directory “org.eclipse.cdt.managedbuilder.core.tests/resources/toolChainConversionProjects/test21” and copy the test21.zip file into the directory.

 

 

Thanks & Regards,

Sunil

 

 

 

Index: tests/org/eclipse/cdt/managedbuilder/core/tests/MultiVersionSupportTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/MultiVersionSupportTests.java,v
retrieving revision 1.1
diff -u -r1.1 MultiVersionSupportTests.java
--- tests/org/eclipse/cdt/managedbuilder/core/tests/MultiVersionSupportTests.java	9 Sep 2005 14:24:38 -0000	1.1
+++ tests/org/eclipse/cdt/managedbuilder/core/tests/MultiVersionSupportTests.java	14 Sep 2005 17:41:19 -0000
@@ -12,6 +12,14 @@
 package org.eclipse.cdt.managedbuilder.core.tests;
 
 
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Map;
 
 import junit.framework.Test;
@@ -31,16 +39,24 @@
 import org.eclipse.cdt.managedbuilder.core.IToolChain;
 import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
 import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature;
+import org.eclipse.cdt.managedbuilder.projectconverter.UpdateManagedProjectManager;
+import org.eclipse.cdt.managedbuilder.testplugin.CTestPlugin;
+import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
 
 import org.eclipse.core.resources.IProject;
 
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProjectDescription;
 import org.eclipse.core.resources.IWorkspace;
 import org.eclipse.core.resources.IWorkspaceDescription;
 import org.eclipse.core.resources.IWorkspaceRoot;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
 
 import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.ui.dialogs.IOverwriteQuery;
 
 
 public class MultiVersionSupportTests extends TestCase {
@@ -62,6 +78,8 @@
 		suite.addTest(new MultiVersionSupportTests("testConfigurationDescription"));	//$NON-NLS-1$
 		suite.addTest(new MultiVersionSupportTests("testVersionInfo"));	//$NON-NLS-1$
 		suite.addTest(new MultiVersionSupportTests("testVersionsSupportedAttribute"));	//$NON-NLS-1$
+		suite.addTest(new MultiVersionSupportTests("testToolChainConversion_CDT20")); //$NON-NLS-1$
+		suite.addTest(new MultiVersionSupportTests("testToolChainConversion_CDT21")); //$NON-NLS-1$
 
 		//$JUnit-END$
 		return suite;
@@ -374,4 +392,164 @@
 		cfgs = mproj.getConfigurations();
 		assertNotNull(cfgs);		
 	}
+	
+	public void testToolChainConversion_CDT20() throws Exception {
+		// Pass CDT version as '2.0', and 'true' to update Project
+		doTestProjectUpdate("2.0", true);	//$NON-NLS-1$
+		
+		String tmpDir = System.getProperty("java.io.tmpdir");	//$NON-NLS-1$	
+		
+		File inputFile = new File(tmpDir + "/converterOutput20.txt");	//$NON-NLS-1$
+		try {
+			assertTrue(inputFile.exists());
+			
+			String expectedContent = "Converter for CDT 2.0 Project is invoked";	//$NON-NLS-1$
+			
+			BufferedReader data = new BufferedReader(new FileReader(inputFile));
+			String actualContent;
+			
+			if ((actualContent = data.readLine()) != null) {
+				assertEquals(actualContent,expectedContent);
+			}			
+			
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();			
+		}
+	}
+	
+	public void testToolChainConversion_CDT21() throws Exception {
+		// Pass CDT version as '2.1', and 'true' to update Project
+		doTestProjectUpdate("2.1", true);	//$NON-NLS-1$
+		
+		String tmpDir = System.getProperty("java.io.tmpdir");	//$NON-NLS-1$	
+		
+		File inputFile = new File(tmpDir + "/converterOutput21.txt");	//$NON-NLS-1$
+		try {
+			assertTrue(inputFile.exists());
+			
+			String expectedContent = "Converter for CDT 2.1 Project is invoked";	//$NON-NLS-1$
+			
+			BufferedReader data = new BufferedReader(new FileReader(inputFile));
+			String actualContent;
+			
+			if ((actualContent = data.readLine()) != null) {
+				assertEquals(actualContent,expectedContent);
+			}			
+			
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();			
+		}
+	}
+	
+	
+	
+	private IProject getCDT_TestProject(String cdtVersion) {
+
+		IProject project = null;
+		File file = null;
+		
+		if (cdtVersion.equalsIgnoreCase("2.0")) {	//$NON-NLS-1$
+			file = CTestPlugin.getFileInPlugin(new Path(
+					"resources/toolChainConversionProjects/test20"));	//$NON-NLS-1$
+		} else if (cdtVersion.equals("2.1")) {	//$NON-NLS-1$
+			file = CTestPlugin.getFileInPlugin(new Path(
+			"resources/toolChainConversionProjects/test21"));	//$NON-NLS-1$
+		}
+
+		if (file == null) {
+			fail("Test project directory " + file.getName()	//$NON-NLS-1$
+					+ " is missing.");	//$NON-NLS-1$
+			return null;
+		}
+
+		File projectZips[] = file.listFiles(new FileFilter() {
+			public boolean accept(File pathname) {
+				if (pathname.isDirectory())
+					return false;
+				return true;
+			}
+		});
+
+		ArrayList projectList = new ArrayList(projectZips.length);
+		assertEquals(projectZips.length, 1);
+
+		try {
+			String projectName = projectZips[0].getName();
+			if (!projectName.endsWith(".zip"))
+				fail("No projects found in test 'toolChainConversionProjects' project directory "	//$NON-NLS-1$
+						+ file.getName()
+						+ ".  The .zip file may be missing or corrupt.");	//$NON-NLS-1$
+
+			projectName = projectName.substring(0, projectName.length()
+					- ".zip".length());	//$NON-NLS-1$
+			if (projectName.length() == 0)
+				fail("No projects found in test 'toolChainConversionProjects' project directory "	//$NON-NLS-1$
+						+ file.getName()
+						+ ".  The .zip file may be missing or corrupt.");	//$NON-NLS-1$
+			IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+		// Path path = (Path) root.getLocation();
+			IPath location = new Path( root.getLocation().toString() );
+			project = ManagedBuildTestHelper.createProject(
+					projectName, projectZips[0], null, null);
+			if (project != null)
+				projectList.add(project);
+		} catch (Exception e) {
+			System.out.println("Exception Occured.");	//$NON-NLS-1$
+		}
+
+		if (projectList.size() == 0) {
+			fail("No projects found in test project directory "		//$NON-NLS-1$
+					+ file.getName()
+					+ ".  The .zip file may be missing or corrupt.");	//$NON-NLS-1$
+			return null;
+		}
+		return project;
+	}
+	
+	private void doTestProjectUpdate(String cdtVersion, boolean updateProject) {
+		IOverwriteQuery queryALL = new IOverwriteQuery(){
+			public String queryOverwrite(String file) {
+				return ALL;
+			}};
+		IOverwriteQuery queryNOALL = new IOverwriteQuery(){
+			public String queryOverwrite(String file) {
+				return NO_ALL;
+			}};
+		
+		UpdateManagedProjectManager.setUpdateProjectQuery(updateProject ? queryALL : queryNOALL);
+
+		final IProject project = getCDT_TestProject(cdtVersion);
+		if (project == null)
+			return;
+
+		// the project conversion occurs the first time
+		// ManagedBuildManager.getBuildInfo gets called
+		// If requires it also invokes converters for the project.
+		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
+
+		// check whether the managed build info is converted
+		boolean isCompatible = UpdateManagedProjectManager
+				.isCompatibleProject(info);
+		assertTrue(isCompatible);
+
+		if (isCompatible) {
+			// check for correct update
+			if (!updateProject) {
+				// TODO: if the user has chosen not to update the
+				// project the
+				// .cdtbuild file should not change
+			} else {
+				// Make sure that we have a valid project
+				if (info == null || info.getManagedProject() == null
+						|| info.getManagedProject().isValid() == false) {
+					fail("the project \"" + project.getName()	//$NON-NLS-1$
+							+ "\" was not properly converted");	//$NON-NLS-1$
+				}
+			}
+		}
+		ManagedBuildTestHelper.removeProject(project.getName());
+	}
+	
 }
Index: tests/org/eclipse/cdt/managedbuilder/core/tests/ProjectConverter20.java
===================================================================
RCS file: tests/org/eclipse/cdt/managedbuilder/core/tests/ProjectConverter20.java
diff -N tests/org/eclipse/cdt/managedbuilder/core/tests/ProjectConverter20.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/org/eclipse/cdt/managedbuilder/core/tests/ProjectConverter20.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,30 @@
+package org.eclipse.cdt.managedbuilder.core.tests;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.eclipse.cdt.managedbuilder.core.IBuildObject;
+import org.eclipse.cdt.managedbuilder.core.IConvertManagedBuildObject;
+
+public class ProjectConverter20 implements IConvertManagedBuildObject {
+
+	public IBuildObject convert(IBuildObject buildObj, String fromId,
+			String toId, boolean isConfirmed) {
+		
+		String tmpDir = System.getProperty("java.io.tmpdir");	//$NON-NLS-1$
+		
+		File outputFile = new File(tmpDir + "/converterOutput20.txt");	//$NON-NLS-1$
+		try {
+			FileWriter out = new FileWriter(outputFile);			
+			out.write("Converter for CDT 2.0 Project is invoked");	//$NON-NLS-1$
+			out.close();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+		//	e.printStackTrace();
+			System.out.println("Exception raised.");	//$NON-NLS-1$
+		}
+		return buildObj;
+	}
+
+}
Index: tests/org/eclipse/cdt/managedbuilder/core/tests/ProjectConverter21.java
===================================================================
RCS file: tests/org/eclipse/cdt/managedbuilder/core/tests/ProjectConverter21.java
diff -N tests/org/eclipse/cdt/managedbuilder/core/tests/ProjectConverter21.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/org/eclipse/cdt/managedbuilder/core/tests/ProjectConverter21.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,30 @@
+package org.eclipse.cdt.managedbuilder.core.tests;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.eclipse.cdt.managedbuilder.core.IBuildObject;
+import org.eclipse.cdt.managedbuilder.core.IConvertManagedBuildObject;
+
+public class ProjectConverter21 implements IConvertManagedBuildObject {
+
+	public IBuildObject convert(IBuildObject buildObj, String fromId,
+			String toId, boolean isConfirmed) {
+
+		String tmpDir = System.getProperty("java.io.tmpdir");	//$NON-NLS-1$	
+		
+		File outputFile = new File(tmpDir + "/converterOutput21.txt");	//$NON-NLS-1$
+		try {
+			FileWriter out = new FileWriter(outputFile);			
+			out.write("Converter for CDT 2.1 Project is invoked");	//$NON-NLS-1$
+			out.close();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+		//	e.printStackTrace();
+			System.out.println("Exception raised.");	//$NON-NLS-1$
+		}
+		return buildObj;
+	}
+
+}
Index: src/org/eclipse/cdt/managedbuilder/internal/core/Builder.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Builder.java,v
retrieving revision 1.10
diff -u -r1.10 Builder.java
--- src/org/eclipse/cdt/managedbuilder/internal/core/Builder.java	20 Jun 2005 20:52:52 -0000	1.10
+++ src/org/eclipse/cdt/managedbuilder/internal/core/Builder.java	14 Sep 2005 17:41:36 -0000
@@ -792,7 +792,7 @@
 	 * converters and stores them.
 	 */
 
-	private void checkForMigrationSupport() {
+	public void checkForMigrationSupport() {
 
 		String tmpId = null;
 		boolean isExists = false;
Index: src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java,v
retrieving revision 1.39
diff -u -r1.39 Tool.java
--- src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java	10 Jul 2005 03:25:24 -0000	1.39
+++ src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java	14 Sep 2005 17:41:37 -0000
@@ -2442,7 +2442,7 @@
 	 * converters and stores them.
 	 */
 
-	private void checkForMigrationSupport() {
+	public void checkForMigrationSupport() {
 
 		boolean isExists = false;
 	
Index: src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java,v
retrieving revision 1.14
diff -u -r1.14 ToolChain.java
--- src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java	20 Jun 2005 20:52:52 -0000	1.14
+++ src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java	14 Sep 2005 17:41:37 -0000
@@ -1475,7 +1475,7 @@
 	 * converters and adds them to the list.
 	 */
 
-	private void checkForMigrationSupport() {
+	public void checkForMigrationSupport() {
 
 		String tmpId = null;
 		boolean isExists = false;
@@ -1507,7 +1507,7 @@
 			// toolChain version is supported
 
 			String baseId = ManagedBuildManager.getIdFromIdAndVersion(superClassId);
-			String version = ManagedBuildManager.getVersionFromIdAndVersion(superClassId);
+			String version = getVersionFromId().toString();
 
 			IToolChain[] toolChainElements = (IToolChain[]) subMap.values().toArray();
 			
Index: src/org/eclipse/cdt/managedbuilder/projectconverter/UpdateManagedProject20.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/projectconverter/UpdateManagedProject20.java,v
retrieving revision 1.9
diff -u -r1.9 UpdateManagedProject20.java
--- src/org/eclipse/cdt/managedbuilder/projectconverter/UpdateManagedProject20.java	28 Jun 2005 16:51:53 -0000	1.9
+++ src/org/eclipse/cdt/managedbuilder/projectconverter/UpdateManagedProject20.java	14 Sep 2005 17:41:37 -0000
@@ -34,7 +34,10 @@
 import org.eclipse.cdt.managedbuilder.core.IToolReference;
 import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
 import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
+import org.eclipse.cdt.managedbuilder.internal.core.Builder;
 import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.internal.core.Tool;
+import org.eclipse.cdt.managedbuilder.internal.core.ToolChain;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IWorkspace;
@@ -216,7 +219,8 @@
 		// Convert the tool references
 		
 		IToolChain toolChain = newConfig.getToolChain();
-		
+		((ToolChain)toolChain).checkForMigrationSupport();
+
 		if(targetEl.hasAttribute(ITarget.OS_LIST)){
 			String oses = targetEl.getAttribute(ITarget.OS_LIST);
 			String osList[] = oses.split(","); //$NON-NLS-1$
@@ -271,6 +275,12 @@
 			builder.setArguments(makeArguments);
 		}
 
+//		 by now if a builder is going to be created, it will have been
+		Builder builder = (Builder)toolChain.getBuilder();
+		if (! builder.isExtensionElement()) {
+			builder.checkForMigrationSupport();
+		}
+
 		NodeList toolRefNodes = oldConfig.getElementsByTagName(IConfigurationV2.TOOLREF_ELEMENT_NAME);
 		for (int refIndex = 0; refIndex < toolRefNodes.getLength(); ++refIndex) {
 			try{
@@ -334,6 +344,9 @@
 					ConverterMessages.getFormattedString("UpdateManagedProject20.5",toolId), null)); //$NON-NLS-1$
 		}
 			
+		// Check for migration support 
+		((Tool)tool).checkForMigrationSupport();
+		
 		//the tool found, proceed with conversion ...
 
 		if(oldToolRef.hasAttribute(IToolReference.COMMAND))

Attachment: Test21.zip
Description: Test21.zip

Attachment: Test20.zip
Description: Test20.zip


Back to the top