From bd20ae72862da3cca63e723abf6377a2ee547389 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 8 Oct 2009 21:44:21 +0000 Subject: [PATCH] bug 212596: JUnit failures in cdt.managedbuilder.test.suite Java generics and other cleanup --- .../testplugin/ManagedBuildTestHelper.java | 22 +++++---- .../tests/ManagedProject30MakefileTests.java | 46 ++++++++----------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java index 34aaa9147bb..00312da5237 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java @@ -70,7 +70,6 @@ public class ManagedBuildTestHelper { private static final String rcbsToolInputTypeName = new String("Resource Custom Build Step Input Type"); //$NON-NLS-1$ private static final String rcbsToolOutputTypeId = new String("org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype"); //$NON-NLS-1$ private static final String rcbsToolOutputTypeName = new String("Resource Custom Build Step Output Type"); //$NON-NLS-1$ - private static final String PATH_SEPERATOR = ";"; //$NON-NLS-1$ /* (non-Javadoc) @@ -291,7 +290,6 @@ public class ManagedBuildTestHelper { addManagedBuildNature(project); // Find the base project type definition - IProjectType[] projTypes = ManagedBuildManager.getDefinedProjectTypes(); IProjectType projType = ManagedBuildManager.getProjectType(projectTypeId); Assert.assertNotNull(projType); @@ -301,6 +299,7 @@ public class ManagedBuildTestHelper { newProject = ManagedBuildManager.createManagedProject(project, projType); } catch (Exception e) { Assert.fail("Failed to create managed project for: " + project.getName()); + return; } Assert.assertEquals(newProject.getName(), projType.getName()); Assert.assertFalse(newProject.equals(projType)); @@ -344,6 +343,7 @@ public class ManagedBuildTestHelper { static public void addManagedBuildNature (IProject project) { // Create the buildinformation object for the project IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project); + Assert.assertNotNull(info); // info.setValid(true); // Add the managed build nature @@ -362,6 +362,7 @@ public class ManagedBuildTestHelper { desc.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, ManagedBuildManager.INTERFACE_IDENTITY); } catch (CoreException e) { Assert.fail("Test failed on adding managed builder as scanner info provider: " + e.getLocalizedMessage()); + return; } try { desc.saveProjectData(); @@ -537,6 +538,7 @@ public class ManagedBuildTestHelper { input = new FileReader(fullPath.toFile()); } catch (Exception e) { Assert.fail("File " + fullPath.toString() + " could not be read: " + e.getLocalizedMessage()); + return null; } //InputStream input = file.getContents(true); // A different way to read the file... int c; @@ -582,6 +584,7 @@ public class ManagedBuildTestHelper { srcReader = new FileReader(srcFile.toFile()); } catch (Exception e) { Assert.fail("File " + file.toString() + " could not be read."); + return null; } if (file.segmentCount() > 1) { IPath newDir = tmpSrcDir; @@ -598,6 +601,7 @@ public class ManagedBuildTestHelper { writer = new FileWriter(destFile.toFile()); } catch (Exception e) { Assert.fail("File " + files[i].toString() + " could not be written."); + return null; } try { int c; @@ -631,14 +635,13 @@ public class ManagedBuildTestHelper { if (!tmpSrcDirFile.exists()) { Assert.fail("Temporary directory " + tmpSrcDirFile.toString() + " does not exist."); } else { - boolean succeed; for (int i=0; i list = new ArrayList(); ITool tools[] = rcConfig.getTools(); for (int i = 0; i < tools.length; i++) { ITool tool = tools[i]; @@ -759,7 +761,7 @@ public class ManagedBuildTestHelper { } } if(list.size() != 0) - return (ITool[])list.toArray(new ITool[list.size()]); + return list.toArray(new ITool[list.size()]); return null; } diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedProject30MakefileTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedProject30MakefileTests.java index aeb94d91236..63568f103e5 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedProject30MakefileTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedProject30MakefileTests.java @@ -18,27 +18,32 @@ package org.eclipse.cdt.managedbuilder.core.tests; import java.io.File; import java.io.FileFilter; import java.util.ArrayList; -import java.util.Iterator; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.cdt.managedbuilder.core.IAdditionalInput; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; import org.eclipse.cdt.managedbuilder.core.IManagedProject; import org.eclipse.cdt.managedbuilder.core.IOutputType; -import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; -import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.ITool; -import org.eclipse.cdt.managedbuilder.internal.core.Tool; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.internal.core.ToolChain; 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.*; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IPathVariableManager; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -68,7 +73,7 @@ public class ManagedProject30MakefileTests extends TestCase { // TODO: testLinkedFolder fails intermittently saying that it cannot find // the makefiles to compare. This appears to be a test set issue, // rather than an MBS functionality issue - //suite.addTest(new ManagedProject30MakefileTests("test30LinkedFolder")); + suite.addTest(new ManagedProject30MakefileTests("test30LinkedFolder")); suite.addTest(new ManagedProject30MakefileTests("test30CopyandDeploy")); suite.addTest(new ManagedProject30MakefileTests("test30DeleteFile")); suite.addTest(new ManagedProject30MakefileTests("test30NoFilesToBuild")); @@ -92,7 +97,7 @@ public class ManagedProject30MakefileTests extends TestCase { } private IProject[] createProject(String projName, IPath location, String projectTypeId, boolean containsZip){ - ArrayList projectList = null; + ArrayList projectList = new ArrayList(); if (containsZip) { File testDir = CTestPlugin.getFileInPlugin(new Path("resources/test30Projects/" + projName)); if(testDir == null) { @@ -108,7 +113,7 @@ public class ManagedProject30MakefileTests extends TestCase { } }); - projectList = new ArrayList(projectZips.length); + projectList = new ArrayList(projectZips.length); for(int i = 0; i < projectZips.length; i++){ try{ String projectName = projectZips[i].getName(); @@ -133,12 +138,13 @@ public class ManagedProject30MakefileTests extends TestCase { try{ IProject project = ManagedBuildTestHelper.createProject(projName, null, location, projectTypeId); if(project != null) - projectList = new ArrayList(1); + projectList = new ArrayList(1); projectList.add(project); - } catch(Exception e){} + } catch(Exception e){ + } } - return (IProject[])projectList.toArray(new IProject[projectList.size()]); + return projectList.toArray(new IProject[projectList.size()]); } private IProject[] createProjects(String projName, IPath location, String projectTypeId, boolean containsZip) { @@ -148,11 +154,6 @@ public class ManagedProject30MakefileTests extends TestCase { public String queryOverwrite(String file) { return ALL; }}; - IOverwriteQuery queryNOALL = new IOverwriteQuery(){ - public String queryOverwrite(String file) { - return NO_ALL; - }}; - UpdateManagedProjectManager.setBackupFileOverwriteQuery(queryALL); UpdateManagedProjectManager.setUpdateProjectQuery(queryALL); @@ -390,11 +391,11 @@ public class ManagedProject30MakefileTests extends TestCase { IProject[] projects = createProjects("deleteFile", null, null, true); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); - ArrayList resourceList = new ArrayList(1); + ArrayList resourceList = new ArrayList(1); IProject project = projects[0]; IFile projfile = project.getFile("filetobedeleted.cxx"); resourceList.add(projfile); - final IResource[] fileResource = (IResource[])resourceList.toArray(new IResource[resourceList.size()]); + final IResource[] fileResource = resourceList.toArray(new IResource[resourceList.size()]); IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { workspace.delete(fileResource, false, null); @@ -461,7 +462,6 @@ public class ManagedProject30MakefileTests extends TestCase { IProject project = projects[0]; IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); IConfiguration config = info.getDefaultConfiguration(); - IFile projfile = project.getFile("main.cxx"); config.setPreannouncebuildStep("Pre-announce Build Step"); config.setPrebuildStep("echo 'executing Pre-Build Step' "); config.setPostannouncebuildStep("Post-announce Build Step"); @@ -552,13 +552,7 @@ public class ManagedProject30MakefileTests extends TestCase { for (int i=0; i