1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

lets throw the exception so that we can get full back trace instead of asserting

This commit is contained in:
David Inglis 2004-03-25 19:39:19 +00:00
parent ffde7d87bc
commit b173623edb
2 changed files with 48 additions and 56 deletions

View file

@ -125,7 +125,7 @@ public class IndexManagerTests extends TestCase {
/* /*
* Utils * Utils
*/ */
private IProject createProject(String projectName) { private IProject createProject(String projectName) throws CoreException {
ICProject cPrj = CProjectHelper.createCCProject(projectName, "bin"); ICProject cPrj = CProjectHelper.createCCProject(projectName, "bin");
return cPrj.getProject(); return cPrj.getProject();
} }

View file

@ -40,34 +40,31 @@ public class CProjectHelper {
/** /**
* Creates a ICProject. * Creates a ICProject.
*/ */
public static ICProject createCProject(final String projectName, String binFolderName){ public static ICProject createCProject(final String projectName, String binFolderName) throws CoreException {
final IWorkspace ws = ResourcesPlugin.getWorkspace(); final IWorkspace ws = ResourcesPlugin.getWorkspace();
final IProject newProject[] = new IProject[1]; final IProject newProject[] = new IProject[1];
try { ws.run(new IWorkspaceRunnable() {
ws.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException { public void run(IProgressMonitor monitor) throws CoreException {
IWorkspaceRoot root = ws.getRoot(); IWorkspaceRoot root = ws.getRoot();
IProject project = root.getProject(projectName); IProject project = root.getProject(projectName);
if (!project.exists()) { if (!project.exists()) {
project.create(null); project.create(null);
} else { } else {
project.refreshLocal(IResource.DEPTH_INFINITE, null); project.refreshLocal(IResource.DEPTH_INFINITE, null);
}
if (!project.isOpen()) {
project.open(null);
}
if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
String projectId = CTestPlugin.PLUGIN_ID + ".TestProject";
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
CCorePlugin.getDefault().mapCProjectOwner(project, projectId, false);
}
newProject[0] = project;
} }
}, null); if (!project.isOpen()) {
} catch (CoreException e) { project.open(null);
Assert.fail(getMessage(e.getStatus())); }
} if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
String projectId = CTestPlugin.PLUGIN_ID + ".TestProject";
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
CCorePlugin.getDefault().mapCProjectOwner(project, projectId, false);
}
newProject[0] = project;
}
}, null);
return CCorePlugin.getDefault().getCoreModel().create(newProject[0]); return CCorePlugin.getDefault().getCoreModel().create(newProject[0]);
} }
@ -84,22 +81,19 @@ public class CProjectHelper {
return message.toString(); return message.toString();
} }
public static ICProject createCCProject(final String projectName, final String binFolderName) { public static ICProject createCCProject(final String projectName, final String binFolderName) throws CoreException {
final IWorkspace ws = ResourcesPlugin.getWorkspace(); final IWorkspace ws = ResourcesPlugin.getWorkspace();
final ICProject newProject[] = new ICProject[1]; final ICProject newProject[] = new ICProject[1];
try { ws.run(new IWorkspaceRunnable() {
ws.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException { public void run(IProgressMonitor monitor) throws CoreException {
ICProject cproject = createCProject(projectName, binFolderName); ICProject cproject = createCProject(projectName, binFolderName);
if (!cproject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) { if (!cproject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
addNatureToProject(cproject.getProject(), CCProjectNature.CC_NATURE_ID, null); addNatureToProject(cproject.getProject(), CCProjectNature.CC_NATURE_ID, null);
}
newProject[0] = cproject;
} }
}, null); newProject[0] = cproject;
} catch (CoreException e) { }
Assert.fail(getMessage(e.getStatus())); }, null);
}
return newProject[0]; return newProject[0];
} }
@ -145,11 +139,10 @@ public class CProjectHelper {
} }
/** /**
* Adds a folder container to a ICProject and imports all files contained * Adds a folder container to a ICProject and imports all files contained in the given Zip file.
* in the given Zip file.
*/ */
public static ICContainer addCContainerWithImport(ICProject cproject, String containerName, ZipFile zipFile) public static ICContainer addCContainerWithImport(ICProject cproject, String containerName, ZipFile zipFile)
throws InvocationTargetException, CoreException { throws InvocationTargetException, CoreException {
ICContainer root = addCContainer(cproject, containerName); ICContainer root = addCContainer(cproject, containerName);
importFilesFromZip(zipFile, root.getPath(), null); importFilesFromZip(zipFile, root.getPath(), null);
return root; return root;
@ -170,11 +163,9 @@ public class CProjectHelper {
int x; int x;
IArchive[] myArchives; IArchive[] myArchives;
IArchiveContainer archCont; IArchiveContainer archCont;
/*********************************************************************** /***************************************************************************************************************************
* Since ArchiveContainer.getArchives does not wait until all the * Since ArchiveContainer.getArchives does not wait until all the archives in the project have been parsed before returning
* archives in the project have been parsed before returning the list, * the list, we have to do a sync ArchiveContainer.getChildren first to make sure we find all the archives.
* we have to do a sync ArchiveContainer.getChildren first to make sure
* we find all the archives.
*/ */
archCont = testProject.getArchiveContainer(); archCont = testProject.getArchiveContainer();
myArchives = archCont.getArchives(); myArchives = archCont.getArchives();
@ -211,12 +202,12 @@ public class CProjectHelper {
public static IBinary findObject(ICProject testProject, String name) { public static IBinary findObject(ICProject testProject, String name) {
ICElement[] sourceRoots = testProject.getChildren(); ICElement[] sourceRoots = testProject.getChildren();
for (int i = 0; i < sourceRoots.length; i++) { for (int i = 0; i < sourceRoots.length; i++) {
ISourceRoot root = (ISourceRoot)sourceRoots[i]; ISourceRoot root = (ISourceRoot) sourceRoots[i];
ICElement[] myElements = root.getChildren(); ICElement[] myElements = root.getChildren();
for (int x = 0; x < myElements.length; x++) { for (int x = 0; x < myElements.length; x++) {
if (myElements[x].getElementName().equals(name)) { if (myElements[x].getElementName().equals(name)) {
if (myElements[x] instanceof IBinary) { if (myElements[x] instanceof IBinary) {
return ((IBinary)myElements[x]); return ((IBinary) myElements[x]);
} }
} }
} }
@ -230,12 +221,12 @@ public class CProjectHelper {
public static ITranslationUnit findTranslationUnit(ICProject testProject, String name) { public static ITranslationUnit findTranslationUnit(ICProject testProject, String name) {
ICElement[] sourceRoots = testProject.getChildren(); ICElement[] sourceRoots = testProject.getChildren();
for (int i = 0; i < sourceRoots.length; i++) { for (int i = 0; i < sourceRoots.length; i++) {
ISourceRoot root = (ISourceRoot)sourceRoots[i]; ISourceRoot root = (ISourceRoot) sourceRoots[i];
ICElement[] myElements = root.getChildren(); ICElement[] myElements = root.getChildren();
for (int x = 0; x < myElements.length; x++) { for (int x = 0; x < myElements.length; x++) {
if (myElements[x].getElementName().equals(name)) { if (myElements[x].getElementName().equals(name)) {
if (myElements[x] instanceof ITranslationUnit) { if (myElements[x] instanceof ITranslationUnit) {
return ((ITranslationUnit)myElements[x]); return ((ITranslationUnit) myElements[x]);
} }
} }
} }
@ -249,7 +240,7 @@ public class CProjectHelper {
public static ICElement findElement(ICProject testProject, String name) { public static ICElement findElement(ICProject testProject, String name) {
ICElement[] sourceRoots = testProject.getChildren(); ICElement[] sourceRoots = testProject.getChildren();
for (int i = 0; i < sourceRoots.length; i++) { for (int i = 0; i < sourceRoots.length; i++) {
ISourceRoot root = (ISourceRoot)sourceRoots[i]; ISourceRoot root = (ISourceRoot) sourceRoots[i];
ICElement[] myElements = root.getChildren(); ICElement[] myElements = root.getChildren();
for (int x = 0; x < myElements.length; x++) { for (int x = 0; x < myElements.length; x++) {
if (myElements[x].getElementName().equals(name)) { if (myElements[x].getElementName().equals(name)) {
@ -271,11 +262,11 @@ public class CProjectHelper {
} }
private static void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) private static void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor)
throws InvocationTargetException { throws InvocationTargetException {
ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(srcZipFile); ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(srcZipFile);
try { try {
ImportOperation op = ImportOperation op = new ImportOperation(destPath, structureProvider.getRoot(), structureProvider,
new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, new ImportOverwriteQuery()); new ImportOverwriteQuery());
op.run(monitor); op.run(monitor);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// should not happen // should not happen
@ -283,8 +274,9 @@ public class CProjectHelper {
} }
private static class ImportOverwriteQuery implements IOverwriteQuery { private static class ImportOverwriteQuery implements IOverwriteQuery {
public String queryOverwrite(String file) { public String queryOverwrite(String file) {
return ALL; return ALL;
} }
} }
} }