mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
- remove make core dependency from project creation
- assert project create/deletion failure with detailed messages - use common (were possible) project create/deletion methods in CProjectHelper. - fixed problem with dep test when generating code the file was never closed causing project deletion to fail on win32
This commit is contained in:
parent
69cb22837f
commit
e05e298eb2
15 changed files with 254 additions and 381 deletions
|
@ -19,7 +19,6 @@ import junit.framework.Test;
|
|||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.INamespace;
|
||||
|
@ -27,12 +26,8 @@ import org.eclipse.cdt.core.model.IStructure;
|
|||
import org.eclipse.cdt.internal.core.model.CElement;
|
||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
import org.eclipse.core.internal.resources.ResourceException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
|
@ -63,7 +58,7 @@ public class CModelElementsFailedTests extends TestCase {
|
|||
monitor = new NullProgressMonitor();
|
||||
String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
|
||||
|
||||
fCProject= CProjectHelper.createCProject("TestProject1", "bin");
|
||||
fCProject= CProjectHelper.createCCProject("TestProject1", "bin");
|
||||
headerFile = fCProject.getProject().getFile("CModelElementsTest.h");
|
||||
if (!headerFile.exists()) {
|
||||
try{
|
||||
|
@ -73,27 +68,10 @@ public class CModelElementsFailedTests extends TestCase {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
|
||||
addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
|
||||
IProjectDescription description = proj.getDescription();
|
||||
String[] prevNatures= description.getNatureIds();
|
||||
String[] newNatures= new String[prevNatures.length + 1];
|
||||
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
|
||||
newNatures[prevNatures.length]= natureId;
|
||||
description.setNatureIds(newNatures);
|
||||
proj.setDescription(description, monitor);
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
try{
|
||||
CProjectHelper.delete(fCProject);
|
||||
}
|
||||
catch (ResourceException e) {}
|
||||
catch (CoreException e) {}
|
||||
CProjectHelper.delete(fCProject);
|
||||
}
|
||||
|
||||
public void testBug36379() {
|
||||
|
|
|
@ -19,8 +19,8 @@ import junit.framework.Test;
|
|||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||
|
@ -34,18 +34,15 @@ import org.eclipse.cdt.internal.core.search.PatternSearchJob;
|
|||
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
|
||||
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
||||
import org.eclipse.cdt.internal.core.sourcedependency.DependencyQueryJob;
|
||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||
import org.eclipse.core.internal.resources.ResourceException;
|
||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
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.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
@ -116,11 +113,25 @@ import org.eclipse.core.runtime.Platform;
|
|||
if (testProject.exists()){
|
||||
try {
|
||||
testProject.delete(true,monitor);
|
||||
} catch (ResourceException e) {
|
||||
} catch (CoreException e) {
|
||||
fail(getMessage(e.getStatus()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getMessage(IStatus status) {
|
||||
StringBuffer message = new StringBuffer("[");
|
||||
message.append(status.getMessage());
|
||||
if (status.isMultiStatus()) {
|
||||
IStatus children[] = status.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
message.append(getMessage(children[i]));
|
||||
}
|
||||
}
|
||||
message.append("]");
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
public void testDependencyTree() throws Exception{
|
||||
//Add a file to the project
|
||||
importFile("c.h","resources/dependency/c.h");
|
||||
|
@ -614,7 +625,8 @@ import org.eclipse.core.runtime.Platform;
|
|||
fail(e1.getMessage());
|
||||
}
|
||||
writer.close();
|
||||
|
||||
buff.close();
|
||||
|
||||
FileInputStream buff2 = new FileInputStream(tempUtilFile);
|
||||
tempFile.setContents(buff2,true,false,null);
|
||||
tempFile.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
|
@ -646,40 +658,8 @@ import org.eclipse.core.runtime.Platform;
|
|||
*/
|
||||
private IProject createProject(String projectName) throws CoreException
|
||||
{
|
||||
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
|
||||
IProject project= root.getProject(projectName);
|
||||
IProject cproject = null;
|
||||
try{
|
||||
if (!project.exists()) {
|
||||
project.create(null);
|
||||
} else {
|
||||
project.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
}
|
||||
if (!project.isOpen()) {
|
||||
project.open(null);
|
||||
}
|
||||
|
||||
//Fill out a project description
|
||||
IPath defaultPath = Platform.getLocation();
|
||||
IPath newPath = project.getFullPath();
|
||||
if (defaultPath.equals(newPath))
|
||||
newPath = null;
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
IProjectDescription description = workspace.newProjectDescription(project.getName());
|
||||
description.setLocation(newPath);
|
||||
//Create the project
|
||||
cproject = CCorePlugin.getDefault().createCProject(description,project,monitor,MakeCorePlugin.MAKE_PROJECT_ID); //.getCoreModel().create(project);
|
||||
|
||||
if( !cproject.hasNature(CCProjectNature.CC_NATURE_ID) ){
|
||||
addNatureToProject(cproject, CCProjectNature.CC_NATURE_ID, null);
|
||||
}
|
||||
}
|
||||
catch (CoreException e){
|
||||
cproject = project;
|
||||
cproject.open(null);
|
||||
}
|
||||
|
||||
return cproject;
|
||||
ICProject cproject = CProjectHelper.createCCProject(projectName, "bin");
|
||||
return cproject.getProject();
|
||||
|
||||
}
|
||||
|
||||
|
@ -698,14 +678,4 @@ import org.eclipse.core.runtime.Platform;
|
|||
|
||||
return file;
|
||||
}
|
||||
|
||||
private void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
|
||||
IProjectDescription description = proj.getDescription();
|
||||
String[] prevNatures= description.getNatureIds();
|
||||
String[] newNatures= new String[prevNatures.length + 1];
|
||||
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
|
||||
newNatures[prevNatures.length]= natureId;
|
||||
description.setNatureIds(newNatures);
|
||||
proj.setDescription(description, monitor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,29 +19,23 @@ import junit.framework.Test;
|
|||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||
import org.eclipse.cdt.internal.core.index.IQueryResult;
|
||||
import org.eclipse.cdt.internal.core.index.impl.IFileDocument;
|
||||
import org.eclipse.cdt.internal.core.search.indexing.IIndexConstants;
|
||||
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
|
||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||
import org.eclipse.core.internal.resources.ResourceException;
|
||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
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.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
/**
|
||||
* @author bgheorgh
|
||||
|
@ -89,15 +83,28 @@ public class IndexManagerTests extends TestCase {
|
|||
} catch (Exception e1) {
|
||||
}
|
||||
//Delete project
|
||||
if (testProject.exists()){
|
||||
if (testProject.exists()) {
|
||||
try {
|
||||
testProject.delete(true,monitor);
|
||||
} catch (ResourceException e) {
|
||||
testProject.delete(true, monitor);
|
||||
} catch (CoreException e) {
|
||||
fail(getMessage(e.getStatus()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getMessage(IStatus status) {
|
||||
StringBuffer message = new StringBuffer("[");
|
||||
message.append(status.getMessage());
|
||||
if (status.isMultiStatus()) {
|
||||
IStatus children[] = status.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
message.append(getMessage(children[i]));
|
||||
}
|
||||
}
|
||||
message.append("]");
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite(IndexManagerTests.class.getName());
|
||||
|
||||
|
@ -117,43 +124,9 @@ public class IndexManagerTests extends TestCase {
|
|||
/*
|
||||
* Utils
|
||||
*/
|
||||
private IProject createProject(String projectName) throws CoreException
|
||||
{
|
||||
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
|
||||
IProject project= root.getProject(projectName);
|
||||
IProject cproject = null;
|
||||
try{
|
||||
if (!project.exists()) {
|
||||
project.create(null);
|
||||
} else {
|
||||
project.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
}
|
||||
if (!project.isOpen()) {
|
||||
project.open(null);
|
||||
}
|
||||
|
||||
//Fill out a project description
|
||||
IPath defaultPath = Platform.getLocation();
|
||||
IPath newPath = project.getFullPath();
|
||||
if (defaultPath.equals(newPath))
|
||||
newPath = null;
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
IProjectDescription description = workspace.newProjectDescription(project.getName());
|
||||
description.setLocation(newPath);
|
||||
//Create the project
|
||||
cproject = CCorePlugin.getDefault().createCProject(description,project,monitor,MakeCorePlugin.MAKE_PROJECT_ID); //.getCoreModel().create(project);
|
||||
|
||||
if( !cproject.hasNature(CCProjectNature.CC_NATURE_ID) ){
|
||||
addNatureToProject(cproject, CCProjectNature.CC_NATURE_ID, null);
|
||||
}
|
||||
}
|
||||
catch (CoreException e){
|
||||
cproject = project;
|
||||
cproject.open(null);
|
||||
}
|
||||
|
||||
return cproject;
|
||||
|
||||
private IProject createProject(String projectName) {
|
||||
ICProject cPrj = CProjectHelper.createCCProject(projectName, "bin");
|
||||
return cPrj.getProject();
|
||||
}
|
||||
|
||||
private IFile importFile(String fileName, String resourceLocation)throws Exception{
|
||||
|
@ -168,16 +141,7 @@ public class IndexManagerTests extends TestCase {
|
|||
fileDoc = new IFileDocument(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
private void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
|
||||
IProjectDescription description = proj.getDescription();
|
||||
String[] prevNatures= description.getNatureIds();
|
||||
String[] newNatures= new String[prevNatures.length + 1];
|
||||
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
|
||||
newNatures[prevNatures.length]= natureId;
|
||||
description.setNatureIds(newNatures);
|
||||
proj.setDescription(description, monitor);
|
||||
}
|
||||
|
||||
/*
|
||||
* Start of tests
|
||||
*/
|
||||
|
@ -270,12 +234,12 @@ public class IndexManagerTests extends TestCase {
|
|||
*/
|
||||
private void safeDelete(IProject testProject) throws InterruptedException, CoreException {
|
||||
try {
|
||||
testProject.delete(true,monitor);
|
||||
testProject.delete(true, monitor);
|
||||
} catch (CoreException e) {
|
||||
Thread.sleep(5000);
|
||||
testProject.delete(true,monitor);
|
||||
testProject.delete(true, monitor);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void testRemoveFileFromIndex() throws Exception{
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.eclipse.cdt.core.model.ICElement;
|
|||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.testplugin.util.ExpectedStrings;
|
||||
import org.eclipse.core.internal.resources.ResourceException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
|
@ -129,11 +128,7 @@ public class ArchiveTests extends TestCase {
|
|||
* Called after every test case method.
|
||||
*/
|
||||
protected void tearDown() {
|
||||
try{
|
||||
CProjectHelper.delete(testProject);
|
||||
}
|
||||
catch (ResourceException e) {}
|
||||
catch (CoreException e) {}
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
|
|
|
@ -19,7 +19,6 @@ import org.eclipse.cdt.core.model.ICElement;
|
|||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.testplugin.util.ExpectedStrings;
|
||||
import org.eclipse.core.internal.resources.ResourceException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
|
@ -55,24 +54,7 @@ public class BinaryTests extends TestCase {
|
|||
super(name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#finalize()
|
||||
*/
|
||||
protected void finalize() throws Throwable {
|
||||
super.finalize();
|
||||
|
||||
/**
|
||||
* Make sure we leave the workspace clean for the next set of tests
|
||||
*/
|
||||
try{
|
||||
CProjectHelper.delete(testProject);
|
||||
}
|
||||
catch (ResourceException e) {}
|
||||
catch (CoreException e) {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the test fixture.
|
||||
*
|
||||
|
@ -182,15 +164,7 @@ public class BinaryTests extends TestCase {
|
|||
* Called after every test case method.
|
||||
*/
|
||||
protected void tearDown() throws CoreException, InterruptedException {
|
||||
/* Let everything settle down before we try to delete the project.
|
||||
*/
|
||||
Thread.sleep(500);
|
||||
try{
|
||||
CProjectHelper.delete(testProject);
|
||||
}
|
||||
catch (ResourceException e) {}
|
||||
catch (CoreException e) {}
|
||||
|
||||
CProjectHelper.delete(testProject);
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
|
|
|
@ -11,6 +11,7 @@ package org.eclipse.cdt.core.model.tests;
|
|||
* Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -18,7 +19,6 @@ import junit.framework.Test;
|
|||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IEnumeration;
|
||||
|
@ -43,12 +43,8 @@ import org.eclipse.cdt.internal.core.model.MethodTemplate;
|
|||
import org.eclipse.cdt.internal.core.model.StructureTemplate;
|
||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
import org.eclipse.core.internal.resources.ResourceException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
|
@ -67,11 +63,11 @@ public class CModelElementsTests extends TestCase {
|
|||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
protected void setUp() {
|
||||
monitor = new NullProgressMonitor();
|
||||
String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
|
||||
|
||||
fCProject= CProjectHelper.createCProject("TestProject1", "bin");
|
||||
fCProject= CProjectHelper.createCCProject("TestProject1", "bin");
|
||||
headerFile = fCProject.getProject().getFile("CModelElementsTest.h");
|
||||
if (!headerFile.exists()) {
|
||||
try{
|
||||
|
@ -79,29 +75,15 @@ public class CModelElementsTests extends TestCase {
|
|||
headerFile.create(fileIn,false, monitor);
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
|
||||
addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
|
||||
IProjectDescription description = proj.getDescription();
|
||||
String[] prevNatures= description.getNatureIds();
|
||||
String[] newNatures= new String[prevNatures.length + 1];
|
||||
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
|
||||
newNatures[prevNatures.length]= natureId;
|
||||
description.setNatureIds(newNatures);
|
||||
proj.setDescription(description, monitor);
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
try{
|
||||
CProjectHelper.delete(fCProject);
|
||||
}
|
||||
catch (ResourceException e) {}
|
||||
catch (CoreException e) {}
|
||||
}
|
||||
|
||||
public void testCModelElements(){
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.core.model.tests;
|
|||
***********************************************************************/
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
|
@ -20,7 +21,6 @@ import junit.framework.Test;
|
|||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
||||
import org.eclipse.cdt.core.model.IBuffer;
|
||||
|
@ -34,12 +34,8 @@ import org.eclipse.cdt.internal.core.model.CModelManager;
|
|||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.testplugin.TestPluginLauncher;
|
||||
import org.eclipse.core.internal.resources.ResourceException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
|
@ -68,11 +64,11 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen
|
|||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
protected void setUp() {
|
||||
monitor = new NullProgressMonitor();
|
||||
String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
|
||||
|
||||
fCProject= CProjectHelper.createCProject("TestProject1", "bin");
|
||||
fCProject= CProjectHelper.createCCProject("TestProject1", "bin");
|
||||
//Path filePath = new Path(ResourcesPlugin.getWorkspace().getRoot().getLocation().toString()+ fCProject.getPath().toString()+ "/WorkingCopyTest.h");
|
||||
headerFile = fCProject.getProject().getFile("WorkingCopyTest.h");
|
||||
if (!headerFile.exists()) {
|
||||
|
@ -81,11 +77,10 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen
|
|||
headerFile.create(fileIn,false, monitor);
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
|
||||
addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null);
|
||||
}
|
||||
|
||||
// register with the model manager to listen to delta changes
|
||||
CModelManager.getDefault().addElementChangedListener(this);
|
||||
|
@ -94,22 +89,8 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen
|
|||
changedElements = new Vector(20);
|
||||
}
|
||||
|
||||
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
|
||||
IProjectDescription description = proj.getDescription();
|
||||
String[] prevNatures= description.getNatureIds();
|
||||
String[] newNatures= new String[prevNatures.length + 1];
|
||||
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
|
||||
newNatures[prevNatures.length]= natureId;
|
||||
description.setNatureIds(newNatures);
|
||||
proj.setDescription(description, monitor);
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
try{
|
||||
CProjectHelper.delete(fCProject);
|
||||
}
|
||||
catch (ResourceException e) {}
|
||||
catch (CoreException e) {}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,21 +5,17 @@
|
|||
package org.eclipse.cdt.core.model.tests;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
import org.eclipse.core.internal.resources.ResourceException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
|
@ -58,11 +54,11 @@ public abstract class IntegratedCModelTest extends TestCase {
|
|||
*/
|
||||
abstract public String getSourcefileResource();
|
||||
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
monitor = new NullProgressMonitor();
|
||||
String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
|
||||
|
||||
fCProject= CProjectHelper.createCProject("TestProject1", "bin");
|
||||
fCProject= CProjectHelper.createCCProject("TestProject1", "bin");
|
||||
|
||||
sourceFile = fCProject.getProject().getFile( getSourcefileResource() );
|
||||
if (!sourceFile.exists()) {
|
||||
|
@ -71,33 +67,16 @@ public abstract class IntegratedCModelTest extends TestCase {
|
|||
sourceFile.create(fileIn,false, monitor);
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
|
||||
addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
try{
|
||||
CProjectHelper.delete(fCProject);
|
||||
}
|
||||
catch (ResourceException e) {}
|
||||
catch (CoreException e) {}
|
||||
|
||||
CProjectHelper.delete(fCProject);
|
||||
}
|
||||
|
||||
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
|
||||
IProjectDescription description = proj.getDescription();
|
||||
String[] prevNatures= description.getNatureIds();
|
||||
String[] newNatures= new String[prevNatures.length + 1];
|
||||
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
|
||||
newNatures[prevNatures.length]= natureId;
|
||||
description.setNatureIds(newNatures);
|
||||
proj.setDescription(description, monitor);
|
||||
}
|
||||
|
||||
protected ITranslationUnit getTU() {
|
||||
TranslationUnit tu = new TranslationUnit(fCProject, sourceFile);
|
||||
// parse the translation unit to get the elements tree
|
||||
|
|
|
@ -12,12 +12,12 @@ package org.eclipse.cdt.core.model.tests;
|
|||
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.model.IBuffer;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
@ -25,12 +25,8 @@ import org.eclipse.cdt.core.model.IWorkingCopy;
|
|||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.testplugin.TestPluginLauncher;
|
||||
import org.eclipse.core.internal.resources.ResourceException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
|
@ -58,11 +54,11 @@ public class WorkingCopyTests extends TestCase {
|
|||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
protected void setUp() {
|
||||
monitor = new NullProgressMonitor();
|
||||
String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
|
||||
|
||||
fCProject= CProjectHelper.createCProject("TestProject1", "bin");
|
||||
fCProject= CProjectHelper.createCCProject("TestProject1", "bin");
|
||||
//Path filePath = new Path(ResourcesPlugin.getWorkspace().getRoot().getLocation().toString()+ fCProject.getPath().toString()+ "/WorkingCopyTest.h");
|
||||
headerFile = fCProject.getProject().getFile("WorkingCopyTest.h");
|
||||
if (!headerFile.exists()) {
|
||||
|
@ -71,29 +67,14 @@ public class WorkingCopyTests extends TestCase {
|
|||
headerFile.create(fileIn,false, monitor);
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
|
||||
addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
|
||||
IProjectDescription description = proj.getDescription();
|
||||
String[] prevNatures= description.getNatureIds();
|
||||
String[] newNatures= new String[prevNatures.length + 1];
|
||||
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
|
||||
newNatures[prevNatures.length]= natureId;
|
||||
description.setNatureIds(newNatures);
|
||||
proj.setDescription(description, monitor);
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
try{
|
||||
CProjectHelper.delete(fCProject);
|
||||
}
|
||||
catch (ResourceException e) {}
|
||||
catch (CoreException e) {}
|
||||
CProjectHelper.delete(fCProject);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -244,12 +244,22 @@
|
|||
</run>
|
||||
</application>
|
||||
</extension>
|
||||
<extension
|
||||
<extension
|
||||
id="TestProject"
|
||||
name="%TestProject.name"
|
||||
name="C/C++ Test Project"
|
||||
point="org.eclipse.cdt.core.CProject">
|
||||
<cproject
|
||||
class="org.eclipse.cdt.testplugin.TestProject">
|
||||
</cproject>
|
||||
</extension>
|
||||
</extension>
|
||||
<extension
|
||||
id="TestScanner"
|
||||
name="C/C++ Test Scanner"
|
||||
point="org.eclipse.cdt.core.ScannerInfoProvider">
|
||||
<cextension>
|
||||
<run
|
||||
class="org.eclipse.cdt.testplugin.TestScannerProvider">
|
||||
</run>
|
||||
</cextension>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
|
@ -17,30 +17,24 @@ import java.io.FileInputStream;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||
import org.eclipse.cdt.core.search.ICSearchResultCollector;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.core.search.SearchEngine;
|
||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.testplugin.FileManager;
|
||||
import org.eclipse.core.internal.resources.ResourceException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
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.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -108,50 +102,8 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants {
|
|||
}
|
||||
|
||||
private IProject createProject(String projectName) throws CoreException {
|
||||
IWorkspaceRoot root = workspace.getRoot();
|
||||
IProject project = root.getProject(projectName);
|
||||
IProject cproject = null;
|
||||
try{
|
||||
|
||||
if( !project.exists() ) {
|
||||
project.create( null );
|
||||
} else {
|
||||
project.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
}
|
||||
|
||||
if( !project.isOpen() ) {
|
||||
project.open( null );
|
||||
}
|
||||
|
||||
//Fill out a project description
|
||||
IPath defaultPath = Platform.getLocation();
|
||||
IPath newPath = project.getFullPath();
|
||||
|
||||
if (defaultPath.equals(newPath))
|
||||
newPath = null;
|
||||
|
||||
IProjectDescription description = workspace.newProjectDescription(project.getName());
|
||||
|
||||
description.setLocation(newPath);
|
||||
|
||||
//Create the project
|
||||
cproject = CCorePlugin.getDefault().createCProject( description,
|
||||
project,
|
||||
monitor,
|
||||
MakeCorePlugin.MAKE_PROJECT_ID);
|
||||
|
||||
if( !project.hasNature(CCProjectNature.CC_NATURE_ID) ){
|
||||
addNatureToProject(project, CCProjectNature.CC_NATURE_ID, null);
|
||||
}
|
||||
}
|
||||
catch (CoreException e){
|
||||
cproject = project;
|
||||
cproject.open(null);
|
||||
}
|
||||
|
||||
return cproject;
|
||||
|
||||
|
||||
ICProject cPrj = CProjectHelper.createCCProject(projectName, "bin");
|
||||
return cPrj.getProject();
|
||||
}
|
||||
|
||||
private void importFile(String fileName, String resourceLocation)throws Exception{
|
||||
|
@ -166,19 +118,7 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
private void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
|
||||
IProjectDescription description = proj.getDescription();
|
||||
|
||||
String[] prevNatures = description.getNatureIds();
|
||||
String[] newNatures = new String[ prevNatures.length + 1 ];
|
||||
|
||||
System.arraycopy( prevNatures, 0, newNatures, 0, prevNatures.length );
|
||||
newNatures[ prevNatures.length ] = natureId;
|
||||
description.setNatureIds( newNatures );
|
||||
proj.setDescription( description, monitor );
|
||||
}
|
||||
|
||||
protected void search(IWorkspace workspace, ICSearchPattern pattern, ICSearchScope scope, ICSearchResultCollector collector) {
|
||||
searchEngine.search( workspace, pattern, scope, collector, false );
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package org.eclipse.cdt.testplugin;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CProjectNature;
|
||||
import org.eclipse.cdt.core.model.IArchive;
|
||||
|
@ -16,11 +20,14 @@ import org.eclipse.core.resources.IFolder;
|
|||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.ui.dialogs.IOverwriteQuery;
|
||||
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
|
||||
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
|
||||
|
@ -28,35 +35,77 @@ import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
|
|||
* Helper methods to set up a ICProject.
|
||||
*/
|
||||
public class CProjectHelper {
|
||||
|
||||
/**
|
||||
* Creates a ICProject.
|
||||
*/
|
||||
public static ICProject createCProject(String projectName,
|
||||
String binFolderName) throws CoreException {
|
||||
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||
IProject project = root.getProject(projectName);
|
||||
if (!project.exists()) {
|
||||
project.create(null);
|
||||
} else {
|
||||
project.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
public static ICProject createCProject(final String projectName, String binFolderName){
|
||||
final IWorkspace ws = ResourcesPlugin.getWorkspace();
|
||||
final IProject newProject[] = new IProject[1];
|
||||
try {
|
||||
ws.run(new IWorkspaceRunnable() {
|
||||
public void run(IProgressMonitor monitor) throws CoreException {
|
||||
IWorkspaceRoot root = ws.getRoot();
|
||||
IProject project = root.getProject(projectName);
|
||||
if (!project.exists()) {
|
||||
project.create(null);
|
||||
} else {
|
||||
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);
|
||||
} catch (CoreException e) {
|
||||
Assert.fail(getMessage(e.getStatus()));
|
||||
}
|
||||
if (!project.isOpen()) {
|
||||
project.open(null);
|
||||
}
|
||||
if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
|
||||
String projectId = CTestPlugin.PLUGIN_ID + ".TestProject";
|
||||
CCorePlugin.getDefault()
|
||||
.mapCProjectOwner(project, projectId, false);
|
||||
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
|
||||
}
|
||||
ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(
|
||||
project);
|
||||
return cproject;
|
||||
|
||||
return CCorePlugin.getDefault().getCoreModel().create(newProject[0]);
|
||||
}
|
||||
|
||||
private static String getMessage(IStatus status) {
|
||||
StringBuffer message = new StringBuffer("[");
|
||||
message.append(status.getMessage());
|
||||
if (status.isMultiStatus()) {
|
||||
IStatus children[] = status.getChildren();
|
||||
for( int i = 0; i < children.length; i++) {
|
||||
message.append(getMessage(children[i]));
|
||||
}
|
||||
}
|
||||
message.append("]");
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
public static ICProject createCCProject(final String projectName, final String binFolderName) {
|
||||
final IWorkspace ws = ResourcesPlugin.getWorkspace();
|
||||
final ICProject newProject[] = new ICProject[1];
|
||||
try {
|
||||
ws.run(new IWorkspaceRunnable() {
|
||||
public void run(IProgressMonitor monitor) throws CoreException {
|
||||
ICProject cproject = createCProject(projectName, binFolderName);
|
||||
if (!cproject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
|
||||
addNatureToProject(cproject.getProject(), CCProjectNature.CC_NATURE_ID, null);
|
||||
}
|
||||
newProject[0] = cproject;
|
||||
}
|
||||
}, null);
|
||||
} catch (CoreException e) {
|
||||
Assert.fail(getMessage(e.getStatus()));
|
||||
}
|
||||
return newProject[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a ICProject.
|
||||
*/
|
||||
public static void delete(ICProject cproject) throws CoreException {
|
||||
public static void delete(ICProject cproject) {
|
||||
try {
|
||||
cproject.getProject().delete(true, true, null);
|
||||
} catch (CoreException e) {
|
||||
|
@ -64,15 +113,19 @@ public class CProjectHelper {
|
|||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e1) {
|
||||
} finally {
|
||||
cproject.getProject().delete(true, true, null);
|
||||
try {
|
||||
cproject.getProject().delete(true, true, null);
|
||||
} catch (CoreException e2) {
|
||||
Assert.fail(getMessage(e2.getStatus()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a source container to a ICProject.
|
||||
*/
|
||||
public static ICContainer addSourceContainer(ICProject cproject,
|
||||
String containerName) throws CoreException {
|
||||
public static ICContainer addSourceContainer(ICProject cproject, String containerName) throws CoreException {
|
||||
IProject project = cproject.getProject();
|
||||
ICContainer container = null;
|
||||
if (containerName == null || containerName.length() == 0) {
|
||||
|
@ -86,25 +139,26 @@ public class CProjectHelper {
|
|||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a source container to a ICProject and imports all files contained
|
||||
* in the given Zip file.
|
||||
*/
|
||||
public static ICContainer addSourceContainerWithImport(ICProject cproject,
|
||||
String containerName, ZipFile zipFile)
|
||||
throws InvocationTargetException, CoreException {
|
||||
public static ICContainer addSourceContainerWithImport(ICProject cproject, String containerName, ZipFile zipFile)
|
||||
throws InvocationTargetException, CoreException {
|
||||
ICContainer root = addSourceContainer(cproject, containerName);
|
||||
importFilesFromZip(zipFile, root.getPath(), null);
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a source folder from a ICProject.
|
||||
*/
|
||||
public static void removeSourceContainer(ICProject cproject,
|
||||
String containerName) throws CoreException {
|
||||
public static void removeSourceContainer(ICProject cproject, String containerName) throws CoreException {
|
||||
IFolder folder = cproject.getProject().getFolder(containerName);
|
||||
folder.delete(true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to find an archive with the given name in the workspace
|
||||
*/
|
||||
|
@ -128,6 +182,7 @@ public class CProjectHelper {
|
|||
}
|
||||
return (null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to find a binary with the given name in the workspace
|
||||
*/
|
||||
|
@ -145,6 +200,7 @@ public class CProjectHelper {
|
|||
}
|
||||
return (null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to find an object with the given name in the workspace
|
||||
*/
|
||||
|
@ -157,16 +213,16 @@ public class CProjectHelper {
|
|||
for (x = 0; x < myElements.length; x++) {
|
||||
if (myElements[x].getElementName().equals(name))
|
||||
if (myElements[x] instanceof IBinary) {
|
||||
return ((IBinary) myElements[x]);
|
||||
return ((IBinary)myElements[x]);
|
||||
}
|
||||
}
|
||||
return (null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to find a TranslationUnit with the given name in the workspace
|
||||
*/
|
||||
public static ITranslationUnit findTranslationUnit(ICProject testProject,
|
||||
String name) {
|
||||
public static ITranslationUnit findTranslationUnit(ICProject testProject, String name) {
|
||||
int x;
|
||||
ICElement[] myElements;
|
||||
myElements = testProject.getChildren();
|
||||
|
@ -175,11 +231,12 @@ public class CProjectHelper {
|
|||
for (x = 0; x < myElements.length; x++) {
|
||||
if (myElements[x].getElementName().equals(name))
|
||||
if (myElements[x] instanceof ITranslationUnit) {
|
||||
return ((ITranslationUnit) myElements[x]);
|
||||
return ((ITranslationUnit)myElements[x]);
|
||||
}
|
||||
}
|
||||
return (null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to find an element with the given name in the workspace
|
||||
*/
|
||||
|
@ -195,8 +252,8 @@ public class CProjectHelper {
|
|||
}
|
||||
return (null);
|
||||
}
|
||||
private static void addNatureToProject(IProject proj, String natureId,
|
||||
IProgressMonitor monitor) throws CoreException {
|
||||
|
||||
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
|
||||
IProjectDescription description = proj.getDescription();
|
||||
String[] prevNatures = description.getNatureIds();
|
||||
String[] newNatures = new String[prevNatures.length + 1];
|
||||
|
@ -205,19 +262,19 @@ public class CProjectHelper {
|
|||
description.setNatureIds(newNatures);
|
||||
proj.setDescription(description, monitor);
|
||||
}
|
||||
private static void importFilesFromZip(ZipFile srcZipFile, IPath destPath,
|
||||
IProgressMonitor monitor) throws InvocationTargetException {
|
||||
ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(
|
||||
srcZipFile);
|
||||
|
||||
private static void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor)
|
||||
throws InvocationTargetException {
|
||||
ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(srcZipFile);
|
||||
try {
|
||||
ImportOperation op = new ImportOperation(destPath,
|
||||
structureProvider.getRoot(), structureProvider,
|
||||
new ImportOverwriteQuery());
|
||||
ImportOperation op =
|
||||
new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, new ImportOverwriteQuery());
|
||||
op.run(monitor);
|
||||
} catch (InterruptedException e) {
|
||||
// should not happen
|
||||
}
|
||||
}
|
||||
|
||||
private static class ImportOverwriteQuery implements IOverwriteQuery {
|
||||
public String queryOverwrite(String file) {
|
||||
return ALL;
|
||||
|
|
|
@ -8,15 +8,20 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.testplugin;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ICDescriptor;
|
||||
import org.eclipse.cdt.core.ICOwner;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class TestProject implements ICOwner {
|
||||
|
||||
public void configure(ICDescriptor cproject) throws CoreException {
|
||||
public void configure(ICDescriptor cDescriptor) throws CoreException {
|
||||
cDescriptor.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, TestScannerProvider.SCANNER_ID);
|
||||
}
|
||||
|
||||
public void update(ICDescriptor cproject, String extensionID) throws CoreException {
|
||||
public void update(ICDescriptor cDescriptor, String extensionID) throws CoreException {
|
||||
if ( extensionID.equals(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID)) {
|
||||
cDescriptor.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, TestScannerProvider.SCANNER_ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Created on Jan 16, 2004
|
||||
*
|
||||
* Copyright (c) 2002,2003 QNX Software Systems Ltd.
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.testplugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
|
||||
public class TestScannerInfo implements IScannerInfo {
|
||||
private Map emptyMap = new HashMap(0);
|
||||
|
||||
public Map getDefinedSymbols() {
|
||||
return emptyMap;
|
||||
}
|
||||
|
||||
public String[] getIncludePaths() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Created on Jan 16, 2004
|
||||
*
|
||||
* Copyright (c) 2002,2003 QNX Software Systems Ltd.
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.testplugin;
|
||||
|
||||
import org.eclipse.cdt.core.AbstractCExtension;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
public class TestScannerProvider extends AbstractCExtension implements IScannerInfoProvider {
|
||||
|
||||
public final static String SCANNER_ID = CTestPlugin.PLUGIN_ID + "TestScanner";
|
||||
|
||||
public IScannerInfo getScannerInformation(IResource resource) {
|
||||
return new TestScannerInfo();
|
||||
}
|
||||
|
||||
public void subscribe(IResource resource, IScannerInfoChangeListener listener) {
|
||||
}
|
||||
|
||||
public void unsubscribe(IResource resource, IScannerInfoChangeListener listener) {
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue