Having worked with a number of languages and tools over the years, I've learned one thing: work with the tools you have, learn them, master them, then make life easier by sharing the knowledge. Whether Java, C++, VB, or COBOL, I've always applied the same philosophy with success. I love studying manuals and being a keyboard addict, the list of keyboard shortcuts is often my favorite page. Byron is a DZone MVB and is not an employee of DZone and has posted 18 posts at DZone. View Full User Profile

Checkout Multiple Projects Automatically Into Your Eclipse Workspace With Team Project Sets

02.13.2010
| 14363 views |
  • submit to reddit

When working in Eclipse, you’ll often end up with a number of projects in your workspace that constitute an application. You could have a multi-tiered system with a web, server and database project and other miscellaneous ones. Or if you’re an Eclipse RCP developer, you could end up with dozens of plugins each represented by a project.

Although multiple projects give you modularity (which is good), they can make it difficult to manage the workspace (which is bad). Developers have to check out each project individually from different locations in the repository. Sometimes they even have to get projects from multiple repositories. This is a painstakingly long and error-prone task.

But an easier way to manage multiple projects is with Eclipse’s Team Project Sets (TPS). Creating a workspace becomes as easy as importing an XML file and waiting for Eclipse to do its job. Yes, there are other more sophisticated tools out there that do this and more (eg. Maven and Buckminster) but team project sets are a good enough start if you haven’t got anything set up and may be good enough for the longer term as well, depending on how your team works.

Create a Team Project Set to share with other developers

It’s easy to create a team project set (TPS).  The first thing is to start with a workspace that already has all the projects checked out. Then it’s as easy as choosing File > Export > Team > Team Project Set, selecting the projects you want to export and then entering a file name. Done.

But it’s always better to see it in action. In the video, I export 3 projects that I’ve already checked out from Subversion into a TPS file.

Notes:

  • You can select which projects should go into the TPS. This way you can exclude irrelevant or personal projects you’ve got in your workspace.
  • Eclipse adds the extension .psf if you don’t provide one.

The exported file is an XML file, with the default extension of psf, so in the video the file would be music.psf. There is a project entry for each project you exported that includes the project’s name and its repository location, separated by commas. Once created, the file is easy to edit so go ahead and make your own changes if you want to. Here is an example of what it looks like:

<?xml version="1.0" encoding="UTF-8"?>
<psf version="2.0">
<provider id="org.tigris.subversion.subclipse.core.svnnature">
svn/repo/music-application/trunk,music-application"/>
svn/repo/music-db/trunk,music-db"/>
svn/repo/music-web/trunk,music-web"/>
</provider>
</psf>

Import the Team Project Set to checkout multiple projects into your workspace

Now for the fun part. To import a team project set (TPS), start with any workspace (normally an empty one) and choose File > Import > Team > Team Project Set. Choose the TPS file that someone else kindly exported for you and then wait for Eclipse to do its magic.

Notes:

  • If you have an existing project in your workspace whose name matches a project in the TPS, Eclipse will prompt you whether you want to overwrite the project. I always choose No To All, since overwriting the project will mean you lose any changes you made to it. But if you have the urge to start from scratch then you can choose Yes.
  • The import also creates a link to the repository in SVN Repositories, so you don’t have to do that. If one already exists, it will not duplicate it but reuse the existing connection.
  • The process may take a while depending on the number of projects in the TPS and the speed of your repo checkouts. You can choose to run the import in the background (as I did in the video), giving you the opportunity to use Eclipse while the import happens. Otherwise, grab some coffee and wait for it to finish the checkouts.

Gotcha: You may find that Eclipse 3.4 and lower may actually create a repository connection per project if the repository didn’t exist beforehand, which is not ideal. To solve this, create an initial repository root that’s shared by the projects and then do the import of the TPS. This problem has been fixed in 3.5

Managing the team project set and working with branches

I’d recommend checking in the team project set into your repository and versioning/tagging it along with the rest of your code base. With each release you may be adding/removing projects and consequently updating the TPS, so it’s important that the TPS matches what the repo looks like at that point.

As projects are added/removed with each release, you have 3 possibilities:

  • Recreate the TPS from an existing workspace: Same as the steps above, but it means that whoever does the export needs to maintain an up to date workspace to reflect the current project structure.
  • Modify an existing TPS with the new/deleted project: This entails adding/removing an entry from the PSF file. Not a lot of maintenance, but someone needs to remember to do this.
  • Automatically create/update the TPS: You could write a script that somehow updates the TPS to reflect the new repo structure. For example, if you’re developing an Eclipse RCP application, the PDE Build provides a map file that could be used as input to create the PSF file.

If you want to checkout a branch other than trunk, just open the PSF file and do a Find/Replace of trunk with your branch name. You could also introduce an automated process as part of your build/release scripts to update the TPS with the correct branch and check it back in automatically, but that’s really optional.

From http://eclipseone.wordpress.com

Published at DZone with permission of Byron M, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Rajesh Dave replied on Thu, 2010/02/18 - 4:47am

Great... This is very simple and helpful... Thanks for sharing it.

Subhashish Dutta replied on Tue, 2010/05/11 - 3:44am

Thanks a lot for the article. That really helped. Do you know of a way to run some task post the import? e.g. I have a workspace setup tool that creates ANT builders for each project and also modifies the project classpaths. Assuming that the tool is available at a specific location, I'd like to invoke execution of the tool after the .psf import is complete.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.