17

I would like to have a shell script create an entire CDT project on the command line and add it to a workspace. I'm willing to generate the .project and .cproject files myself, but I'd like something that would actually do the adding of the project to the workspace, because that is an opaque binary file that I'd rather not have to mess with.

I looked at both Buckminster and the Monkey Project, but I wasn't sure if either would do what I wanted. Anyone have any experience on this front and know what a good solution is?

Thanks,

Nathan

Nathan
  • 1,218
  • 3
  • 19
  • 35

4 Answers4

10

What version of CDT are you using?

If you have the recent CDT 6+ installed, you can perform a project import (as well as build), from the command line. To do this:

eclipse -nosplash 
    -application org.eclipse.cdt.managedbuilder.core.headlessbuild 
    -import {[uri:/]/path/to/project} 
    -build {project_name | all} 
    -cleanBuild {projec_name | all}

The import switch can be used by itself. You'll need to specify the workspace you wish to import into with -data as normal to Eclipse. The switches illustrated above are provided by the CDT managedbuild plugin, but should work with non-CDT projects (if not, let me know -- I wrote the feature ;) ).

See this question on headless build for more details on the other switches.

Community
  • 1
  • 1
James Blackburn
  • 4,492
  • 2
  • 27
  • 24
  • 4
    I looked briefly at this, but I didn't realize that 'import' meant 'import from source directory'. This seems like it might be at least on the right track. A couple questions: Is there a way to specify a project name? What is the default? Also, this doesn't appear to work when eclipse is running. Am I doing something wrong? Thanks! – Nathan Jan 11 '10 at 21:08
  • 1
    Is there any way to add a project with a relative pathname (i.e. within the workspace directory -- what the New Project wizards call the default location)? – James Jun 03 '11 at 00:36
  • I'm getting an error stating that `org.eclipse.cdt.managedbuilder.core.headlessbuild` doesn't exist. Any solution to that? – Jason John Aug 05 '14 at 13:51
  • 1
    I'm currently using this technique. I only do the -import '/my/path/to/project' and don't use the -build or -cleanBuild parameters (as I don't want the project to be built). However, I notice that if I import a project with many files in it (hundreds), there is a long stall (a few minutes) before the project gets imported. If I try import a smaller project (containing a dozen files), the delay is shorter. A few seconds. Just wondering, what is happening here? (My guess was it was busy indexing?) And is there a way to avoid it? – Gurce Aug 12 '15 at 07:49
  • Can I somehow get this working with an already running instance of eclipse - I always get the error "Workspace already in use!" – Martin Gerhardy Mar 01 '16 at 12:49
  • Then error is clear enough; the same will happen if you launch the IDE twice. Use a different workspace, specifying it with the `-data` argument – Mawg says reinstate Monica Oct 12 '16 at 08:34
3

I believe all you need is to do is create a folder here:

WORKSPACE_DIR\.metadata\.plugins\org.eclipse.core.resources\.projects\YOUR_PROJECT_NAME

and a .location file in it.

You can either use the Eclipse Resources API, or try to implement it yourself based on the current implementation

I don't know if there's an easiest way

  • So basically what you're saying is that I need to roll it myself rather than making eclipse do it for me? Also, in that directory I notice a lot more project folders than I have actual projects, which suggests to me that there's also a separate registry of projects somewhere that I'd have to add my own project to. – Nathan Nov 19 '09 at 18:51
  • 1
    Well, what I'm saying is that you should use the Eclipse API to add your project to the workspace but, you can look at the implementation if you want to perform the same actions in a quick & dirty way (with a shell script let's say). I don't think the other files are important, it's just files created after the project is added when Eclipse analyse the content (index, markers...) – Alexandre Pauzies Nov 19 '09 at 21:52
2

This page contains also some convenience script: http://lugendal.wordpress.com/2009/07/22/eclipse-ctd-new-project-fast/

ff.
  • 21
  • 1
0

There is a ant+groovy script in a different post, see https://stackoverflow.com/a/16949573/2457383

Disclaimer: The other post is also mine :)

Community
  • 1
  • 1
Robert
  • 31
  • 4