Renaming Projects with the Perforce Plug-in for Eclipse
If you you’re a Perforce customer and an Eclipse user, you should use the Perforce plugin for Eclipse. It makes the job managing check-ins and check-outs easy, allowing you to stay nearly fulltime in your environment. Unfortunately, renaming an Eclipse plugin project isn’t supported very nicely.
The Perforce plugin does support rename and move-refactoring of Java packages and files. In addition, the right-click option to rename a plugin project is enabled if you try it. Naturally, you expect to rename your project just as easily, hoping the Perforce plugin takes care of the version control mess underneath. No can do.
Let's say, to be politicallty correct, you’ve been asked by your manager to rename your "com.funcompany.fu.core" project to "com.profitablecompany.foo.core." How can you do this safely, given that there may be half a dozen other projects that rely on fu.core? After dozens of painful experiences I've arrived at a sequence you should be able to safely repeat. Following the procedure below, you can rename-refactor to your heart's content.
Well maybe not quite.
Really, this behavior should be part of the Perforce plugin for Eclipse. Until then…
Renaming Steps
- Determine:
- Target plugin directory
- Plugin project name
- Optional: new package name
- Unit tests you’ll run to verify no problems after renaming
- Move the plugin project files to their new directory using p4 integrate. I usually choose “filespec” and leave the default options enabled which will move the HEAD revision. Finish this by doing p4 submit.
- Remove the old project from your Eclipse workspace and re-import it. This is can be done from the Import -> External Plugins and Fragments, in which case you must then re-share the project using the righ-click menu’s Team -> Share Project. Or, in the Perforce perspective, in the P4 Depots viewer, right-click the directory that contains the .project file and select “Import as Project…” If using the Java Perspective, you’ll see your project in the Package Explorer with it’s new name. Note: Using the P4 Depots viewer, you must first refresh to see the newly p4 integrated (renamed) plugin.
- In the Package Explorer (in Plugin or Java Perspective), delete the old plugin project and leave the default selection “Do not delete contents,” when shown the confirmation dialog.
- Fix the project ID for renamed, imported plugin. Each project has an ID that, our case, won’t be the same name as the name created when re-importing the project into your workspace. Do this by opening the MANIFEST.MF and entering the correct name in the ID: field on the Overview tab. Save.
- Refactor -> Rename the package name. An Eclipse convention is to name Java packages with the same as the plugin project. The nice thing about doing this is that the Perforce plugin handles nicely. You’ll see same number of a files “Open for Delete” and “Open for Add” in your Default changelist. Submit it.
- Do a clean build of your workspace to make sure there are no lingering problems. If you have unit tests (hopefully you do), run them.
- p4 delete the old project.
- You’re done! Happy coding.
Other Helpful Perforce Links
Perforce with Ant:
http://ant.apache.org/manual/OptionalTasks/perforce.html#intro
Perforce Command Line Reference:
http://www.perforce.com/perforce/doc.042/manuals/cmdref/index.html
Perforce Best Practices (some good stuff in here for any SCM)
http://www.perforce.com/perforce/bestpractices.html
I can't believe p4 still doesn't have cool support for Java IDEs nor that it is still not Java projects friendly.
I used to work with perforce in C based projects, that was fine but when we started to versioning Java with it... Thank God my current project uses Subversion.
Posted by: Phillip Calçado | January 01, 2006 at 08:18 PM