views:

856

answers:

3

I had to move my eclipse workspace from Linux to windows when my desktop crashed. A week later I copy it back to Linux, code happily, commit to cvs. And alas, windows newlines have polluted many files, so cvs diff dumps the entrire file, even when I changed a line or two!

I could cook up a script, but I am wondering if it will mess up my eclipse project files. Comments please.

+1  A: 

You could give it a try. The problem is that Windows inserts a carriage return as well as a line feed when given a new line. Unix-systems just insert a line feed. So the extra carriage return character could be the reason why your eclipse messes up with the newlines.

Grab one or two files from your project and convert them. You could use Notepad++ to do so. Just open the file, go to Format->Convert to Unix (when you are using windows).

In Linux just try this on a command line:

sed 's/$'"/`echo \\\r`/" yourfile.java > output.java
Ham
I have around 10k files! So had to automate it somehow. Thanks for the advice!
Vasu
+2  A: 

There is a handy bash utility - dos2unix - which is a DOS/MAC to UNIX text file format converter, that if not already installed on your distro, should be able to be easily installed via a package manager. dos2unix man page

BenHayden
I was planning to write a script to recursively do this over my eclipse workspace. Only worry was corrupting any eclipse internal project files. Thanks for your suggestion!
Vasu
+4  A: 

As mentioned here and here:

Set file encoding to UTF-8 and line-endings for new files to Unix, so that text files are saved in a format that is not specific to the Windows OS and most easily shared across heterogeneous developer desktops:

  • Navigate to the Workspace preferences (General:Workspace)
  • Change the Text File Encoding to UTF-8
  • Change the New Text File Line Delimiter to Other and choose Unix from the pick-list

alt text

  • Note: to convert the line endings of an existing file, open the file in Eclipse and choose File : Convert Line Delimiters to : Unix

Tip: You can easily convert existing file by selecting then in the Package Explorer, and then going to the menu entry File : Convert Line Delimiters to : Unix

VonC
Thats exactly what I was looking for! I had already changed it for new files, but the option to convert - missed my eyes. Thanks VonC!
Vasu
@Vasu: you're welcome :). The Outline view and Package Explorer contain some features for multi-selected elements which are often overlooked.
VonC