Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] CDT project creation question

Title: Is 5.0 done?
Hello,

I just finsihed writing a simple project that will eventually be used in a code generator for a modeling tool.

Below I have added two functions that create a makefile based project, and a managed project from a simple "wizard" ... I have "reverse engineered" the code from CDT itself, unit tests, and google posts ...

If anyone has time i'd appreciate any feedback on the functions (as i am new to eclipse and especially integrating with CDT).

Cheers,
Jim

ps sorry about posting in html ... i did it to preserve the code formating ...

private boolean CreateManagedProject()
{
try
{
//
// Create a new CDT project
//
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(page1.GetProjectName()+"_ManagedPrj");
IPath projectLocation = project.getRawLocation();

if (project.exists()) {
project.delete(true, true, null);
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProjectDescription description = workspace.newProjectDescription(project.getName());

if ((projectLocation != null) && (!projectLocation.equals(Platform.getLocation()))) {
description.setLocation(projectLocation);
}

//
// This code C project and make natures ...
//

project.create(null);
project.open(null);
CProjectNature.addCNature(project, null);
IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
info.setValid(true);
ManagedCProjectNature.addManagedNature(project, null);
ManagedCProjectNature.addManagedBuilder(project, null);

/*
// NOTE: I am sure if its better to use code above or this code ...
CCorePlugin.getDefault().createCProject(description, project, null, MakeCorePlugin.MAKE_PROJECT_ID);
IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
info.setValid(true);
ManagedCProjectNature.addManagedNature(project, null);
ManagedCProjectNature.addManagedBuilder(project, null);
*/

ICDescriptor desc = null;
try {
desc = CCorePlugin.getDefault().getCProjectDescription(project, true);
desc.remove(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID);
desc.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, ManagedBuildManager.INTERFACE_IDENTITY);
} catch (CoreException e) {
//TODO
//Assert.fail("Test failed on adding managed builder as scanner info provider: " + e.getLocalizedMessage());
}
try {
desc.saveProjectData();
} catch (CoreException e) {
//TODO
//Assert.fail("Test failed on saving the ICDescriptor data: " + e.getLocalizedMessage());
}

IProjectType[] projTypes = ManagedBuildManager.getDefinedProjectTypes();
IProjectType projType = ManagedBuildManager.getProjectType("cdt.managedbuild.target.gnu.exe");
if (projType==null)
{
//TODO
}

IManagedProject newProject = null;
newProject = ManagedBuildManager.createManagedProject(project, projType);

ManagedBuildManager.setNewProjectVersion(project);

IConfiguration defaultConfig = null;
IConfiguration[] configs = projType.getConfigurations();
for (int i = 0; i < configs.length; ++i) {
// Make the first configuration the default
if (i == 0) {
defaultConfig = newProject.createConfiguration(configs[i], projType.getId() + "." + i);
} else {
newProject.createConfiguration(configs[i], projType.getId() + "." + i);
}
}
ManagedBuildManager.setDefaultConfiguration(project, defaultConfig);

IConfiguration cfgs[] = newProject.getConfigurations();
for(int i = 0; i < cfgs.length; i++){
cfgs[i].setArtifactName(newProject.getDefaultArtifactName());
}

ManagedBuildManager.getBuildInfo(project).setValid(true);


//
// This code creates a makefile, helloworld.c file, and some folders ...
//
CreateHelloWorldFile(project);
IFolder src = "" "src");

//
// Configure project to use PE debugger for windows
// On linux this would be ELF
//
ICExtensionReference[] binaryParsers= CCorePlugin.getDefault().getBinaryParserExtensions(project);
if (binaryParsers == null || binaryParsers.length == 0) {
ICProjectDescription desc_bp= CCorePlugin.getDefault().getProjectDescription(project);
if (desc_bp == null) {
return false;
}
desc_bp.getDefaultSettingConfiguration().create(
CCorePlugin.BINARY_PARSER_UNIQ_ID,
CCorePlugin.PLUGIN_ID + "." + "ELF"//CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID
);


CCorePlugin.getDefault().setProjectDescription(project, desc_bp);
}

return true;

}
catch (BuildException be)
{
//TODO
}
catch (CoreException ce)
{
//TODO
}
finally
{
//TODO
}
return true;
}



private boolean CreateMakeFileProject()
{
try
{
//
// Create a new CDT project
//
//String projectID=
// "org.eclipse.cdt.managedbuilder.core.configurationDataProvider";
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(page1.GetProjectName()+"_MakefilePrj");
IPath projectLocation = project.getRawLocation();

if (project.exists()) {
project.delete(true, true, null);
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProjectDescription description = workspace.newProjectDescription(project.getName());

if ((projectLocation != null) && (!projectLocation.equals(Platform.getLocation()))) {
description.setLocation(projectLocation);
}

//
// This code C project and make natures ...
//
project.create(null);
project.open(null);
CProjectNature.addCNature(project, null);
MakeProjectNature.addNature(project, null);
ScannerConfigNature.addScannerConfigNature(project);
ScannerConfigNature.initializeDiscoveryOptions(project);
//CCorePlugin.getDefault().mapCProjectOwner(project, projectID, true);

//
// This code creates a makefile, helloworld.c file, and some folders ...
//
CreateMyMakefile(project);
CreateHelloWorldFile(project);

IFolder src = "" "src");

//
// Configure project to use PE debugger for windows
// On linux this would be ELF
//
ICExtensionReference[] binaryParsers= CCorePlugin.getDefault().getBinaryParserExtensions(project);
if (binaryParsers == null || binaryParsers.length == 0) {
ICProjectDescription desc= CCorePlugin.getDefault().getProjectDescription(project);
if (desc == null) {
return false;
}
desc.getDefaultSettingConfiguration().create(
CCorePlugin.BINARY_PARSER_UNIQ_ID,
CCorePlugin.PLUGIN_ID + "." + "ELF"//CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID
);


CCorePlugin.getDefault().setProjectDescription(project, desc);
}

return true;

}
catch (CoreException ce)
{
//TODO
}
finally
{
//TODO
}
return true;
}



Back to the top