COMP 310
|
Safely Moving and Renaming Packages and
Folders in Eclipse
|
 |
WARNING!
Eclipse and Subclipse do not interact properly when
moving or renaming packages and folders. Simply moving or
renaming the folders as one might naturally do in Eclipse via almost any means
is VERY likely to result in conflicts between Eclipse and Subversion that
prevent the committing of code to the repository.
DO NOT EVER
- Manipulate a folder outside of the Eclipse environment, e.g. from a file
explorer.
- Drag-and-drop a package or folder to a new location in Eclipse
- Rename a folder in Eclipse
- Refactor an entire folder
A Safe(r) Procedure
The following procedure appears to be reasonably safe but
if you encounter any problems contact the course staff immediately!
Moving a package/folder:
Do not modify any
files or do anything else with your system until the entire process is
completed!
Contact the course staff IMMEDIATELY if you encounter
any problems and DO NOT PROCEED.
- Commit your entire codebase. Make sure that ALL teammates
have also fully committed their code! Be sure that
everything has the little yellow cylinders and nothing has black asterisks
on it.
- Do not have any teammates work on the affected package(s) unitl
the process is complete.
- There are two possible techniques (See the special case below if you are just
changing the capitalizations of a folder and not changing its spelling
or location):
- Rename the package (works even when there are sub-packages)
- If you are moving the package into another "parent" package,
i.e. as a new sub-package, be sure that if the parent package
already exists, there are no sub-packages already with the same
name.
- If the parent package does not exist, do NOT make it.
- Right-click the package you want to move, and select "
Refactor/Rename..."
-- NOT "Move
"!
- Modify the name of the package to reflect its desired new
position in the package hierarchy, e.g.
- Prepend any new parent package name(s) if you are
moving the package to downwards in the package hierarchy.
- or remove parent package name(s) if the package is moving
upwards in the package hierarchy.
- Be sure to select the "
Update references
" and "Rename
subpackages
" options
- Click "
Ok
".
- Or, Move all the files in the package (works only if there are no
sub-packages)
- Create a new empty package where you want the files to end up.
- REFACTOR all the FILES in the old package to move them to
the new package by selecting the desired files, right-clicking and
selecting "
Refactor/Move..."
-
- Do NOT just drap-and-drop the files!
- Your original package should be empty when you are done.
- Be sure to select the "
Update references...
" option
- Click "
Ok
".
- Commit your entire codebase.
- Open up the SVN Exploring Perspective
- In the repository, if the original package still exists, delete the
empty original package. Do NOT delete it if it
still has contents because this means that the moving process did not
complete successfully! Ask for help!
- Do a
Team/Update to Head
to make sure you have the latest
version. This should also cause the old package to disappear if it
hasn't already.
- Clean your project: The
process of moving packages can cause Eclipse to become out of sync with its
code files resulting is strange errors where Eclipse complains about not
recognizing certain classes in perfectly valid code.
- In the main menu of Eclipse go to "Project/Clean..."
- In the dialog that pops up, be sure that the desired project is
checked.
- Click OK to make
Eclipse delete all the compiled files in the project's bin directory.
- If the project is set to auto-compile ("Build
Automatically", the default), Eclipse will immediately and
automatically recompile everything, resyncing with the code files and
any spurious errors should disappear. If the project
is not set for auto-compile, manually click "Project/Build
All".
- Commit your entire codebase.
- Tell ALL team members update their projects:
- In the Java Perspective, right-click the entire
project and select
Team/Update to Head.
Special Case for Just Changing the
Capitalization of a Package/Folder
Technically this is a problem only on Windows machines,
where the operating system ignores the case in folder names. To be
safe however, this practice is highly recommended for ALL systems.
When simply changing the capitalization of a package or
folder (i.e. not moving it as well), the operating system does not necessarily
create a new, separate folder to do so. Subversion however, assumes
that a new folder has been created. Attempting
to commit a simply re-capitalized folder could result in data loss.
Note that this issue does not apply to moving folders to a new location where
the name is the same except for capitalization.
To solve this problem, one has to move the contents of
the original package/folder twice, once into a temporary package/folder and then
once into the final, properly capitalized package/folder.
Making In-place Capitalization Changes to the
Name of a Package/Folder
- Perform the above procedure to move all the contents of the original
package to a temporary package (or any distinctly different name, e.g.
originalPackage_temp).
- Now that the original package has been removed, create the desired
final package with the corrected capitalization.
- Perform the above procedure to move all the contents of the temporary
folder to the new final destination folder.
© 2017 by Stephen Wong