Home » Language IDEs » C / C++ IDE (CDT) » Programatically create a project?
|
Re: Programatically create a project? [message #227977 is a reply to message #227953] |
Sat, 13 December 2008 17:54 |
Andrew Gvozdev Messages: 257 Registered: July 2009 |
Senior Member |
|
|
Bryan Hunt wrote:
> Is there a section of code I could lift from a unit test that
> programatically creates a C / C++ project?
> I'm using the CDT launcher, and I need to write a unit test that uses
> the launcher. In order for the launcher to be happy, I must have a
> valid C / C++ project. I don't need to create an executable, just
> enough for the launcher to consider it a valid project.
I suppose the most accurate code would be C/C++ New Project Wizard code. I
also referred to org.eclipse.cdt.projectmodel.tests in
org.eclipse.cdt.managedbuilder.core.tests. Here is an excerpt of the code
I am using for my tests, this would create Standard Makefile project:
// Create and persist Standard Makefile project
{
// Create model project and accompanied project description
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IProject newProjectHandle = root.getProject(projectName);
Assert.assertNotNull(newProjectHandle);
Assert.assertFalse(newProjectHandle.exists());
IProjectDescription description =
workspace.newProjectDescription(newProjectHandle.getName());
IProject project =
CCorePlugin.getDefault().createCDTProject(description, newProjectHandle,
new NullProgressMonitor());
Assert.assertTrue(newProjectHandle.isOpen());
ICProjectDescriptionManager mngr =
CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription des = mngr.createProjectDescription(project,
false);
ManagedProject mProj = new ManagedProject(des);
Configuration cfg = new Configuration(mProj, null,
"your.configuration.id", "YourConfigurationName");
IBuilder bld = cfg.getEditableBuilder();
Assert.assertNotNull(bld);
Assert.assertFalse(bld.isInternalBuilder());
bld.setManagedBuildOn(false);
CConfigurationData data = cfg.getConfigurationData();
Assert.assertNotNull(data);
des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDE R_ID, data);
// Persist the project description
mngr.setProjectDescription(project, des);
project.close(null);
}
Thanks,
Andrew
> Bryan
|
|
|
Re: Programatically create a project? [message #228143 is a reply to message #227977] |
Thu, 18 December 2008 02:36 |
Bryan Hunt Messages: 366 Registered: July 2009 |
Senior Member |
|
|
Andrew,
Thanks for the info. I was able to use this code to get my unit test
working. :)
Bryan
On 2008-12-13 11:54:11 -0600, angvoz.dev@gmail.com (Andrew Gvozdev) said:
> Bryan Hunt wrote:
>
>> Is there a section of code I could lift from a unit test that
>> programatically creates a C / C++ project?
>
>> I'm using the CDT launcher, and I need to write a unit test that uses
>> the launcher. In order for the launcher to be happy, I must have a
>> valid C / C++ project. I don't need to create an executable, just
>> enough for the launcher to consider it a valid project.
>
> I suppose the most accurate code would be C/C++ New Project Wizard
> code. I also referred to org.eclipse.cdt.projectmodel.tests in
> org.eclipse.cdt.managedbuilder.core.tests. Here is an excerpt of the
> code I am using for my tests, this would create Standard Makefile
> project:
>
> // Create and persist Standard Makefile project
> {
> // Create model project and accompanied project description
> IWorkspace workspace = ResourcesPlugin.getWorkspace();
> IWorkspaceRoot root = workspace.getRoot();
>
> IProject newProjectHandle = root.getProject(projectName);
> Assert.assertNotNull(newProjectHandle);
> Assert.assertFalse(newProjectHandle.exists());
>
> IProjectDescription description =
> workspace.newProjectDescription(newProjectHandle.getName());
> IProject project =
> CCorePlugin.getDefault().createCDTProject(description,
> newProjectHandle, new NullProgressMonitor());
> Assert.assertTrue(newProjectHandle.isOpen());
>
> ICProjectDescriptionManager mngr =
> CoreModel.getDefault().getProjectDescriptionManager();
> ICProjectDescription des = mngr.createProjectDescription(project, false);
> ManagedProject mProj = new ManagedProject(des);
>
> Configuration cfg = new Configuration(mProj, null,
> "your.configuration.id", "YourConfigurationName");
>
> IBuilder bld = cfg.getEditableBuilder();
> Assert.assertNotNull(bld);
> Assert.assertFalse(bld.isInternalBuilder());
>
> bld.setManagedBuildOn(false);
>
> CConfigurationData data = cfg.getConfigurationData();
> Assert.assertNotNull(data);
> des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDE R_ID, data);
>
> // Persist the project description
> mngr.setProjectDescription(project, des);
>
> project.close(null);
> }
>
>
> Thanks,
> Andrew
>
>> Bryan
|
|
|
Re: Programatically create a project? [message #229922 is a reply to message #227977] |
Tue, 03 February 2009 14:02 |
Andrew Gvozdev Messages: 257 Registered: July 2009 |
Senior Member |
|
|
For the cross-reference, I posted also how to create managed project
programatically in this thread:
http://www.nabble.com/Programatically-create-CDT-project-td2 1096039.html
Andrew Gvozdev wrote:
> Bryan Hunt wrote:
>> Is there a section of code I could lift from a unit test that
>> programatically creates a C / C++ project?
>> I'm using the CDT launcher, and I need to write a unit test that uses
>> the launcher. In order for the launcher to be happy, I must have a
>> valid C / C++ project. I don't need to create an executable, just
>> enough for the launcher to consider it a valid project.
> I suppose the most accurate code would be C/C++ New Project Wizard code. I
> also referred to org.eclipse.cdt.projectmodel.tests in
> org.eclipse.cdt.managedbuilder.core.tests. Here is an excerpt of the code
> I am using for my tests, this would create Standard Makefile project:
> // Create and persist Standard Makefile project
> {
> // Create model project and accompanied project description
> IWorkspace workspace = ResourcesPlugin.getWorkspace();
> IWorkspaceRoot root = workspace.getRoot();
> IProject newProjectHandle = root.getProject(projectName);
> Assert.assertNotNull(newProjectHandle);
> Assert.assertFalse(newProjectHandle.exists());
> IProjectDescription description =
> workspace.newProjectDescription(newProjectHandle.getName());
> IProject project =
> CCorePlugin.getDefault().createCDTProject(description, newProjectHandle,
> new NullProgressMonitor());
> Assert.assertTrue(newProjectHandle.isOpen());
> ICProjectDescriptionManager mngr =
> CoreModel.getDefault().getProjectDescriptionManager();
> ICProjectDescription des = mngr.createProjectDescription(project,
> false);
> ManagedProject mProj = new ManagedProject(des);
> Configuration cfg = new Configuration(mProj, null,
> "your.configuration.id", "YourConfigurationName");
> IBuilder bld = cfg.getEditableBuilder();
> Assert.assertNotNull(bld);
> Assert.assertFalse(bld.isInternalBuilder());
> bld.setManagedBuildOn(false);
> CConfigurationData data = cfg.getConfigurationData();
> Assert.assertNotNull(data);
> des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDE R_ID, data);
> // Persist the project description
> mngr.setProjectDescription(project, des);
> project.close(null);
> }
> Thanks,
> Andrew
>> Bryan
|
|
|
Re: Programatically create a project? [message #231197 is a reply to message #227977] |
Thu, 05 March 2009 14:19 |
John Moule Messages: 13 Registered: July 2009 |
Junior Member |
|
|
Hi,
I've used the code you posted successfully (thanks a lot), but I also want
to use a specific toolchain when the project is created. The toolchain (a
slightly adapted GNU one) exists in my toolset plugin and I can
successfully create a project with this toolchain using the new project
wizard. But now I'd like the ability to do this programmatically. I'd like
to specify myToolChain like this:
...
Configuration cfg = new Configuration(mProj, myToolChain,
"com.xyz.microtoolset.toolchain.gnu.base", "XYZ Micro Toolset");
...
But I can't figure how to create the myToolChain object easily. I've
looked at the constructors in
org.eclipse.cdt.managedbuilder.internal.core.ToolChain but I don't
understand how to specify the various params they require using what I've
got.
Any tips would be gratefully received.
cheers john
Andrew Gvozdev wrote:
> Bryan Hunt wrote:
>> Is there a section of code I could lift from a unit test that
>> programatically creates a C / C++ project?
>> I'm using the CDT launcher, and I need to write a unit test that uses
>> the launcher. In order for the launcher to be happy, I must have a
>> valid C / C++ project. I don't need to create an executable, just
>> enough for the launcher to consider it a valid project.
> I suppose the most accurate code would be C/C++ New Project Wizard code. I
> also referred to org.eclipse.cdt.projectmodel.tests in
> org.eclipse.cdt.managedbuilder.core.tests. Here is an excerpt of the code
> I am using for my tests, this would create Standard Makefile project:
> // Create and persist Standard Makefile project
> {
> // Create model project and accompanied project description
> IWorkspace workspace = ResourcesPlugin.getWorkspace();
> IWorkspaceRoot root = workspace.getRoot();
> IProject newProjectHandle = root.getProject(projectName);
> Assert.assertNotNull(newProjectHandle);
> Assert.assertFalse(newProjectHandle.exists());
> IProjectDescription description =
> workspace.newProjectDescription(newProjectHandle.getName());
> IProject project =
> CCorePlugin.getDefault().createCDTProject(description, newProjectHandle,
> new NullProgressMonitor());
> Assert.assertTrue(newProjectHandle.isOpen());
> ICProjectDescriptionManager mngr =
> CoreModel.getDefault().getProjectDescriptionManager();
> ICProjectDescription des = mngr.createProjectDescription(project,
> false);
> ManagedProject mProj = new ManagedProject(des);
> Configuration cfg = new Configuration(mProj, null,
> "your.configuration.id", "YourConfigurationName");
> IBuilder bld = cfg.getEditableBuilder();
> Assert.assertNotNull(bld);
> Assert.assertFalse(bld.isInternalBuilder());
> bld.setManagedBuildOn(false);
> CConfigurationData data = cfg.getConfigurationData();
> Assert.assertNotNull(data);
> des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDE R_ID, data);
> // Persist the project description
> mngr.setProjectDescription(project, des);
> project.close(null);
> }
> Thanks,
> Andrew
>> Bryan
|
|
|
Re: Programatically create a project? [message #231220 is a reply to message #231197] |
Fri, 06 March 2009 11:55 |
John Moule Messages: 13 Registered: July 2009 |
Junior Member |
|
|
Hi,
... I've sussed it. I struck gold in
org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; its full of
useful statics. So to get my toolchain that I'm interested in I use the
following (note error checks not included!):
IToolChain[] tcs = ManagedBuildManager.getRealToolChains();
ToolChain tc=null;
for (int i=0; i<tcs.length; i++) {
if(tcs[i].getName().contains("XYZ Micro Toolset")) {
tc = (ToolChain) tcs[i];
break;
}
}
Configuration cfg = new Configuration(mProj, tc,
"com.xyz.microtoolset.toolchain.gnu.base", "XYZ Micro Toolset");
cheers john
John Moule wrote:
> Hi,
> I've used the code you posted successfully (thanks a lot), but I also want
> to use a specific toolchain when the project is created. The toolchain (a
> slightly adapted GNU one) exists in my toolset plugin and I can
> successfully create a project with this toolchain using the new project
> wizard. But now I'd like the ability to do this programmatically. I'd like
> to specify myToolChain like this:
> ...
> Configuration cfg = new Configuration(mProj, myToolChain,
> "com.xyz.microtoolset.toolchain.gnu.base", "XYZ Micro Toolset");
> ...
> But I can't figure how to create the myToolChain object easily. I've
> looked at the constructors in
> org.eclipse.cdt.managedbuilder.internal.core.ToolChain but I don't
> understand how to specify the various params they require using what I've
> got.
> Any tips would be gratefully received.
> cheers john
> Andrew Gvozdev wrote:
>> Bryan Hunt wrote:
>>> Is there a section of code I could lift from a unit test that
>>> programatically creates a C / C++ project?
>>> I'm using the CDT launcher, and I need to write a unit test that uses
>>> the launcher. In order for the launcher to be happy, I must have a
>>> valid C / C++ project. I don't need to create an executable, just
>>> enough for the launcher to consider it a valid project.
>> I suppose the most accurate code would be C/C++ New Project Wizard code. I
>> also referred to org.eclipse.cdt.projectmodel.tests in
>> org.eclipse.cdt.managedbuilder.core.tests. Here is an excerpt of the code
>> I am using for my tests, this would create Standard Makefile project:
>> // Create and persist Standard Makefile project
>> {
>> // Create model project and accompanied project description
>> IWorkspace workspace = ResourcesPlugin.getWorkspace();
>> IWorkspaceRoot root = workspace.getRoot();
>> IProject newProjectHandle = root.getProject(projectName);
>> Assert.assertNotNull(newProjectHandle);
>> Assert.assertFalse(newProjectHandle.exists());
>> IProjectDescription description =
>> workspace.newProjectDescription(newProjectHandle.getName());
>> IProject project =
>> CCorePlugin.getDefault().createCDTProject(description, newProjectHandle,
>> new NullProgressMonitor());
>> Assert.assertTrue(newProjectHandle.isOpen());
>> ICProjectDescriptionManager mngr =
>> CoreModel.getDefault().getProjectDescriptionManager();
>> ICProjectDescription des = mngr.createProjectDescription(project,
>> false);
>> ManagedProject mProj = new ManagedProject(des);
>> Configuration cfg = new Configuration(mProj, null,
>> "your.configuration.id", "YourConfigurationName");
>> IBuilder bld = cfg.getEditableBuilder();
>> Assert.assertNotNull(bld);
>> Assert.assertFalse(bld.isInternalBuilder());
>> bld.setManagedBuildOn(false);
>> CConfigurationData data = cfg.getConfigurationData();
>> Assert.assertNotNull(data);
>> des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDE R_ID, data);
>> // Persist the project description
>> mngr.setProjectDescription(project, des);
>> project.close(null);
>> }
>> Thanks,
>> Andrew
>>> Bryan
|
|
| | | | | | | | | | | | | |
Goto Forum:
Current Time: Tue Apr 23 09:30:06 GMT 2024
Powered by FUDForum. Page generated in 0.09391 seconds
|