Conveniently move a class to a different package in eclipse without borking svn
Asked Answered
V

6

21

When moving a file from old.package to new.package I want two things to happen:

  1. Update all references to that class (in all files of the project) so that the new package is used
  2. svn move old/package/Foo.java new/package/Foo.java

I use subversive within Eclipse Ganymede. When I just drag the file from one package to the other, all references get updated and the file is moved around on the filesystem. But SVN is unaware of this and therefore the svn move old/package/foo.java new/package/Foo.java command does not work (obviously) when old/package/Foo.java does not exist (because eclipse has moved it already).

Is there a way to have eclipse do it's refactoring but using svn to move the file on the filesystem? I hope I'm just missing something obvious :-)

Vesuvius answered 7/1, 2009 at 11:45 Comment(1)
The clearcase plugin for Eclipse (CCRC) does attempt to do this, it moves the files in ClearCase as well as changes the references. It does get it wrong sometimes but it usually works.Large
O
16

I use Subclipse and it does support moving files between packages

Octahedron answered 7/1, 2009 at 12:13 Comment(6)
actually 'support moving' is a misnomer. It recognizes that some files are absent, and some files are new, but it doesn't know anything about moving files per se...Iridectomy
Are you sure? Then how does subclipse know if I'm moving a file (during refactoring) or if I'm just deleting one and creating another file?Womankind
I'm pretty sure it doesn't know. Look at the commit report when you commit a refactored (moved) class; it has one line for delete, another file for create. Eclipse knows the relationships, Subclipse is just a SVN-plugin for Eclipse, which knows nothing about Java, or anything else, than SVN.Iridectomy
I think you're right when it comes to Subversion - moves in svn are just copies and deletes. But Subclipse is another story - it knows about the moves due to its Eclipse integration - and it "supports moves" by applying the appropriate svn action.Womankind
Exactly what Ole said, I don't really care HOW subclipse implements this in terms of SVN commands, but I know it DOES recognize the action and apply the correct SVN commands to support it.Octahedron
+1 I typically don't like IDE integration, but when you are doing a lot of refactoring with source that's under version control, this is a must!Cephalothorax
U
3

I've been experimenting, and think I've found the way:

1) Tortoise-move the file using the right-click-drag context menu (or whatever SVN method you want).

2) Use the windows filesystem to move it back.

3) Drag-move the file in Eclipse to update all the references.

4) Commit - it shows as a delete/add, but it saves the history, and it does change the package references in one commit (keeping each commit buildable).

Old question, but I keep returning to it, so this is my documentation!

Ugrian answered 13/7, 2010 at 20:40 Comment(1)
Well, OK, your title does say "conveniently" - but I find this more convenient than going through every single error in Eclipse.Ugrian
A
1

Yuval's right. This sounds like a (very unfortunate!) deficiency in Subversive. (having no experience with Subversive I can't say for sure) Subclipse definitely handles this properly by hooking into the right APIs in Eclipse.

Aeromarine answered 7/1, 2009 at 17:46 Comment(0)
G
0

You can not do both at the same time because moving the files alone is not enough. The files need to be modified in order for your code to be compilable again. So refactor with Eclipse and let Subclipse do its magic (remove old files, add new files) after the move.

Garmaise answered 7/1, 2009 at 12:17 Comment(0)
C
0

This is old but still a problem. I use refactor to move the class associated with the servlet to the new package. Then open web.xml, find the servlet and prepend the new package name to the servlet-class tag. I moved GetArticle servlet from default package to the api package:

 <servlet>
    <description></description>
    <display-name>GetArticles</display-name>
    <servlet-name>GetArticles</servlet-name>
    <servlet-class>api.GetArticles</servlet-class>
 </servlet>
Christean answered 8/4 at 9:25 Comment(0)
R
-1

If you let Eclipse do the refactoring then surely it will make changes in the actual files which SVN should pick up when you commit the root directory? I don't think a move will cut it though, SVN will have to pick up that the file is missing from its original directory but re-add it from the new directory. It's a sticky situation, I wouldn't know what the best method is, I'd just do the refactoring and then commit the root personally, even though it wouldn't be a move.

Rockoon answered 7/1, 2009 at 11:50 Comment(1)
Yes, apart from SVN, all is good when refactoring using Eclipse. When I move with SVN, all is good except for references to that file in the sourcecode. What I can do is move to the new package using eclipse, then manually move back and refactor with eclipse. That is not really a quick way to do it.Vesuvius

© 2022 - 2024 — McMap. All rights reserved.