Saturday 6 November 2010

Refactoring with P4Eclipse in Eclipse

As of version 2009.1, the P4Eclipse plugin uses the Perforce move command during refactoring operations. To support refactoring in Eclipse, the 2009.1 version of P4Eclipse performs a series of edits (check-outs), moves, and adds, as needed, to make the repository reflect the changes to your project. Eclipse supports several types of refactoring.

Please note that this behavior requires the Perforce server to be at 2009.1 or higher. The "Use 'move' command during refactoring operations" setting must also be enabled in your preferences. It is the default setting.

This article discusses:

"Rename" renames the selected element and, if requested, corrects all references to the elements.

Rename performs the following steps:

Checks the file out, and checks out any other affected files.Performs a move operation from the original name to the new one.User submits all files manually in the same changelist.

The P4 Log Console shows the P4 commands executed:

Executing p4 edit /Users/bruno/perforce/workspaces/20091_ws/Affected.java /Users/bruno/perforce/workspaces/20091_ws/Original.java Executing p4 move -cdefault //depot/test01/src/Original.java /Users/bruno/perforce/workspaces/20091_ws/NewOriginal.java Executing p4 submit -i

The P4 Pending Changelists View shows the state of your workspace:

"Move" moves the selected elements and, if requested, corrects all references to the elements.

Move performs the following steps:

Checks the file out, and checks out any other affected files.Performs a move operation from the original location to the new one.User submits all files manually in the same changelist.

The P4 Log Console shows the P4 commands executed:

Executing p4 edit /Users/bruno/perforce/workspaces/20091_ws/Affected.java /Users/bruno/perforce/workspaces/20091_ws/Original.java Executing p4 move -cdefault //depot/test01/src/Original.java /Users/bruno/perforce/workspaces/20091_ws/target/Original.java Executing p4 submit -i

"Extract Interface" creates a new interface with a set of methods, and makes the selected class implement the interface.

Extract Interface performs the following steps:

Checks out the file, and any other affected files.Opens the new interface file for adding to the depot.All files are submitted in the same changelist.

The P4 Log Console shows the P4 commands executed:

Executing p4 edit /Users/bruno/perforce/workspaces/20091_ws/Affected.java /Users/bruno/perforce/workspaces/20091_ws/Original.java Executing p4 add -f /Users/bruno/perforce/workspaces/20091_ws/IOriginal.java Executing p4 submit -i

If you need to revert your changes from a previous rename or move, you can use Eclipse's functionality to reverse the changes. The plug-in will use the move command to do the revert.

This operation is much simpler than it was in 2008.2.

The P4 Log Console shows the P4 commands executed:

Executing p4 edit /Users/bruno/perforce/workspaces/20091_ws/Affected.java /Users/bruno/perforce/workspaces/20091_ws/NewOriginal.java Executing p4 move -cdefault //depot/test01/NewOriginal.java /Users/bruno/perforce/workspaces/20091_ws/Original.java Executing p4 submit -i

View the original article here

No comments:

Post a Comment